Calcite | Level 5

## Using 1 Constraint OR Another Constraint

Greetings,

I'm using Proc Optmodel.

A part of my code is:

set setgroup = 1..10;

number IsItTrue {setgroup};

var NewValue {setgroup};

Since "IsItTrue" is group of boolean values (0, 1), I want to add a constraint that if IsItTrue = 0, the constraint is acheived, but if IsItTrue = 1, the constraint is acheived if NewValue is above or equal 20.

So one constraint IsItTrue (or IsItTrue * NewValue) (<) = 0 OR another constraint IsItTrue * NewValue >= 20.

How can I write this in Optmodel?

At another place in the model, I use NewValue * IsItTrue to keep only the NewValue of IsItTrue and make sure the total is higher than 3000, but this new constraint is on individual values, not the total, and it is for different sides (one is lower or equal than 0 while the other is above or equel 20).

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
SAS Super FREQ

## Re: Using 1 Constraint OR Another Constraint

OK, it sounds like your desired logical implication for each i in setgroup is:

"IsItTrue[i] = 0 or NewValue[i] >= 20"

Equivalently:

"if IsItTrue[i] = 1 then NewValue[i] >= 20"

You can enforce the logical implication with a linear constraint:

``con {i in setgroup: IsItTrue[i] = 1}: NewValue[i] >= 20;``

If IsItTrue[i] were a binary decision variable instead of a binary constant and NewValue[i] has a lower bound of 0, you would need a different linear constraint:

``con {i in setgroup}: NewValue[i] >= 20 * IsItTrue[i];``
3 REPLIES 3
SAS Super FREQ

## Re: Using 1 Constraint OR Another Constraint

It sounds like you want to introduce linear constraints to enforce a logical implication of the form:

if IsItTrue[g] = 0 or (IsItTrue[g] = 1 and NewValue[g] >= 20) then (something).

What is the "something" here?

Calcite | Level 5

## Re: Using 1 Constraint OR Another Constraint

I'm using a constraint like this

number TotalValues = 1000;

con sum{i in setgroup}(NewValue[i] * IsItTrue[i]) >= TotalValues;

I want to use the result of the "if" as a constraint, that for each value in setgroup, IsItTrue[i] is either 0 or NewValue[i] is >= 20;

The "if" would give a value, but how do I specify the "g" in your example or that the "something" is the pass/fail value of the constraint?

If I write

con and{i in setgroup} (IsItTrue[i] = 0 or NewValue[i] >= 20);

it gives me a synthax error and I don't know why.

SAS Super FREQ

## Re: Using 1 Constraint OR Another Constraint

OK, it sounds like your desired logical implication for each i in setgroup is:

"IsItTrue[i] = 0 or NewValue[i] >= 20"

Equivalently:

"if IsItTrue[i] = 1 then NewValue[i] >= 20"

You can enforce the logical implication with a linear constraint:

``con {i in setgroup: IsItTrue[i] = 1}: NewValue[i] >= 20;``

If IsItTrue[i] were a binary decision variable instead of a binary constant and NewValue[i] has a lower bound of 0, you would need a different linear constraint:

``con {i in setgroup}: NewValue[i] >= 20 * IsItTrue[i];``
Discussion stats
• 3 replies
• 633 views
• 0 likes
• 2 in conversation