0001 function om = userfcn_direction_mll_formulation(om,args)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 define_constants;
0014 mpc = get_mpc(om);
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_vars(om,'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_constraints(om,'dir_mll',A_dirmll,-Pl0,-Pl0,{'Pg','alpha'});
0039
0040 om = add_costs(om,'alpha_cost',struct('Cw',-1),{'alpha'});
0041
0042
0043
0044 idx_var_gen = find(mpc.dir_var_gen_all);
0045 if ~isempty(idx_var_gen)
0046
0047 om = add_vars(om,'beta',1,0,0,inf);
0048 Pg0 = mpc.gen(idx_var_gen,PG)/mpc.baseMVA;
0049 nb_var_gen = length(idx_var_gen);
0050 idx_A_var_gen_i = [1:nb_var_gen 1:nb_var_gen]';
0051 idx_A_var_gen_j = [idx_var_gen;(n_g+n_vl+1)*ones(nb_var_gen,1)];
0052 vals_A_var_gen = [ones(nb_var_gen,1);-nonzeros(mpc.dir_var_gen_all)];
0053 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);
0054 om = add_constraints(om,'dir_var_gen',A_var_gen,...
0055 Pg0,Pg0,{'Pg','beta'});
0056
0057
0058 om = add_costs(om,'beta_cost',struct('Cw',-1e3),{'beta'});
0059
0060 A_beta_alpha = [-1 1];
0061 om = add_constraints(om,'beta_alpha',A_beta_alpha,-Inf,0,{'alpha','beta'});
0062 end