BookmarkSubscribeRSS Feed
nehajain23
Calcite | Level 5

Hello, 

 

I am new to SAS and also using PROC OPTMODEL for the first time. I am trying to do unit commitment of generators. 

I have loads from hour 1 to 24. 

In a particular constraint, I wish to assign the next state of a variable based on a condition. 

Code : 

con count{i in PLANTS, j in HOUROP}:
if sum{i in PLANTS, j in HOUROP} use_plant[i,j] < pl_minup[i] then use_plant[i,j+1] = 1;

 

However, since my loads (j in HOUROP) has values from only 1 to 24, the following error appears 

Error: 

ERROR: The array subscript 'use_plant[1,25]' is invalid at line 217 column 68.
ERROR: The array subscript 'use_plant[2,25]' is invalid at line 217 column 68.
 
I need to limit this constraint to work only till hour =23. I am finding trouble in doing so. Would appreciate any kind of help. 
Thank you!
1 REPLY 1
RobPratt
SAS Super FREQ

To avoid the error, you can use a logical condition in the constraint declaration:

con count{i in PLANTS, j in HOUROP: j+1 in HOUROP}:

But you also need to rewrite the IF-THEN logic as a linear constraint.  Your desired implication is equivalent to its contrapositive:

/* if use_plant[i,j+1] = 0 then sum{i in PLANTS, j in HOUROP} use_plant[i,j] >= pl_minup[i] */

You can capture this with a big-M constraint:

pl_minup[i] - sum{i in PLANTS, j in HOUROP} use_plant[i,j] <= (pl_minup[i] - 0) * use_plant[i,j+1];

This simplifies to:

sum{i in PLANTS, j in HOUROP} use_plant[i,j] >= pl_minup[i] * (1 - use_plant[i,j+1]);

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1 reply
  • 841 views
  • 0 likes
  • 2 in conversation