0001 function om = userfcn_direction_mll_formulation(om,mpopt,args)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 define_constants;
0014 mpc = om.get_mpc();
0015 dir_mll = mpc.dir_mll;
0016
0017
0018 idx_vl = isload(mpc.gen);
0019 n_vl = sum(idx_vl);
0020 n_g = size(mpc.gen,1)-n_vl;
0021 if length(dir_mll) ~= n_vl
0022 error_msg = ['The number of dispatchable loads is not equal to the '...
0023 'length of the direction vector'];
0024 error(error_msg);
0025 end
0026
0027 om.add_var('alpha',1,0,0,inf);
0028
0029
0030
0031 Pl0 = -mpc.gen(idx_vl,PG)/mpc.baseMVA;
0032
0033 int_idx_disp_loads = find(idx_vl);
0034 idx_A_dirmll_i = [1:n_vl 1:n_vl]';
0035 idx_A_dirmll_j = [int_idx_disp_loads' (n_g+n_vl+1)*ones(1,n_vl)]';
0036 vals_A_dirmll = [ones(n_vl,1);dir_mll];
0037 A_dirmll = sparse(idx_A_dirmll_i,idx_A_dirmll_j,vals_A_dirmll,n_vl,n_g+n_vl+1);
0038 om.add_lin_constraint('dir_mll',A_dirmll,-Pl0,-Pl0,{'Pg','alpha'});
0039
0040 om.add_quad_cost('alpha_cost',[],-1,0,{'alpha'});
0041
0042
0043
0044 idx_var_gen = find(mpc.dir_var_gen_all);
0045 if ~isempty(idx_var_gen)
0046 Pg0 = mpc.gen(idx_var_gen,PG)/mpc.baseMVA;
0047 nb_var_gen = length(idx_var_gen);
0048 idx_A_var_gen_i = [1:nb_var_gen 1:nb_var_gen]';
0049 idx_A_var_gen_j = [idx_var_gen;(n_g+n_vl+1)*ones(nb_var_gen,1)];
0050 vals_A_var_gen = [ones(nb_var_gen,1);-nonzeros(mpc.dir_var_gen_all)];
0051 A_var_gen = sparse(idx_A_var_gen_i,idx_A_var_gen_j,vals_A_var_gen,nb_var_gen,n_g+n_vl+1);
0052 om.add_constraints('dir_var_gen',A_var_gen,...
0053 Pg0,Pg0,{'Pg','alpha'});
0054 end