Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio

Optimization Problem

Reply
Contributor
Posts: 59

Optimization Problem

Hello, i have to solve an optimization problem.

I attached two slides where you can see optimization problem(maximum revenue) with constraints and example.

What procedure can i use to solve problem, and how i write this optimization? I never used OR before.

Thank you

 

 


Slide1.JPGSlide2.JPG
SAS Employee
Posts: 448

Re: Optimization Problem

[ Edited ]

You can use the OPTMODEL procedure in SAS/OR to formulate and solve optimization problems.  There is a whole book of examples to help you.

 

Contributor
Posts: 59

Re: Optimization Problem

The problem thay i don't have sas SAS/OR, only SAS/IML. Can i use it to solve optimization?

Thank you

Super User
Posts: 9,769

Re: Optimization Problem

Here are several questions.
What does Px stand for , how do you define Px ?
How do you define x1=1 ? when you choose both cola and  peanuts ? or just one of them ?

Here is iML code for your  example by Genetic Algorithm.



proc iml;
start func(x) global(x1,x2,x3,m,c,p,items,idx); 
if any(idx=sum(x)) then do;
 temp=p[loc(x)];
 xx=all(element(x1,temp))||
    all(element(x2,temp))||
    all(element(x3,temp)) ;   
 obj= sum(m#xx)-sum(c#x); 
end;
else obj=-99999;
 return (obj);
finish;


items=3;

p={cola peanuts cheese beer};
m={10 20 30};
c={5 3 1 4};
n=ncol(p);
idx=1:items;
encoding=repeat({0,1},1,n);

x1={cola peanuts};
x2={peanuts cheese};
x3={peanuts beer};

id=gasetup(2,n,12345678);
call gasetobj(id,1,"func");
call gasetcro(id,0.95,2);
call gasetmut(id,0.95,3);
call gasetsel(id,100,1,1);
call gainit(id,10000,encoding); 

niter = 1000;
do i = 1 to niter;
 call garegen(id);
 call gagetval(value, id);
end;
call gagetmem(mem, value, id, 1);

print (p[loc(mem)])[l="members"],value[l = "Max Value:"] ;
call gaend(id);
quit;




OUTPUT:

members
PEANUTS
CHEESE
BEER


Max Value:
42

SAS Employee
Posts: 448

Re: Optimization Problem

GA provides no measure of optimality for the solution it returns, and so you should probably use that only when a specialized solver is not available.  In particular, if you are going to use IML to solve a MILP, you might as well call the MILPSOLVE subroutine, which invokes the same MILP solver that is accessible from PROC OPTMODEL.  The PROC OPTMODEL syntax will more closely match your algebraic formulation.

Contributor
Posts: 59

Re: Optimization Problem

Unfortunately i don't have SAS/OR, only SAS/IML. Can i solve this optimization with SAS/IML?

Please see attached file.  Thank you


Optimization.jpg
Contributor
Posts: 59

Re: Optimization Problem

Unfortunately i don't have SAS/OR, only SAS/IML. I attached more normal explanation. please see it. I have a lot of itemsets(X), they can be different bu size, for example, in one you can gave only milk, in other you have milk and sugar.

i have two decision variables to be optimized P and Q.(they binary variables, and got two values : 1 or zero, 1 means that product was choosen). Thank you for your help

 

 


Optimization.jpg
Super User
Posts: 9,769

Re: Optimization Problem

Yeah. GA can't guarantee the optimal solution. But if the number of items is not too big, I think GA is ok .
And change number of iteration in my code to be bigger and make sure to get better solution.

I still am not understand Q1>=P1 .
Q1,P1  in (0 ,1) ?
How do you define P1=1 , when x1=both cola and peanuts ?

Contributor
Posts: 59

Re: Optimization Problem

That means when i choose itemset X1, and this itemset adds profit i.e P1=1, then every product inside itemset X1 have to be choosen, i.e i itemset X1 has three products then all Q1, Q2 and Q3 have to be equal to 1. P and Q decision binary variables. The problem that i have to data sets, one that include all itemsets and the second all products and their cost. I really dont know if sas can solve this problem. Maybe try other language?
Super User
Posts: 9,769

Re: Optimization Problem

So My GA code is doing that. I also want see @rob post OR code, that might be your best choice.
Contributor
Posts: 59

Re: Optimization Problem

Thank you for your help

SAS Employee
Posts: 448

Re: Optimization Problem

Here it is in PROC OPTMODEL with the MILP solver:

proc optmodel;
   set ITEMS = /cola peanuts cheese beer/;
   num cost {ITEMS} = [5 3 1 4];
   set ITEM_SETS = 1..3;
   set <str> X {ITEM_SETS};
   X[1] = /cola peanuts/;
   X[2] = /peanuts cheese/;
   X[3] = /peanuts beer/;
   num m {ITEM_SETS} = [10 20 30];

   var P {ITEM_SETS} binary;
   var Q {ITEMS} binary;
   con SelectThreeItems:
      sum {i in ITEMS} Q[i] <= 3;
   con SetImpliesItem {s in ITEM_SETS, i in X[s]}:
      P[s] <= Q[i];
   max Z = sum {s in ITEM_SETS} m[s] * P[s] - sum {i in ITEMS} cost[i] * Q[i];

   solve;
   print P Q;
quit;

SAS Output

Solution Summary
Solver MILP
Algorithm Branch and Cut
Objective Function Z
Solution Status Optimal
Objective Value 42
   
Relative Gap 0
Absolute Gap 0
Primal Infeasibility 0
Bound Infeasibility 0
Integer Infeasibility 0
   
Best Bound 42
Nodes 1
Iterations 4
Presolve Time 0.00
Solution Time 0.00

[1] P
1 0
2 1
3 1

[1] Q
beer 1
cheese 1
cola 0
peanuts 1
Ask a Question
Discussion stats
  • 11 replies
  • 635 views
  • 1 like
  • 3 in conversation