-
Notifications
You must be signed in to change notification settings - Fork 0
/
bus_WaitingTimeOracle.m
33 lines (30 loc) · 1.13 KB
/
bus_WaitingTimeOracle.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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function optgappct = find_optgap(x)
% this code computes the optimality gap at a given x for the discrete quadratic
% problem
optgappct = norm(x);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function optgappct = bus_optgap(x)
% this code computes the optimality gap at a given x for the d-bus scheduling
% problem with lambda = 10, gamma = 100
sum2 = 0;
lambda = 10;
gamma = 100;
sortedx = sort(x);
d = size(x,1);
for j = 1 : ( d + 1 )
if ( ( j > 1 ) && ( j < (d + 1) ) )
sum2 = sum2 + ( sortedx (j) - sortedx(j-1) )^2;
elseif ( j == 1 )
sum2 = sum2 + ( sortedx(j) - 0 )^2;
else
sum2 = sum2 + ( gamma - sortedx(j-1) )^2;
end
end
f_x = ( lambda / 2 ) * sum2;
opt_value = lambda * gamma^2 / ( 2 );
optgappct = 100 * ( f_x / (opt_value)) - 1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%