syntax problem of priorities on multidimensional variables

Dear all,

I, too, am only a beginner in understanding GAMS, and right now the problem is setting branching priorities for binary variables in my MIP.
Say, I modeled a problem using the TSP idea. The transition variable is Z(k,m,p) (so: Z(k=k1,m=m1,p=p1)=1 if state k1 is directly prior to state m1 during period p1, 0 otherwise). NB States k and m are aliases and not all possible states K are used.

Following the Users Guide, I already tried the following.
model.prioropt=1;
z.prior(k,‘small’)=1;
z.prior(k,‘large’)=2;
z.prior(m,‘small’)=1;
z.prior(m,‘large’)=2;

This resulted in error 148 on each of the set size (Dimension different - The symbol is referenced with more/less indices as declared).

Then, I tried instead:
z.prior(k,m,p,‘small’)=1;
z.prior(k,m,p,‘large’)=2;

This resulted in the same error (148) at the same position.

As a last resort, I tried the congruence with summations:
z.prior((k,m,p),‘small’)=1;
z.prior((k,m,p),‘large’)=2;

Here I received error 36 on the first closing brackets (‘=’ or ‘…’ or ‘:=’ or ‘$=’ operator expected rest of statement ignored).

I hope the problem is clear as described.

NB I know this transition variable can also be implemented as an SOS1 variable, but that forces the (now) continuous variable that governs the ‘visit’ (E(m,p)) to be discrete again. Even then a similar question as the above could be phrased, as only a fraction of all states are used (about 20%).

Regards,
Henry Vermue


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/wF_6HV9OKasJ.
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 Henry



The error message is quite clear: you are trying to assign a value to a variable with different dimensions as declared before: You use z.prior, which is defined over k, m and p.

Then you try to assign a value to z.prior(k,”small”), so obviously one dimension is missing.

In the second try, you try to assign a value to z.prior which now has 4 dimension (one too many).

If this “small”, etc. is not in k,m or p, you probably should define Z over this set too.

This is by the way one of the great features of Gams: it does dimension checking if you declare your parameters and variables explicitly.

If you have a parameter defined over a set k which contains several elements like Hongkong, Amsterdam, etc.,

you could declare it like myparameter, but then Gams doesn’t check your dimensions.

E.g. if you have written somewhere myparameter(“Hongkongx”), although you meant “Hongkong”, Gams wouldn’t complain,

but as you didn’t define myparameter for “Hongkong” itself, it will assume the default value of 0.

If you would have declared your parameter as myparameter(k), Gams will complain if you write “Hongkongx”).

Hopes this was helpful.



Cheers


\


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 HJW Vermue
Gesendet: Montag, 21. Januar 2013 14:18
An: gamsworld@googlegroups.com
Betreff: syntax problem of priorities on multidimensional variables



Dear all,

I, too, am only a beginner in understanding GAMS, and right now the problem is setting branching priorities for binary variables in my MIP.
Say, I modeled a problem using the TSP idea. The transition variable is Z(k,m,p) (so: Z(k=k1,m=m1,p=p1)=1 if state k1 is directly prior to state m1 during period p1, 0 otherwise). NB States k and m are aliases and not all possible states K are used.

Following the Users Guide, I already tried the following.

model.prioropt=1;
z.prior(k,‘small’)=1;
z.prior(k,‘large’)=2;
z.prior(m,‘small’)=1;
z.prior(m,‘large’)=2;


This resulted in error 148 on each of the set size (Dimension different - The symbol is referenced with more/less indices as declared).

Then, I tried instead:

z.prior(k,m,p,‘small’)=1;
z.prior(k,m,p,‘large’)=2;


This resulted in the same error (148) at the same position.

As a last resort, I tried the congruence with summations:

z.prior((k,m,p),‘small’)=1;
z.prior((k,m,p),‘large’)=2;


Here I received error 36 on the first closing brackets (‘=’ or ‘…’ or ‘:=’ or ‘$=’ operator expected rest of statement ignored).

I hope the problem is clear as described.

NB I know this transition variable can also be implemented as an SOS1 variable, but that forces the (now) continuous variable that governs the ‘visit’ (E(m,p)) to be discrete again. Even then a similar question as the above could be phrased, as only a fraction of all states are used (about 20%).

Regards,
Henry Vermue


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/wF_6HV9OKasJ.
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.

Hello Renger,

Ah, yes, I what you’re trying to say. (Set K must have an element with name or ‘small’ or ‘large’.)

However, ‘small’ and ‘large’ are properties of the prior-suffix, so naturally ‘small’ and ‘large’ are not in k. (At least, according to the users guide.) Since these two words are “keywords” I even doubt applying priorities would even work if one would have elements with that name, but that’s a useless and irrelevant discussion.

To conclude: In part you’re right, same set size solves the problem with inserting ‘small’ and ‘large’ for each of the variables (which is in my opinion insufficiently explained in the users’ guide)

For others with similar problems, correct syntax is in above case:
model.prioropt=1;
z.prior(‘small’,m,p)=1;
z.prior(‘large’,m,p)=2;
z.prior(k,‘small’,p)=1;
z.prior(k,‘large’,p)=2;

Cheers,
Henry

On Monday, January 21, 2013 2:30:30 PM UTC+1, Renger van Nieuwkoop wrote:

Hi Henry



The error message is quite clear: you are trying to assign a value to a variable with different dimensions as declared before: You use z.prior, which is defined over k, m and p.

Then you try to assign a value to z.prior(k,”small”), so obviously one dimension is missing.

In the second try, you try to assign a value to z.prior which now has 4 dimension (one too many).

If this “small”, etc. is not in k,m or p, you probably should define Z over this set too.

This is by the way one of the great features of Gams: it does dimension checking if you declare your parameters and variables explicitly.

If you have a parameter defined over a set k which contains several elements like Hongkong, Amsterdam, etc.,

you could declare it like myparameter, but then Gams doesn’t check your dimensions.

E.g. if you have written somewhere myparameter(“Hongkongx”), although you meant “Hongkong”, Gams wouldn’t complain,

but as you didn’t define myparameter for “Hongkong” itself, it will assume the default value of 0.

If you would have declared your parameter as myparameter(k), Gams will complain if you write “Hongkongx”).

Hopes this was helpful.



Cheers


\


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 HJW Vermue
Gesendet: Montag, 21. Januar 2013 14:18
An: gams...@googlegroups.com
Betreff: syntax problem of priorities on multidimensional variables



Dear all,

I, too, am only a beginner in understanding GAMS, and right now the problem is setting branching priorities for binary variables in my MIP.
Say, I modeled a problem using the TSP idea. The transition variable is Z(k,m,p) (so: Z(k=k1,m=m1,p=p1)=1 if state k1 is directly prior to state m1 during period p1, 0 otherwise). NB States k and m are aliases and not all possible states K are used.

Following the Users Guide, I already tried the following.

model.prioropt=1;
z.prior(k,‘small’)=1;
z.prior(k,‘large’)=2;
z.prior(m,‘small’)=1;
z.prior(m,‘large’)=2;


This resulted in error 148 on each of the set size (Dimension different - The symbol is referenced with more/less indices as declared).

Then, I tried instead:

z.prior(k,m,p,‘small’)=1;
z.prior(k,m,p,‘large’)=2;


This resulted in the same error (148) at the same position.

As a last resort, I tried the congruence with summations:

z.prior((k,m,p),‘small’)=1;
z.prior((k,m,p),‘large’)=2;


Here I received error 36 on the first closing brackets (‘=’ or ‘…’ or ‘:=’ or ‘$=’ operator expected rest of statement ignored).

I hope the problem is clear as described.

NB I know this transition variable can also be implemented as an SOS1 variable, but that forces the (now) continuous variable that governs the ‘visit’ (E(m,p)) to be discrete again. Even then a similar question as the above could be phrased, as only a fraction of all states are used (about 20%).

Regards,
Henry Vermue


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/wF_6HV9OKasJ.
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/-/O7hGAkV2CGgJ.
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.

hello

can use from multi objective in gams?


On Mon, Jan 21, 2013 at 10:18 PM, HJW Vermue wrote:

Dear all,

I, too, am only a beginner in understanding GAMS, and right now the problem is setting branching priorities for binary variables in my MIP.
Say, I modeled a problem using the TSP idea. The transition variable is Z(k,m,p) (so: Z(k=k1,m=m1,p=p1)=1 if state k1 is directly prior to state m1 during period p1, 0 otherwise). NB States k and m are aliases and not all possible states K are used.

Following the Users Guide, I already tried the following.
model.prioropt=1;
z.prior(k,‘small’)=1;
z.prior(k,‘large’)=2;
z.prior(m,‘small’)=1;
z.prior(m,‘large’)=2;

This resulted in error 148 on each of the set size (Dimension different - The symbol is referenced with more/less indices as declared).

Then, I tried instead:
z.prior(k,m,p,‘small’)=1;
z.prior(k,m,p,‘large’)=2;

This resulted in the same error (148) at the same position.

As a last resort, I tried the congruence with summations:
z.prior((k,m,p),‘small’)=1;
z.prior((k,m,p),‘large’)=2;

Here I received error 36 on the first closing brackets (‘=’ or ‘…’ or ‘:=’ or ‘$=’ operator expected rest of statement ignored).

I hope the problem is clear as described.

NB I know this transition variable can also be implemented as an SOS1 variable, but that forces the (now) continuous variable that governs the ‘visit’ (E(m,p)) to be discrete again. Even then a similar question as the above could be phrased, as only a fraction of all states are used (about 20%).

Regards,
Henry Vermue


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/wF_6HV9OKasJ.
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.

Dear Sad,

Well, it is quite unclear to me what you exactly mean. The question does not specify in what way multiple objective functions are used. In either case, both nested and summed objective functions are possible to be optimized. When this response doesn’t answer your question, I advice you to open a new discussion with a bit more details about your problem.

And Renger: Many thanks for the very fast response, though I did not tell that right away, your answer really helped me a lot. (Maybe my initial answer was harsher than intended, as I had problems with GAMS-syntax, not necessarily with the underlying concepts.)

Cheers,
Henry

On Monday, January 21, 2013 3:10:24 PM UTC+1, sad wrote:

hello

can use from multi objective in gams?


On Mon, Jan 21, 2013 at 10:18 PM, HJW Vermue wrote:

Dear all,

I, too, am only a beginner in understanding GAMS, and right now the problem is setting branching priorities for binary variables in my MIP.
Say, I modeled a problem using the TSP idea. The transition variable is Z(k,m,p) (so: Z(k=k1,m=m1,p=p1)=1 if state k1 is directly prior to state m1 during period p1, 0 otherwise). NB States k and m are aliases and not all possible states K are used.

Following the Users Guide, I already tried the following.
model.prioropt=1;
z.prior(k,‘small’)=1;
z.prior(k,‘large’)=2;
z.prior(m,‘small’)=1;
z.prior(m,‘large’)=2;

This resulted in error 148 on each of the set size (Dimension different - The symbol is referenced with more/less indices as declared).

Then, I tried instead:
z.prior(k,m,p,‘small’)=1;
z.prior(k,m,p,‘large’)=2;

This resulted in the same error (148) at the same position.

As a last resort, I tried the congruence with summations:
z.prior((k,m,p),‘small’)=1;
z.prior((k,m,p),‘large’)=2;

Here I received error 36 on the first closing brackets (‘=’ or ‘…’ or ‘:=’ or ‘$=’ operator expected rest of statement ignored).

I hope the problem is clear as described.

NB I know this transition variable can also be implemented as an SOS1 variable, but that forces the (now) continuous variable that governs the ‘visit’ (E(m,p)) to be discrete again. Even then a similar question as the above could be phrased, as only a fraction of all states are used (about 20%).

Regards,
Henry Vermue


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/wF_6HV9OKasJ.
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/-/77OkLs6DzXoJ.
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 want to maximize bellow equation simultaneously

CarnotA(f) … sum(k,Demand(k,‘Dmax’))-sum(k,Dem(f,k))-[sum(k,Demand(k,‘ad’))(power_plant(‘A’,‘a’)+2power_plant(‘A’,‘b’)Power(f,‘A’))]-Power(f,‘A’)=e=0;
CarnotB(f) … sum(k,Demand(k,‘Dmax’))-sum(k,Dem(f,k))-[sum(k,Demand(k,‘ad’))
(power_plant(‘B’,‘a’)+2power_plant(‘B’,‘b’)Power(f,‘B’))]-Power(f,‘B’)=e=0;
CarnotC(f) … sum(k,Demand(k,‘Dmax’))-sum(k,Dem(f,k))-[sum(k,Demand(k,‘ad’))
(power_plant(‘C’,‘a’)+2
power_plant(‘C’,‘b’)Power(f,‘C’))]-Power(f,‘C’)=e=0;
CarnotD(f) … sum(k,Demand(k,‘Dmax’))-sum(k,Dem(f,k))-[sum(k,Demand(k,‘ad’))
(power_plant(‘D’,‘a’)+2power_plant(‘D’,‘b’)Power(f,‘D’))]-Power(f,‘D’)=e=0;
CarnotE(f) … sum(k,Demand(k,‘Dmax’))-sum(k,Dem(f,k))-[sum(k,Demand(k,‘ad’))
(power_plant(‘E’,‘a’)+2
power_plant(‘E’,‘b’)*Power(f,‘E’))]-Power(f,‘E’)=e=0;

tank a lot.


On Tue, Jan 22, 2013 at 12:59 AM, HJW Vermue wrote:

Dear Sad,

Well, it is quite unclear to me what you exactly mean. The question does not specify in what way multiple objective functions are used. In either case, both nested and summed objective functions are possible to be optimized. When this response doesn’t answer your question, I advice you to open a new discussion with a bit more details about your problem.

And Renger: Many thanks for the very fast response, though I did not tell that right away, your answer really helped me a lot. (Maybe my initial answer was harsher than intended, as I had problems with GAMS-syntax, not necessarily with the underlying concepts.)

Cheers,
Henry


On Monday, January 21, 2013 3:10:24 PM UTC+1, sad wrote:

hello

can use from multi objective in gams?


On Mon, Jan 21, 2013 at 10:18 PM, HJW Vermue wrote:

Dear all,

I, too, am only a beginner in understanding GAMS, and right now the problem is setting branching priorities for binary variables in my MIP.
Say, I modeled a problem using the TSP idea. The transition variable is Z(k,m,p) (so: Z(k=k1,m=m1,p=p1)=1 if state k1 is directly prior to state m1 during period p1, 0 otherwise). NB States k and m are aliases and not all possible states K are used.

Following the Users Guide, I already tried the following.
model.prioropt=1;
z.prior(k,‘small’)=1;
z.prior(k,‘large’)=2;
z.prior(m,‘small’)=1;
z.prior(m,‘large’)=2;

This resulted in error 148 on each of the set size (Dimension different - The symbol is referenced with more/less indices as declared).

Then, I tried instead:
z.prior(k,m,p,‘small’)=1;
z.prior(k,m,p,‘large’)=2;

This resulted in the same error (148) at the same position.

As a last resort, I tried the congruence with summations:
z.prior((k,m,p),‘small’)=1;
z.prior((k,m,p),‘large’)=2;

Here I received error 36 on the first closing brackets (‘=’ or ‘…’ or ‘:=’ or ‘$=’ operator expected rest of statement ignored).

I hope the problem is clear as described.

NB I know this transition variable can also be implemented as an SOS1 variable, but that forces the (now) continuous variable that governs the ‘visit’ (E(m,p)) to be discrete again. Even then a similar question as the above could be phrased, as only a fraction of all states are used (about 20%).

Regards,
Henry Vermue


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/wF_6HV9OKasJ.
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/-/77OkLs6DzXoJ.

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.

Sad,
Unfortunately you can’t maximize equations, only variables, so you have to formulate some kind variable of that incorporates the variables you are interested in. Say, you would like to minimize the total power, then define the define for example, variable: “totpower”, equation: “toteq”, and efficiency “w(f,alphabet)” then your equation could be something like:

toteq … sum((f,alphabet),w(f,alphabet)*Power(f,alphabet))=e=totpower.

Yes, I set the set name of ‘A’,… to alphabet, which is probably incorrect.

-me

On Monday, January 21, 2013 6:15:26 PM UTC+1, sad wrote:

I want to maximize bellow equation simultaneously

CarnotA(f) … sum(k,Demand(k,‘Dmax’))-sum(k,Dem(f,k))-[sum(k,Demand(k,‘ad’))(power_plant(‘A’,‘a’)+2power_plant(‘A’,‘b’)Power(f,‘A’))]-Power(f,‘A’)=e=0;
CarnotB(f) … sum(k,Demand(k,‘Dmax’))-sum(k,Dem(f,k))-[sum(k,Demand(k,‘ad’))
(power_plant(‘B’,‘a’)+2power_plant(‘B’,‘b’)Power(f,‘B’))]-Power(f,‘B’)=e=0;
CarnotC(f) … sum(k,Demand(k,‘Dmax’))-sum(k,Dem(f,k))-[sum(k,Demand(k,‘ad’))
(power_plant(‘C’,‘a’)+2
power_plant(‘C’,‘b’)Power(f,‘C’))]-Power(f,‘C’)=e=0;
CarnotD(f) … sum(k,Demand(k,‘Dmax’))-sum(k,Dem(f,k))-[sum(k,Demand(k,‘ad’))
(power_plant(‘D’,‘a’)+2power_plant(‘D’,‘b’)Power(f,‘D’))]-Power(f,‘D’)=e=0;
CarnotE(f) … sum(k,Demand(k,‘Dmax’))-sum(k,Dem(f,k))-[sum(k,Demand(k,‘ad’))
(power_plant(‘E’,‘a’)+2
power_plant(‘E’,‘b’)*Power(f,‘E’))]-Power(f,‘E’)=e=0;

tank a lot.


On Tue, Jan 22, 2013 at 12:59 AM, HJW Vermue wrote:

Dear Sad,

Well, it is quite unclear to me what you exactly mean. The question does not specify in what way multiple objective functions are used. In either case, both nested and summed objective functions are possible to be optimized. When this response doesn’t answer your question, I advice you to open a new discussion with a bit more details about your problem.

And Renger: Many thanks for the very fast response, though I did not tell that right away, your answer really helped me a lot. (Maybe my initial answer was harsher than intended, as I had problems with GAMS-syntax, not necessarily with the underlying concepts.)

Cheers,
Henry


On Monday, January 21, 2013 3:10:24 PM UTC+1, sad wrote:

hello

can use from multi objective in gams?


On Mon, Jan 21, 2013 at 10:18 PM, HJW Vermue wrote:

Dear all,

I, too, am only a beginner in understanding GAMS, and right now the problem is setting branching priorities for binary variables in my MIP.
Say, I modeled a problem using the TSP idea. The transition variable is Z(k,m,p) (so: Z(k=k1,m=m1,p=p1)=1 if state k1 is directly prior to state m1 during period p1, 0 otherwise). NB States k and m are aliases and not all possible states K are used.

Following the Users Guide, I already tried the following.
model.prioropt=1;
z.prior(k,‘small’)=1;
z.prior(k,‘large’)=2;
z.prior(m,‘small’)=1;
z.prior(m,‘large’)=2;

This resulted in error 148 on each of the set size (Dimension different - The symbol is referenced with more/less indices as declared).

Then, I tried instead:
z.prior(k,m,p,‘small’)=1;
z.prior(k,m,p,‘large’)=2;

This resulted in the same error (148) at the same position.

As a last resort, I tried the congruence with summations:
z.prior((k,m,p),‘small’)=1;
z.prior((k,m,p),‘large’)=2;

Here I received error 36 on the first closing brackets (‘=’ or ‘…’ or ‘:=’ or ‘$=’ operator expected rest of statement ignored).

I hope the problem is clear as described.

NB I know this transition variable can also be implemented as an SOS1 variable, but that forces the (now) continuous variable that governs the ‘visit’ (E(m,p)) to be discrete again. Even then a similar question as the above could be phrased, as only a fraction of all states are used (about 20%).

Regards,
Henry Vermue


To view this discussion on the web visit https://groups.google.com/d/msg/gamsworld/-/wF_6HV9OKasJ.
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/-/77OkLs6DzXoJ.

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/-/I3rUesVWVhEJ.
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.