BookmarkSubscribeRSS Feed
gupta_shubham
Obsidian | Level 7

Hi,

 

I want to use something similar to Heaviside function to create a unit pulse. Unit pulse is required because I want to define some objective function and constraint which are piece-wise linear. For example from x=0 to 10, y=x , x>=10 , y=20-x. I am unable to find out a function which could help me to write such formulation without having to write multiple if-else statement. 

 

 

3 REPLIES 3
RobPratt
SAS Super FREQ

Does your x variable have an upper bound?  Is the rest of your optimization model linear?

gupta_shubham
Obsidian | Level 7

Ideally I don't want to have any upper bound on x. Lower bound is x>0. Also my whole optimization has non linear constraints and objective function but I can simple approximated version with linear constraints 

RobPratt
SAS Super FREQ

If y - x is in [-M_1,M_1] and y - (20 - x) is in [-M_2,M_2] for suitably chosen constants M_1 and M_2, you can linearize the relationship between x and y by introducing a binary variable z and the following constraints:

-M_1 * z <= y - x <= M_1 * z

-M_2 * (1 - z) <= y - (20 - x) <= M_2 * (1 - z)

 

If z = 0, the first pair of constraints force y = x.  If z = 1, the second pair of constraints force y = 20 - x.

 

Depending on your objective and other constraints, you might be able to avoid the bounds and binary variables.  For example, if you want to maximize y, you can just impose y <= x and y <= 20 - x.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 777 views
  • 0 likes
  • 2 in conversation