I'm a new GAMS user. I am trying to model and solve a problem using

binary variables.

In the problem I have two sets:

set

t time periods /t1*t7/

l location /L1*L5/ ;

Currently, I do not have an objective function and I am just trying to

satisfy the constraints of my problem. I have a simplifed case of my

problem working.

Simplified case equations and constraints:

- I have a binary variable x with 35 entries

binary variable x(t,l)

- "Equation1" Solves for the supply at time period for each location

(L1, L2, L3, L4, and L5). The supply depends on the binary variable x

(t,l). For example:

x(t1,L1) = 1, then the supply value would INCREASE

x(t1,L1) = 0, then the supply value would DECREASE

- "Equation2" The sum of all the binary variables x(t,l) over a time

period must equal 1 (only one location can have increasing supply

during a given time period). Example:

equation2(t) .. sum(l,x(t,l)) =e= 1 ;

- "Equation3" Provides the upper limit of the supply value that can be

reached at each location.

- "Equation4" Provides the lower limit of the supply value that can be

reached at each location.

This simplified case solves correctly (satisfies all constraints).

Current problem:

My problem is that currently (in the simplified case), the binary

variable can move to any location from one time period to the next.

So, if the supply gets too low at location 5 (L5), the binary variable

can jump from any location to L5 (example, from L1 during time period

t4 to L5 during time period t5).

What I need to tell GAMS is that the binary variable can only move 1

spot from time period to time period. Example:

At t1, x(t1,'L1') = 1 (so the binary variable is at L1).

The supply value is low at L5.

But the binary variable can only move in the following manner:

t1 -> x(t1,'L1') = 1

t2 -> x(t2,'L2') = 1

t3 -> x(t3,'L3') = 1

t4 -> x(t4,'L4') = 1

t5 -> x(t5,'L5') = 1 (finally arrives at L5)

Also, the binary variable can't move from L1 to L5 (imagine the

locations are in a line, unable to wrap around).

Can anyone provide an idea (or similar example problem implementation,

if possible) on how to model this in GAMS? I tried the following:

m1(t)$((ord(t) lt card(t)) and (x(t,'b1') eq 1)) .. x(t+1,'L1') + x(t

+1,'L2') =e= 1 ;

m2(t)$(ord(t) lt card(t) and x(t,'b2') = 1) .. x(t+1,'L2') + x(t

+1,'L1') + x(t+1,'L3') =e= 1 ;

m3(t)$(ord(t) lt card(t) and x(t,'b3') = 1) .. x(t+1,'L3') + x(t

+1,'L2') + x(t+1,'L4') =e= 1 ;

m4(t)$(ord(t) lt card(t) and x(t,'b4') = 1) .. x(t+1,'L4') + x(t

+1,'L3') + x(t+1,'L5') =e= 1 ;

m5(t)$(ord(t) lt card(t) and x(t,'b5') = 1) .. x(t+1,'L5') + x(t

+1,'L4') =e= 1 ;

But I got the following error from GLPK (using mip):

**** The following MIP errors were detected in model first:

**** 57 equation m1 .. VAR operands relational or boolean

**** 57 equation m2 .. VAR operands relational or boolean

**** 57 equation m3 .. VAR operands relational or boolean

**** 57 equation m4 .. VAR operands relational or boolean

**** 57 equation m5 .. VAR operands relational or boolean

I don't understand these error messages...

In summary:

I would appreciate any help (examples, books, etc.) on how to

constrain the movement on the binary variable to the position that is

either 1) the same (L2 to L2 is legal) or 2) adjacent (L2 can only

move to L1 or L3, if not staying at L2). I am stuck and getting

frustrated. Thank you!

You can not have a variable in a dollar condition. That would make the model nonlinear: you are writing essentially an if-then expression.

If I read the description correctly you could do something like:

positive variable pos(t) 'position at t';

defpos(t).. pos(t) =e= sum(L, ord(L)*x(t,L));

bound1pos(t-1).. pos(t) =L= pos(t-1) +1;

bound2pos(t-1).. pos(t) =G= pos(t-1) -1;

## No comments:

## Post a Comment