BookmarkSubscribeRSS Feed
Yasmine
Calcite | Level 5

Hello,

I have a decision variable (x) that should be outputted from an optimization problem

This variable should be outputted as binary, taking only the values of "0" OR "1"

How can I define that at SAS proc iml?

As I can't find a syntax that puts that as a condition

In addition, I tried the below equation to be added to the constraints of my optimization problem, which ends up with the same meaning, but it gave no results

x*(1-x)=0

Please help

this is very urgent and I have due date with very limited timingssssssssssss

thanks a lot

16 REPLIES 16
Rick_SAS
SAS Super FREQ

In the SAS DATA step and in PROC IML you can form a logical expression that evaluates to true (1) or false (0).
For example, if you want to return 1 when x>0.7, just write

result = ( x>0.7 ); /* 0 or 1 */

Yasmine
Calcite | Level 5

sorry cant get what you mean quite well,

here are the below equations that I need to write at sas proc iml:

b+0.1*c>0

where b is a decision variable representing my coefficients at the model

c is a binary decision variable that should be outputted as 0 or 1, so how can I express that at my iml program?

Rick_SAS
SAS Super FREQ

Are you using the NLPQN function? If so, I think you need to specify the nonlinear constraint by using the NLC= option. See

the doc chapter "Nonlinear Optimization Examples: Parameter Constraints"

Yasmine
Calcite | Level 5

unfortunately, that doesn't solve my problem:

the below is my model I need to write at sas proc iml:

b(i)-0.1*c(i)>0

b(i)-c(i)<0

sum c(i)=4;

given that i=1.........6

these equations shows that: if c (it is outputted) =1, then 0.1<b<1

and if c=0, then b=0

This means that I need 4 c's =1 and 2 c's =0

and also I need 2 b's=0 and 4 b's having values ranging from 0.1 to 1

where b is a decision variable representing my coefficients at the model

c is a binary decision variable that should be outputted as 0 or 1, so how can I express that at my iml program?

did you get what I am trying to output?

Hutch_sas
SAS Employee

One quick and dirty way to handle this would be to enumerate the 15 different possibilites for c and optimize b individually for each sub-problem.  Are you trying to solve just this specific problem or is it an example of a more general problem you are trying to solve?

Yasmine
Calcite | Level 5

Wow, that would be too difficult as that is just an example of equations at many problems I am trying to handle Smiley Sad

are there any other ways of solving that problem? I have been trying to solve that problem for several monthsssssssssssss

PLEASE HELPPPPPPPPP

Hutch_sas
SAS Employee

what is your objective function?

Hutch_sas
SAS Employee

Depending on the problem size and your objective function, there are different ways to solve the problem you describe. If your objective function is linear, then you have a Mixed Integer Linear Program. If you have SAS/OR available to you, then you can use PROC OPTMILP to solve that directly.

If your objective function is a general non-linear function, then you have a Mixed Integer Non-linear Programming problem (MINLP) which in general is difficult to solve. If that is the case then in IML your best bet would be to use the Genetic Algorithm routines to try and solve your problem.

If you are trying to fit a traditional statistical model  like a linear or logistic regression, then SAS/STAT offers extensive variable selection algorithms you can use to find the optimal set of decision variables.

Perhaps if you would describe the original problem that would help in figuring out the best way to solve it..

Rick_SAS
SAS Super FREQ

Try using the augmented Lagrangian method. The method gets rid of the nonlinear constraint by rewriting the objective function to include a penalty term.  By adding a "nuisance parameterm," you can solve the original problem.  For example, you might try introducing a new parameter lambda>0 and optimizing the objective function

OrigObjective + lambda*x*(1-x) + 10000*(x*(1-x))##2

In order to get rid of the penalty terms, x will be driven to 0 or 1 during the optimization.

Yasmine
Calcite | Level 5

Here is my model:

Minimize dp+dn

subject to
b0+biXij+dn-dp=0

bi-0.1*ci>0

bi-ci<0

sum ci=4

where i=1..........6

j is my set of observations

and my decision variables are:

b, dp, dn, and c

hope that makes my problem more clear for you to please assisttttttttttttttttt

Yasmine
Calcite | Level 5

I need also to make a simulation for that problem?

and also sometimes I have non-linear constraints at another problem I am doing simulation for and using at that stage nlpqn at sas proc iml

Hutch_sas
SAS Employee

This appears to be a MILP problem. The best SAS tool to solve this would be PROC OPTMILP in SAS/OR. Do you have that
available?

Yasmine
Calcite | Level 5

unfortunately no Smiley Sad

is there any other way using sas proc iml please?

I am using nlpqn call

Hutch_sas
SAS Employee

Here is what I recommend, going back to my earlier suggestion.

1) generate all possible c vectors

2) for each c vector, solve the optimization problem treating the c as a constant.

this gives you a simple optimization problem with linear constraints.

3) the c vector that gives you the best optimum value coresponds to your global optimum value.

Here's how to get started:

Create a module that solves the problem for a given c vector, treating c as a constant, like

start optimize(opt_value, opt_vec) global( c);

/* set up constraints */

   ...

   call nlpqn(rc, opt_vec, "objective_function"....); /* do optimization  for a given c vector*/

   opt_value = objective_function(opt_vec);

finish;

then loop through all the possible values of c:

ncoeff = 6; /* total number of c variables */

subset_size = 4; /* number of c variables to set to 1 */

perms = allcomb(ncoeff,subset_size); /* get all permutations of 4 out of 6 elements */

optval = 1e30; /* initialize to some some huge value */

do i = 1 to nrow(perms);

  /* set up c vector */

  c = j(ncoeff, 1, 0);

  c[  perms[i,],   1  ] = 1;

  run optimize(value, vector);

  if value < optval then do;

    /* save optimal values */

    optval = value;

    optvec = vector;

    optc = c;

  end;

end;

now you should have your optimum decision variables in optvec and optc and your optimum value in optval

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 16 replies
  • 2138 views
  • 0 likes
  • 3 in conversation