Hi Sean

We are almost there: If you define a variable or parameter you have to use the set m and not the set ms. So “table y(l,m)” (same with the definition of an equation although you can declare the definition afterward with the subset).

To get the last element, you could use this trick:

set m /1*5/;

set ms(m) /2,3/;

parameter numberlast;

loop(ms, loop(m$sameas(m,ms), numberlast = ord(m)););

display numberlast;

Just put the loop above within the while part.

You then define the equation over m and add the $-constraint as follows:

cons(m)$(ord(m) eq numberlast)…

Hope this helps!

Cheers

Renger

\

Modelworks

Gewerbestrasse 15

3600 Thun â€“ Switzerland

+41 79 818 53 73

Info@modelworks.ch

blog.modelworks.ch

From: gamsworld@googlegroups.com [gamsworld@googlegroups.com] on behalf of Sean [shahrooz.shahparvari@gmail.com]

Sent: Tuesday, February 16, 2016 00:20

To: gamsworld

Subject: Re: How to change(update) defined set over While(or loop)?

Hi Renger,

Thank you very much for your response and time. However, the trick does not work for me as I faced with " Assigned set used as domain" and " " ord illegal with non-constant set or use if a * universe" errors on the other variables and parameters which include set(ms). On the same example:

Set m /City1*City5/

ms(m) Subset of m;

- Initalize all to be unsatisfied

ms(m) = yes;

///////////////////////////////////////////////////////////

Tables y(L,ms)

city1 … city5

L1 2 5

L2 4 4

Variables:

X(ms,L)

///////////////////////////////////////////////////////////

equation cons(m);

Obj… â€œMaximize demand satisfaction for each cityâ€ ;

- write down the equations for ms: (or use cons(m)ms(m)..
cons(ms)(ord(ms) eq Card(ms))… / All I need is to create this constraint over the while ( ord (ms) = last member of unsatisfied set) /

Model problem MIP;

While( â€œSum (m, demand) >0â€ ,

Solve Problem

unsatisfied(ms) = “Calculate unsatisfied demand”

ms(m)(unsatisfied(m) = 0) = no;
ms(m)(unsatisfied(m) >0) = yes;

display Unsatisfied demand;

);

Any Idea on how to resolve it would be greatly appreciated.

Cheers,

Anthoy,

On Tuesday, 16 February 2016 03:19:33 UTC+11, Renger van Nieuwkoop wrote:

Hi Anthoy

The trick is here to use a dynamic set. Here an example that might work in your case (perhaps you have to finetune it):

Set m /City1*City5/

ms(m) Subset of m;

- Initalize all to be unsatisfied

ms(m) = yes;

equation cons(m);

Obj… â€œMaximize demand satisfaction for each cityâ€ ;

- write down the equations for ms: (or use cons(m)$ms(m)…

cons(ms)…

Model problem MIP;

While( â€œSum (m, demand) >0â€ ,

Solve Problem

unsatisfied(ms) = “Calculate unsatisfied demand”

ms(m)(unsatisfied(m) = 0) = no;
ms(m)(unsatisfied(m) >0) = yes;

display Unsatisfied demand;

);

Cheers

Renger

Modelworks

Gewerbestrasse 15

3600 Thun â€“ Switzerland

+41 79 818 53 73

Info@modelworks.ch

blog.modelworks.ch

From: gams...@googlegroups.com [gams…@googlegroups.com] on behalf of Anthony [anthoy.o…@gmail.com]

Sent: Saturday, February 13, 2016 22:21

To: gamsworld

Subject: How to change(update) defined set over While(or loop)?

I am wondering how to update a Set over While operator to use card(updated_set) in one constraint. for better illustration look at the following simple syntax:

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Set m /City1*City5/

Parameter Demand(m) / City1 100, City2 50, City3 200, City4 100, City5 100/

Equations

Obj… â€œMaximize demand satisfaction for each cityâ€ ;

Cons(m)$(ord(m) eq card(m))… â€œOrd(m) should be last city that still has unsatisfied demand â€ ;

Model problem MIP;

While( â€œSum (m, demand) >0â€ ,

Solve Problem

Unsatisfied(m) = “Calculate unsatisfied demand”

m$(Unsatisfied(m) >0) = yes ;

display Unsatisfied demand;

);

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

In the above example the output of the first run should be unsatisfied(m) /City2 50, City3 200/ Then:

I expect the model update the set m (remove the satisfied cities) for the next run as this:

Set m /city1*city 2/ (the two unsatisfied cities from the last run) SO THAT BE ABLE to put:

â€œord(m) eq card(m)=card(city3) in the model’s constraint for the next run.

at the moment I faced with this error: changing Set is now Allowed …

Is there any trick that I can use to solve my problem and save the results till the problem is solved over the while??

–

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.

To post to this group, send email to gams...@googlegroups.com.

Visit this group at https://groups.google.com/group/gamsworld.

For more options, visit https://groups.google.com/d/optout.

–

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.

To post to this group, send email to gamsworld@googlegroups.com.

Visit this group at https://groups.google.com/group/gamsworld.

For more options, visit https://groups.google.com/d/optout.

–

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.

To post to this group, send email to gamsworld@googlegroups.com.

Visit this group at https://groups.google.com/group/gamsworld.

For more options, visit https://groups.google.com/d/optout.