Help me...plz :(

39 views
Skip to first unread message

송철호

unread,
Jul 10, 2013, 8:40:36 PM7/10/13
to gams...@googlegroups.com
Hi all.
 
I'm very confused and tired.
 
Could you help me to correct gams code?
 
My code as followed.
 
=============================================================
$title assigning rooms
$offsymxref
$offsymlist
set
i person /1*5/
j room   /1*5/
k time slot "ex : 8~10am 10~12 12~14 14~16 16~18" /1*5/
 
j1(j) union of room1 /1,2/
j2(j) union of room1 /2,3/
j3(j) union of room1 /3,4/
j4(j) union of room1 /3,4,5/
 
alias(i,ip);
alias(j,jp);
alias(k,kp);
 
parameter
demand(i) demand for room in a day
          /1 3, 2 4, 3 5, 4 2, 5 2/
dist(i)   maximum distance to walk
          /1 0.5, 2 0.8, 3 1, 4 0.5, 5 0.5/
demand_uni(i) demand for union-room at the same timeslot in a day
          /1 1, 2 1, 3 1, 4 1, 5 1/
table
d(i,j)
         1       2       3       4       5
1        0.2     0.5     0.6     0.8     0.1
2        1       0.9     0.4     0.6     0.7
3        0.3     0.9     0.4     0.2     0.5
4        0.6     0.5     0.1     0.8     0.9
5        0.2     0.6     0.7     0.9     0.3
 
variable z minimizing distance;
 
binary variable x 1 if x is asssigned otherwise 0;
 
equation
obj                  objective function(minimizing distance)
no_overlap(i,j,k)    not allowed 1 more person in a room
demandfor(i)         demand for room in a day
distance(i,j,k)      maximum distance to walk
demandfor_uni(i)     demand for union-room at the same timeslot in a day
;
obj..         z =e= sum(i, sum(j, sum(k, d(i,j)*x(i,j,k))));
no_overlap(i,j,k).. sum(ip, x(ip,j,k)) =e= 1;
demandfor(i)..      sum(jp, sum(kp, x(i,jp,kp))) =g= demand(i);
distance(i,j,k)..     d(i,j)*x(i,j,k) =l= Dist(i);
demandfor_uni(i)..  sum(jp, sum(kp, x(i,jp,kp))) =g= demand_uni(i);
 
model assign /all/;
solve assign using mip minimizing z;
display x.l, z.l;
option
mip=xa;
=============================================================
Thank you
~!!!

Claudio Delpino

unread,
Jul 11, 2013, 11:57:01 AM7/11/13
to gams...@googlegroups.com
Hi: There are no problems with this code I can see... ¿What bothers you?

Regards
Claudio


--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
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 http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

송철호

unread,
Jul 11, 2013, 6:44:31 PM7/11/13
to gams...@googlegroups.com
Hi
I got the wrong solution.
x is the All zero.
And union room constraint did not meet in this code.
Thanks..

mohsen sadr

unread,
Jul 12, 2013, 7:45:39 AM7/12/13
to gams...@googlegroups.com
*hello my friend.I am Mohsen.I thing this is better than yours.I correct some of your mistakes,and I write the reason's of  other mistakes :) good luck
set
*you have to write it like this: i persion /p1*p5/ >> I correct it for u
i person /p1*p5/
j room   /r1*r5/
k time slot "ex : 8~10am 10~12 12~14 14~16 16~18" /t1*t5/
parameters
*you have to write it like this : j1(j) union of room1 /r1 1,r2 2/
j1(j) union of room1 /1,2/
j2(j) union of room1 /2,3/
j3(j) union of room1 /3,4/
j4(j) union of room1 /3,4,5/



alias(i,ip);
alias(j,jp);
alias(k,kp);

parameter
*same mistake as sets  >>
demand(i) demand for room in a day
          /p1 3,p2 4,p3 5,p4 2,p5 2/
dist(i)   maximum distance to walk
          /p1 0.5, p2 0.8, p3 1, p4 0.5, p5 0.5/
demand_uni(i) demand for union-room at the same timeslot in a day
          /p1 1,p2 1,p3 1,p4 1,p5 1/;
table d(i,j)
* table should be like this
          r1      r2      r3      r4       r5
p1        0.2     0.5     0.6     0.8      0.1
p2        1.0     0.9     0.4     0.6      0.7
p3        0.3     0.9     0.4     0.2      0.5
p4        0.6     0.5     0.1     0.8      0.9
p5        0.2     0.6     0.7     0.9      0.3

variables
*use if or $ in equations
z ;

binary variable
x1(ip,j,k)
x2(i,jp,kp) ;
*you must define ip,jp and kp in sets!!!!

equation
*

mohsen sadr

unread,
Jul 12, 2013, 7:55:02 AM7/12/13
to gams...@googlegroups.com

*this is ok . change it in your way

set
*you have to write it like this: i persion /p1*p5/ >> I correct it for u
i person /p1*p5/
j room   /r1*r5/
k time slot "ex : 8~10am 10~12 12~14 14~16 16~18" /t1*t5/
parameters
*you have to write it like this : j1(j) union of room1 /r1 1,r2 2/
j1(j) union of room1 /r1 1/
j2(j) union of room1 /r2 2/
j3(j) union of room1 /r3 3/
j4(j) union of room1 /r4 4/



alias(i,ip);
alias(j,jp);
alias(k,kp);

parameter
*same mistake as sets  >>
demand(i) demand for room in a day
          /p1 3,p2 4,p3 5,p4 2,p5 2/
dist(i)   maximum distance to walk
          /p1 0.5, p2 0.8, p3 1, p4 0.5, p5 0.5/
demand_uni(i) demand for union-room at the same timeslot in a day
          /p1 1,p2 1,p3 1,p4 1,p5 1/;
table d(i,j)
* table should be like this
          r1      r2      r3      r4       r5
p1        0.2     0.5     0.6     0.8      0.1
p2        1.0     0.9     0.4     0.6      0.7
p3        0.3     0.9     0.4     0.2      0.5
p4        0.6     0.5     0.1     0.8      0.9
p5        0.2     0.6     0.7     0.9      0.3

variables
*use if or $ in equations
z ;

binary variable
x1(ip,j,k)
x2(i,jp,kp)
x3(i,j,k) ;
*you must define ip,jp and kp in sets!!!!

equation
*
obj                  objective function(minimizing distance)
no_overlap(i,j,k)    not allowed 1 more person in a room
demandfor(i)         demand for room in a day
distance(i,j,k)      maximum distance to walk
demandfor_uni(i)     demand for union-room at the same timeslot in a day
;

obj..         z =e= sum(i, sum(j, sum(k, d(i,j)*x3(i,j,k))));
no_overlap(i,j,k).. sum(ip, x1(ip,j,k)) =e= 1;
demandfor(i)..      sum(jp, sum(kp, x2(i,jp,kp))) =g= demand(i);
distance(i,j,k)..     d(i,j)*x3(i,j,k) =l= Dist(i);
demandfor_uni(i)..  sum(jp, sum(kp, x2(i,jp,kp))) =g= demand_uni(i);

model assign /all/;
solve assign using mip minimizing z;
display x1.l,x2.l,x3.l ,z.l;
option
mip=xa;



송철호

unread,
Jul 13, 2013, 12:34:53 AM7/13/13
to gams...@googlegroups.com
Thanks. my freind~
I ran the gams program using your code.
But, objective function and x3 variable are "0".
I really really need a help set and constrainst about "demand for union-room at the same timeslot in a day" .
I appreaciate..
 
Yours sincerely,
Song,

mohsen sadr

unread,
Jul 14, 2013, 5:35:40 PM7/14/13
to gams...@googlegroups.com
and I think this equation is one of your broblems 'distance(i,j,k)..     d(i,j)*x3(i,j,k) =l= Dist(i);' this means  d(i,j)*x3(i,j,k) has to be lower than dis(i) and GAMS will take 0 for all of that.


On Mon, Jul 15, 2013 at 1:55 AM, mohsen sadr <msmohs...@gmail.com> wrote:
Hi 송철호
it is because of demand for union-room at the same time slot in a day is depend on only j,but you want to insert two or three number inside it.I think you can use j1(j,r) for example.and define it as a tabel like this:
 table j1(j,r) union of room r
          rr1      rr2     rr3      rr4
r1        1       0       0        0
r2        1       2       0        0
r3        0       2       3        0
r4        0       0       3        4 ;
it is just an example,change it in true type.and before doing it insert r and define it
good luck my friend :)




 


mohsen sadr

unread,
Jul 14, 2013, 5:25:42 PM7/14/13
to gams...@googlegroups.com

송철호

unread,
Jul 15, 2013, 6:54:25 AM7/15/13
to gams...@googlegroups.com
Thanks. Very much!
But. I don't understand what means the table, r, factor of matrix. And How can i use this table? How can i compose the constraint?

Thanks...

mohsen sadr

unread,
Jul 16, 2013, 10:48:34 AM7/16/13
to gams...@googlegroups.com
*copy this to gams and run it 
 set
*you have to write it like this: i persion /p1*p5/ >> I correct it for u
i person /p1*p5/
j room   /r1*r5/
k time slot "ex : 8~10am 10~12 12~14 14~16 16~18" /t1*t5/
r number of unions /e1*e3/ ;
alias(i,ip);
alias(j,jp);
alias(k,kp);

parameter
*same mistake as sets  >>
demand(i) demand for room in a day
          /p1 3,p2 4,p3 5,p4 2,p5 2/
dist(i)   maximum distance to walk
          /p1 0.5, p2 0.8, p3 1, p4 0.5, p5 0.5/
demand_uni(i) demand for union-room at the same timeslot in a day
          /p1 1,p2 1,p3 1,p4 1,p5 1/;
table d(i,j)
* table should be like this
          r1      r2      r3      r4       r5
p1        0.2     0.5     0.6     0.8      0.1
p2        1.0     0.9     0.4     0.6      0.7
p3        0.3     0.9     0.4     0.2      0.5
p4        0.6     0.5     0.1     0.8      0.9
p5        0.2     0.6     0.7     0.9      0.3 ;
table jr(j,r)
         e1      e2      e3
r1       1       2       0
r2       2       3       0
r3       3       4       0
r4       3       4       5
r5       0       0       0 ;
variables
*use if or $ in equations
z ;

binary variable
x1(ip,j,k)
x2(i,jp,kp)
X(i,j,k) ;


equation

mohsen sadr

unread,
Jul 16, 2013, 10:50:42 AM7/16/13
to gams...@googlegroups.com
where do you use j1(j)...j4(j)??? I did not see that in equations and objectice function!

송철호

unread,
Jul 16, 2013, 11:01:10 AM7/16/13
to gams...@googlegroups.com
Thanks.
J1..j4 are used only constraints. Demand uni.
I always thank you!

mohsen sadr

unread,
Jul 16, 2013, 11:07:43 AM7/16/13
to gams...@googlegroups.com
you are welcome.is it ok?



--
You received this message because you are subscribed to a topic in the Google Groups "gamsworld" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gamsworld/fs0NhIL6eYs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gamsworld+...@googlegroups.com.

송철호

unread,
Jul 16, 2013, 11:13:46 AM7/16/13
to gams...@googlegroups.com

What is this?

> welcome.is

mohsen sadr

unread,
Jul 17, 2013, 5:07:04 AM7/17/13
to gams...@googlegroups.com
nothing. ... forget it


On Tue, Jul 16, 2013 at 7:43 PM, 송철호 <two...@gmail.com> wrote:

What is this?

> welcome.is

Reply all
Reply to author
Forward
0 new messages