coefficient mismatch Topic is solved

Problems with modeling
Post Reply
abdullahturk
User
User
Posts: 4
Joined: 2 years ago

coefficient mismatch

Post by abdullahturk »

Hi everybody,

I have i and t sets as follows:

Sets

t /0*15/
i /0*5/;

And, I have objective function as floows:

obj(i)$(ord(i)=6).. Z =e= sum(t, x(i,t)*ord(t)); (x(i,t) is a binary variable)

When I write the above objective function in its open form:

obj =e= 0*x(5,0)+1*x(5,1)+2*x(5,2)+...+15*(5,15)

But, when I run the program, the solution is as follows:

obj =e= 1*x(5,0)+2*(5,1)+3*(5,2)+...+16*x(5,15)

I mean, t coefficients do not match with the open version. I don't understand where is the problem.

Thank you.
User avatar
bussieck
Moderator
Moderator
Posts: 1042
Joined: 7 years ago

Re: coefficient mismatch

Post by bussieck »

You correctly pick the i=5 with $(ord(i)=6. Why do you expect that the ord(t) starts with 0? If you want the t "value", then either use (ord(t)-1) or t.val:

Code: Select all

obj(i)$(i.val=5).. Z =e= sum(t, x(i,t)*t.val);
-Michael
abdullahturk
User
User
Posts: 4
Joined: 2 years ago

Re: coefficient mismatch

Post by abdullahturk »

Thank you, Michael. It works. As you said, I coded ord(t) as (ord(t)-1). Since I want t value, I need to start at zero.
But I want to ask another question. I want to code an inequation (or constraint) with the same sets (t /0*15/ and i /0*5/). The constraint is as follows:
constraint (k4).jpg
constraint (k4).jpg (4.23 KiB) Viewed 10708 times
And, I coded the exact form of the constraint in GAMS as follows (Here, x(i,t) is binary variable, R and r(i) are parameters.) (Also, x(i,t) is written as x10, x20,... and r(i) is written as r1,r2,...):

kaynak1.. r1*x(10+r2*x20+r3*x30+r4*x40 =l= R;
kaynak2.. r1*(x10+x11)+r2*(x20+x21)+r3*(x30+x31)+r4*(x40+x41) =l=R;
kaynak3.. r1*(x10+x11+x12)+r2*(x20+x21+x22)+r3*(x30+x31+x32)+r4*(x40+x41+x42) =l=R;
kaynak4.. r1*(x10+x11+x12+x13)+r2*(x21+x22+x23)+r3*(x30+x31+x32+x33)+r4*(x40+x41+x42+x43) =l=R;
kaynak5.. r1*(x11+x12+x13+x14)+r2*(x22+x23+x24)+r3*(x30+x31+x32+x33+x34)+r4*(x40+x41+x42+x43+x44) =l=R;
kaynak6.. r1*(x12+x13+x14+x15)+r2*(x23+x24+x25)+r3*(x31+x32+x33+x34+x35)+r4*(x40+x41+x42+x43+x44+x45) =l=R;
kaynak7.. r1*(x13+x14+x15+x16)+r2*(x24+x25+x26)+r3*(x32+x33+x34+x35+x36)+r4*(x40+x41+x42+x43+x44+x45+x46) =l=R;
kaynak8.. r1*(x14+x15+x16+x17)+r2*(x25+x26+x27)+r3*(x33+x34+x35+x36+x37)+r4*(x40+x41+x42+x43+x44+x45+x46+x47) =l=R;
kaynak9.. r1*(x15+x16+x17+x18)+r2*(x26+x27+x28)+r3*(x34+x35+x36+x37+x38)+r4*(x41+x42+x43+x44+x45+x46+x47+x48) =l=R;
kaynak10.. r1*(x16+x17+x18+x19)+r2*(x27+x28+x29)+r3*(x35+x36+x37+x38+x39)+r4*(x42+x43+x44+x45+x46+x47+x48+x49) =l=R;
kaynak11.. r1*(x17+x18+x19+x110)+r2*(x28+x29+x210)+r3*(x36+x37+x38+x39+x310)+r4*(x43+x44+x45+x46+x47+x48+x49+x410) =l=R;
kaynak12.. r1*(x18+x19+x110+x111)+r2*(x29+x210+x211)+r3*(x37+x38+x39+x310+x311)+r4*(x44+x45+x46+x47+x48+x49+x410+x411) =l=R;
kaynak13.. r1*(x19+x110+x111+x112)+r2*(x210+x211+x212)+r3*(x38+x39+x310+x311+x312)+r4*(x45+x46+x47+x48+x49+x410+x411+x412) =l=R;
kaynak14.. r1*(x110+x111+x112+x113)+r2*(x211+x212+x213)+r3*(x39+x310+x311+x312+x313)+r4*(x46+x47+x48+x49+x410+x411+x412+x413) =l=R;
kaynak15.. r1*(x111+x112+x113+x114)+r2*(x212+x213+x214)+r3*(x310+x311+x312+x313+x314)+r4 (x47+x48+x49+x410+x411+x412+x413+x414) =l=R;
kaynak16.. r1*(x112+x113+x114+x115)+r2*(x213+x214+x215)+r3*(x311+x312+x313+x314+x315)+r4 (x48+x49+x410+x411+x412+x413+x414+x415) =l=R;

As above, I obtain the desired result in GAMs with its exact form. I coded it as follows but I can obtain the true value:

Code: Select all

k3(t).. sum((i,q)$((ord(q)=max(0, ord(t)-p(i)+1)), r(i)*x(i,q)) =l= R;
How can I code the constraint seen in the image?
Post Reply