-
Notifications
You must be signed in to change notification settings - Fork 1
/
runOptimization.m
48 lines (35 loc) · 1001 Bytes
/
runOptimization.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
%% Run optimization
fprintf("Preparing data and parameters.\n");
%% Setup problem parameters/data
p = Initialization();
p.b = p.b*2;
p.s = p.b/2; % correct for supply infeasibility
% convert to column matrices
p.dO = p.dO(:);
p.dD = p.dD(:);
p.cO = p.cO(:);
p.cD = p.cD(:);
p.dOinc = p.dOinc(:);
p.dDinc = p.dDinc(:);
%% Setup optimization parameters
opts = struct();
opts.nIter = 5;
opts.innerIter = 1000;
opts.c0 = 5;
opts.beta = 5;
opts.gamma = 50;
%% Run algorithm
nConstraints = 2*p.N*p.N*p.T + 2*p.N*p.T + 1;
u_init = zeros(nConstraints, 1);
x_init = ones(2*p.N*p.N*p.T, 1);
fprintf("Starting optimization.\n")
[x, u, history] = augLagrangeMethod(p, opts, u_init, x_init);
%% plot results
objValues = vertcat(history(:).objectiveValues);
figure;
semilogy(objValues);
xlabel("iterations");
ylabel("objective value ($)");
title(sprintf("Objective value for %s (\\alpha_O=%0.2f; \\alpha_D=%0.2f)", p.system, p.alphaO, p.alphaD));
%% Save data
save(sprintf("results-%s.mat", datetime));