How to use optimization variable in if condition and how to multiple an optimization variable with an optim. expression?

10 views (last 30 days)
Hello everybody, I'm trying to solve a unit commitment problem using intlinprog with problem-based optimization method. I have two problems. 1) I need to multiply an optimization variable that shows the commitment status of any unit with an optimization expression that shows the time off and I'm getting an error: "Error using optim.internal.problemdef.Times.getTimesOperator At least one argument must be numeric."
ans = state(i,j).*t_off(i,j)
Is there any way to multiply an optimization variable with an optimization expression?
2) The most serious problem I have encountered when I'm trying to create a logical operator in an if, using the optimization expression toff, and I'm getting an error: "Conversion to logical from optim.problemdef.OptimizationConstraint is not possible" . What I'm trying to do for example :
if toff<10
statement1
end
if toff>=10
statement2
end
Does anyone have any ideas that could help??? Thanks in advance

Answers (1)

Mary Fenelon
Mary Fenelon on 2 May 2018
Multiplying two optimization variables results in a quadratic expression and these aren't allowed in a mixed-integer linear program.
There is an example of a unit commitment problem here that might give you some ideas on how to formulate the constraint you need without multiplying variables. There is a more complex version of a unit commitment problem here .
Look here for a way to model the logical constraint.
  3 Comments
Mary Fenelon
Mary Fenelon on 4 May 2018
Yes, you can specify linear constraints to model those logical constraints using the same pattern x - My <= 0. For the first:
  • t_i_j - M1*(1-state_i_j) <= 0 where 0 <= t_i_j <= M1
  • t_i_j - toff_i_j-1 - 1 - M2*state_i_j <= 0 where 0 <= t_i_j - t_i_j-1 - 1 <= M2
For the second, you need to add a binary variable y that is 1 when t > 10:
  • (t - 10) - M3*y <= 0 where 0 <= t - 10 <= M3
Use y to compute the value of C.
Sanyam Maheshwari
Sanyam Maheshwari on 21 Jul 2020
I am also facing the issue with my optimization problem.
global SL V p r k m n C Z s
SL = [0.75 0.75 0.75 0.75];
V = 94100;
p = [0.07,0.18,0.2,0.3];
r = [55 55 55 55;
47 47 47 47;
45 45 45 45;
49 49 49 49];
k = [33 33 33 33;
28 28 28 28;
29 29 29 29;
30 30 30 30];
m = 4;
n= 4;
C = [78,69,70,73;
64,68,56,59;
34,39,42,41;
52,47,48,45];
Z =[250 250 250 250;
320 320 320 320;
440 440 440 440;
350 350 350 350];
s = [110,95,99,100];
global SL V r k m n C Z s
% Generating Variables
Q = optimvar('Q',m,n,'LowerBound',0,'UpperBound',Z);
b = optimvar('b',m,n,'Type','integer','LowerBound',0,'UpperBound',1);
rng
y = rand(4);
x = sym('x',[4,1]);
% limit of integration
l = y*Q;
q = sum(l(:));
% Constraints
% Budget Constraint
B = C*b*y*Q;
budget = sum(B(:)) <= V;
% normal constraint
normal = int(normpdf(x, 400, 100),q,Inf) <=SL;
% each product connects to exactly one supplier
con4 = sum(b,1) == ones(m,1)';
% Objective Function:-
% optimization problem
demandprob = optimproblem;
% Revenue
revenue = sum(s*b*x,1);
% Cost
cost = sum(sum(C*b*y*Q,1),2);
%Salvage
salvage = sum(b*r*(sum(sum(y*Q - x,1),2)),1);
% Revenue when demand is more
revenue2 = sum(s*b*y*Q,2);
% Salvage when demand is more
salvage2 = sum(b*k*(x - sum(sum(y*Q,1),2)),1);
% The objective function to maximize the below Expected Profit
demandprob.Objective = int(((revenue - cost + salvage).*normpdf(x, 400, 100)),0,q); + int(((revenue2 - cost - salvage2).*normpdf(x, 400, 100)),q,Inf);
% Include the constraints in the problem.
demandprob.Constraints.budget = budget;
demandprob.Constraints.normal = normal;
demandprob.Constraints.con4 = con4;
opts = optimoptions('intlinprog','Display','off','PlotFcn',@optimplotmilp);
% Call the solver to find the solution.
[sol,fval,exitflag,output] = solve(demandprob,'options',opts);
Also I want to maximize this optimization problem
What should I do further.
please help

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!