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
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.
The problem thay i don't have sas SAS/OR, only SAS/IML. Can i use it to solve optimization?
Thank you
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
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.
Unfortunately i don't have SAS/OR, only SAS/IML. Can i solve this optimization with SAS/IML?
Please see attached file. Thank you
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
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 ?
Thank you for your help
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 |
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.