Looped Distance Help

I am fairly new to GAMS and am trying to implement code that will allow me to loop through all of my regions (generally defined by four or five inequalities) and calculate the shortest distance between each set. The problems that I am encountering are as follows: 1) My code is returning an “Uncontrolled Set” error when ran as seen below and 2) I don’t know how to filter the constraints programmatically so that when calculating the distance between say regions one and two, only those constraints are active and so on (Currently constraints are modified manually based on a shortest path type problem). I have been struggling with this problem for a few days now trying everything I can and reading everything I can but to no avail. If anyone can provide any help I would be extremely grateful.

set n/1,2,3/;
set s/1,2,3/;
alias(n,nn);

parameter z(s) /1=0,2=0,3=0/;

free variables x(n),y(n),Obj;
equations Rect1,Rect2,Rect3,Rect4,Parr1,Parr2,Parr3,Parr4,Dia1,Dia2,Dia3,Dia4,objdef;

Rect1… y(‘2’) =l= 6+999*(1-z(‘2’));
Rect2… y(‘2’) =g= 5-999*(1-z(‘2’));
Rect3… x(‘2’) =g= -1-999*(1-z(‘2’));
Rect4… x(‘2’) =l= 1+999*(1-z(‘2’));

Parr1… y(‘3’) =l= -0.5x(‘3’)+999(1-z(‘3’));
Parr2… y(‘3’) =g= -0.5x(‘3’) -1-999(1-z(‘3’));
Parr3… x(‘3’) =l= -4+999*(1-z(‘3’));
Parr4… x(‘3’) =g= -6-999*(1-z(‘3’));

Dia1… y(‘1’) =l= x(‘1’)-2+999*(1-z(‘1’));
Dia2… y(‘1’) =l= -x(‘1’) + 8+999*(1-z(‘1’));
Dia3… y(‘1’) =g= -x(‘1’) + 6-999*(1-z(‘1’));
Dia4… y(‘1’) =g= x(‘1’) - 4-999*(1-z(‘1’));

objdef… Obj=e= sqrt((x(nn)-x(n))(x(nn)-x(n))+(y(nn)-y(n))(y(nn)-y(n)));

model problem1 /all/;
option solprint = off;
alias (n,j);
alias (nn,k);
parameter minimumDistance(j,k);
loop((j,k)$(ord(j) ne ord(k)),
solve problem1 using nlp minimizing Obj;
minimumdistance(j,k)=Obj.lo;
);
option nlp = baron;

\

To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/l_jPh9XsAZ4J.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

Dear Andrew,

I also dont know GAMS very well, but I had same problem (the uncontrolled set error) with you. For this error you need to write your sets to the equation name, too.

for example,

you should write:

Rect1(n)… y(‘2’) =l= 6+999*(1-z(‘2’));
Rect2(n)… y(‘2’) =g= 5-999*(1-z(‘2’));
Rect3(n)… x(‘2’) =g= -1-999*(1-z(‘2’));
Rect4(n)… x(‘2’) =l= 1+999*(1-z(‘2’));


you should do this for your all constraints and objective that has set. For your other problem, I dont have any idea.

I hope this helps,

Thanks

Mesude

On Dec 23, 2012, at 10:26 AM, Andrew Orso wrote:

I am fairly new to GAMS and am trying to implement code that will allow me to loop through all of my regions (generally defined by four or five inequalities) and calculate the shortest distance between each set. The problems that I am encountering are as follows: 1) My code is returning an “Uncontrolled Set” error when ran as seen below and 2) I don’t know how to filter the constraints programmatically so that when calculating the distance between say regions one and two, only those constraints are active and so on (Currently constraints are modified manually based on a shortest path type problem). I have been struggling with this problem for a few days now trying everything I can and reading everything I can but to no avail. If anyone can provide any help I would be extremely grateful.

set n/1,2,3/;
set s/1,2,3/;
alias(n,nn);

parameter z(s) /1=0,2=0,3=0/;

free variables x(n),y(n),Obj;
equations Rect1,Rect2,Rect3,Rect4,Parr1,Parr2,Parr3,Parr4,Dia1,Dia2,Dia3,Dia4,objdef;

Rect1… y(‘2’) =l= 6+999*(1-z(‘2’));
Rect2… y(‘2’) =g= 5-999*(1-z(‘2’));
Rect3… x(‘2’) =g= -1-999*(1-z(‘2’));
Rect4… x(‘2’) =l= 1+999*(1-z(‘2’));

Parr1… y(‘3’) =l= -0.5x(‘3’)+999(1-z(‘3’));
Parr2… y(‘3’) =g= -0.5x(‘3’) -1-999(1-z(‘3’));
Parr3… x(‘3’) =l= -4+999*(1-z(‘3’));
Parr4… x(‘3’) =g= -6-999*(1-z(‘3’));

Dia1… y(‘1’) =l= x(‘1’)-2+999*(1-z(‘1’));
Dia2… y(‘1’) =l= -x(‘1’) + 8+999*(1-z(‘1’));
Dia3… y(‘1’) =g= -x(‘1’) + 6-999*(1-z(‘1’));
Dia4… y(‘1’) =g= x(‘1’) - 4-999*(1-z(‘1’));

objdef… Obj=e= sqrt((x(nn)-x(n))(x(nn)-x(n))+(y(nn)-y(n))(y(nn)-y(n)));

model problem1 /all/;
option solprint = off;
alias (n,j);
alias (nn,k);
parameter minimumDistance(j,k);
loop((j,k)$(ord(j) ne ord(k)),
solve problem1 using nlp minimizing Obj;
minimumdistance(j,k)=Obj.lo;
);
option nlp = baron;


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/l_jPh9XsAZ4J.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

Hi Andrew



First of all: take a look in this forum at my comments in the question with the title “error 125 and error 149”. It will give you some insight on why your equation objdef is not working.

Your objective “obj” is defined on the right hand side over the sets n and nn and not for a single value (left hand side). These dimensions should be equal, so Gams complains.

You are looking for the minimum value of a group of values. An objective function has a single dimension, yours has a dimension of 3,

so you have to redefine your problem in such a way that you have a single value objective function.



Cheers

Renger




\


Modelworks

Gewerbestrasse 15

3600 Thun – Switzerland

+41 79 818 53 73

Info@modelworks.ch

blog.modelworks.ch









Von: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] Im Auftrag von Andrew Orso
Gesendet: Sonntag, 23. Dezember 2012 17:27
An: gamsworld@googlegroups.com
Betreff: Looped Distance Help



I am fairly new to GAMS and am trying to implement code that will allow me to loop through all of my regions (generally defined by four or five inequalities) and calculate the shortest distance between each set. The problems that I am encountering are as follows: 1) My code is returning an “Uncontrolled Set” error when ran as seen below and 2) I don’t know how to filter the constraints programmatically so that when calculating the distance between say regions one and two, only those constraints are active and so on (Currently constraints are modified manually based on a shortest path type problem). I have been struggling with this problem for a few days now trying everything I can and reading everything I can but to no avail. If anyone can provide any help I would be extremely grateful.

set n/1,2,3/;
set s/1,2,3/;
alias(n,nn);

parameter z(s) /1=0,2=0,3=0/;

free variables x(n),y(n),Obj;
equations Rect1,Rect2,Rect3,Rect4,Parr1,Parr2,Parr3,Parr4,Dia1,Dia2,Dia3,Dia4,objdef;

Rect1… y(‘2’) =l= 6+999*(1-z(‘2’));
Rect2… y(‘2’) =g= 5-999*(1-z(‘2’));
Rect3… x(‘2’) =g= -1-999*(1-z(‘2’));
Rect4… x(‘2’) =l= 1+999*(1-z(‘2’));

Parr1… y(‘3’) =l= -0.5x(‘3’)+999(1-z(‘3’));
Parr2… y(‘3’) =g= -0.5x(‘3’) -1-999(1-z(‘3’));
Parr3… x(‘3’) =l= -4+999*(1-z(‘3’));
Parr4… x(‘3’) =g= -6-999*(1-z(‘3’));

Dia1… y(‘1’) =l= x(‘1’)-2+999*(1-z(‘1’));
Dia2… y(‘1’) =l= -x(‘1’) + 8+999*(1-z(‘1’));
Dia3… y(‘1’) =g= -x(‘1’) + 6-999*(1-z(‘1’));
Dia4… y(‘1’) =g= x(‘1’) - 4-999*(1-z(‘1’));

objdef… Obj=e= sqrt((x(nn)-x(n))(x(nn)-x(n))+(y(nn)-y(n))(y(nn)-y(n)));

model problem1 /all/;
option solprint = off;
alias (n,j);
alias (nn,k);
parameter minimumDistance(j,k);
loop((j,k)$(ord(j) ne ord(k)),
solve problem1 using nlp minimizing Obj;
minimumdistance(j,k)=Obj.lo;
);
option nlp = baron;

\

To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/l_jPh9XsAZ4J.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

I did finally figure out an answer to my question. For anyone with the same problem, I created a set iter and then another set constraintcut(iter) which let me “activate” an equation by saying constraintcut(iter) = Yes. The set constraintcut goes in parenthesis right after the equation i.e. Equation1(constraintcut(‘1’))… x*y;

On Sunday, December 30, 2012 2:40:19 PM UTC-5, Renger van Nieuwkoop wrote:

Hi Andrew



First of all: take a look in this forum at my comments in the question with the title “error 125 and error 149”. It will give you some insight on why your equation objdef is not working.

Your objective “obj” is defined on the right hand side over the sets n and nn and not for a single value (left hand side). These dimensions should be equal, so Gams complains.

You are looking for the minimum value of a group of values. An objective function has a single dimension, yours has a dimension of 3,

so you have to redefine your problem in such a way that you have a single value objective function.



Cheers

Renger




\


Modelworks

Gewerbestrasse 15

3600 Thun – Switzerland

+41 79 818 53 73

In…@modelworks.ch

blog.modelworks.ch









Von: gams...@googlegroups.com [mailto:gams...@googlegroups.com] Im Auftrag von Andrew Orso
Gesendet: Sonntag, 23. Dezember 2012 17:27
An: gams...@googlegroups.com
Betreff: Looped Distance Help



I am fairly new to GAMS and am trying to implement code that will allow me to loop through all of my regions (generally defined by four or five inequalities) and calculate the shortest distance between each set. The problems that I am encountering are as follows: 1) My code is returning an “Uncontrolled Set” error when ran as seen below and 2) I don’t know how to filter the constraints programmatically so that when calculating the distance between say regions one and two, only those constraints are active and so on (Currently constraints are modified manually based on a shortest path type problem). I have been struggling with this problem for a few days now trying everything I can and reading everything I can but to no avail. If anyone can provide any help I would be extremely grateful.

set n/1,2,3/;
set s/1,2,3/;
alias(n,nn);

parameter z(s) /1=0,2=0,3=0/;

free variables x(n),y(n),Obj;
equations Rect1,Rect2,Rect3,Rect4,Parr1,Parr2,Parr3,Parr4,Dia1,Dia2,Dia3,Dia4,objdef;

Rect1… y(‘2’) =l= 6+999*(1-z(‘2’));
Rect2… y(‘2’) =g= 5-999*(1-z(‘2’));
Rect3… x(‘2’) =g= -1-999*(1-z(‘2’));
Rect4… x(‘2’) =l= 1+999*(1-z(‘2’));

Parr1… y(‘3’) =l= -0.5x(‘3’)+999(1-z(‘3’));
Parr2… y(‘3’) =g= -0.5x(‘3’) -1-999(1-z(‘3’));
Parr3… x(‘3’) =l= -4+999*(1-z(‘3’));
Parr4… x(‘3’) =g= -6-999*(1-z(‘3’));

Dia1… y(‘1’) =l= x(‘1’)-2+999*(1-z(‘1’));
Dia2… y(‘1’) =l= -x(‘1’) + 8+999*(1-z(‘1’));
Dia3… y(‘1’) =g= -x(‘1’) + 6-999*(1-z(‘1’));
Dia4… y(‘1’) =g= x(‘1’) - 4-999*(1-z(‘1’));

objdef… Obj=e= sqrt((x(nn)-x(n))(x(nn)-x(n))+(y(nn)-y(n))(y(nn)-y(n)));

model problem1 /all/;
option solprint = off;
alias (n,j);
alias (nn,k);
parameter minimumDistance(j,k);
loop((j,k)$(ord(j) ne ord(k)),
solve problem1 using nlp minimizing Obj;
minimumdistance(j,k)=Obj.lo;
);
option nlp = baron;

\

To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/l_jPh9XsAZ4J.
To post to this group, send email to gams...@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/OQ3Z16V_9vYJ.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.

Reply-to: gamsworld@googlegroups.com



发自我的 iPad

在 2012-12-29,0:13,Mesude Ozturk 写道:





Dear Andrew,

I also dont know GAMS very well, but I had same problem (the uncontrolled set error) with you. For this error you need to write your sets to the equation name, too.

for example,

you should write:

Rect1(n)… y(‘2’) =l= 6+999*(1-z(‘2’));
Rect2(n)… y(‘2’) =g= 5-999*(1-z(‘2’));
Rect3(n)… x(‘2’) =g= -1-999*(1-z(‘2’));
Rect4(n)… x(‘2’) =l= 1+999*(1-z(‘2’));


you should do this for your all constraints and objective that has set. For your other problem, I dont have any idea.

I hope this helps,

Thanks

Mesude

On Dec 23, 2012, at 10:26 AM, Andrew Orso wrote:

I am fairly new to GAMS and am trying to implement code that will allow me to loop through all of my regions (generally defined by four or five inequalities) and calculate the shortest distance between each set. The problems that I am encountering are as follows: 1) My code is returning an “Uncontrolled Set” error when ran as seen below and 2) I don’t know how to filter the constraints programmatically so that when calculating the distance between say regions one and two, only those constraints are active and so on (Currently constraints are modified manually based on a shortest path type problem). I have been struggling with this problem for a few days now trying everything I can and reading everything I can but to no avail. If anyone can provide any help I would be extremely grateful.

set n/1,2,3/;
set s/1,2,3/;
alias(n,nn);

parameter z(s) /1=0,2=0,3=0/;

free variables x(n),y(n),Obj;
equations Rect1,Rect2,Rect3,Rect4,Parr1,Parr2,Parr3,Parr4,Dia1,Dia2,Dia3,Dia4,objdef;

Rect1… y(‘2’) =l= 6+999*(1-z(‘2’));
Rect2… y(‘2’) =g= 5-999*(1-z(‘2’));
Rect3… x(‘2’) =g= -1-999*(1-z(‘2’));
Rect4… x(‘2’) =l= 1+999*(1-z(‘2’));

Parr1… y(‘3’) =l= -0.5x(‘3’)+999(1-z(‘3’));
Parr2… y(‘3’) =g= -0.5x(‘3’) -1-999(1-z(‘3’));
Parr3… x(‘3’) =l= -4+999*(1-z(‘3’));
Parr4… x(‘3’) =g= -6-999*(1-z(‘3’));

Dia1… y(‘1’) =l= x(‘1’)-2+999*(1-z(‘1’));
Dia2… y(‘1’) =l= -x(‘1’) + 8+999*(1-z(‘1’));
Dia3… y(‘1’) =g= -x(‘1’) + 6-999*(1-z(‘1’));
Dia4… y(‘1’) =g= x(‘1’) - 4-999*(1-z(‘1’));

objdef… Obj=e= sqrt((x(nn)-x(n))(x(nn)-x(n))+(y(nn)-y(n))(y(nn)-y(n)));

model problem1 /all/;
option solprint = off;
alias (n,j);
alias (nn,k);
parameter minimumDistance(j,k);
loop((j,k)$(ord(j) ne ord(k)),
solve problem1 using nlp minimizing Obj;
minimumdistance(j,k)=Obj.lo;
);
option nlp = baron;


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/l_jPh9XsAZ4J.
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.


To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.