[AMPL 24558] Trying to Apply Conditional/Logical Operators in Constraints

Hello Forum,

I am attempting to apply conditional/logical operators in my constraints and am receiving errors. I exemplify two separate applications where I am having issues doing so.

First, I am trying to model a heat exchanger type system. One of my variables being solved is maxCoolingDelivered which represents how much cooling should be deployed by the heat exchanger. It is defined as an integer, and I had enforced that this should be between 0 and 100 inclusive as below:

subject to maxCoolingDeliveredBounded1{t in TIME, z in ZONE}: 0 <= maxCoolingDelivered[t,z];

subject to maxCoolingDeliveredBounded2{t in TIME, z in ZONE}: 100 >= maxCoolingDelivered[t,z];

I experienced no errors and solutions were provided.

Now I would like AMPL to consider maxCoolingDelivered to take a value as an integer between 0 and 90 inclusive or 100 (so it cannot take 91 through 99 inclusive). I attempted to use

subject to maxCoolingDeliveredBounded1{t in TIME, z in ZONE}: (0 <= maxCoolingDelivered[t,z] <=90) or (maxCoolingDelivered[t,z] = 100);

However, the error I see is below.

Gurobi 9.5.2: nonconvex=2

timelim=450

mipgap=0.005

Gurobi 9.5.2: logical constraint _slogcon[1] is not an indicator constraint

due to bad comparison with _svar[8608].

Second, in a separate model, I’d like to model a fan to run if there are any requests to do so. FanStartStopCommandDesired is a binary variable indexed over time and zone, and HVACFanStartStopCommand is a binary variable indexed over time and HVAC. I tried

subject to FanStartStopRequestedSentToHVAC { t in TIME, z in ZONE, h in HVAC: if FanCommandRequested[t,1]=1 or FanCommandRequested[t,2]=1 or FanCommandRequested[t,3]=1}: HVACRunCommand[t,1] = 1;

which gave me an error of

syntax error

context: subject to FanStartStopRequestedSentToHVAC { t in TIME, z in ZONE, h in HVAC: if FanCommandRequested[t,1]=1 or FanCommandRequested[t,2]=1 or >>> FanCommandRequested[t,3]=1} <<< : HVACRunCommand[t,1] = 1;

And then I tried

subject to FanStartStopRequestedSentToHVAC { t in TIME, z in ZONE, h in HVAC}: HVACRunCommand[t,1] = FanCommandRequested[t,1] or FanCommandRequested[t,2] or FanCommandRequested[t,3];

Where I was told simply that the problem is infeasible. This leads me to believe that perhaps I applied the logical operator or’s correctly.

Can you advise if I am applying the use of conditional/logical expressions correctly in these constraints?

Thank you very much for your input.

To use logical operators in constraints, you will need to upgrade Gurobi to version 10. It’s available on your My Downloads page in the AMPL Portal, and in all current AMPL bundles and packages. A description of all the available logical operators is given in our Modeling Guide for MP-based AMPL Solvers.

For your first example, if you prefer to keep using Gurobi 9.5.2, then instead of defining constraint maxCoolingDeliveredBounded1 you can specify the range of values for variable maxCoolingDelivered in its var statement:

var maxCoolingDelivered {TIME,ZONE} integer in 0..90 union {100};

AMPL will automatically convert this definition to a form that any solver can handle.

For you second constraint, you will need to fix some things. You mention variables FanStartStopCommandDesired and HVACFanStartStopCommand, but those variables do not appear in the constraint. Also you are indexing the constraint over {t in TIME, z in ZONE, h in HVAC}, but h does not appear anywhere in the constraint expression.