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.
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];
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?
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.
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 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.