BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
etiennel
Calcite | Level 5

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
RobPratt
SAS Super FREQ

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

View solution in original post

3 REPLIES 3
RobPratt
SAS Super FREQ

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?

etiennel
Calcite | Level 5

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.

 

RobPratt
SAS Super FREQ

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1083 views
  • 0 likes
  • 2 in conversation