-
Notifications
You must be signed in to change notification settings - Fork 0
/
QPSolverEuropeAfrica.m
50 lines (38 loc) · 1.06 KB
/
QPSolverEuropeAfrica.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
49
50
function opt_y = QPSolverEuropeAfrica(euc,afc,gwp)
%Scaling down values
euc = euc/1e+10;
afc= afc/1e+10;
% define decision variables
y = sdpvar(size(euc,1),size(afc,1),'full');
% define objective function
objective = sum(gwp'*y + gwp'*y.^2);
% initialize constraints
constraints = [];
% add nonnegativity constraints
constraints = [constraints, y>=0];
%Availability constraint
for j=1:size(euc,1)
constraints = [constraints, sum(y(j,:)) <= euc(j)];
end
%Demand constraint
for i=1:size(afc,1)
constraints = [constraints, sum(y(:,i)) == afc(i)];
end
% specify solver settings
opt_settings = sdpsettings('solver', 'gurobi', 'verbose', 0);
% run solver
diagnosis = optimize(constraints, objective, opt_settings);
% display solver report
disp('solver report:');
disp(diagnosis);
% retrieve and display optimal objective value
disp('optimal objective value:');
opt_objective = value(objective);
disp(opt_objective);
% retrieve and display optimal solution values
disp('optimal solution values:');
opt_y = value(y);
disp(opt_y);
%Scaling back values up
opt_y = opt_y*1e+10;
end