Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 01-17-2019 12:31 PM
(632 views)

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.

- Tags:
- optmodel

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.