Constraints subject to multiple conditions

964 views
Skip to first unread message

anonp...@gmail.com

unread,
Feb 10, 2017, 8:25:42 AM2/10/17
to AMPL Modeling Language
Hi all,

I am trying to create a constraint that would only get used if two conditions apply. 

I know if I only had one condition, it would look like this:
subject to Time {t in 1..T}:
   avail[t] > 0 ==> sum {p in PROD} (1/rate[p]) * Make[p] <= avail;

But if I want both "avail[t] > 0" , and another condition, say "cost[t] > 0", essentially have an and function, how would I do it?

Cheers,

Robert Fourer

unread,
Feb 10, 2017, 2:56:04 PM2/10/17
to am...@googlegroups.com
It appears from the context that both avail and cost are parameters. Thus you should put the conditions in the indexing rather than the constraint expression:

subject to Time {t in 1..T: avail[t] > 0 and cost[t] > 0}:
sum {p in PROD} (1/rate[p]) * Make[p,t] <= avail[t];

Bob Fourer
am...@googlegroups.com

=======

jonathan...@u.northwestern.edu

unread,
Feb 10, 2017, 8:09:50 PM2/10/17
to AMPL Modeling Language, 4...@ampl.com
Hi Bob,

Appreciate the response! If they were variables instead, how would I proceed?

Once again, thanks!

Robert Fourer

unread,
Feb 11, 2017, 11:41:38 AM2/11/17
to am...@googlegroups.com

If avail[t] and cost[t] are variables then you need to reformulate using additional binary (zero-one) variables to put the constraint into a form that standard solvers will accept.  To start you can define

   var za {1..T} binary;
   ...
   subject to zadef {t in 1..T}: za[t] = 0 ==> avail[t] = 0;

Then avail[t] > 0 will imply za[t] = 1.  The same can be done for binary variables zc[t] associated with cost[t].  Next you can define binary variables z[t] constrained by

   subject to zdef {t in 1..T}: z[t] = 0 ==> za[t] + zc[t] <= 1;

Then za[t] = zc[t] = 1 will imply z[t] = 1.  Finally you can have "z[t] = 1 ==> (your constraint);".  Because these constraints are all of the form "binary-var = 0 ==> linear-constraint" or "binary-var = 1 ==> linear-constraint" they are in the form of "indicator" constraints accepted by CPLEX or Gurobi (vers 7.0).  For other solvers these constraints can be reformulated to linear constraints by using well-known tricks; there are some examples in the Integer Programming chapter of the AMPL book (http://ampl.com/BOOK/CHAPTERS/23-integer.pdf).

Bob Fourer
am...@googlegroups.com


--
You received this message because you are subscribed to the Google Groups "AMPL Modeling Language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ampl+uns...@googlegroups.com.
To post to this group, send email to am...@googlegroups.com.
Visit this group at https://groups.google.com/group/ampl.
For more options, visit https://groups.google.com/d/optout.

Bred

unread,
May 2, 2017, 6:00:52 AM5/2/17
to AMPL Modeling Language, 4...@ampl.com
Hi,

Could you please also explain, how one could write the code incase the model requires a seperation of different values for one of the two variables?

For example  "avail[t] > 0" but for cost[t] the condition depends on either "cost[t]=0.33" or "cost[t]=0.66" or "cost[t]=1"

Thank you alot in advance!
Reply all
Reply to author
Forward
0 new messages