Define a variable using different sets

Archive of Gamsworld Google Group
Post Reply
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Define a variable using different sets

Post by Archiver »


Hi everyone,

I need your help in solving this problem I have. Suppose I have 2 sets, i and j (both holds values from 1 to 5). How to define a variable V such that it can be used as both V(i) and V(j) in an equation. For example, I want to set an equation (constraint) that says V(i) + V(k) =e= 1, but I can't assign both i and k to the same variable V. I have tried creating another variable Vv(k) but then this produces wrong results.

Thank you.

--
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 https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

RE: Define a variable using different sets

Post by Archiver »


Hi Tri



It is not completely clear for me what you intent is. If you want to use both V(i) and V(j), you could define the set i and define an alias (alias(i,j)). But then your equation doesn’t make much sense for this would mean that all V(i) and V(k) are equal to 0.5.

Could you explain in more detail what you want to achieve?

Cheers

Renger



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Tri Nguyen
Sent: Mittwoch, 6. April 2016 14:22
To: gamsworld
Subject: Define a variable using different sets



Hi everyone,



I need your help in solving this problem I have. Suppose I have 2 sets, i and j (both holds values from 1 to 5). How to define a variable V such that it can be used as both V(i) and V(j) in an equation. For example, I want to set an equation (constraint) that says V(i) + V(k) =e= 1, but I can't assign both i and k to the same variable V. I have tried creating another variable Vv(k) but then this produces wrong results.



Thank you.



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

--
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 https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

Re: Define a variable using different sets

Post by Archiver »


Hi Renger.

Thank you for your prompt reply. Basically, I'm learning gams and I'm trying to replicate this system as shown. I have included set i and j to show the flow from one equipment to another. In addition, under parameters, I've included the length and width parameters as: length(i) and width(i). however, these parameters applies for j as well as they represent the same equipment. I'm unsure of how I could phrase the problem such that I'm not double counting the equipment.

Hope that this is clearer for you.




On Wednesday, April 6, 2016 at 8:23:20 PM UTC+8, Tri Nguyen wrote:Hi everyone,


I need your help in solving this problem I have. Suppose I have 2 sets, i and j (both holds values from 1 to 5). How to define a variable V such that it can be used as both V(i) and V(j) in an equation. For example, I want to set an equation (constraint) that says V(i) + V(k) =e= 1, but I can't assign both i and k to the same variable V. I have tried creating another variable Vv(k) but then this produces wrong results.

Thank you.

--
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 https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Archiver
User
User
Posts: 7876
Joined: 7 years ago

RE: Define a variable using different sets

Post by Archiver »


Hi Tri



Perhaps this is helpful:



Set i equipment /1*5/;

Alias(i,j);



Parameter

Connections(i,j) Available connections between equipment,

Width(i) Witdh of instrument,

Length(i) Length of instrument;



Connections(i,j) = 0;

Connections(“1”,”2”) = 1;

Connections(“2”,”3”) = 1;

Connections(“1”,”3”) = 1;

Connections(“1”,”2”) = 1;

Connections(“2”,”4”) = 1;

Connections(“4”,”5”) = 1;



Variable F(i,j) Flow from i to j;



Equations

balance(i,j) outgoing flow is equal to 90% of ingoing flow;



Balance(i)..

0.9 * Sum(j$connections(j,i), Flow(j,i)) =E= sum(k$connections(i,k), Flow(i,k));



Hope this helps



Cheers

Renger







From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of Tri Nguyen
Sent: Mittwoch, 6. April 2016 15:12
To: gamsworld
Subject: Re: Define a variable using different sets



Hi Renger.



Thank you for your prompt reply. Basically, I'm learning gams and I'm trying to replicate this system as shown. I have included set i and j to show the flow from one equipment to another. In addition, under parameters, I've included the length and width parameters as: length(i) and width(i). however, these parameters applies for j as well as they represent the same equipment. I'm unsure of how I could phrase the problem such that I'm not double counting the equipment.



Hope that this is clearer for you.





On Wednesday, April 6, 2016 at 8:23:20 PM UTC+8, Tri Nguyen wrote:Hi everyone,



I need your help in solving this problem I have. Suppose I have 2 sets, i and j (both holds values from 1 to 5). How to define a variable V such that it can be used as both V(i) and V(j) in an equation. For example, I want to set an equation (constraint) that says V(i) + V(k) =e= 1, but I can't assign both i and k to the same variable V. I have tried creating another variable Vv(k) but then this produces wrong results.



Thank you.



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

--
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 https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Post Reply