RE: [AMPL 10064] indicator function

32 views
Skip to first unread message

Robert Fourer

unread,
Feb 24, 2015, 1:47:04 PM2/24/15
to am...@googlegroups.com
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?


Reply all
Reply to author
Forward
0 new messages