Help me...plz :(

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 /15/
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잘린 ì½˜í…ì¸ í‘œì‹œ~!!!
안녕하세요.

ë‚´ê°€ 그리드를 ì •ì˜í•´ì•¼í•©ë‹ˆë‹¤. 그리드는 매듭을 ê°€ì§€ê³ ìžˆìœ¼ë©°, 일부 knots.there에서 소비됩니다.
매듭으로 ì „ì†¡ë˜ëŠ” 것을의 ê· í˜• 플러스 소비 (있는 경우) 멀리가는 무슨 같아야합니다.

내가 세트가
I / K1 / K2, K3, K4, K5
/ J / K1, K2, K3, K4, K5

어느로부터 매듭을 의미합니다.

ë‚´ ë°©ì •ì‹ì€ 밸런스 작업을 ì§„í–‰ :
EQ1 … 합계 (I, 교통 (I, J)) = E = SUM (J, 교통) + 소비 (I, J)

하지만이 ë‚ ìƒìˆ˜ 또는로 ìž…ë ¥í•˜ê±°ë‚˜ í†µì œ 집합을 ì œê³µí•©ë‹ˆë‹¤ … 이미 í†µì œí•˜ì—ìžˆë‹¤.

ë‹¹ì‹ ì€ correctely ê·¸ ë°©ì •ì‹ì„ ì •ì˜í•˜ëŠ” 나를 도울 수 있습니까?

감사합니다


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.
For more options, visit https://groups.google.com/groups/opt_out.

\

Hi: There are no problems with this code I can see… ¿What bothers you?

Regards
Claudio


On Wed, Jul 10, 2013 at 9:40 PM, ì†¡ì² í˜¸ wrote:

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 /15/
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잘린 ì½˜í…ì¸ í‘œì‹œ~!!!
안녕하세요.

ë‚´ê°€ 그리드를 ì •ì˜í•´ì•¼í•©ë‹ˆë‹¤. 그리드는 매듭을 ê°€ì§€ê³ ìžˆìœ¼ë©°, 일부 knots.there에서 소비됩니다.
매듭으로 ì „ì†¡ë˜ëŠ” 것을의 ê· í˜• 플러스 소비 (있는 경우) 멀리가는 무슨 같아야합니다.

내가 세트가
I / K1 / K2, K3, K4, K5
/ J / K1, K2, K3, K4, K5

어느로부터 매듭을 의미합니다.

ë‚´ ë°©ì •ì‹ì€ 밸런스 작업을 ì§„í–‰ :
EQ1 … 합계 (I, 교통 (I, J)) = E = SUM (J, 교통) + 소비 (I, J)

하지만이 ë‚ ìƒìˆ˜ 또는로 ìž…ë ¥í•˜ê±°ë‚˜ í†µì œ 집합을 ì œê³µí•©ë‹ˆë‹¤ … 이미 í†µì œí•˜ì—ìžˆë‹¤.

ë‹¹ì‹ ì€ correctely ê·¸ ë°©ì •ì‹ì„ ì •ì˜í•˜ëŠ” 나를 도울 수 있습니까?

감사합니다


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.
For more options, visit https://groups.google.com/groups/opt_out.



\

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.
For more options, visit https://groups.google.com/groups/opt_out.

\

Hi
I got the wrong solution.
x is the All zero.
And union room constraint did not meet in this code.
Thanks…

\

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 :slight_smile: good luck
set
you have to write it like this: i persion /p1p5/ >> I correct it for u
i person /p1
p5/
j room /r1r5/
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
*
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;


\

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.
For more options, visit https://groups.google.com/groups/opt_out.

\

*this is ok . change it in your way

set
you have to write it like this: i persion /p1p5/ >> I correct it for u
i person /p1p5/
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;


\

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.
For more options, visit https://groups.google.com/groups/opt_out.

\

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,


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.
For more options, visit https://groups.google.com/groups/opt_out.

\

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 :slight_smile:






\

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.
For more options, visit https://groups.google.com/groups/opt_out.

\

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 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 :slight_smile:







\

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.
For more options, visit https://groups.google.com/groups/opt_out.

\

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…

\

copy this to gams and run it
set
you have to write it like this: i persion /p1p5/ >> I correct it for u
i person /p1
p5/
j room /r1r5/
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

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;


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.
For more options, visit https://groups.google.com/groups/opt_out.

\

where do you use j1(j)…j4(j)??? I did not see that in equations and objectice function!


On Tue, Jul 16, 2013 at 7:18 PM, mohsen sadr wrote:

copy this to gams and run it
set
you have to write it like this: i persion /p1p5/ >> I correct it for u
i person /p1
p5/
j room /r1r5/
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

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;

\

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.
For more options, visit https://groups.google.com/groups/opt_out.

\

Thanks.
J1…j4 are used only constraints. Demand uni.
I always thank you!

\

you are welcome.is it ok?


On Tue, Jul 16, 2013 at 7:31 PM, ì†¡ì² í˜¸ wrote:

Thanks.
J1…j4 are used only constraints. Demand uni.
I always thank you!


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+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.


\

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.
For more options, visit https://groups.google.com/groups/opt_out.

\

What is this?

welcome.is


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.
For more options, visit https://groups.google.com/groups/opt_out.

\

nothing. … forget it


On Tue, Jul 16, 2013 at 7:43 PM, ì†¡ì² í˜¸ wrote:

What is this?

welcome.is


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+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at http://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/groups/opt_out.



\

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.
For more options, visit https://groups.google.com/groups/opt_out.

\