CPLEX if-then constraint with decision variables

2,514 views
Skip to first unread message

Matthew Tsang

unread,
Jul 3, 2013, 12:34:07 PM7/3/13
to am...@googlegroups.com

Hello,

I have made the following if-then constraint to my objective function.  The constraint aims to keep S1, a binary decision variable, to stay on the same value for 2 continuous iterations throughout the run.  However, cplex does not allow a decision variable to be involved in such a circumstance (possibly in a if-then statement).  I wonder if there is any alternative way to code this. 

 Thank you for your time in advnace!


forall(t in 3..NumIteration)

{

  if(S1[t-2] != S1[t-1])

      {

      S1[t] == S1[t-1];

      }          

}

Robert Fourer

unread,
Jul 18, 2013, 7:04:52 PM7/18/13
to am...@googlegroups.com

Optimization models make a distinction between the objective, which is a function of the variables that is to be minimized, and the constraints, which are restrictions on the values of the variables.  What you have written looks like a collection of constraints that have the form:

 

   S1[t-2] != S1[t-1]  implies  S1[t] == S1[t-1]

 

In other words the patterns 0 1 0 and 1 0 1 must be disallowed.  This can be specified by two linear constraints:

 

   (1-S1[t-2]) + S1[t-1] + (1-S1[t]) <= 2

   S1[t-2] + (1-S1[t-1]) + S1[t] <= 2

 

In AMPL the first would be written as

 

   subj to Stay1 {t in 3..NumIteration}:

      (1-S1[t-2]) + S1[t-1] + (1-S1[t]) <= 2;

 

and the second similarly.

 

Bob Fourer

am...@googlegroups.com

 

 

From: am...@googlegroups.com [mailto:am...@googlegroups.com]

On Behalf Of Matthew Tsang
Sent: Wednesday, July 3, 2013 11:34 AM
To: am...@googlegroups.com
Subject: [AMPL 7226] CPLEX if-then constraint with decision variables

I have made the following if-then constraint to my objective function.  The constraint aims to keep S1, a binary decision variable, to stay on the same value for 2 continuous iterations throughout the run.  However, cplex does not allow a decision variable to be involved in such a circumstance (possibly in a if-then statement).  I wonder if there is any alternative way to code this. 

forall(t in 3..NumIteration)

Reply all
Reply to author
Forward
0 new messages