Dear Johan ,
First of all, thank you for the great job you are doing with Yalmip.
I have an optimization problem that I am not sure how to pose, and if it can be solved in a linear or quadratic way using YALMIP + Gurobi. I write the problem without objective because the main issue is whether it is possible to write some constraints or not.
I have 3 products (P1, P2, and P3). Their sum can be maximum Pmax e.g. Pmax=30. Assume their initial value is given e.g. P1=10, P2=10, P3=10.
At every moment in time (e.g. from 1 to 10 ), I have to check how many products I have and:
- if I have enough P1 (P1>=P1_take), I have to take a certain quantity of P1_take.
- if I have not enough P1(P1<=(P1_take-small_number)), and if I have enough P2 (P2>=P2_take) I have to take the quantity of P2_take.
- if I have not enough P1(P1<=(P1_take-small_number)), and if I have not enough P2 (P2<=(P2_take-small_number)), and if I have enough P3(P3>=P3_take) I have to take the quantity of P3_take.
I remark that, for example, if I have enough P1 I have to take only P1_take, even if P2>=P2_take and P3>=P3_take.
Also, I know that the use of "small_number" does not make the problem very robust (every alternative is welcome).
I do not know how (and if it is possible) to write the above mentioned constraints.
I worked out a code draft without the if-constraints, to show how I am approaching the problem, but I am not sure how to continue.
T=10; %Time steps max
P_max=30;
P1_take=2;
P2_take=1;
P3_take=0.5;
P1=sdpvar(T,1,'full');
P1_bounds=[(0 <= P1):'LB_P1', (P1 <=P_max):'UB_P1'] ;
P2=sdpvar(T,1,'full');
P2_bounds=[(0 <= P2):'LB_P2', (P2 <=P_max):'UB_P2'] ;
P3=sdpvar(T,1,'full');
P3_bounds=[(0 <= P3):'LB_P3', (P3 <=P_max):'UB_P3'] ;
Take1_bin=binvar(T,1); %Binary variable deciding if P1 is taken
Take2_bin=binvar(T,1); %Binary variable deciding if P2 is taken
Take3_bin=binvar(T,1); %Binary variable deciding if P3 is taken
Take=sdpvar(T,1,'full'); %variable determining the quantity taken
Take_bounds=[(0 <= Take):'LB_Take', (Take <=P1_take):'UB_Take'] ; %P1_take is the biggest quantity that can be taken, so it is the upper bound
Bounds=[P1_bounds,P2_bounds,P3_bounds,Take_bounds];
Cons0=[P1(1,1) == 10 , P2(1,1) == 10 ,P3(1,1) == 10 ]:'P_initial';
Cons1=[(P1 + P2 + P3) <= P_max.*ones(T,1)]:'Sum_P';
Cons2=[Take == Take1_bin.*P1_take + Take2_bin.*P2_take + Take3_bin.*P3_take ]:'Take';
Cons3=[(Take1_bin + Take2_bin + Take3_bin) <= ones(T,1) ]:'Sum_Take_bin'; %Maximum one quantity should be taken
Constraints=[Bounds, Cons0,...
Cons1,...
Cons2,...
Cons3...
];
Options =sdpsettings('verbose',2,'solver','gurobi','debug',1);
Solution=optimize(Constraints,[],Options);
Thank you very much for your time.