MILP problem which is a function of time
조회 수: 3 (최근 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
채택된 답변
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
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.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File 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!