Re: for loop

58 views
Skip to first unread message

Guido Diepen

unread,
Jan 10, 2013, 4:30:42 AM1/10/13
to ai...@googlegroups.com
Hi Ylona,

You can use domain conditions in AIMMS to loop over elements of a set that fulfill a certain requirement. You can add a domain condition with the |-operator (i.e. the such-that operator). You can find an example of this on the AIMMS blog (http://blog.aimms.com/2011/11/generate-indexed-constraint-except-for-certain-elements/) or in the AIMMS documentation.

In your case, if IsOpen is a parameter, you could create the sum as follows:

sum( (p,c) | IsOpen(p) , ......)

I suspect however that IsOpen is a decision variable in your problem (i.e. the model will have to decide which centers to open). If this is indeed the case (and you want/need to stay linear), you can't use if statements in the definition of the constraint. You will have to work with additional constraints that limit the amount that can be transported out of a center, for example with a constraint:
OnlyTransportOutWhenOpen(p)
sum( c , Transport(p,c) ) <=  MaxAvailableInPlant(p) * IsOpen(p)

If the plant p is closed, this constraint will ensure the value of transport must be 0. 

Guido Diepen
AIMMS Specialist

On Friday, January 4, 2013 12:51:44 PM UTC+1, Ylona Meeuwenberg wrote:
Hello,

I want to make a for-loop but don't know how. I want this for loop in a constraint. If this even possible? The for loop i want to make is;

For each p
   If ( IsOpen(p) = 1)
       Sum[ c, Unittransportcost(p,c) * Transport(p,c)] <= 26400 * Sum[c, Transport(p,c)]
  endif
enfor

this is a variant on the beginners tutorial on aimmes.
Alle the customers are plants but it is really expensive to open a plant. So aimms looks for the optimal opening of the plants so all customers get there demand. Now I want that the distance between 1 plant and all his customers is smaller dan 26400.  
Reply all
Reply to author
Forward
0 new messages