The problem is feasible, but the value of the objective function reached the Upper bound #1338
Unanswered
Arsam99
asked this question in
Problems using YALMIP
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
recently i have been reading an article where I need to solve a defender-attacker-defender model as tri-level optimization, the first level became master problem and the second level with third level become subproblem as max-min bilevel problem.
base on dual theory the max-min problem became a single level max that i have strugling to solve it.
the below code is single level max subproblem that is feasible but value of objective function reach upper bound for every input value.
please check my model and give me some advise.
clc
clear
close all
%% sets and variables
L = 38;
l = (1:38)';
N = 24;
n = (1:24)';
j = 32;
R = 2;
S = 3;
iter = 1;
Gj = (1:32)';
ol = [1;1;1;2;2;3;3;4;5;6;7;8;8;9;9;10;10;11;11;12;12;13;14;15;15;15;...
15;16;16;17;17;18;18;19;19;20;20;21];
dl = [2;3;5;4;6;9;24;9;10;10;8;9;10;11;12;11;12;13;14;13;23;23;16;16;...
21;21;24;17;19;18;22;21;21;20;20;23;23;22];
Jn =cell(N,1);
Jn{1} = (1:4)' ;
Jn{2} = (5:8)' ;
Jn{7} = (9:11)' ;
Jn{13} = (12:14)' ;
Jn{15} = (15:20)' ;
Jn{16} = 21 ;
Jn{18} = 22 ;
Jn{21} = 23 ;
Jn{22} = (24:29)';
Jn{23} = (30:32)';
bigM = 1e5;
Pl_bar = [175;175;175;175;175;175;400;175;175;175;175;175;175;...
400;400;400;400;500;500;500;500;500;500;500;...
500;500;500;500;500;500;500;500;500;500;500;500;500;500];
delta_bar_cap = 2piones([N,1]);
Dn = [108;97;180;74;71;136;125;171;175;195;0;0;265;194;317;100;...
0;33;181;128;0;0;0;0];
UB = 1e5; %Upper bound
% vl: attack decision variable, 0 for attacked, 1 for otherwise
vl = binvar(L,1,'full');
% dn: load shedding at node n
dn = sdpvar(N,1,'full');
% delta_n = phase angle at node n
delta_n = sdpvar(N,1,'full');
% gj: generation level of generator j
gj = sdpvar(j,1,'full');
% pl: power flow on line l
pl = sdpvar(L,1,'full');
%% SubProblem
xl = randi([5 50],L,1)
random_indices2 = randperm(L, R);
z_hat = zeros([L,1]);
z_hat(random_indices2,1)=1;
CCGSubCon39 = [];
CCGSubCon40 = [];
L_alpha2 = zeros([L,1]);
L_beta2 = zeros([L,1]);
l_iter2 = 1;
for l_iter2=1:L
if z_hat(l_iter2,1) == 0
L_alpha2(l_iter2,iter) = l_iter2;
end
if z_hat(l_iter2,1) == 1
L_beta2(l_iter2,iter) = l_iter2;
end
end
%% define SP variables
%objective function variables
phi_big = sdpvar(L,1,'full');
phi_small = sdpvar(L,1,'full');
beta = sdpvar(L,1,'full');
tau_small = sdpvar(L,1,'full');
gamma_small = sdpvar(numel(Gj),1,'full');
xi_small = sdpvar(N,1,'full');
chi_small = sdpvar(N,1,'full');
alpha_sp = sdpvar(N,1,'full');
theta_small = sdpvar(L,1,'full');
rho_small = sdpvar(L,1,'full');
mu_small = sdpvar(L,1,'full');
Lambda_small = sdpvar(N,1,'full');
%% constraints
CCGSubCon = [sum(1-vl(:,iter))<=S]:'con36'
for l_iter9 = 1:L
if z_hat(l_iter9)==1
vl(l_iter9)=1
end
end
term38 = sdpvar(L,1,'full');
term39 = sdpvar(L,1,'full');
term3839 = sdpvar(N,1,'full');
l_iter3 = 1;
for l_iter3 = 1:L
ol1 = ol(l_iter3)
dl1 = dl(l_iter3)
for n8=1:N
if L_beta2(l_iter3)
=0=0term38(L_beta2(l_iter3)) = mu_small(L_beta2(l_iter3)) + phi_big(L_beta2(l_iter3)) + phi_small(L_beta2(l_iter3))
end
if L_alpha2(l_iter3)
term39(L_alpha2(l_iter3)) = (beta(L_alpha2(l_iter3)) + tau_small(L_alpha2(l_iter3)))*xl(L_alpha2(l_iter3)) + theta_small(L_alpha2(l_iter3)) + rho_small(L_alpha2(l_iter3))
end
end
CCGSubCon = [CCGSubCon,...
[1e-7 <= sum(term38) + sum(term39) + sum(term3839)<= 1e-5]:'con38,39']
CCGSubCon39 = [];
n4 = 1
for n4 = 1:N
if n4==1
for j=1:numel(Jn{1})
CCGSubCon39 = [CCGSubCon39,...
(gamma_small(j) + Lambda_small(n4) <= -1e-5):['con39-b' num2str(n4) '-j' num2str(j)]]
end
end
end
CCGSubCon = [CCGSubCon, CCGSubCon39];
% CCGSubCon40 = [];
term401 = sdpvar(L,1,'full');
term402 = sdpvar(L,1,'full');
term403 = sdpvar(L,1,'full');
term404 = sdpvar(L,1,'full');
term405 = sdpvar(N,1,'full');
l_iter2 = 1;
n5 = 1
for n5 = 1:N
for l_iter2=1:L
dll = dl(l_iter2);
oll = ol(l_iter2);
if dll == n5
if L_beta2(l_iter2)
= 0= 0term401(L_beta2(l_iter2)) = mu_small(L_beta2(l_iter2))
end
if L_alpha2(l_iter2)
term404(L_alpha2(l_iter2)) = (beta(L_alpha2(l_iter2))+tau_small(L_alpha2(l_iter2)))
end
end
if oll == n5
if L_beta2(l_iter2)
= 0= 0term402(L_beta2(l_iter2)) = -mu_small(L_beta2(l_iter2))
end
if L_alpha2(l_iter2)
term403(L_alpha2(l_iter2)) = -(beta(L_alpha2(l_iter2))+tau_small(L_alpha2(l_iter2)))
end
end
term405(n5) = (xi_small(n5)+chi_small(n5))*xl(l_iter2)
end
end
CCGSubCon40 = [1e-7 <= sum(term401) + sum(term402) + sum(term403) + sum(term404) + sum(term405)<= 1e-5]
CCGSubCon = [CCGSubCon, CCGSubCon40]
CCGSubCon = [CCGSubCon,...
sum(Lambda_small + alpha_sp) <= 1]
CCGSubCon = [[CCGSubCon],...
[-1e10<= gamma_small<=0]:'con42']
CCGSubCon = [[CCGSubCon],...
[-1e10<= xi_small<=0, -1e10<= alpha_sp<=0]:'con43']
CCGSubCon = [[CCGSubCon],...
[+1e10>=chi_small>=0]:'con44']
for l_iter6=1:L
if L_alpha2(l_iter6)~=0
CCGSubCon = [[CCGSubCon],...
[beta(L_alpha2(l_iter6))<=0, theta_small(L_alpha2(l_iter6))<=0, tau_small(L_alpha2(l_iter6))>=0, rho_small(L_alpha2(l_iter6))>=0]:['con45-L' num2str(L_alpha2(l_iter6))]]
end
end
for l_iter4 = 1:L
if L_beta2(l_iter4)~=0
CCGSubCon = [[CCGSubCon],...
[phi_big(L_beta2(l_iter4))<=0, phi_small(L_beta2(l_iter4))>=0]:['con46-L' num2str(L_beta2(l_iter4))]]
end
end
A1 = sdpvar(L,1,'full');
A2 = sdpvar(L,1,'full');
A3 = sdpvar(L,1,'full');
A4 = sdpvar(L,1,'full');
term1 = sdpvar(L,1,'full');
term2 = sdpvar(L,1,'full');
term3 = sdpvar(numel(Gj),1,'full');
term4 = sdpvar(N,1,'full');
term5 = sdpvar(N,1,'full');
term6 = sdpvar(L,1,'full');
SPobjCon = []
for l_iter7 = 1:L
la = L_alpha2(l_iter7);
lb = L_beta2(l_iter7);
if lb~=0
term1(L_beta2(l_iter7)) = Pl_bar(l_iter7)(phi_big(l_iter7)-phi_small(l_iter7))
end
if la~=0
term2(l_iter7) = bigM(beta(l_iter7)-tau_small(l_iter7)+A2(l_iter7)-A1(l_iter7))
SPobjCon = [SPobjCon,...
A1>=0,...
A1<=beta(l_iter7)+bigM*(1-vl(l_iter7,iter)),...
A1>= -bigMvl(l_iter7,iter),...
A1(l_iter7) <= 0,...
A2(l_iter7) <= tau_small(l_iter7),...
A2(l_iter7) >= tau_small(l_iter7)-bigM(1-vl(l_iter7,iter)),...
A2 <= bigM*vl(l_iter7,iter),...
A2 >= 0]
end
for j3=1:numel(Gj)
term3(j3) = Gj(j3)*gamma_small(j3)
end
for n7=1:N
term4(n7) = delta_bar_cap(n7)*(xi_small(n7)-chi_small(n7))
term5(n7) = Dn(n7)*alpha_sp(n7)
end
%%
SPObj = sum(term1)+sum(term2)+sum(term3)+sum(term4)+sum(term5)+sum(term6)
CCGSubCon = [CCGSubCon,SPobjCon ]
CCGSubCon = [CCGSubCon,...
-1e5<=A1<=1e5,-1e5<=A2<=1e5,-1e5<=A3<=1e5,-1e5<=A4<=1e5,...
-1e5<=term1<=1e5,-1e5<=term2<=1e5,-1e5<=term3<=1e5,-1e5<=term4<=1e5,-1e5<=term5<=1e5]
sol8 = optimize([CCGSubCon,-inf<=SPObj<=UB ], -SPObj,sdpsettings('solver','cplex','verbose',0))
if sol8.problem==0
SPObj_val = value(SPObj)
V_vector1 = value(vl(:,1));
phibigval = value(phi_big);
ohismall = value(phi_small);
betaval = value(beta);
tauval = value(tau_small);
gammasmalval = value(gamma_small);
xismallval = value(xi_small);
chival = value(chi_small);
alphaspval = value(alpha_sp);
thetaval = value(theta_small);
rhoval = value(rho_small);
muval = value(mu_small);
lambdaval = value(Lambda_small);
[l L_beta2 value(mu_small) value(phi_big) value(phi_small)]
[l L_alpha2 value(beta) value(theta_small) value(tau_small) value(rho_small)]
[l V_vector1 z_hat]
end
Beta Was this translation helpful? Give feedback.
All reactions