Set one variable depending on change in another

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

Set one variable depending on change in another

Post by Archiver »


Hi,

I am working on a model with 2 binary variables that represent a state of an object. y is a year in a set.
VARIABLES
ISNEW(y)
ISACTIVE(y);

Once ISACTIVE changes from 0 to 1 ISNEW should be 1 for one year.
How can this be achieved? I tried
equation$(ISACTIVE(y-1) eq 0 and ISACTIVE(y) eq 1)..ISNEW(y) =e= 1;

but this does give me 0 for every isnew even if isactive changes.

Any help would be greatly appreciated!

--
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: Set one variable depending on change in another

Post by Archiver »


Hi OHA



This is surely not GAMS conform. You can’t have equations depending on variables.

If you have a question, you should add the code that is producing the error.



Cheers

Renger



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of OHA
Sent: Mittwoch, 30. März 2016 21:44
To: gamsworld
Subject: Set one variable depending on change in another



Hi,



I am working on a model with 2 binary variables that represent a state of an object. y is a year in a set.

VARIABLES
ISNEW(y)
ISACTIVE(y);


Once ISACTIVE changes from 0 to 1 ISNEW should be 1 for one year.

How can this be achieved? I tried

equation$(ISACTIVE(y-1) eq 0 and ISACTIVE(y) eq 1)..ISNEW(y) =e= 1;


but this does give me 0 for every isnew even if isactive changes.



Any help would be greatly appreciated!

--
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: Set one variable depending on change in another

Post by Archiver »


OHA: I think this should do what you want. Heads first disjunctive programming (Disclaimer: I'm not an expert in this kind of stuff).

ISNEW(y) =e= ISACTIVE(y)-ISACTIVE(y-1)

Allowed (feasible) values:
0 0 0
1 1 0
0 1 1

I guess you have a ward against this state (ISACTIVE(y)=g=ISACTIVE(y-1)):

? 0 1

Hope to help!
Claudio



On Thu, Mar 31, 2016 at 5:15 AM, Renger van Nieuwkoop wrote:

Hi OHA



This is surely not GAMS conform. You can’t have equations depending on variables.

If you have a question, you should add the code that is producing the error.



Cheers

Renger



From: gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com] On Behalf Of OHA
Sent: Mittwoch, 30. März 2016 21:44
To: gamsworld
Subject: Set one variable depending on change in another



Hi,



I am working on a model with 2 binary variables that represent a state of an object. y is a year in a set.

VARIABLES
ISNEW(y)
ISACTIVE(y);


Once ISACTIVE changes from 0 to 1 ISNEW should be 1 for one year.

How can this be achieved? I tried

equation$(ISACTIVE(y-1) eq 0 and ISACTIVE(y) eq 1)..ISNEW(y) =e= 1;


but this does give me 0 for every isnew even if isactive changes.



Any help would be greatly appreciated!

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


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