Your param "fact" is being computed correctly. In fact you could define it as
param fact {k in 0..nu} = if k = 0 then 1 else k*fact[k-1];
You can't prevent AMPL from computing fact[k] by multiplying it by zero. Probably what you want is to use an "if" expression to avoid computing fact[k] for values of k outside the defined range, such as
if k in A then fact[k] else 0
Bob Fourer
am...@googlegroups.com
=======
From:
am...@googlegroups.com [mailto:
am...@googlegroups.com] On Behalf Of Chiara Fratto
Sent: Monday, February 23, 2015 10:17 AM
To:
am...@googlegroups.com
Subject: [AMPL 10064] indicator function
I am having some issues when I try to write an equation in AMPL.
I want to write the following function:
{indicator function for k in A} * factorial [k]
where I defined factorial as follows:
param fact {0..nu}; # factorials-nu is the highest number needed
let fact[0] := 1;
let {k in 1..nu} fact[k] := k*fact[k-1];
and the indicator function is defined as a parameter.
The factorial is not defined for k outside of the region A.
However, when I try to solve for the model, AMPL still tries to evaluate
factorial [k] when k in not in A, even if the factorial is multiplied by zero.
Is there a way to get around this?