Hi Kreeti

As Gams tells you the set J is not controlled. You define the equation over I and control it using J.

This is only possible if you have something like TIMEGAP(I,J)$… or if you have J used in the equation itself in a sum or prod

Cheers

Renger

Von: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] Im Auftrag von Kreeti Das

Gesendet: Freitag, 22. MÃ¤rz 2013 06:31

An: gamsworld@googlegroups.com

Betreff: Re: compare two sets

Hello,

I am trying to run the following code, but facing the error : set for ord not controlled for the constraint TIMEGAP(I). I want z(i,j) summed over j in sets of five (first from 1 to 5, then 2 to 6, then 3 to 7 and so on). I am not able to debug. Kindly help.

*DEFINE SETS*

SETS

I Kind of planes /C-54, C-130, C-47, C-141, C-5, C-17/

J Sequence number /170/;

ALIAS(J, K);

SCALAR

N Total number of slots;

N=CARD(J);

*DEFINE PARAMETERS

PARAMETERS

P(I) Payload of plane of kind I

/C-54 10

C-130 19

C-47 6

C-141 34

C-5 145

C-17 85 /

C(I) Crew capacity of plane of kind I

/C-54 4

C-130 5

C-47 4

C-141 7

C-5 7

C-17 3 /

F(I) Fligh time of plane of kind I in minutes

/C-54 60

C-130 43

C-47 72

C-141 32

C-5 30

C-17 30 /;

*DEFINE VARIABLES

VARIABLES

CARGO Total Cargo capacity;

POSITIVE VARIABLES

T(J) Total time from before takeoff to landing taken by plane in slot J;

INTEGER VARIABLE

X(I) Number of planes of kind i used;

BINARY VARIABLES

Z(I,J) Plane of kind I is in slot J;

EQUATIONS

OBJFUN Maximize Cargo

ONESHIFT Maximum number of planes in one shift

DEMAND Daily demand of supplies

CREW Maximum crew capacity per day

ONESLOT(J) There is plane of only one kind in one sequence

TIMEGAP(I) In five slots similar kind of plane will be used only once

PLANE_SLOT(I,J) Relation between slot binary variable and number of planes

TIME_EVAL(J) Evaluate the total time required for each slot keeping flight of first plane at t=0

CONSTR(J) Time difference between consecutive flights is greater than equal to 3 minutes;

OBJFUN…CARGO =E= SUM(I,P(I)*X(I));

ONESHIFT… SUM(I,X(I))=E=70;

DEMAND… SUM(I, P(I)*X(I))=G=1252;

CREW… SUM(I,C(I)*X(I))=L=512;*

ONESLOT(J)… SUM(I,Z(I,J))=E=1;

TIMEGAP(I) (ORD(J) LT N-3).. SUM(K (ORD(K) GT (ORD(J)-1) AND ORD(K) LT (ORD(J)+5)), Z(I,K))=E=1;

PLANE_SLOT(I,J)… Z(I,J)=L=X(I);

TIME_EVAL(J)… T(J)=E= 3(ORD(J)-1) + SUM(I,F(I)*Z(I,J));

CONSTR(J) $(ORD(J) LT N)… T(J+1)-T(J)=G=3;

*DEFINE MODEL AND SOLVER

MODEL AIRLIFT /ALL/;

AIRLIFT.OPTCR=1e-5; AIRLIFT.OPTCA=1e-7;

SOLVE AIRLIFT USING MIP MAXIMIZING CARGO;

*DISPLAY

DISPLAY X.L, Z.L, CARGO.L;

On Wednesday, 11 January 2012 17:32:32 UTC+8, Mohammad Sadegh Tavallali wrote:

Hello

Thanks for your response.

I should apologize as I realized that there has been a typo in my previous comment. It should had been:

SET C(a,b);

C (a,b) $ [ORD(b)>ORD(a)]=YES ;

Then you can use this set C(a,b) in other proceeding equations or assignments. Such as :

EQUATION EQ1(a,b);

EQ1(a,b)$C(a,b)… DEMAND(b)=L=DEMAND(a);

So if set a and b have 3 members each (3x3 totally) , you will declare only 3 equations (i.e. it picks the correct combinations). Of course there are other ways of doing the same.

If I assume that you only need (b>a) , then your TOTAL equation would then be something similar to :

m=E=sum( (a,b)$C(a,b), 100*ord(a)*ord(b) );

You should be able to easily map this to what exactly you need.

I hope it helps.

Regards

Ù…ØÙ…Ø¯ ØµØ§Ø¯Ù‚ ØªÙˆÙ„Ù‘Ù„ÛŒ

Mohammad Sadegh Tavallali

On Tue, Jan 10, 2012 at 1:15 AM, chen li wrote:

Hi Tavallali,

Thanks for your reply, yet, I think I don’t need to define a new set, what I mean is in my whole project, I want gams to pick proper elements in a and b and meet the demand that the element picked in b must be less than a, so I am trying to figure out what kind of command would let gams do the picking for me.

And I tried your suggestion, first I defined a new set and then I added a equation"eqation_one… (a,b) $ [ORD(b)>ORD(a)]=YES ;" however, gams told me that dimension different and set for ‘ord’ is not controlled. I also tried to add the set name before (a,b) in the equation, tried to use"=e=" in the equation ,but all of them didn’t work. Maybe I missed something, could you give me some other advice?

I appreciate your help!

Thank you very much!

Best,

Helena

2012/1/7 Tavallali

Hello

Would you please elaborate a bit more on your comment: "the number I pick in

set b will always be less than the number I pick in set a.

"

Do you mean you need to define a set that contains the members with bORD(a)]=YES ;

I hope it helps.

Regards

Ù…ØÙ…Ø¯ ØµØ§Ø¯Ù‚ ØªÙˆÙ„Ù‘Ù„ÛŒ

Mohammad Sadegh Tavallali

On Sat, Jan 7, 2012 at 7:28 AM, helena wrote:

Dear all,

I am a new to Gams, I got stucked on comparing two sets.

So here is my gams:

set a /1*200/*

b /1200/

variables m;

equation total;

total… m=e=sum(a$(ord(a)<150), sum(b$(ord(b)<ord(b)+20),

100*(ord(a)*(ord(b))) ));

I want to add a constraint to demonstrate that the number I pick in

set b will always be less than the number I pick in set a. So what

should I do?

I appreciate your help!!

Best,

Helena

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 http://groups.google.com/group/gamsworld?hl=en.

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

\