MILP problem which is a function of time

10 次查看(过去 30 天)
i have solved my MILP problem using intlinprog, that part was fine. I am now extending the same problem but now it is depedent on time (i.e. I was to solve the optimization problem for each hour time step).
my question is: How do I extend my objective function and constraints to be time depedent?
thank you
  9 个评论
sibabalo noludwwe
sibabalo noludwwe 2020-4-14
Thanks ill try that. May you refer me to a matlab site of how i can achieve to use my previous results for the next if possible
Ameer Hamza
Ameer Hamza 2020-4-14
Please see my answer below for explanation.

请先登录,再进行评论。

采纳的回答

Ameer Hamza
Ameer Hamza 2020-4-14
I have modified this example from the documentation: https://www.mathworks.com/help/optim/ug/intlinprog.html#mw_cd504ff9-629b-402f-acb0-7aa7c7926290 to explain the effect of using the solution from the previous time step as an initial point for the next iteration. In the following example, I used a for loop to solve an MILP problem 20 times, each time slightly varying the objective function.
First, check the code which does not use the solution from the last iteration as an initial guess of next iteration. The initial guess is always the same.
Aeq = [22 13 26 33 21 3 14 26
39 16 22 28 26 30 23 24
18 14 29 27 30 38 26 26
41 26 28 36 18 38 16 26];
beq = [ 7872
10466
11322
12058];
N = 8;
lb = zeros(N,1);
intcon = 1:N;
f = [2 10 13 17 7 5 7 3];
x0 = [8 62 23 103 53 84 46 34];
opts = optimoptions('intlinprog', 'Display', 'off');
tic
for i=1:20
f(3:5) = randi([1 15], 1, 3); % objective function is changed in each iteration
[x2,fval2] = intlinprog(f,intcon,[],[],Aeq,beq,lb,[],x0,opts);
end
toc
Time of execution
Elapsed time is 24.518613 seconds.
The following code update the initial guess
Aeq = [22 13 26 33 21 3 14 26
39 16 22 28 26 30 23 24
18 14 29 27 30 38 26 26
41 26 28 36 18 38 16 26];
beq = [ 7872
10466
11322
12058];
N = 8;
lb = zeros(N,1);
intcon = 1:N;
f = [2 10 13 17 7 5 7 3];
x0 = [8 62 23 103 53 84 46 34];
opts = optimoptions('intlinprog', 'Display', 'off');
tic
for i=1:20
f(3:5) = randi([1 15], 1, 3);
[x2,fval2] = intlinprog(f,intcon,[],[],Aeq,beq,lb,[],x0,opts);
x0 = x2;
end
toc
Time of execution
Elapsed time is 8.489186 seconds.
This example shows a speed gain of about 3 times. The actual gain can vary from problem to problem, but still, it is better than just using a random initial guess.
  19 个评论
Ameer Hamza
Ameer Hamza 2020-4-30
This is quite strange behavior. I couldn't see any reason why this should be happening. I recommend starting two instances of MATLAB and run both code line by line. You will definitely see the difference at some point.
sibabalo noludwwe
I am running the same code i just comment the for loop and bring it back in. So its the code

请先登录,再进行评论。

更多回答(1 个)

sibabalo noludwwe
sibabalo noludwwe 2020-4-30
LP: Optimal objective value is -4.403333.
Branch and Bound:
nodes total num int integer relative
explored time (s) solution fval gap (%)
3 1.95 1 -3.750000e+00 9.403509e+00
4 2.67 2 -3.930000e+00 5.409060e+00
5 3.13 2 -3.930000e+00 0.000000e+00
Optimal solution found.
Intlinprog stopped because the objective value is within a gap tolerance of the optimal value,
options.AbsoluteGapTolerance = 0 (the default value). The intcon variables are integer within tolerance,
options.IntegerTolerance = 1e-05 (the default value).
Number of critical loads restored = 3.930000
Control variables =
Columns 1 through 11...... and so on
for the other time ste this is the solution
No feasible solution found.
Intlinprog stopped because no point satisfies the constraints.
Number of critical loads restored =
Control variables =

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by