├── examples.m ├── library ├── @stateV1 │ ├── change_parameters.m │ ├── directionaldiff.m │ ├── edge_list.m │ ├── fixed_points_nearby.m │ ├── fx.m │ ├── grad_lyapunov.m │ ├── hessian_lyapunov.m │ ├── initiate_state.m │ ├── jacobian_f.m │ ├── lyapunov_energy.m │ ├── numeric_grad_lyapunov.m │ ├── numeric_hessian_lyapunov.m │ ├── onoff.m │ ├── onoff_energy.m │ ├── pack_x.m │ ├── power_flow.m │ ├── power_flow_energy.m │ ├── skew_matrix.m │ ├── solve_dynamic.m │ ├── stateV1.m │ ├── turn_off_lines.m │ └── unpack_x.m └── matpower5.1 │ ├── @opf_model │ ├── display.m │ ├── get_mpc.m │ └── opf_model.m │ ├── @opt_model │ ├── add_constraints.m │ ├── add_costs.m │ ├── add_vars.m │ ├── build_cost_params.m │ ├── compute_cost.m │ ├── describe_idx.m │ ├── display.m │ ├── get.m │ ├── getN.m │ ├── get_cost_params.m │ ├── get_idx.m │ ├── getv.m │ ├── linear_constraints.m │ ├── opt_model.m │ └── userdata.m │ ├── AUTHORS │ ├── Contents.m │ ├── LICENSE │ ├── MATPOWER-manual-6.0b1.pdf │ ├── README │ ├── README.txt │ ├── add_userfcn.m │ ├── bustypes.m │ ├── case118.m │ ├── case1354pegase.m │ ├── case14.m │ ├── case2383wp.m │ ├── case24_ieee_rts.m │ ├── case2736sp.m │ ├── case2737sop.m │ ├── case2746wop.m │ ├── case2746wp.m │ ├── case2869pegase.m │ ├── case30.m │ ├── case300.m │ ├── case3012wp.m │ ├── case30Q.m │ ├── case30pwl.m │ ├── case3120sp.m │ ├── case3375wp.m │ ├── case39.m │ ├── case4gs.m │ ├── case5.m │ ├── case57.m │ ├── case6ww.m │ ├── case89pegase.m │ ├── case9.m │ ├── case9241pegase.m │ ├── case9Q.m │ ├── case9target.m │ ├── case_ieee30.m │ ├── case_info.m │ ├── caseformat.m │ ├── cdf2mpc.m │ ├── clp_options.m │ ├── compare_case.m │ ├── connected_components.m │ ├── cpf_corrector.m │ ├── cpf_default_callback.m │ ├── cpf_p.m │ ├── cpf_p_jac.m │ ├── cpf_predictor.m │ ├── cplex_options.m │ ├── d2AIbr_dV2.m │ ├── d2ASbr_dV2.m │ ├── d2Ibr_dV2.m │ ├── d2Sbr_dV2.m │ ├── d2Sbus_dV2.m │ ├── dAbr_dV.m │ ├── dIbr_dV.m │ ├── dSbr_dV.m │ ├── dSbus_dV.m │ ├── dcopf.m │ ├── dcopf_solver.m │ ├── dcpf.m │ ├── dd50cdf.m │ ├── define_constants.m │ ├── docs │ ├── CHANGES │ ├── CHANGES.txt │ ├── TN1-OPF-Auctions.pdf │ ├── TN2-OPF-Derivatives.pdf │ └── manual.pdf │ ├── e2i_data.m │ ├── e2i_field.m │ ├── ext2int.m │ ├── extract_islands.m │ ├── extras │ ├── misc │ │ ├── check_feasibility.m │ │ ├── checklimits.m │ │ ├── loss2bus.m │ │ ├── makeBloss.m │ │ └── make_opf_feasible.m │ ├── reduction │ │ ├── BuildYMat.m │ │ ├── DefBoundary.m │ │ ├── DoReduction.m │ │ ├── EQRODAssignment.m │ │ ├── Example_9bus.m │ │ ├── GenerateBCIRC.m │ │ ├── Initiation.m │ │ ├── LoadRedistribution.m │ │ ├── MPReduction.m │ │ ├── MakeMPCr.m │ │ ├── MapBus.m │ │ ├── MoveExGen.m │ │ ├── Network_Reduction_Toolbox.pdf │ │ ├── PartialNumLU.m │ │ ├── PartialSymLU.m │ │ ├── PivotData.m │ │ ├── PreProcessData.m │ │ ├── RODAssignment.m │ │ ├── SelfLink.m │ │ └── TinneyOne.m │ ├── sdp_pf │ │ ├── addToA.m │ │ ├── case2local.m │ │ ├── case3sc.m │ │ ├── combineCost.m │ │ ├── combineMaxCliques.m │ │ ├── documentation │ │ │ ├── lesieutre_molzahn_borden_demarco-allerton2011.pdf │ │ │ ├── molzahn_dawar_lesieutre_demarco-irep2013.pdf │ │ │ ├── molzahn_demarco_lesieutre-pfcondition_tech_report.pdf │ │ │ ├── molzahn_holzer_lesieutre_demarco-large_scale_sdp_opf.pdf │ │ │ ├── molzahn_lesieutre_demarco-globaloptcond.pdf │ │ │ ├── molzahn_lesieutre_demarco-pfcondition.pdf │ │ │ └── sdp_pf_documentation.pdf │ │ ├── insolvablepf.m │ │ ├── insolvablepf_limitQ.m │ │ ├── insolvablepfsos.m │ │ ├── insolvablepfsos_limitQ.m │ │ ├── makeIncidence.m │ │ ├── makesdpmat.m │ │ ├── mat2vec.m │ │ ├── maxCardSearch.m │ │ ├── mpoption_info_sdp_pf.m │ │ ├── mpoption_info_yalmip.m │ │ ├── prim.m │ │ ├── recoverFromW.m │ │ ├── runsdpopf.m │ │ ├── sdp_pf_ver.m │ │ ├── sdpopf_solver.m │ │ ├── soln9mod_opf.mat │ │ ├── soln9mod_opf_Plim.mat │ │ ├── t_case9mod_opf.m │ │ ├── t_insolvablepf.m │ │ ├── t_insolvablepf_limitQ.m │ │ ├── t_insolvablepfsos.m │ │ ├── t_insolvablepfsos_limitQ.m │ │ ├── t_opf_sdpopf.m │ │ ├── t_testglobalopt.m │ │ ├── testGlobalOpt.m │ │ └── yalmip_options.m │ ├── se │ │ ├── case3bus_P6_6.m │ │ ├── checkDataIntegrity.m │ │ ├── doSE.m │ │ ├── getV0.m │ │ ├── getVarName.m │ │ ├── isobservable.m │ │ ├── outputpfsoln.m │ │ ├── outputsesoln.m │ │ ├── run_se.m │ │ ├── se_intro.pdf │ │ ├── test_se.m │ │ ├── test_se_14bus.m │ │ └── test_se_14bus_err.m │ ├── smartmarket │ │ ├── SM_CHANGES │ │ ├── auction.m │ │ ├── case2off.m │ │ ├── idx_disp.m │ │ ├── off2case.m │ │ ├── pricelimits.m │ │ ├── printmkt.m │ │ ├── runmarket.m │ │ ├── runmkt.m │ │ └── smartmkt.m │ └── state_estimator │ │ ├── runse.m │ │ └── state_est.m │ ├── fairmax.m │ ├── fdpf.m │ ├── find_islands.m │ ├── fmincopf.m │ ├── fmincopf_solver.m │ ├── gausspf.m │ ├── gen17.m │ ├── get_losses.m │ ├── get_reorder.m │ ├── glpk_options.m │ ├── gurobi_options.m │ ├── gurobiver.m │ ├── hasPQcap.m │ ├── have_fcn.m │ ├── i2e_data.m │ ├── i2e_field.m │ ├── iceland.m │ ├── idx_brch.m │ ├── idx_bus.m │ ├── idx_cost.m │ ├── idx_dcline.m │ ├── idx_gen.m │ ├── int2ext.m │ ├── ipopt_options.m │ ├── ipoptopf_solver.m │ ├── isload.m │ ├── ktropf_solver.m │ ├── load2disp.m │ ├── loadcase.m │ ├── makeAang.m │ ├── makeApq.m │ ├── makeAvl.m │ ├── makeAy.m │ ├── makeB.m │ ├── makeBdc.m │ ├── makeJac.m │ ├── makeLODF.m │ ├── makePTDF.m │ ├── makeSbus.m │ ├── makeYbus.m │ ├── margcost.m │ ├── mips.m │ ├── mipsopf_solver.m │ ├── mipsver.m │ ├── miqps_cplex.m │ ├── miqps_glpk.m │ ├── miqps_gurobi.m │ ├── miqps_matpower.m │ ├── miqps_mosek.m │ ├── miqps_ot.m │ ├── modcost.m │ ├── mosek_options.m │ ├── mosek_symbcon.m │ ├── mplinsolve.m │ ├── mpoption.m │ ├── mpoption_info_clp.m │ ├── mpoption_info_cplex.m │ ├── mpoption_info_fmincon.m │ ├── mpoption_info_glpk.m │ ├── mpoption_info_gurobi.m │ ├── mpoption_info_intlinprog.m │ ├── mpoption_info_ipopt.m │ ├── mpoption_info_knitro.m │ ├── mpoption_info_linprog.m │ ├── mpoption_info_mips.m │ ├── mpoption_info_mosek.m │ ├── mpoption_info_quadprog.m │ ├── mpoption_old.m │ ├── mpver.m │ ├── nested_struct_copy.m │ ├── newtonpf.m │ ├── opf.m │ ├── opf_args.m │ ├── opf_consfcn.m │ ├── opf_costfcn.m │ ├── opf_execute.m │ ├── opf_hessfcn.m │ ├── opf_setup.m │ ├── pfsoln.m │ ├── poly2pwl.m │ ├── polycost.m │ ├── pqcost.m │ ├── printpf.m │ ├── psse2mpc.m │ ├── psse_convert.m │ ├── psse_convert_hvdc.m │ ├── psse_convert_xfmr.m │ ├── psse_parse.m │ ├── psse_parse_line.m │ ├── psse_parse_section.m │ ├── psse_read.m │ ├── qps_bpmpd.m │ ├── qps_clp.m │ ├── qps_cplex.m │ ├── qps_glpk.m │ ├── qps_gurobi.m │ ├── qps_ipopt.m │ ├── qps_matpower.m │ ├── qps_mips.m │ ├── qps_mosek.m │ ├── qps_ot.m │ ├── remove_userfcn.m │ ├── run_userfcn.m │ ├── runcpf.m │ ├── rundcopf.m │ ├── rundcpf.m │ ├── runduopf.m │ ├── runopf.m │ ├── runopf_w_res.m │ ├── runpf.m │ ├── runuopf.m │ ├── savecase.m │ ├── scale_load.m │ ├── set_reorder.m │ ├── t │ ├── pretty_print_acopf.txt │ ├── pretty_print_dcopf.txt │ ├── soln9_dcopf.mat │ ├── soln9_dcpf.mat │ ├── soln9_opf.mat │ ├── soln9_opf_PQcap.mat │ ├── soln9_opf_Plim.mat │ ├── soln9_opf_ang.mat │ ├── soln9_opf_extras1.mat │ ├── soln9_pf.mat │ ├── t_auction_case.m │ ├── t_auction_minopf.m │ ├── t_auction_mips.m │ ├── t_auction_tspopf_pdipm.m │ ├── t_begin.m │ ├── t_case30_userfcns.m │ ├── t_case9_dcline.m │ ├── t_case9_opf.m │ ├── t_case9_opfv2.m │ ├── t_case9_pf.m │ ├── t_case9_pfv2.m │ ├── t_case_ext.m │ ├── t_case_info_eg.txt │ ├── t_case_int.m │ ├── t_cpf.m │ ├── t_cpf_cb1.m │ ├── t_cpf_cb2.m │ ├── t_dcline.m │ ├── t_end.m │ ├── t_ext2int2ext.m │ ├── t_get_losses.m │ ├── t_hasPQcap.m │ ├── t_hessian.m │ ├── t_is.m │ ├── t_islands.m │ ├── t_jacobian.m │ ├── t_loadcase.m │ ├── t_makeLODF.m │ ├── t_makePTDF.m │ ├── t_margcost.m │ ├── t_mips.m │ ├── t_miqps_matpower.m │ ├── t_modcost.m │ ├── t_mplinsolve.m │ ├── t_mpoption.m │ ├── t_mpoption_ov.m │ ├── t_nested_struct_copy.m │ ├── t_off2case.m │ ├── t_ok.m │ ├── t_opf_dc_bpmpd.m │ ├── t_opf_dc_clp.m │ ├── t_opf_dc_cplex.m │ ├── t_opf_dc_glpk.m │ ├── t_opf_dc_gurobi.m │ ├── t_opf_dc_ipopt.m │ ├── t_opf_dc_mips.m │ ├── t_opf_dc_mips_sc.m │ ├── t_opf_dc_mosek.m │ ├── t_opf_dc_ot.m │ ├── t_opf_fmincon.m │ ├── t_opf_ipopt.m │ ├── t_opf_knitro.m │ ├── t_opf_minopf.m │ ├── t_opf_mips.m │ ├── t_opf_mips_sc.m │ ├── t_opf_model.m │ ├── t_opf_softlims.m │ ├── t_opf_tspopf_pdipm.m │ ├── t_opf_tspopf_scpdipm.m │ ├── t_opf_tspopf_tralm.m │ ├── t_opf_userfcns.m │ ├── t_pf.m │ ├── t_printpf.m │ ├── t_psse.m │ ├── t_psse_case.raw │ ├── t_psse_case2.m │ ├── t_psse_case2.raw │ ├── t_psse_case3.m │ ├── t_psse_case3.raw │ ├── t_qps_matpower.m │ ├── t_run_tests.m │ ├── t_runmarket.m │ ├── t_runopf_w_res.m │ ├── t_scale_load.m │ ├── t_skip.m │ ├── t_total_load.m │ ├── t_totcost.m │ └── test_matpower.m │ ├── toggle_dcline.m │ ├── toggle_iflims.m │ ├── toggle_reserves.m │ ├── toggle_softlims.m │ ├── total_load.m │ ├── totcost.m │ ├── uopf.m │ └── update_mupq.m ├── license.txt └── readme.txt /examples.m: -------------------------------------------------------------------------------- 1 | %% An example on using the continuous cascade model. 2 | % The details of all the functions can be found in ../library/@stateV1 3 | 4 | clear all; 5 | 6 | % The model is written as a class "stateV1" saved in library. 7 | addpath(genpath('../library')); 8 | 9 | 10 | %% Step 0: initiate the class 11 | % Input the name of a mpc that is saved in /library/matpower5.1. 12 | % Examples include "case9", "case39", "iceland", and etc. Check the 13 | % matpower5.1 folder in library. 14 | S = stateV1('case39'); 15 | 16 | 17 | %% Step 1: Try out some built-in functions in the model 18 | 19 | % Example 0: Find the nearest fixed point starting from a given state. 20 | current_state = S.x; 21 | x_star = fixed_points_nearby(S,current_state); 22 | 23 | % Example 1: break the state vector into w (frequency), ga (generator 24 | % angle), ba (bus angle), and eita (line status). 25 | [w,ga,ba,eita] = unpack_x(S,S.x); 26 | 27 | % Example 3: the value of lyapunov function on current_state. 28 | energy = lyapunov_energy(S,current_state); 29 | 30 | % Example 4: return the edge_list of the power grid. 31 | elist = edge_list(S); 32 | 33 | 34 | %% Step 2: Some functions that can be used in cascade model. 35 | % 2.0) A cascade model starts from a steady state solution. 36 | % 2.1) Cascade is triggered by a line removal 37 | % 2.2) Solve the dynamic and observe if at any time point there is a 38 | % overload. If there is, remove the line and solve the dynamic from the 39 | % time point of removal. 40 | 41 | % Example 0: solve dynamics for certain amount of time. 42 | time_length = 10; % indicate the total time to model 43 | [Tspan, Y1] = solve_dynamic(S,time_length); 44 | 45 | % Example 1: remove certain lines. 46 | E = edge_list(S);% get the edgelist 47 | I = E('from');J=E('to');IJ=[I J]; 48 | line = IJ(1,:);% select a line. 49 | S.x = turn_off_lines(S,line);% update the state x 50 | 51 | % Example 2: calculate the power flow (or energy) on each lines (virtual and real). 52 | [Pf_vir,Pf_line] = power_flow(S, current_state); 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /library/@stateV1/change_parameters.m: -------------------------------------------------------------------------------- 1 | function new_para = change_parameters(S, dName, dValue) 2 | % change the 'dName' in S.parameters to the 'dValue' that user chooses 3 | new_para = S.parameters; 4 | 5 | oldValue = getfield(new_para,dName); 6 | if ~isequal(size(oldValue(:)),size(dValue(:))) 7 | error('The size of the new parameters does not match the old parameters.'); 8 | else 9 | new_para = setfield(new_para,dName,dValue); 10 | end 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /library/@stateV1/directionaldiff.m: -------------------------------------------------------------------------------- 1 | function [dd,err,finaldelta] = directionaldiff(fun,x0,vec) 2 | % directionaldiff: estimate of the directional derivative of a function of n variables 3 | % usage: [grad,err,finaldelta] = directionaldiff(fun,x0,vec) 4 | % 5 | % Uses derivest to provide both a directional derivative 6 | % estimates plus an error estimates. fun needs not be vectorized. 7 | % 8 | % arguments: (input) 9 | % fun - analytical function to differentiate. fun must 10 | % be a function of the vector or array x0. Fun needs 11 | % not be vectorized. 12 | % 13 | % x0 - vector location at which to differentiate fun 14 | % If x0 is an nxm array, then fun is assumed to be 15 | % a function of n*m variables. 16 | % 17 | % vec - vector defining the line along which to take the 18 | % derivative. Vec should be the same size as x0. It 19 | % need not be a vector of unit length. 20 | % 21 | % arguments: (output) 22 | % dd - scalar estimate of the first derivative of fun 23 | % in the SPECIFIED direction. 24 | % 25 | % err - error estimate of the directional derivative 26 | % 27 | % finaldelta - vector of final step sizes chosen for 28 | % each partial derivative. 29 | % 30 | % 31 | % Example: 32 | % At the global minimizer (1,1) of the Rosenbrock function, 33 | % compute the directional derivative in the direction [1 2] 34 | % It should be 0. 35 | % 36 | % rosen = @(x) (1-x(1)).^2 + 105*(x(2)-x(1).^2).^2; 37 | % [dd,err] = directionaldiff(rosen,[1 1]) 38 | % 39 | % dd = 40 | % 0 41 | % err = 42 | % 0 43 | % 44 | % 45 | % See also: derivest, gradest, gradient 46 | % 47 | % 48 | % Author: John D'Errico 49 | % e-mail: woodchips@rochester.rr.com 50 | % Release: 1.0 51 | % Release date: 3/5/2007 52 | 53 | % get the size of x0 so we can make sure vec is 54 | % the same shape. 55 | sx = size(x0); 56 | if numel(x0)~=numel(vec) 57 | error 'vec and x0 must be the same sizes' 58 | end 59 | vec = vec(:); 60 | vec = vec/norm(vec); 61 | vec = reshape(vec,sx); 62 | 63 | [dd,err,finaldelta] = derivest(@(t) fun(x0+t*vec), ... 64 | 0,'deriv',1,'vectorized','no'); 65 | 66 | end % mainline function end 67 | 68 | 69 | -------------------------------------------------------------------------------- /library/@stateV1/edge_list.m: -------------------------------------------------------------------------------- 1 | function elist = edge_list(S) 2 | ng = S.parameters.ng; 3 | 4 | % flow on the real lines, considering the status of lines. 5 | I = S.vmpc.branch(ng+1:end,1); 6 | J = S.vmpc.branch(ng+1:end,2); 7 | 8 | dis = false; 9 | if dis 10 | disp('---transmission lines---') 11 | disp('from to'); 12 | disp('------------'); 13 | for i = 1:length(I) 14 | disp([num2str(I(i)) ' ' num2str(J(i))]); 15 | end 16 | end 17 | elist = containers.Map({'from','to'},{I,J}); 18 | end 19 | -------------------------------------------------------------------------------- /library/@stateV1/fixed_points_nearby.m: -------------------------------------------------------------------------------- 1 | function x_star = fixed_points_nearby(S,x0) 2 | % find the nearest fixed points starting from x0 3 | % f_x = @(x) S.fx(0,x); 4 | % [x_star,~]=fsolve(f_x,x0); 5 | 6 | % another way is to find the grad_lyapunov=0 7 | f_x = @(x) S.grad_lyapunov(x); 8 | [x_star,~]=fsolve(f_x,x0); 9 | end -------------------------------------------------------------------------------- /library/@stateV1/fx.m: -------------------------------------------------------------------------------- 1 | function dxdt = fx(S,t,x) % dynamic function 2 | %% 3 | % dxdt=fx(State,time,x) 4 | 5 | %% 6 | %[nb,ng,nl,Bij,Cij,Pg,Pl,Dg,Dl,Mg,Tl] = unpack_parameters(S); 7 | nb = S.parameters.nb; 8 | ng = S.parameters.ng; 9 | nl = S.parameters.nl; 10 | Bij = S.parameters.Bij; 11 | Cij = S.parameters.Cij; 12 | Pg = S.parameters.Pg(:); 13 | Pl = S.parameters.Pl(:); 14 | Dg = S.parameters.Dg(:); 15 | Dl = S.parameters.Dl(:); 16 | Mg = S.parameters.Mg(:); 17 | Tl = S.parameters.Tl(:); 18 | 19 | %[w,ga,ba,eita] = unpack_x(x,S); 20 | w = x(1:ng);w =w(:);% generator frequency 21 | ga = x(ng+1:2*ng-1);ga=ga(:);% generator angle 1-by-(ng-1) 22 | ba = x(2*ng:2*ng+nb-1);ba=ba(:);% bus angle 1-by-nb 23 | eita = x(2*ng+nb:2*ng+nb+nl-1);eita=eita(:);% branch status 24 | 25 | %% 26 | baseMVA = S.vmpc.baseMVA; 27 | 28 | % power flow on each branch 29 | FROM_BUS=1;TO_BUS=2; 30 | I = S.vmpc.branch(end-nl+1:end,FROM_BUS)-ng;J = S.vmpc.branch(end-nl+1:end,TO_BUS)-ng;% index of original power network 31 | IND = sub2ind(size(Bij),I,J); 32 | %z = Bij(IND).*(1-cos(ba(I)-ba(J))); % power flow energy on each transmission line 33 | z = Bij(IND).*(1-cos(ba(I)-ba(J))).*baseMVA; % power flow energy on each transmission line 34 | 35 | % adjust the Bij according to the status 36 | Bij(IND) = Bij(IND).*eita; 37 | IND2 = sub2ind(size(Bij),J,I); 38 | Bij(IND2) = Bij(IND2).*eita; 39 | b = [zeros(ng,ng) Cij;Cij' Bij]; 40 | alpha = [0; ga(:);ba(:)];%ref angle + generator angle + bus angle 41 | P = [Pg(:); Pl(:)];% power input,ng+nb 42 | 43 | %!!!!!!!!The following can be turned off if P(1) has been balanced when S 44 | %is initiated. 45 | %P(1) = -sum(P(2:end)); % balance power supply and demand using the slack 46 | 47 | % complementary variables 48 | y = zeros(ng+nb,1);%netpower withdraw at each node 49 | for i = 1 : ng+nb 50 | y(i) = sum(b(i,:)'.*sin(alpha(i)-alpha(:)))*baseMVA+P(i); 51 | %y(i) = sum(b(i,:)'.*sin(alpha(i)-alpha(:)))+P(i); 52 | end 53 | 54 | % 55 | dwdt = -(Dg.*w+y(1:ng))./Mg; 56 | dgadt = w(2:ng) - w(1); 57 | dbadt = -y(ng+1:ng+nb)./Dl-w(1); 58 | %deitadt = Tl.*S.onoff(eita)-z; 59 | deitadt = 10*(S.onoff(eita)-z./Tl); 60 | dxdt = [dwdt;dgadt;dbadt;deitadt]; 61 | 62 | end -------------------------------------------------------------------------------- /library/@stateV1/grad_lyapunov.m: -------------------------------------------------------------------------------- 1 | function gphi = grad_lyapunov(S,x0) 2 | % gradient of lyapunov function. 3 | 4 | Cij = S.parameters.Cij; % Cij = const1 if the i'th generator connects to j'th bus 5 | Bij = S.parameters.Bij; % Bij~=0 if there is a line connecting bus i to bus j 6 | ng = S.parameters.ng; 7 | nl = S.parameters.nl; 8 | nb = S.parameters.nb; 9 | Pg = S.parameters.Pg; 10 | Pl = S.parameters.Pl; 11 | Mg = S.parameters.Mg; 12 | Tl = S.parameters.Tl; 13 | 14 | [w,ga,ba,eita] = unpack_x(S,x0); 15 | ga = [0;ga];%ref angle +bus angle 16 | 17 | baseMVA = S.vmpc.baseMVA; 18 | 19 | 20 | %% 21 | dw = Mg(:).*w(:); 22 | 23 | % 24 | dga = zeros(ng-1,1); 25 | for i = 2:ng 26 | dga(i-1) = sum(Cij(i,:)'.*sin(ga(i)-ba(:)))*baseMVA+Pg(i); 27 | end 28 | 29 | % 30 | dba = zeros(nb,1); 31 | % power flow on each branch 32 | FROM_BUS=1;TO_BUS=2; 33 | I = S.vmpc.branch(end-nl+1:end,FROM_BUS)-ng;J = S.vmpc.branch(end-nl+1:end,TO_BUS)-ng;% index of original power network 34 | IND = sub2ind(size(Bij),I,J); 35 | z = Bij(IND).*(1-cos(ba(I)-ba(J))).*baseMVA; % power flow energy on each transmission line 36 | 37 | % adjust the Bij according to the status 38 | Bij(IND) = Bij(IND).*eita; 39 | IND2 = sub2ind(size(Bij),J,I); 40 | Bij(IND2) = Bij(IND2).*eita; 41 | b = [zeros(ng,ng) Cij;Cij' Bij]; 42 | alpha = [ga(:);ba(:)];% generator angle + bus angle 43 | P = [Pg(:); Pl(:)];% power input,ng+nb 44 | 45 | %!!!!!!!!!!!!!!!!!! The following can be turned off, if the P(1) is 46 | %balanced when S is initiated. 47 | P(1) = -sum(P(2:end));% balance power supply and demand using the slack bus 48 | 49 | for i = ng+1 : ng+nb 50 | dba(i-ng) = sum(b(i,:)'.*sin(alpha(i)-alpha(:)))*baseMVA+P(i); 51 | end 52 | 53 | % 54 | deita = -Tl.*S.onoff(eita)+z(:); 55 | 56 | 57 | %% 58 | gphi = [dw;dga;dba;deita]; 59 | 60 | end 61 | -------------------------------------------------------------------------------- /library/@stateV1/hessian_lyapunov.m: -------------------------------------------------------------------------------- 1 | function H = hessian_lyapunov(S,x0) 2 | % H = jacobian(grad(lyapunov_energy)) 3 | % H = [ M 0 0 0; 4 | % 0 Beta K 0; 5 | % 0 K' F G; 6 | % 0 0 G' Eta; ] 7 | 8 | Cij = S.parameters.Cij; % Cij = const1 if the i'th generator connects to j'th bus 9 | Bij = S.parameters.Bij; % Bij~=0 if there is a line connecting bus i to bus j 10 | ng = S.parameters.ng; 11 | nl = S.parameters.nl; 12 | nb = S.parameters.nb; 13 | 14 | Mg = S.parameters.Mg; 15 | Tl = S.parameters.Tl; 16 | 17 | [~,ga,ba,eita] = unpack_x(S,x0); 18 | ga = [0;ga]; 19 | 20 | baseMVA = S.vmpc.baseMVA; 21 | 22 | 23 | 24 | %% 25 | M = diag(Mg);% ng-by-ng 26 | 27 | % 28 | beta = zeros(1,ng-1); 29 | for i = 1:ng 30 | beta(i) = sum(Cij(i,:)'.*cos(ga(i)-ba))*baseMVA; 31 | end 32 | Beta = diag(beta(2:ng)); 33 | 34 | % K has the same structure as Cij without the first row 35 | K = zeros(size(Cij)); 36 | [i1,i2] = find(Cij); 37 | for c = 1 : ng 38 | i = i1(c); j = i2(c); 39 | K(i,j) = -Cij(i,j)*cos(ga(i)-ba(j))*baseMVA; 40 | end 41 | K(1,:) = []; 42 | 43 | % 44 | F = zeros(size(Bij)); 45 | % power flow on each branch 46 | FROM_BUS=1;TO_BUS=2; 47 | I = S.vmpc.branch(end-nl+1:end,FROM_BUS)-ng;J = S.vmpc.branch(end-nl+1:end,TO_BUS)-ng;% index of original power network 48 | IND = sub2ind(size(Bij),I,J); 49 | F(IND) = -Bij(IND).*cos(ba(I)-ba(J)).*eita.*baseMVA; % power flow term on each transmission line 50 | IND2 = sub2ind(size(Bij),J,I); 51 | F(IND2) = -Bij(IND2).*cos(ba(J)-ba(I)).*eita.*baseMVA; % power flow term on each transmission line 52 | for i = 1 : nb 53 | F(i,i) = -sum(F(i,:))+sum(beta(find(Cij(:,i)))); 54 | end 55 | 56 | 57 | % 58 | G = zeros(nb,nl); 59 | for l = 1:nl 60 | i = I(l);j = J(l); 61 | G(i,l) = Bij(i,j)*sin(ba(i)-ba(j))*baseMVA; 62 | G(j,l) = Bij(i,j)*sin(ba(j)-ba(i))*baseMVA; 63 | end 64 | 65 | 66 | % 67 | fun = @(x) S.onoff(x); 68 | Eta = zeros(nl,nl); 69 | for l = 1 :length(eita) 70 | [grad_eta,~,~] = gradest(fun,eita(l)); 71 | Eta(l,l) = -grad_eta*Tl(l); 72 | end 73 | 74 | 75 | H = [M zeros(ng,ng-1) zeros(ng,nb) zeros(ng,nl); 76 | zeros(ng-1,ng) Beta K zeros(ng-1,nl); 77 | zeros(nb,ng) K' F G; 78 | zeros(nl,ng) zeros(nl,ng-1) G' Eta]; 79 | 80 | return -------------------------------------------------------------------------------- /library/@stateV1/jacobian_f.m: -------------------------------------------------------------------------------- 1 | function J = jacobian_f(S,x) 2 | 3 | J = S.skew_matrix() * hessian_lyapunov(S,x); 4 | 5 | end -------------------------------------------------------------------------------- /library/@stateV1/lyapunov_energy.m: -------------------------------------------------------------------------------- 1 | function l = lyapunov_energy(S,x) 2 | % The lyapunov energy 3 | Mg = S.parameters.Mg; 4 | Tl = S.parameters.Tl; 5 | Pg = S.parameters.Pg; 6 | Pl = S.parameters.Pl; 7 | 8 | [w,ga,ba,eita] = unpack_x(S,x); 9 | ga = [0;ga]; 10 | 11 | ke = 1/2*sum(Mg.*w.*w);% kinectic energy 12 | [E_vir,E_line] = power_flow_energy(S,x); 13 | fe = sum(E_vir('energy'))+sum(E_line('energy'));% flow energy 14 | se = sum(Tl(:).*S.onoff_energy(eita));% state energy 15 | 16 | pe = sum(ga.*Pg) + sum(ba.*Pl); 17 | 18 | l = ke + fe + se + pe; 19 | 20 | end -------------------------------------------------------------------------------- /library/@stateV1/numeric_grad_lyapunov.m: -------------------------------------------------------------------------------- 1 | function [grad_l,err] = numeric_grad_lyapunov(S,x0) 2 | 3 | 4 | fun = @(x) lyapunov_energy(S,x); 5 | [grad_l,err,~] = gradest(fun,x0); 6 | 7 | if err>1e-6 8 | error('can not estimate the lyapunov gradient'); 9 | end 10 | 11 | end -------------------------------------------------------------------------------- /library/@stateV1/numeric_hessian_lyapunov.m: -------------------------------------------------------------------------------- 1 | function H = numeric_hessian_lyapunov(S,x0) 2 | 3 | fun = @(x) lyapunov_energy(S,x); 4 | 5 | [H,err] = hessian(fun,x0); 6 | 7 | if err>1e-6 8 | error('can not estimate the Hessian gradient'); 9 | end 10 | 11 | end -------------------------------------------------------------------------------- /library/@stateV1/onoff.m: -------------------------------------------------------------------------------- 1 | function t = onoff(g) 2 | 3 | % Normalized status function: 4 | % The status of a component is represented by a continous variable g, ranging 5 | % from zero to one. Before simulation, we indicate the threshold g_c below which g will be driven to 6 | % a region close to zero. At the region near one, the local maximum of 7 | % onoff(g) is one, that is onoff(g_star)=1. 8 | % Version: 2015-07 9 | 10 | t = 1./(10.*g)-1./(10.*(1-g))+10.*g.^4-5.2627; 11 | 12 | end -------------------------------------------------------------------------------- /library/@stateV1/onoff_energy.m: -------------------------------------------------------------------------------- 1 | function E = onoff_energy(g) 2 | % Normalized status energy function: 3 | % The status of a component is represented by a continous variable g, ranging 4 | % from zero to one. Before simulation, we indicate the threshold g_c below which g will be driven to 5 | % a region close to zero. 6 | 7 | % see lyapunov_energy also 8 | % Version: 2016-03 9 | 10 | E = -1/10.*log(g)-1/10.*log(1-g)-2*g.^5+5.2627.*g; 11 | %E = 2.*log(1-g)+x.*log(1./x-1)-40g.^3; 12 | % %% set up parameters 13 | % b = 20; 14 | % a1 = 10; 15 | % a2 = a1 * b; 16 | % 17 | % %% 18 | % % g=g_star, theta takes the maximum 19 | % g_star =1 - log(a2/a1)/(a2-a1); 20 | % 21 | % % assume g\n'); 26 | else 27 | display(om.mpc); 28 | end 29 | -------------------------------------------------------------------------------- /library/matpower5.1/@opf_model/get_mpc.m: -------------------------------------------------------------------------------- 1 | function mpc = get_mpc(om) 2 | %GET_MPC Returns the MATPOWER case struct. 3 | % MPC = GET_MPC(OM) 4 | % 5 | % See also OPT_MODEL. 6 | 7 | % MATPOWER 8 | % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 9 | % by Ray Zimmerman, PSERC Cornell 10 | % 11 | % $Id: get_mpc.m 2644 2015-03-11 19:34:22Z ray $ 12 | % 13 | % This file is part of MATPOWER. 14 | % Covered by the 3-clause BSD License (see LICENSE file for details). 15 | % See http://www.pserc.cornell.edu/matpower/ for more info. 16 | 17 | mpc = om.mpc; 18 | -------------------------------------------------------------------------------- /library/matpower5.1/@opf_model/opf_model.m: -------------------------------------------------------------------------------- 1 | function om = opf_model(mpc) 2 | %OPF_MODEL Constructor for OPF model class. 3 | % OM = OPF_MODEL(MPC) 4 | % 5 | % This class implements the OPF model object used to encapsulate 6 | % a given OPF problem formulation. It allows for access to optimization 7 | % variables, constraints and costs in named blocks, keeping track of the 8 | % ordering and indexing of the blocks as variables, constraints and costs 9 | % are added to the problem. 10 | % 11 | % This class is a sub-class of OPT_MODEL and simply adds the 'mpc' 12 | % field for storing the MATPOWER case struct used to build the object 13 | % along with the get_mpc() method. 14 | % 15 | % The following is the structure of the data in the OPF model object. 16 | % Each field of .idx or .data is a struct whose field names are the names 17 | % of the corresponding blocks of vars, constraints or costs (found in 18 | % order in the corresponding .order field). The description next to these 19 | % fields gives the meaning of the value for each named sub-field. 20 | % E.g. om.var.data.v0.Pg contains a vector of initial values for the 'Pg' 21 | % block of variables. 22 | % 23 | % om 24 | % .opt_model - the corresponding OPT_MODEL object 25 | % .mpc - MATPOWER case struct used to create this model object 26 | % .baseMVA 27 | % .bus 28 | % .branch 29 | % .gen 30 | % .gencost 31 | % .A (if present, must have l, u) 32 | % .l 33 | % .u 34 | % .N (if present, must have fparm, H, Cw) 35 | % .fparm 36 | % .H 37 | % .Cw 38 | % 39 | % See also OPT_MODEL. 40 | 41 | % MATPOWER 42 | % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 43 | % by Ray Zimmerman, PSERC Cornell 44 | % 45 | % $Id: opf_model.m 2644 2015-03-11 19:34:22Z ray $ 46 | % 47 | % This file is part of MATPOWER. 48 | % Covered by the 3-clause BSD License (see LICENSE file for details). 49 | % See http://www.pserc.cornell.edu/matpower/ for more info. 50 | 51 | if nargin == 0 52 | es = struct(); 53 | s = struct('mpc', es); 54 | om = opt_model; 55 | om = class(s, 'opf_model', om); 56 | else 57 | if isa(mpc,'opf_model') 58 | om = mpc; 59 | else 60 | if isfield(mpc, 'om') %% avoid nesting 61 | s = struct('mpc', rmfield(mpc, 'om')); 62 | else 63 | s = struct('mpc', mpc); 64 | end 65 | om = opt_model; 66 | om = class(s, 'opf_model', om); 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /library/matpower5.1/@opt_model/describe_idx.m: -------------------------------------------------------------------------------- 1 | function label = describe_idx(om, idx_type, idxs) 2 | %DESCRIBE_IDX Identifies variable, constraint and cost row indices. 3 | % LABEL = DESCRIBE_IDX(OM, IDX_TYPE, IDXS) 4 | % 5 | % Returns strings describing (name and index) the variable, constraint 6 | % or cost row that corresponds to the indices in IDXS. IDX_TYPE must be 7 | % one of the following: 'var', 'lin', 'nln', or 'cost', corresponding 8 | % to indices for variables, linear constraints, non-linear constraints 9 | % and cost rows, respectively. The return value is a string if IDXS is 10 | % a scalar, otherwise it is a cell array of strings of the same 11 | % dimension as IDXS. 12 | % 13 | % Examples: 14 | % label = describe_idx(om, 'var', 87)); 15 | % labels = describe_idx(om, 'lin', [38; 49; 93])); 16 | % 17 | % See also OPT_MODEL. 18 | 19 | % MATPOWER 20 | % Copyright (c) 2012-2015 by Power System Engineering Research Center (PSERC) 21 | % by Ray Zimmerman, PSERC Cornell 22 | % 23 | % $Id: describe_idx.m 2644 2015-03-11 19:34:22Z ray $ 24 | % 25 | % This file is part of MATPOWER. 26 | % Covered by the 3-clause BSD License (see LICENSE file for details). 27 | % See http://www.pserc.cornell.edu/matpower/ for more info. 28 | 29 | label = cell(size(idxs)); %% pre-allocate return cell array 30 | for i = 1:length(idxs(:)) 31 | ii = idxs(i); 32 | if ii > om.(idx_type).N 33 | error('@opt_model/describe_idx: index exceeds maximum %s index (%d)', idx_type, om.(idx_type).N); 34 | end 35 | if ii < 1 36 | error('@opt_model/describe_idx: index must be positive'); 37 | end 38 | for k = om.(idx_type).NS:-1:1 39 | name = om.(idx_type).order(k).name; 40 | idx = om.(idx_type).order(k).idx; 41 | if isempty(idx) 42 | if ii >= om.(idx_type).idx.i1.(name) 43 | label{i} = sprintf('%s(%d)', name, ii - om.(idx_type).idx.i1.(name) + 1); 44 | break; 45 | end 46 | else 47 | s = substruct('.', name, '()', idx); 48 | if ii >= subsref(om.(idx_type).idx.i1, s) 49 | idxstr = sprintf('%d', idx{1}); 50 | for j = 2:length(idx) 51 | idxstr = sprintf('%s,%d', idxstr, idx{j}); 52 | end 53 | label{i} = sprintf('%s(%s)(%d)', name, idxstr, ... 54 | ii - subsref(om.(idx_type).idx.i1, s) + 1); 55 | break; 56 | end 57 | end 58 | end 59 | end 60 | if isscalar(idxs) %% return scalar 61 | label = label{1}; 62 | end 63 | -------------------------------------------------------------------------------- /library/matpower5.1/@opt_model/get.m: -------------------------------------------------------------------------------- 1 | function val = get(om, varargin) 2 | %GET Returns the value of a field. 3 | % VAL = GET(OM, FIELD1, FIELD2, ...) 4 | % 5 | % Example: 6 | % var_order = get(om, 'var', 'order'); 7 | % 8 | % See also OPT_MODEL. 9 | 10 | % MATPOWER 11 | % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 12 | % by Ray Zimmerman, PSERC Cornell 13 | % 14 | % $Id: get.m 2644 2015-03-11 19:34:22Z ray $ 15 | % 16 | % This file is part of MATPOWER. 17 | % Covered by the 3-clause BSD License (see LICENSE file for details). 18 | % See http://www.pserc.cornell.edu/matpower/ for more info. 19 | 20 | val = om; 21 | for k = 1:length(varargin) 22 | if ischar(varargin{k}) 23 | val = val.(varargin{k}); 24 | else 25 | val = val(varargin{k}); 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /library/matpower5.1/@opt_model/getN.m: -------------------------------------------------------------------------------- 1 | function N = getN(om, selector, name, idx) 2 | %GETN Returns the number of variables, constraints or cost rows. 3 | % N = GETN(OM, SELECTOR) 4 | % N = GETN(OM, SELECTOR, NAME) 5 | % N = GETN(OM, SELECTOR, NAME, IDX) 6 | % 7 | % Returns either the total number of variables/constraints/cost rows 8 | % or the number corresponding to a specified named block. 9 | % 10 | % Examples: 11 | % N = getN(om, 'var') : total number of variables 12 | % N = getN(om, 'lin') : total number of linear constraints 13 | % N = getN(om, 'nln') : total number of nonlinear constraints 14 | % N = getN(om, 'cost') : total number of cost rows (in N) 15 | % N = getN(om, 'var', name) : number of variables in named set 16 | % N = getN(om, 'lin', name) : number of linear constraints in named set 17 | % N = getN(om, 'nln', name) : number of nonlinear cons. in named set 18 | % N = getN(om, 'cost', name) : number of cost rows (in N) in named set 19 | % N = getN(om, 'var', name, idx) : number of variables in indexed named set 20 | % 21 | % See also OPT_MODEL. 22 | 23 | % MATPOWER 24 | % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 25 | % by Ray Zimmerman, PSERC Cornell 26 | % 27 | % $Id: getN.m 2644 2015-03-11 19:34:22Z ray $ 28 | % 29 | % This file is part of MATPOWER. 30 | % Covered by the 3-clause BSD License (see LICENSE file for details). 31 | % See http://www.pserc.cornell.edu/matpower/ for more info. 32 | 33 | if nargin < 3 34 | N = om.(selector).N; 35 | else 36 | if isfield(om.(selector).idx.N, name) 37 | if nargin < 4 38 | idx = {}; 39 | end 40 | s1 = substruct('.', name, '()', idx); 41 | N = subsref(om.(selector).idx.N, s1); 42 | else 43 | N = 0; 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /library/matpower5.1/@opt_model/get_cost_params.m: -------------------------------------------------------------------------------- 1 | function cp = get_cost_params(om, name, idx) 2 | %GET_COST_PARAMS Returns the cost parameter struct for user-defined costs. 3 | % CP = GET_COST_PARAMS(OM) 4 | % CP = GET_COST_PARAMS(OM, NAME) 5 | % CP = GET_COST_PARAMS(OM, NAME, IDX) 6 | % 7 | % Requires calling BUILD_COST_PARAMS first to build the full set of 8 | % parameters. Returns the full cost parameter struct for all user-defined 9 | % costs that incorporates all of the named cost sets added via ADD_COSTS, 10 | % or, if a name is provided it returns the cost struct corresponding to 11 | % the named set of cost rows (N still has full number of columns). 12 | % 13 | % The cost parameters are returned in a struct with the following fields: 14 | % N - nw x nx sparse matrix 15 | % Cw - nw x 1 vector 16 | % H - nw x nw sparse matrix (optional, all zeros by default) 17 | % dd, mm - nw x 1 vectors (optional, all ones by default) 18 | % rh, kk - nw x 1 vectors (optional, all zeros by default) 19 | % 20 | % See also OPT_MODEL, ADD_COSTS, BUILD_COST_PARAMS, COMPUTE_COST. 21 | 22 | % MATPOWER 23 | % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 24 | % by Ray Zimmerman, PSERC Cornell 25 | % 26 | % $Id: get_cost_params.m 2644 2015-03-11 19:34:22Z ray $ 27 | % 28 | % This file is part of MATPOWER. 29 | % Covered by the 3-clause BSD License (see LICENSE file for details). 30 | % See http://www.pserc.cornell.edu/matpower/ for more info. 31 | 32 | if ~isfield(om.cost.params, 'N') 33 | error('@opt_model/get_cost_params: must call build_cost_params first'); 34 | end 35 | 36 | cp = om.cost.params; 37 | 38 | if nargin > 1 39 | if getN(om, 'cost', name) 40 | if nargin < 3 || isempty(idx) 41 | if prod(size(om.cost.idx.i1.(name))) == 1 42 | i1 = om.cost.idx.i1.(name); 43 | iN = om.cost.idx.iN.(name); 44 | else 45 | error('@opt_model/get_cost_params: cost set ''%s'' requires an idx arg', name); 46 | end 47 | else 48 | s1 = substruct('.', name, '()', idx); 49 | i1 = subsref(om.cost.idx.i1, s1); 50 | iN = subsref(om.cost.idx.iN, s1); 51 | end 52 | cp.N = cp.N(i1:iN,:); 53 | cp.Cw = cp.Cw(i1:iN); 54 | cp.H = cp.H(i1:iN,i1:iN); 55 | cp.dd = cp.dd(i1:iN); 56 | cp.rh = cp.rh(i1:iN); 57 | cp.kk = cp.kk(i1:iN); 58 | cp.mm = cp.mm(i1:iN); 59 | end 60 | end 61 | -------------------------------------------------------------------------------- /library/matpower5.1/@opt_model/get_idx.m: -------------------------------------------------------------------------------- 1 | function [vv, ll, nn, cc] = get_idx(om) 2 | %GET_IDX Returns the idx struct for vars, lin/nln constraints, costs. 3 | % VV = GET_IDX(OM) 4 | % [VV, LL] = GET_IDX(OM) 5 | % [VV, LL, NN] = GET_IDX(OM) 6 | % [VV, LL, NN, CC] = GET_IDX(OM) 7 | % 8 | % Returns a structure for each with the beginning and ending 9 | % index value and the number of elements for each named block. 10 | % The 'i1' field (that's a one) is a struct with all of the 11 | % starting indices, 'iN' contains all the ending indices and 12 | % 'N' contains all the sizes. Each is a struct whose fields are 13 | % the named blocks. 14 | % 15 | % Examples: 16 | % [vv, ll, nn] = get_idx(om); 17 | % 18 | % For a variable block named 'z' we have ... 19 | % vv.i1.z - starting index for 'z' in optimization vector x 20 | % vv.iN.z - ending index for 'z' in optimization vector x 21 | % vv.N.z - number of elements in 'z' 22 | % 23 | % To extract a 'z' variable from x: 24 | % z = x(vv.i1.z:vv.iN.z); 25 | % 26 | % To extract the multipliers on a linear constraint set 27 | % named 'foo', where mu_l and mu_u are the full set of 28 | % linear constraint multipliers: 29 | % mu_l_foo = mu_l(ll.i1.foo:ll.iN.foo); 30 | % mu_u_foo = mu_u(ll.i1.foo:ll.iN.foo); 31 | % 32 | % The number of nonlinear constraints in a set named 'bar': 33 | % nbar = nn.N.bar; 34 | % (note: the following is preferable ... 35 | % nbar = getN(om, 'nln', 'bar'); 36 | % ... if you haven't already called get_idx to get nn.) 37 | % 38 | % If 'z', 'foo' and 'bar' are indexed sets, then you can 39 | % replace them with something like 'z(i,j)', 'foo(i,j,k)' 40 | % or 'bar(i)' in the examples above. 41 | % 42 | % See also OPT_MODEL, ADD_VARS, ADD_CONSTRAINTS, ADD_COSTS. 43 | 44 | % MATPOWER 45 | % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 46 | % by Ray Zimmerman, PSERC Cornell 47 | % 48 | % $Id: get_idx.m 2644 2015-03-11 19:34:22Z ray $ 49 | % 50 | % This file is part of MATPOWER. 51 | % Covered by the 3-clause BSD License (see LICENSE file for details). 52 | % See http://www.pserc.cornell.edu/matpower/ for more info. 53 | 54 | vv = om.var.idx; 55 | if nargout > 1 56 | ll = om.lin.idx; 57 | if nargout > 2 58 | nn = om.nln.idx; 59 | if nargout > 3 60 | cc = om.cost.idx; 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /library/matpower5.1/@opt_model/userdata.m: -------------------------------------------------------------------------------- 1 | function rv = userdata(om, name, val) 2 | %USERDATA Used to save or retrieve values of user data. 3 | % 4 | % OM = USERDATA(OM, NAME, VAL) saves the value under the given name. 5 | % VAL = USERDATA(OM, NAME) returns the value specified by the given name 6 | % 7 | % This function allows the user to save any arbitrary data in the object 8 | % for later use. This can be useful when using a user function to add 9 | % variables, constraints, costs, etc. For example, suppose some special 10 | % indexing is constructed when adding some variables or constraints. 11 | % This indexing data can be stored and used later to "unpack" the results 12 | % of the solved case. 13 | % 14 | % See also OPT_MODEL. 15 | 16 | % MATPOWER 17 | % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 18 | % by Ray Zimmerman, PSERC Cornell 19 | % 20 | % $Id: userdata.m 2644 2015-03-11 19:34:22Z ray $ 21 | % 22 | % This file is part of MATPOWER. 23 | % Covered by the 3-clause BSD License (see LICENSE file for details). 24 | % See http://www.pserc.cornell.edu/matpower/ for more info. 25 | 26 | if nargin == 3 27 | om.userdata.(name) = val; 28 | rv = om; 29 | else 30 | if isfield(om.userdata, name) 31 | rv = om.userdata.(name); 32 | else 33 | rv = []; 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /library/matpower5.1/AUTHORS: -------------------------------------------------------------------------------- 1 | Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 2 | 3 | Primary developers: 4 | - Ray Zimmerman 5 | - Carlos Murillo-Sanchez 6 | 7 | Other contributors: 8 | - Shrirang Abhyankar 9 | - Rui Bo 10 | - Alberto Borghetti 11 | - Alex Flueck 12 | - Deqiang Gan 13 | - Daniel Molzhan 14 | - James Thorp 15 | -------------------------------------------------------------------------------- /library/matpower5.1/Contents.m: -------------------------------------------------------------------------------- 1 | % MATPOWER 2 | % Version 5.1 20-Mar-2015 3 | % 4 | % MATPOWER is a package of MATLAB(R) M-files for solving power flow and 5 | % optimal power flow problems. It is intended as a simulation tool for 6 | % researchers and educators that is easy to use and modify. MATPOWER is 7 | % designed to give the best performance possible while keeping the code 8 | % simple to understand and modify. It was initially developed as part 9 | % of the PowerWeb project . 10 | % 11 | % MATPOWER can be downloaded from the MATPOWER home page: 12 | % 13 | % http://www.pserc.cornell.edu/matpower/ 14 | % 15 | % MATPOWER is covered by the 3-clause BSD License (see LICENSE for details). 16 | 17 | % MATPOWER 18 | % Copyright (c) 2004-2015 by Power System Engineering Research Center (PSERC) 19 | % by Ray Zimmerman, PSERC Cornell 20 | % 21 | % $Id: Contents.m 2664 2015-03-20 21:31:02Z ray $ 22 | % 23 | % This file is part of MATPOWER. 24 | % Covered by the 3-clause BSD License (see LICENSE file for details). 25 | % See http://www.pserc.cornell.edu/matpower/ for more info. 26 | -------------------------------------------------------------------------------- /library/matpower5.1/MATPOWER-manual-6.0b1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/MATPOWER-manual-6.0b1.pdf -------------------------------------------------------------------------------- /library/matpower5.1/bustypes.m: -------------------------------------------------------------------------------- 1 | function [ref, pv, pq] = bustypes(bus, gen) 2 | %BUSTYPES Builds index lists for each type of bus (REF, PV, PQ). 3 | % [REF, PV, PQ] = BUSTYPES(BUS, GEN) 4 | % Generators with "out-of-service" status are treated as PQ buses with 5 | % zero generation (regardless of Pg/Qg values in gen). Expects BUS and 6 | % GEN have been converted to use internal consecutive bus numbering. 7 | 8 | % MATPOWER 9 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 10 | % by Ray Zimmerman, PSERC Cornell 11 | % 12 | % $Id: bustypes.m 2644 2015-03-11 19:34:22Z ray $ 13 | % 14 | % This file is part of MATPOWER. 15 | % Covered by the 3-clause BSD License (see LICENSE file for details). 16 | % See http://www.pserc.cornell.edu/matpower/ for more info. 17 | 18 | %% constants 19 | [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 20 | VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 21 | [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 22 | MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 23 | QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 24 | 25 | %% get generator status 26 | % bus_gen_status = zeros(size(bus, 1), 1); 27 | % bus_gen_status(gen(:, GEN_BUS)) = gen(:, GEN_STATUS) > 0; 28 | nb = size(bus, 1); 29 | ng = size(gen, 1); 30 | Cg = sparse(gen(:, GEN_BUS), (1:ng)', gen(:, GEN_STATUS) > 0, nb, ng); %% gen connection matrix 31 | %% element i, j is 1 if, generator j at bus i is ON 32 | bus_gen_status = Cg * ones(ng, 1); %% number of generators at each bus that are ON 33 | 34 | 35 | %% form index lists for slack, PV, and PQ buses 36 | ref = find(bus(:, BUS_TYPE) == REF & bus_gen_status); %% reference bus index 37 | pv = find(bus(:, BUS_TYPE) == PV & bus_gen_status); %% PV bus indices 38 | pq = find(bus(:, BUS_TYPE) == PQ | ~bus_gen_status); %% PQ bus indices 39 | 40 | %% pick a new reference bus if for some reason there is none (may have been shut down) 41 | if isempty(ref) 42 | ref = pv(1); %% use the first PV bus 43 | pv = pv(2:length(pv)); %% take it off PV list 44 | end 45 | -------------------------------------------------------------------------------- /library/matpower5.1/case4gs.m: -------------------------------------------------------------------------------- 1 | function mpc = case4gs 2 | %CASE4GS Power flow data for 4 bus, 2 gen case from Grainger & Stevenson. 3 | % Please see CASEFORMAT for details on the case file format. 4 | % 5 | % This is the 4 bus example from pp. 337-338 of "Power System Analysis", 6 | % by John Grainger, Jr., William Stevenson, McGraw-Hill, 1994. 7 | 8 | % MATPOWER 9 | % $Id: case4gs.m 1559 2010-03-10 18:08:32Z ray $ 10 | 11 | %% MATPOWER Case Format : Version 2 12 | mpc.version = '2'; 13 | 14 | %%----- Power Flow Data -----%% 15 | %% system MVA base 16 | mpc.baseMVA = 100; 17 | 18 | %% bus data 19 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 20 | mpc.bus = [ 21 | 1 3 50 30.99 0 0 1 1 0 230 1 1.1 0.9; 22 | 2 1 170 105.35 0 0 1 1 0 230 1 1.1 0.9; 23 | 3 1 200 123.94 0 0 1 1 0 230 1 1.1 0.9; 24 | 4 2 80 49.58 0 0 1 1 0 230 1 1.1 0.9; 25 | ]; 26 | 27 | %% generator data 28 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 29 | mpc.gen = [ 30 | 4 318 0 100 -100 1.02 100 1 318 0 0 0 0 0 0 0 0 0 0 0 0; 31 | 1 0 0 100 -100 1 100 1 0 0 0 0 0 0 0 0 0 0 0 0 0; 32 | ]; 33 | 34 | %% branch data 35 | % fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax 36 | mpc.branch = [ 37 | 1 2 0.01008 0.0504 0.1025 250 250 250 0 0 1 -360 360; 38 | 1 3 0.00744 0.0372 0.0775 250 250 250 0 0 1 -360 360; 39 | 2 4 0.00744 0.0372 0.0775 250 250 250 0 0 1 -360 360; 40 | 3 4 0.01272 0.0636 0.1275 250 250 250 0 0 1 -360 360; 41 | ]; 42 | -------------------------------------------------------------------------------- /library/matpower5.1/case5.m: -------------------------------------------------------------------------------- 1 | function mpc = case5 2 | %CASE5 Power flow data for modified 5 bus, 5 gen case based on PJM 5-bus system 3 | % Please see CASEFORMAT for details on the case file format. 4 | % 5 | % Based on data from ... 6 | % F.Li and R.Bo, "Small Test Systems for Power System Economic Studies", 7 | % Proceedings of the 2010 IEEE Power & Energy Society General Meeting 8 | 9 | % Created by Rui Bo in 2006, modified in 2010, 2014. 10 | % Distributed with permission. 11 | 12 | % MATPOWER 13 | % $Id: case5.m 2408 2014-10-22 20:41:33Z ray $ 14 | 15 | %% MATPOWER Case Format : Version 2 16 | mpc.version = '2'; 17 | 18 | %%----- Power Flow Data -----%% 19 | %% system MVA base 20 | mpc.baseMVA = 100; 21 | 22 | %% bus data 23 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 24 | mpc.bus = [ 25 | 1 2 0 0 0 0 1 1 0 230 1 1.1 0.9; 26 | 2 1 300 98.61 0 0 1 1 0 230 1 1.1 0.9; 27 | 3 2 300 98.61 0 0 1 1 0 230 1 1.1 0.9; 28 | 4 3 400 131.47 0 0 1 1 0 230 1 1.1 0.9; 29 | 5 2 0 0 0 0 1 1 0 230 1 1.1 0.9; 30 | ]; 31 | 32 | %% generator data 33 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 34 | mpc.gen = [ 35 | 1 40 0 30 -30 1 100 1 40 0 0 0 0 0 0 0 0 0 0 0 0; 36 | 1 170 0 127.5 -127.5 1 100 1 170 0 0 0 0 0 0 0 0 0 0 0 0; 37 | 3 323.49 0 390 -390 1 100 1 520 0 0 0 0 0 0 0 0 0 0 0 0; 38 | 4 0 0 150 -150 1 100 1 200 0 0 0 0 0 0 0 0 0 0 0 0; 39 | 5 466.51 0 450 -450 1 100 1 600 0 0 0 0 0 0 0 0 0 0 0 0; 40 | ]; 41 | 42 | %% branch data 43 | % fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax 44 | mpc.branch = [ 45 | 1 2 0.00281 0.0281 0.00712 400 400 400 0 0 1 -360 360; 46 | 1 4 0.00304 0.0304 0.00658 0 0 0 0 0 1 -360 360; 47 | 1 5 0.00064 0.0064 0.03126 0 0 0 0 0 1 -360 360; 48 | 2 3 0.00108 0.0108 0.01852 0 0 0 0 0 1 -360 360; 49 | 3 4 0.00297 0.0297 0.00674 0 0 0 0 0 1 -360 360; 50 | 4 5 0.00297 0.0297 0.00674 240 240 240 0 0 1 -360 360; 51 | ]; 52 | 53 | %%----- OPF Data -----%% 54 | %% generator cost data 55 | % 1 startup shutdown n x1 y1 ... xn yn 56 | % 2 startup shutdown n c(n-1) ... c0 57 | mpc.gencost = [ 58 | 2 0 0 2 14 0; 59 | 2 0 0 2 15 0; 60 | 2 0 0 2 30 0; 61 | 2 0 0 2 40 0; 62 | 2 0 0 2 10 0; 63 | ]; 64 | -------------------------------------------------------------------------------- /library/matpower5.1/case6ww.m: -------------------------------------------------------------------------------- 1 | function mpc = case6ww 2 | %CASE6WW Power flow data for 6 bus, 3 gen case from Wood & Wollenberg. 3 | % Please see CASEFORMAT for details on the case file format. 4 | % 5 | % This is the 6 bus example from pp. 104, 112, 119, 123-124, 549 of 6 | % "Power Generation, Operation, and Control, 2nd Edition", 7 | % by Allen. J. Wood and Bruce F. Wollenberg, John Wiley & Sons, NY, Jan 1996. 8 | 9 | % MATPOWER 10 | % $Id: case6ww.m 1559 2010-03-10 18:08:32Z ray $ 11 | 12 | %% MATPOWER Case Format : Version 2 13 | mpc.version = '2'; 14 | 15 | %%----- Power Flow Data -----%% 16 | %% system MVA base 17 | mpc.baseMVA = 100; 18 | 19 | %% bus data 20 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 21 | mpc.bus = [ 22 | 1 3 0 0 0 0 1 1.05 0 230 1 1.05 1.05; 23 | 2 2 0 0 0 0 1 1.05 0 230 1 1.05 1.05; 24 | 3 2 0 0 0 0 1 1.07 0 230 1 1.07 1.07; 25 | 4 1 70 70 0 0 1 1 0 230 1 1.05 0.95; 26 | 5 1 70 70 0 0 1 1 0 230 1 1.05 0.95; 27 | 6 1 70 70 0 0 1 1 0 230 1 1.05 0.95; 28 | ]; 29 | 30 | %% generator data 31 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 32 | mpc.gen = [ 33 | 1 0 0 100 -100 1.05 100 1 200 50 0 0 0 0 0 0 0 0 0 0 0; 34 | 2 50 0 100 -100 1.05 100 1 150 37.5 0 0 0 0 0 0 0 0 0 0 0; 35 | 3 60 0 100 -100 1.07 100 1 180 45 0 0 0 0 0 0 0 0 0 0 0; 36 | ]; 37 | 38 | %% branch data 39 | % fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax 40 | mpc.branch = [ 41 | 1 2 0.1 0.2 0.04 40 40 40 0 0 1 -360 360; 42 | 1 4 0.05 0.2 0.04 60 60 60 0 0 1 -360 360; 43 | 1 5 0.08 0.3 0.06 40 40 40 0 0 1 -360 360; 44 | 2 3 0.05 0.25 0.06 40 40 40 0 0 1 -360 360; 45 | 2 4 0.05 0.1 0.02 60 60 60 0 0 1 -360 360; 46 | 2 5 0.1 0.3 0.04 30 30 30 0 0 1 -360 360; 47 | 2 6 0.07 0.2 0.05 90 90 90 0 0 1 -360 360; 48 | 3 5 0.12 0.26 0.05 70 70 70 0 0 1 -360 360; 49 | 3 6 0.02 0.1 0.02 80 80 80 0 0 1 -360 360; 50 | 4 5 0.2 0.4 0.08 20 20 20 0 0 1 -360 360; 51 | 5 6 0.1 0.3 0.06 40 40 40 0 0 1 -360 360; 52 | ]; 53 | 54 | %%----- OPF Data -----%% 55 | %% generator cost data 56 | % 1 startup shutdown n x1 y1 ... xn yn 57 | % 2 startup shutdown n c(n-1) ... c0 58 | mpc.gencost = [ 59 | 2 0 0 3 0.00533 11.669 213.1; 60 | 2 0 0 3 0.00889 10.333 200; 61 | 2 0 0 3 0.00741 10.833 240; 62 | ]; 63 | -------------------------------------------------------------------------------- /library/matpower5.1/case9.m: -------------------------------------------------------------------------------- 1 | function mpc = case9 2 | %CASE9 Power flow data for 9 bus, 3 generator case. 3 | % Please see CASEFORMAT for details on the case file format. 4 | % 5 | % Based on data from Joe H. Chow's book, p. 70. 6 | 7 | % MATPOWER 8 | % $Id: case9.m 2408 2014-10-22 20:41:33Z ray $ 9 | 10 | %% MATPOWER Case Format : Version 2 11 | mpc.version = '2'; 12 | 13 | %%----- Power Flow Data -----%% 14 | %% system MVA base 15 | mpc.baseMVA = 100; 16 | 17 | %% bus data 18 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 19 | mpc.bus = [ 20 | 1 3 0 0 0 0 1 1 0 345 1 1.1 0.9; 21 | 2 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 22 | 3 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 23 | 4 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 24 | 5 1 90 30 0 0 1 1 0 345 1 1.1 0.9; 25 | 6 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 26 | 7 1 100 35 0 0 1 1 0 345 1 1.1 0.9; 27 | 8 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 28 | 9 1 125 50 0 0 1 1 0 345 1 1.1 0.9; 29 | ]; 30 | 31 | %% generator data 32 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 33 | mpc.gen = [ 34 | 1 0 0 300 -300 1 100 1 250 10 0 0 0 0 0 0 0 0 0 0 0; 35 | 2 163 0 300 -300 1 100 1 300 10 0 0 0 0 0 0 0 0 0 0 0; 36 | 3 85 0 300 -300 1 100 1 270 10 0 0 0 0 0 0 0 0 0 0 0; 37 | ]; 38 | 39 | %% branch data 40 | % fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax 41 | mpc.branch = [ 42 | 1 4 0 0.0576 0 250 250 250 0 0 1 -360 360; 43 | 4 5 0.017 0.092 0.158 250 250 250 0 0 1 -360 360; 44 | 5 6 0.039 0.17 0.358 150 150 150 0 0 1 -360 360; 45 | 3 6 0 0.0586 0 300 300 300 0 0 1 -360 360; 46 | 6 7 0.0119 0.1008 0.209 150 150 150 0 0 1 -360 360; 47 | 7 8 0.0085 0.072 0.149 250 250 250 0 0 1 -360 360; 48 | 8 2 0 0.0625 0 250 250 250 0 0 1 -360 360; 49 | 8 9 0.032 0.161 0.306 250 250 250 0 0 1 -360 360; 50 | 9 4 0.01 0.085 0.176 250 250 250 0 0 1 -360 360; 51 | ]; 52 | 53 | %%----- OPF Data -----%% 54 | %% generator cost data 55 | % 1 startup shutdown n x1 y1 ... xn yn 56 | % 2 startup shutdown n c(n-1) ... c0 57 | mpc.gencost = [ 58 | 2 1500 0 3 0.11 5 150; 59 | 2 2000 0 3 0.085 1.2 600; 60 | 2 3000 0 3 0.1225 1 335; 61 | ]; 62 | -------------------------------------------------------------------------------- /library/matpower5.1/case9Q.m: -------------------------------------------------------------------------------- 1 | function mpc = case9Q 2 | %CASE9Q Case 9 with costs for reactive generation. 3 | % Please see CASEFORMAT for details on the case file format. 4 | % 5 | % Identical to case9.m, with the addition of non-zero costs for 6 | % reactive power. 7 | 8 | % MATPOWER 9 | % $Id: case9Q.m 2408 2014-10-22 20:41:33Z ray $ 10 | 11 | %% MATPOWER Case Format : Version 2 12 | mpc.version = '2'; 13 | 14 | %%----- Power Flow Data -----%% 15 | %% system MVA base 16 | mpc.baseMVA = 100; 17 | 18 | %% bus data 19 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 20 | mpc.bus = [ 21 | 1 3 0 0 0 0 1 1 0 345 1 1.1 0.9; 22 | 2 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 23 | 3 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 24 | 4 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 25 | 5 1 90 30 0 0 1 1 0 345 1 1.1 0.9; 26 | 6 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 27 | 7 1 100 35 0 0 1 1 0 345 1 1.1 0.9; 28 | 8 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 29 | 9 1 125 50 0 0 1 1 0 345 1 1.1 0.9; 30 | ]; 31 | 32 | %% generator data 33 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 34 | mpc.gen = [ 35 | 1 0 0 300 -300 1 100 1 250 10 0 0 0 0 0 0 0 0 0 0 0; 36 | 2 163 0 300 -300 1 100 1 300 10 0 0 0 0 0 0 0 0 0 0 0; 37 | 3 85 0 300 -300 1 100 1 270 10 0 0 0 0 0 0 0 0 0 0 0; 38 | ]; 39 | 40 | %% branch data 41 | % fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax 42 | mpc.branch = [ 43 | 1 4 0 0.0576 0 250 250 250 0 0 1 -360 360; 44 | 4 5 0.017 0.092 0.158 250 250 250 0 0 1 -360 360; 45 | 5 6 0.039 0.17 0.358 150 150 150 0 0 1 -360 360; 46 | 3 6 0 0.0586 0 300 300 300 0 0 1 -360 360; 47 | 6 7 0.0119 0.1008 0.209 150 150 150 0 0 1 -360 360; 48 | 7 8 0.0085 0.072 0.149 250 250 250 0 0 1 -360 360; 49 | 8 2 0 0.0625 0 250 250 250 0 0 1 -360 360; 50 | 8 9 0.032 0.161 0.306 250 250 250 0 0 1 -360 360; 51 | 9 4 0.01 0.085 0.176 250 250 250 0 0 1 -360 360; 52 | ]; 53 | 54 | %%----- OPF Data -----%% 55 | %% generator cost data 56 | % 1 startup shutdown n x1 y1 ... xn yn 57 | % 2 startup shutdown n c(n-1) ... c0 58 | mpc.gencost = [ 59 | 2 1500 0 3 0.11 5 150; 60 | 2 2000 0 3 0.085 1.2 600; 61 | 2 3000 0 3 0.1225 1 335; 62 | 2 0 0 3 0.2 0 0; 63 | 2 0 0 3 0.05 0 0; 64 | 2 0 0 3 0.3 0 0; 65 | ]; 66 | -------------------------------------------------------------------------------- /library/matpower5.1/case9target.m: -------------------------------------------------------------------------------- 1 | function mpc = case9target 2 | %CASE9TARGET Target injection power flow data for 9 bus, 3 generator case. 3 | % Please see CASEFORMAT for details on the case file format. 4 | % 5 | % Modified version of case9.m used as target for example CPF. 6 | 7 | % MATPOWER 8 | % $Id: case9target.m 2408 2014-10-22 20:41:33Z ray $ 9 | 10 | %% MATPOWER Case Format : Version 2 11 | mpc.version = '2'; 12 | 13 | %%----- Power Flow Data -----%% 14 | %% system MVA base 15 | mpc.baseMVA = 100; 16 | 17 | %% bus data 18 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 19 | mpc.bus = [ 20 | 1 3 0 0 0 0 1 1 0 345 1 1.1 0.9; 21 | 2 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 22 | 3 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 23 | 4 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 24 | 5 1 305.4 123.15 0 0 1 1 0 345 1 1.1 0.9; 25 | 6 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 26 | 7 1 214.11 71.09 0 0 1 1 0 345 1 1.1 0.9; 27 | 8 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 28 | 9 1 235.61 81.44 0 0 1 1 0 345 1 1.1 0.9; 29 | ]; 30 | 31 | %% generator data 32 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 33 | mpc.gen = [ 34 | 1 0 0 300 -300 1 100 1 250 10 0 0 0 0 0 0 0 0 0 0 0; 35 | 2 248 0 300 -300 1 100 1 300 10 0 0 0 0 0 0 0 0 0 0 0; 36 | 3 124.59 0 300 -300 1 100 1 270 10 0 0 0 0 0 0 0 0 0 0 0; 37 | ]; 38 | 39 | %% branch data 40 | % fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax 41 | mpc.branch = [ 42 | 1 4 0 0.0576 0 250 250 250 0 0 1 -360 360; 43 | 4 5 0.017 0.092 0.158 250 250 250 0 0 1 -360 360; 44 | 5 6 0.039 0.17 0.358 150 150 150 0 0 1 -360 360; 45 | 3 6 0 0.0586 0 300 300 300 0 0 1 -360 360; 46 | 6 7 0.0119 0.1008 0.209 150 150 150 0 0 1 -360 360; 47 | 7 8 0.0085 0.072 0.149 250 250 250 0 0 1 -360 360; 48 | 8 2 0 0.0625 0 250 250 250 0 0 1 -360 360; 49 | 8 9 0.032 0.161 0.306 250 250 250 0 0 1 -360 360; 50 | 9 4 0.01 0.085 0.176 250 250 250 0 0 1 -360 360; 51 | ]; 52 | 53 | %%----- OPF Data -----%% 54 | %% generator cost data 55 | % 1 startup shutdown n x1 y1 ... xn yn 56 | % 2 startup shutdown n c(n-1) ... c0 57 | mpc.gencost = [ 58 | 2 1500 0 3 0.11 5 150; 59 | 2 2000 0 3 0.085 1.2 600; 60 | 2 3000 0 3 0.1225 1 335; 61 | ]; 62 | -------------------------------------------------------------------------------- /library/matpower5.1/cpf_p.m: -------------------------------------------------------------------------------- 1 | function P = cpf_p(parameterization, step, z, V, lam, Vprv, lamprv, pv, pq) 2 | %CPF_P Computes the value of the CPF parameterization function. 3 | % 4 | % P = CPF_P(PARAMETERIZATION, STEP, Z, V, LAM, VPRV, LAMPRV, PV, PQ) 5 | % 6 | % Computes the value of the parameterization function at the current 7 | % solution point. 8 | % 9 | % Inputs: 10 | % PARAMETERIZATION : Value of cpf.parameterization option 11 | % STEP : continuation step size 12 | % Z : normalized tangent prediction vector from previous step 13 | % V : complex bus voltage vector at current solution 14 | % LAM : scalar lambda value at current solution 15 | % VPRV : complex bus voltage vector at previous solution 16 | % LAMPRV : scalar lambda value at previous solution 17 | % PV : vector of indices of PV buses 18 | % PQ : vector of indices of PQ buses 19 | % 20 | % Outputs: 21 | % P : value of the parameterization function at the current point 22 | % 23 | % See also CPF_PREDICTOR, CPF_CORRECTOR. 24 | 25 | % MATPOWER 26 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 27 | % by Shrirang Abhyankar, Argonne National Laboratory 28 | % and Ray Zimmerman, PSERC Cornell 29 | % 30 | % $Id: cpf_p.m 2644 2015-03-11 19:34:22Z ray $ 31 | % 32 | % This file is part of MATPOWER. 33 | % Covered by the 3-clause BSD License (see LICENSE file for details). 34 | % See http://www.pserc.cornell.edu/matpower/ for more info. 35 | 36 | %% evaluate P(x0, lambda0) 37 | if parameterization == 1 %% natural 38 | if lam >= lamprv 39 | P = lam - lamprv - step; 40 | else 41 | P = lamprv - lam - step; 42 | end 43 | elseif parameterization == 2 %% arc length 44 | Va = angle(V); 45 | Vm = abs(V); 46 | Vaprv = angle(Vprv); 47 | Vmprv = abs(Vprv); 48 | P = sum(([Va([pv; pq]); Vm(pq); lam] - [Vaprv([pv; pq]); Vmprv(pq); lamprv]).^2) - step^2; 49 | elseif parameterization == 3 %% pseudo arc length 50 | nb = length(V); 51 | Va = angle(V); 52 | Vm = abs(V); 53 | Vaprv = angle(Vprv); 54 | Vmprv = abs(Vprv); 55 | P = z([pv; pq; nb+pq; 2*nb+1])' * ... 56 | ( [Va([pv; pq]); Vm(pq); lam] - [Vaprv([pv; pq]); Vmprv(pq); lamprv] )... 57 | - step; 58 | end 59 | -------------------------------------------------------------------------------- /library/matpower5.1/cpf_p_jac.m: -------------------------------------------------------------------------------- 1 | function [dP_dV, dP_dlam] = cpf_p_jac(parameterization, z, V, lam, Vprv, lamprv, pv, pq) 2 | %CPF_P_JAC Computes partial derivatives of CPF parameterization function. 3 | % 4 | % [DP_DV, DP_DLAM ] = CPF_P_JAC(PARAMETERIZATION, Z, V, LAM, ... 5 | % VPRV, LAMPRV, PV, PQ) 6 | % 7 | % Computes the partial derivatives of the continuation power flow 8 | % parameterization function w.r.t. bus voltages and the continuation 9 | % parameter lambda. 10 | % 11 | % Inputs: 12 | % PARAMETERIZATION : Value of cpf.parameterization option. 13 | % Z : normalized tangent prediction vector from previous step 14 | % V : complex bus voltage vector at current solution 15 | % LAM : scalar lambda value at current solution 16 | % VPRV : complex bus voltage vector at previous solution 17 | % LAMPRV : scalar lambda value at previous solution 18 | % PV : vector of indices of PV buses 19 | % PQ : vector of indices of PQ buses 20 | % 21 | % Outputs: 22 | % DP_DV : partial of parameterization function w.r.t. voltages 23 | % DP_DLAM : partial of parameterization function w.r.t. lambda 24 | % 25 | % See also CPF_PREDICTOR, CPF_CORRECTOR. 26 | 27 | % MATPOWER 28 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 29 | % by Shrirang Abhyankar, Argonne National Laboratory 30 | % and Ray Zimmerman, PSERC Cornell 31 | % 32 | % $Id: cpf_p_jac.m 2644 2015-03-11 19:34:22Z ray $ 33 | % 34 | % This file is part of MATPOWER. 35 | % Covered by the 3-clause BSD License (see LICENSE file for details). 36 | % See http://www.pserc.cornell.edu/matpower/ for more info. 37 | 38 | if parameterization == 1 %% natural 39 | npv = length(pv); 40 | npq = length(pq); 41 | dP_dV = zeros(1, npv+2*npq); 42 | if lam >= lamprv 43 | dP_dlam = 1.0; 44 | else 45 | dP_dlam = -1.0; 46 | end 47 | elseif parameterization == 2 %% arc length 48 | Va = angle(V); 49 | Vm = abs(V); 50 | Vaprv = angle(Vprv); 51 | Vmprv = abs(Vprv); 52 | dP_dV = 2*([Va([pv; pq]); Vm(pq)] - [Vaprv([pv; pq]); Vmprv(pq)])'; 53 | if lam == lamprv %% first step 54 | dP_dlam = 1.0; %% avoid singular Jacobian that would result 55 | %% from [dP_dV, dP_dlam] = 0 56 | else 57 | dP_dlam = 2*(lam-lamprv); 58 | end 59 | elseif parameterization == 3 %% pseudo arc length 60 | nb = length(V); 61 | dP_dV = z([pv; pq; nb+pq])'; 62 | dP_dlam = z(2*nb+1); 63 | end 64 | -------------------------------------------------------------------------------- /library/matpower5.1/d2Ibr_dV2.m: -------------------------------------------------------------------------------- 1 | function [Haa, Hav, Hva, Hvv] = d2Ibr_dV2(Ybr, V, lam) 2 | %D2IBR_DV2 Computes 2nd derivatives of complex branch current w.r.t. voltage. 3 | % [HAA, HAV, HVA, HVV] = D2IBR_DV2(CBR, YBR, V, LAM) returns 4 matrices 4 | % containing the partial derivatives w.r.t. voltage angle and magnitude 5 | % of the product of a vector LAM with the 1st partial derivatives of the 6 | % complex branch currents. Takes sparse branch admittance matrix YBR, 7 | % voltage vector V and nl x 1 vector of multipliers LAM. Output matrices 8 | % are sparse. 9 | % 10 | % Example: 11 | % [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); 12 | % Ybr = Yf; 13 | % [Haa, Hav, Hva, Hvv] = d2Ibr_dV2(Ybr, V, lam); 14 | % 15 | % Here the output matrices correspond to: 16 | % Haa = (d/dVa (dIbr_dVa.')) * lam 17 | % Hav = (d/dVm (dIbr_dVa.')) * lam 18 | % Hva = (d/dVa (dIbr_dVm.')) * lam 19 | % Hvv = (d/dVm (dIbr_dVm.')) * lam 20 | % 21 | % For more details on the derivations behind the derivative code used 22 | % in MATPOWER information, see: 23 | % 24 | % [TN2] R. D. Zimmerman, "AC Power Flows, Generalized OPF Costs and 25 | % their Derivatives using Complex Matrix Notation", MATPOWER 26 | % Technical Note 2, February 2010. 27 | % http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf 28 | 29 | % MATPOWER 30 | % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 31 | % by Ray Zimmerman, PSERC Cornell 32 | % 33 | % $Id: d2Ibr_dV2.m 2644 2015-03-11 19:34:22Z ray $ 34 | % 35 | % This file is part of MATPOWER. 36 | % Covered by the 3-clause BSD License (see LICENSE file for details). 37 | % See http://www.pserc.cornell.edu/matpower/ for more info. 38 | 39 | %% define 40 | nb = length(V); 41 | 42 | diaginvVm = sparse(1:nb, 1:nb, ones(nb, 1)./abs(V), nb, nb); 43 | 44 | Haa = sparse(1:nb, 1:nb, -(Ybr.' * lam) .* V, nb, nb); 45 | Hva = -1j * Haa * diaginvVm; 46 | Hav = Hva; 47 | Hvv = sparse(nb, nb); 48 | -------------------------------------------------------------------------------- /library/matpower5.1/d2Sbr_dV2.m: -------------------------------------------------------------------------------- 1 | function [Haa, Hav, Hva, Hvv] = d2Sbr_dV2(Cbr, Ybr, V, lam) 2 | %D2SBR_DV2 Computes 2nd derivatives of complex power flow w.r.t. voltage. 3 | % [HAA, HAV, HVA, HVV] = D2SBR_DV2(CBR, YBR, V, LAM) returns 4 matrices 4 | % containing the partial derivatives w.r.t. voltage angle and magnitude 5 | % of the product of a vector LAM with the 1st partial derivatives of the 6 | % complex branch power flows. Takes sparse connection matrix CBR, sparse 7 | % branch admittance matrix YBR, voltage vector V and nl x 1 vector of 8 | % multipliers LAM. Output matrices are sparse. 9 | % 10 | % Example: 11 | % f = branch(:, F_BUS); 12 | % Cf = sparse(1:nl, f, ones(nl, 1), nl, nb); 13 | % [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); 14 | % Cbr = Cf; 15 | % Ybr = Yf; 16 | % [Haa, Hav, Hva, Hvv] = d2Sbr_dV2(Cbr, Ybr, V, lam); 17 | % 18 | % Here the output matrices correspond to: 19 | % Haa = (d/dVa (dSbr_dVa.')) * lam 20 | % Hav = (d/dVm (dSbr_dVa.')) * lam 21 | % Hva = (d/dVa (dSbr_dVm.')) * lam 22 | % Hvv = (d/dVm (dSbr_dVm.')) * lam 23 | % 24 | % For more details on the derivations behind the derivative code used 25 | % in MATPOWER information, see: 26 | % 27 | % [TN2] R. D. Zimmerman, "AC Power Flows, Generalized OPF Costs and 28 | % their Derivatives using Complex Matrix Notation", MATPOWER 29 | % Technical Note 2, February 2010. 30 | % http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf 31 | 32 | % MATPOWER 33 | % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 34 | % by Ray Zimmerman, PSERC Cornell 35 | % 36 | % $Id: d2Sbr_dV2.m 2644 2015-03-11 19:34:22Z ray $ 37 | % 38 | % This file is part of MATPOWER. 39 | % Covered by the 3-clause BSD License (see LICENSE file for details). 40 | % See http://www.pserc.cornell.edu/matpower/ for more info. 41 | 42 | %% define 43 | nl = length(lam); 44 | nb = length(V); 45 | 46 | diaglam = sparse(1:nl, 1:nl, lam, nl, nl); 47 | diagV = sparse(1:nb, 1:nb, V, nb, nb); 48 | 49 | A = Ybr' * diaglam * Cbr; 50 | B = conj(diagV) * A * diagV; 51 | D = sparse(1:nb, 1:nb, (A*V) .* conj(V), nb, nb); 52 | E = sparse(1:nb, 1:nb, (A.'*conj(V)) .* V, nb, nb); 53 | F = B + B.'; 54 | G = sparse(1:nb, 1:nb, ones(nb, 1)./abs(V), nb, nb); 55 | 56 | Haa = F - D - E; 57 | Hva = 1j * G * (B - B.' - D + E); 58 | Hav = Hva.'; 59 | Hvv = G * F * G; 60 | -------------------------------------------------------------------------------- /library/matpower5.1/d2Sbus_dV2.m: -------------------------------------------------------------------------------- 1 | function [Gaa, Gav, Gva, Gvv] = d2Sbus_dV2(Ybus, V, lam) 2 | %D2SBUS_DV2 Computes 2nd derivatives of power injection w.r.t. voltage. 3 | % [GAA, GAV, GVA, GVV] = D2SBUS_DV2(YBUS, V, LAM) returns 4 matrices 4 | % containing the partial derivatives w.r.t. voltage angle and magnitude 5 | % of the product of a vector LAM with the 1st partial derivatives of the 6 | % complex bus power injections. Takes sparse bus admittance matrix YBUS, 7 | % voltage vector V and nb x 1 vector of multipliers LAM. Output matrices 8 | % are sparse. 9 | % 10 | % Example: 11 | % [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); 12 | % [Gaa, Gav, Gva, Gvv] = d2Sbus_dV2(Ybus, V, lam); 13 | % 14 | % Here the output matrices correspond to: 15 | % Gaa = (d/dVa (dSbus_dVa.')) * lam 16 | % Gav = (d/dVm (dSbus_dVa.')) * lam 17 | % Gva = (d/dVa (dSbus_dVm.')) * lam 18 | % Gvv = (d/dVm (dSbus_dVm.')) * lam 19 | % 20 | % For more details on the derivations behind the derivative code used 21 | % in MATPOWER information, see: 22 | % 23 | % [TN2] R. D. Zimmerman, "AC Power Flows, Generalized OPF Costs and 24 | % their Derivatives using Complex Matrix Notation", MATPOWER 25 | % Technical Note 2, February 2010. 26 | % http://www.pserc.cornell.edu/matpower/TN2-OPF-Derivatives.pdf 27 | 28 | % MATPOWER 29 | % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 30 | % by Ray Zimmerman, PSERC Cornell 31 | % 32 | % $Id: d2Sbus_dV2.m 2644 2015-03-11 19:34:22Z ray $ 33 | % 34 | % This file is part of MATPOWER. 35 | % Covered by the 3-clause BSD License (see LICENSE file for details). 36 | % See http://www.pserc.cornell.edu/matpower/ for more info. 37 | 38 | n = length(V); 39 | Ibus = Ybus * V; 40 | diaglam = sparse(1:n, 1:n, lam, n, n); 41 | diagV = sparse(1:n, 1:n, V, n, n); 42 | 43 | A = sparse(1:n, 1:n, lam .* V, n, n); 44 | B = Ybus * diagV; 45 | C = A * conj(B); 46 | D = Ybus' * diagV; 47 | E = conj(diagV) * (D * diaglam - sparse(1:n, 1:n, D*lam, n, n)); 48 | F = C - A * sparse(1:n, 1:n, conj(Ibus), n, n); 49 | G = sparse(1:n, 1:n, ones(n, 1)./abs(V), n, n); 50 | 51 | Gaa = E + F; 52 | Gva = 1j * G * (E - F); 53 | Gav = Gva.'; 54 | Gvv = G * (C + C.') * G; 55 | -------------------------------------------------------------------------------- /library/matpower5.1/dcopf.m: -------------------------------------------------------------------------------- 1 | function [varargout] = dcopf(varargin) 2 | %DCOPF Solves a DC optimal power flow. 3 | % This is a simple wrapper function around OPF that sets the 'model' 4 | % option to 'DC' before calling OPF. 5 | % See OPF for the details of input and output arguments. 6 | % 7 | % See also RUNDCOPF. 8 | 9 | % MATPOWER 10 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 11 | % by Ray Zimmerman, PSERC Cornell 12 | % 13 | % $Id: dcopf.m 2644 2015-03-11 19:34:22Z ray $ 14 | % 15 | % This file is part of MATPOWER. 16 | % Covered by the 3-clause BSD License (see LICENSE file for details). 17 | % See http://www.pserc.cornell.edu/matpower/ for more info. 18 | 19 | [mpc, mpopt] = opf_args(varargin{:}); 20 | mpopt = mpoption(mpopt, 'model', 'DC'); 21 | [varargout{1:nargout}] = opf(mpc, mpopt); 22 | -------------------------------------------------------------------------------- /library/matpower5.1/dcpf.m: -------------------------------------------------------------------------------- 1 | function Va = dcpf(B, Pbus, Va0, ref, pv, pq) 2 | %DCPF Solves a DC power flow. 3 | % [VA, SUCCESS] = DCPF(B, PBUS, VA0, REF, PV, PQ) solves for the bus 4 | % voltage angles at all but the reference bus, given the full system 5 | % B matrix and the vector of bus real power injections, the initial 6 | % vector of bus voltage angles (in radians), and column vectors with 7 | % the lists of bus indices for the swing bus, PV buses, and PQ buses, 8 | % respectively. Returns a vector of bus voltage angles in radians. 9 | % 10 | % See also RUNDCPF, RUNPF. 11 | 12 | % MATPOWER 13 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 14 | % by Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales 15 | % and Ray Zimmerman, PSERC Cornell 16 | % 17 | % $Id: dcpf.m 2644 2015-03-11 19:34:22Z ray $ 18 | % 19 | % This file is part of MATPOWER. 20 | % Covered by the 3-clause BSD License (see LICENSE file for details). 21 | % See http://www.pserc.cornell.edu/matpower/ for more info. 22 | 23 | %% initialize result vector 24 | Va = Va0; 25 | 26 | %% update angles for non-reference buses 27 | 28 | Va([pv; pq]) = B([pv; pq], [pv; pq]) \ (Pbus([pv; pq]) - B([pv; pq], ref) * Va0(ref)); 29 | -------------------------------------------------------------------------------- /library/matpower5.1/docs/TN1-OPF-Auctions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/docs/TN1-OPF-Auctions.pdf -------------------------------------------------------------------------------- /library/matpower5.1/docs/TN2-OPF-Derivatives.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/docs/TN2-OPF-Derivatives.pdf -------------------------------------------------------------------------------- /library/matpower5.1/docs/manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/docs/manual.pdf -------------------------------------------------------------------------------- /library/matpower5.1/e2i_field.m: -------------------------------------------------------------------------------- 1 | function mpc = e2i_field(mpc, field, ordering, dim) 2 | %E2I_FIELD Converts fields of MPC from external to internal indexing. 3 | % 4 | % This function performs several different tasks, depending on the 5 | % arguments passed. 6 | % 7 | % MPC = E2I_FIELD(MPC, FIELD, ORDERING) 8 | % MPC = E2I_FIELD(MPC, FIELD, ORDERING, DIM) 9 | % 10 | % When given a case struct that has already been converted to 11 | % internal indexing, this function can be used to convert other data 12 | % structures as well by passing in 2 or 3 extra parameters in 13 | % addition to the case struct. 14 | % 15 | % The 2nd argument is a string or cell array of strings, specifying 16 | % a field in the case struct whose value should be converted by 17 | % a corresponding call to E2I_DATA. The field can contain either a 18 | % numeric or a cell array. The converted value is stored back in the 19 | % specified field, the original value is saved for later use and the 20 | % updated case struct is returned. If FIELD is a cell array of strings, 21 | % they specify nested fields. 22 | % 23 | % The 3rd and optional 4th arguments are simply passed along to 24 | % the call to E2I_DATA. 25 | % 26 | % Examples: 27 | % mpc = e2i_field(mpc, {'reserves', 'cost'}, 'gen'); 28 | % 29 | % Reorders rows of mpc.reserves.cost to match internal generator 30 | % ordering. 31 | % 32 | % mpc = e2i_field(mpc, {'reserves', 'zones'}, 'gen', 2); 33 | % 34 | % Reorders columns of mpc.reserves.zones to match internal 35 | % generator ordering. 36 | % 37 | % See also I2E_FIELD, E2I_DATA, EXT2INT. 38 | 39 | % MATPOWER 40 | % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 41 | % by Ray Zimmerman, PSERC Cornell 42 | % 43 | % $Id: e2i_field.m 2644 2015-03-11 19:34:22Z ray $ 44 | % 45 | % This file is part of MATPOWER. 46 | % Covered by the 3-clause BSD License (see LICENSE file for details). 47 | % See http://www.pserc.cornell.edu/matpower/ for more info. 48 | 49 | if nargin < 4 50 | dim = 1; 51 | end 52 | if ischar(field) 53 | mpc.order.ext.(field) = mpc.(field); 54 | mpc.(field) = e2i_data(mpc, mpc.(field), ordering, dim); 55 | else %% iscell(field) 56 | for k = 1:length(field) 57 | s(k).type = '.'; 58 | s(k).subs = field{k}; 59 | end 60 | mpc.order.ext = subsasgn(mpc.order.ext, s, subsref(mpc, s)); 61 | mpc = subsasgn(mpc, s, ... 62 | e2i_data(mpc, subsref(mpc, s), ordering, dim) ); 63 | end 64 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/misc/loss2bus.m: -------------------------------------------------------------------------------- 1 | function bus_loss = loss2bus(mpc) 2 | %LOSS2BUS Accumulates branch real power losses at downstream buses. 3 | % 4 | % BUS_LOSS = LOSS2BUS(MPC) 5 | % 6 | % Takes a solved AC power flow case as input and returns an 7 | % NB x 1 vector containing all branch active power losses 8 | % accumulated to the bus at the downstream end of the branch. 9 | 10 | % MATPOWER 11 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 12 | % by Ray Zimmerman, PSERC Cornell 13 | % 14 | % $Id: loss2bus.m 2644 2015-03-11 19:34:22Z ray $ 15 | % 16 | % This file is part of MATPOWER. 17 | % Covered by the 3-clause BSD License (see LICENSE file for details). 18 | % See http://www.pserc.cornell.edu/matpower/ for more info. 19 | 20 | define_constants; 21 | 22 | %% create external to internal bus map 23 | nb = size(mpc.bus, 1); %% number of buses 24 | nl = size(mpc.branch, 1); %% number of branches 25 | mb = max(abs([mpc.bus(:, BUS_I); mpc.gen(:, GEN_BUS); ... 26 | mpc.branch(:, F_BUS); mpc.branch(:, T_BUS)])); 27 | e2i = sparse(mpc.bus(:, BUS_I), ones(nb, 1), 1:nb, mb, 1); 28 | 29 | %% assign losses to downstream buses 30 | loss = mpc.branch(:, PF) + mpc.branch(:, PT); 31 | bus_loss = zeros(nb, 1); 32 | for j = 1:nl %% need to use loop to accumulate for multiple lines per bus 33 | if mpc.branch(j, PF) >= mpc.branch(j, PT) 34 | b = T_BUS; 35 | else 36 | b = F_BUS; 37 | end 38 | ib = e2i(mpc.branch(j, b)); 39 | bus_loss(ib) = bus_loss(ib) + loss(j); 40 | end 41 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/reduction/DefBoundary.m: -------------------------------------------------------------------------------- 1 | function [BoundBus]=DefBoundary(mpc,ExBus) 2 | % Subroutine DefBoundary indentify the boundary buses in the given model 3 | % mpc based on the list of external buses (ExBus). 4 | % 5 | % [BoundBus]=DefBoundary(mpc,ExBus) 6 | % 7 | % INPUT DATA: 8 | % mpc - struct, input system model in MATPOWER format 9 | % ExBus - 1*n array, includes external bus indices 10 | % 11 | % OUTPUT DATA: 12 | % BoundBus - 1*n array, Boundary bus indices 13 | % 14 | % Note: 15 | % Boundary buses are the retained buses directly connected to external 16 | % buses. 17 | 18 | % MATPOWER 19 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 20 | % by Yujia Zhu, PSERC ASU 21 | % 22 | % $Id: DefBoundary.m 2655 2015-03-18 16:40:32Z ray $ 23 | % 24 | % This file is part of MATPOWER. 25 | % Covered by the 3-clause BSD License (see LICENSE file for details). 26 | % See http://www.pserc.cornell.edu/matpower/ for more info. 27 | 28 | BoundBus=zeros(size(mpc.bus,1),1); 29 | ExFlag=BoundBus; 30 | ExFlag(ExBus)=1; 31 | 32 | for i = 1:size(mpc.branch,1) 33 | m=mpc.branch(i,1); 34 | n=mpc.branch(i,2); 35 | if ExFlag(m)+ExFlag(n)<2 % exclude external branch 36 | if (ExFlag(m)*n+ExFlag(n)*m)~=0 37 | BoundBus(ExFlag(m)*n+ExFlag(n)*m)=1; 38 | end 39 | end 40 | end 41 | BoundBus=find(BoundBus==1); 42 | 43 | end -------------------------------------------------------------------------------- /library/matpower5.1/extras/reduction/DoReduction.m: -------------------------------------------------------------------------------- 1 | function [mpcreduced,BCIRC,ExBus] = DoReduction(DataB,ERP,CIndx,ExBus,NUMB,dim,BCIRC,newbusnum,oldbusnum,mpc) 2 | % Subroutine DoReduction create the reduced network based on input network 3 | % data. 4 | % 5 | % [mpcreduced,BCIRC,ExBus] = DoReduction(DataB,ERP,CIndx,ExBus,NUMB,dim,BCIRC,newbusnum,oldbusnum,mpc,label) 6 | % 7 | % INPUT DATA: 8 | % DataB: 1*n array, admittance value in input admittance matrix 9 | % ERP: 1*n array, end of row pointer of the input admittance matrix 10 | % CIndx: 1*n array, column indices of every row of the input admittance 11 | % matrix. 12 | % ExBus: 1*n array, external bus indices 13 | % NUMB: 1*n array, bus indices 14 | % dim: scalar, dimension of the input admittance matrix (should be square) 15 | % BCIRC: 1*n array, branch circuit number 16 | % newbusnum: 1*n array, internal bus indices 17 | % oldbusnum: 1*n array, original bus indices 18 | % 19 | % OUTPUT DATA: 20 | % mpcreduced: struct, reduced model, without external generator placement 21 | % and load redistribution 22 | % BCIRC: updated branch circuit number 23 | % ExBus: updated external bus indices 24 | % 25 | % NOTE: The reduced model generated by this subroutine doesn't involve 26 | % external generator placement and load redistribution. It's only good for 27 | % analyze the reduced network (toplogy+reactance). 28 | 29 | % MATPOWER 30 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 31 | % by Yujia Zhu, PSERC ASU 32 | % 33 | % $Id: DoReduction.m 2655 2015-03-18 16:40:32Z ray $ 34 | % 35 | % This file is part of MATPOWER. 36 | % Covered by the 3-clause BSD License (see LICENSE file for details). 37 | % See http://www.pserc.cornell.edu/matpower/ for more info. 38 | 39 | %% Define Boundary Buses 40 | [BoundBus]=DefBoundary(mpc,ExBus); 41 | %% Do Pivot including Tinney One 42 | [DataB,ERP,CIndx,PivOrd,PivInd] = PivotData(DataB,ERP,CIndx,ExBus,NUMB,BoundBus); 43 | %% Do LU factorization (Partial) 44 | [ERPU,CIndxU,ERPEQ,CIndxEQ] = PartialSymLU(CIndx,ERP,dim,length(ExBus),BoundBus); 45 | [DataEQ,DataShunt] = PartialNumLU (CIndx,CIndxU,DataB,dim,ERP,ERPU,length(ExBus),ERPEQ,CIndxEQ,BoundBus); 46 | %% Create the reduced model in MATPOWER format 47 | [mpcreduced,BCIRC,ExBus] = MakeMPCr(ERPEQ,DataEQ,CIndxEQ,DataShunt,ERP,DataB,ExBus,PivInd,PivOrd,BCIRC,newbusnum,oldbusnum,mpc,BoundBus); 48 | end -------------------------------------------------------------------------------- /library/matpower5.1/extras/reduction/Example_9bus.m: -------------------------------------------------------------------------------- 1 | % Example_9bus 2 | % test reduction code on 9-bus system (case9) 3 | % 4 | % Created by Yujia Zhu, yzhu54@asu.edu, Oct. 2014 5 | 6 | % MATPOWER 7 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 8 | % by Yujia Zhu, PSERC ASU 9 | % 10 | % $Id: Example_9bus.m 2655 2015-03-18 16:40:32Z ray $ 11 | % 12 | % This file is part of MATPOWER. 13 | % Covered by the 3-clause BSD License (see LICENSE file for details). 14 | % See http://www.pserc.cornell.edu/matpower/ for more info. 15 | 16 | %% load 9-bus case in MATPOWER format 17 | % If you have installed MATPOWER, you can use function "loadcase" instead 18 | % to read the case data 19 | mpc = loadcase('case9'); % input full model in MATPOWER case format 20 | %% give external bus indices 21 | ExBus=[1,5,8]'; % input list of external buses (buses to be eliminated) 22 | %% run reduction subroutine (MPReduction) 23 | %Input notes: 24 | % mpc: struct, the original full model in MATPOWER case format 25 | % ExBus: 1*n array, list of external buses 26 | [mpcreduced,Link,BCIRCr]=MPReduction(mpc,ExBus,0); % call reduction subroutine 27 | % Output notes: 28 | % 1. The output mpcreduced is the reduced 6 bus model 29 | % 2. All branch B shunts are converted to B shunts on buses 30 | % 3. There are 4 equivalent branches generated in the reduction process 31 | % branch between bus: 2-7, 2-9, 4-6, 7-9, all equivalent branches have 32 | % circuit number 99. 33 | % 4. Equivalent lines have no line ratings. 34 | % 5. Link gives generator bus mapping showing how generators are moved. 35 | % E.g: Generator on bus 1 is moved to bus 4, all other generators are 36 | % not moved since they were on retained buses 37 | % 6. The reduction process will generate equivalent lines with large 38 | % impedance. The software eliminate equivalent lines whose impedance is 39 | % larger than the threshold value. The threshold value in the software is 40 | % 10 times of maximum impedance (reactance) value in the original full 41 | % model. -------------------------------------------------------------------------------- /library/matpower5.1/extras/reduction/GenerateBCIRC.m: -------------------------------------------------------------------------------- 1 | function [BCIRC] = GenerateBCIRC(branch) 2 | % Subroutine GenerateBCIRC is used to detect parallel lines and generate the circuit number of every 3 | % branch. 4 | % 5 | % [BCIRC] = GenerateBCIRC(branch) 6 | % 7 | % INPUT DATA: 8 | % branch: matrix, includes branch data in MATPOWER case format 9 | % 10 | % OUTPUT DATA: 11 | % BCIRC: n*1 vector, includes branch circuit number 12 | % 13 | % NOTE: For one branch, if its circuit number is greater than 1 then it is 14 | % parallel to one of the branch whose circuit number is 1. 15 | 16 | % MATPOWER 17 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 18 | % by Yujia Zhu, PSERC ASU 19 | % 20 | % $Id: GenerateBCIRC.m 2655 2015-03-18 16:40:32Z ray $ 21 | % 22 | % This file is part of MATPOWER. 23 | % Covered by the 3-clause BSD License (see LICENSE file for details). 24 | % See http://www.pserc.cornell.edu/matpower/ for more info. 25 | 26 | [FTnum,m,n]=unique(branch(:,[1,2]),'rows','first'); 27 | n2 = unique(n); 28 | BCIRC = zeros(size(branch,1),1); 29 | for i = 1:length(n2) 30 | Ind = find(n==n2(i)); 31 | BCIRC(Ind)=[1:length(Ind)]'; 32 | end 33 | end -------------------------------------------------------------------------------- /library/matpower5.1/extras/reduction/MapBus.m: -------------------------------------------------------------------------------- 1 | function [mpc]=MapBus(mpc,oldbusnum,newbusnum) 2 | % Subroutine MapBus convert bus indices from oldbusnum to newbusnum. The 3 | % conversion will be done to fields including buses, branches and 4 | % generators. 5 | % 6 | % [mpc]=MapBus(mpc,oldbusnum,newbusnum) 7 | % 8 | % INPUT DATA: 9 | % mpc - struct, input model in MATPOWER format 10 | % oldbusnum - 1*n array, the old bus indices which will be converted "from" 11 | % newbusnum - 1*n array, the new bus indices which will be converted "to" 12 | % 13 | % OUTPUT DATA: 14 | % mpc - sctruct, output model in MATPOWER format with converted bus 15 | % indices. 16 | 17 | % MATPOWER 18 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 19 | % by Yujia Zhu, PSERC ASU 20 | % 21 | % $Id: MapBus.m 2655 2015-03-18 16:40:32Z ray $ 22 | % 23 | % This file is part of MATPOWER. 24 | % Covered by the 3-clause BSD License (see LICENSE file for details). 25 | % See http://www.pserc.cornell.edu/matpower/ for more info. 26 | 27 | % convert bus number 28 | mpc.bus(:,1)=interp1(oldbusnum,newbusnum,mpc.bus(:,1)); 29 | % convert branch terminal bus number 30 | mpc.branch(:,1)=interp1(oldbusnum,newbusnum,mpc.branch(:,1)); 31 | mpc.branch(:,2)=interp1(oldbusnum,newbusnum,mpc.branch(:,2)); 32 | % convert generator bus number 33 | mpc.gen(:,1)=interp1(oldbusnum,newbusnum,mpc.gen(:,1)); 34 | % if isfield(mpc,'dcline') 35 | % % convert hvdc line bus number 36 | % mpc.dcline(:,1)=interp1(oldbusnum,newbusnum,mpc.dcline(:,1)); 37 | % mpc.dcline(:,2)=interp1(oldbusnum,newbusnum,mpc.dcline(:,2)); 38 | % end 39 | end -------------------------------------------------------------------------------- /library/matpower5.1/extras/reduction/Network_Reduction_Toolbox.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/extras/reduction/Network_Reduction_Toolbox.pdf -------------------------------------------------------------------------------- /library/matpower5.1/extras/reduction/PreProcessData.m: -------------------------------------------------------------------------------- 1 | function [mpc,ExBus]=PreProcessData(mpc,ExBus) 2 | % Subroutine PreProcess do following tasks to input model: 3 | % 1. Eliminate all isolated buses 4 | % 2. Eliminate all out-of-service branches 5 | % 3. Eliminate all in-service but connected to isolated bus branches 6 | % 4. Eliminate all HVDC line connected to isolated buses 7 | % 5. Eliminate all generators on isolated buses 8 | % 6. Update the list of external bus (ExBus) by eliminating the isolated 9 | % buses in the list 10 | % 11 | % [mpc,ExBus]=PreProcessData(mpc,ExBus) 12 | % 13 | % INPUT DATA: 14 | % mpc: struct, input original full model (MATPOWER case file) 15 | % ExBus: 1*n array, original list of external buses 16 | % 17 | % OUTPUT DATA: 18 | % mpc: struct, updated model 19 | % ExBus: 1*n array, updated list of external buses 20 | 21 | % MATPOWER 22 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 23 | % by Yujia Zhu, PSERC ASU 24 | % 25 | % $Id: PreProcessData.m 2655 2015-03-18 16:40:32Z ray $ 26 | % 27 | % This file is part of MATPOWER. 28 | % Covered by the 3-clause BSD License (see LICENSE file for details). 29 | % See http://www.pserc.cornell.edu/matpower/ for more info. 30 | 31 | mpc.bus = sortrows(mpc.bus,1); 32 | mpc.branch = sortrows(mpc.branch,[1,2]); 33 | numbr=size(mpc.branch,1); 34 | mpc.branch(mpc.branch(:,11)==0,:)=[];% eliminated all out-of-service lines 35 | isobus=mpc.bus(mpc.bus(:,2)==4,1); 36 | fprintf('\nEliminate %d isolated buses',length(isobus)); 37 | tf1=ismember(mpc.branch(:,1),isobus); 38 | tf2=ismember(mpc.branch(:,2),isobus); 39 | mpc.branch(tf1|tf2,:)=[]; % eliminate all branch connected to isolated buses 40 | fprintf('\nEliminate %d branches',numbr-size(mpc.branch,1)); 41 | 42 | mpc.bus(mpc.bus(:,2)==4,:)=[]; % eliminate all isolated buses 43 | tfgen=ismember(mpc.gen(:,1),isobus); 44 | mpc.gen(tfgen,:)=[]; % eliminate all generators on isolated buses 45 | fprintf('\nEliminate %d generators',length(tfgen(tfgen==1))); 46 | if isfield (mpc,'gencost') 47 | mpc.gencost(tfgen,:)=[]; 48 | end 49 | ind=ismember(ExBus,isobus); 50 | ExBus(ind)=[]; 51 | if isfield(mpc,'dcline') 52 | tfdc1=ismember(mpc.dcline(:,1),isobus); 53 | tfdc2=ismember(mpc.dcline(:,2),isobus); 54 | mpc.dcline(tfdc1|tfdc2,:)=[]; % eliminate dcline connecting isolated terminal 55 | fprintf('\nEliminate %d dc lines',length(length(find(tfdc1|tfdc2)))); 56 | 57 | end 58 | fprintf('\nPreprocessing complete'); 59 | end -------------------------------------------------------------------------------- /library/matpower5.1/extras/reduction/SelfLink.m: -------------------------------------------------------------------------------- 1 | function [LinkPos,LinkArray,Counter] = SelfLink(Link,Start) 2 | % FUNCTION SUMMARY: 3 | % Subroutine SelfLink search the Link array in by self referencing. The 4 | % searching process will stop until a zero is found. Every non-zero 5 | % element found in the searching process will be stored in LinkArray and 6 | % their corresponding index pointers will be stored in LinkPos. Couter 7 | % will count the number of numzero element in LinkArray. 8 | % 9 | % [LinkPos,LinkArray,Counter] = SelfLink(Link,Start) 10 | % 11 | % INPUT DATA: 12 | % Link - N * 1 array containing the link list 13 | % Start- scalar is the starting point of the searching process 14 | % 15 | % OUTPUT DATA: 16 | % Counter - scalar, number of non-zero elements in LinkArray 17 | % LinkArray - N*1 array, containing the non-zero element found in the searching 18 | % process 19 | % LinkPos - N*1 array, containing the index pointers of the non-zero 20 | % elements stored in LinkArray 21 | % 22 | % INTERNAL DATA: 23 | % SelRef - scalar, used to do searching in Link list, which is equal to 24 | % the current found element and also pointer to the next element 25 | % 26 | % NOTE: 27 | % 1. Initiate the SelfRef=Start and Counter=0. Go to step 2. 28 | % Note: The following steps until step 3 are done in the while loop 29 | % 2. While the element found in the Link list (Link(SelfRef)) is not zero 30 | % go to step 2.1 if equal to zero go to step 3. 31 | % 2.1 Increment Counter by 1. Go to step 2.2 32 | % 2.2 Store SelfRef to LinkPos which is the index of current non-zero 33 | % element. Go to step 2.3 34 | % 2.3 Update the SelfRef equal to Link(SelfRef). Go to step 2.4 35 | % 2.4 Store the SelfRef value to LinkArray which is the value of 36 | % current element. Go to step 2. 37 | % 3. End of the subroutine. Return. 38 | 39 | % MATPOWER 40 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 41 | % by Yujia Zhu, PSERC ASU 42 | % 43 | % $Id: SelfLink.m 2655 2015-03-18 16:40:32Z ray $ 44 | % 45 | % This file is part of MATPOWER. 46 | % Covered by the 3-clause BSD License (see LICENSE file for details). 47 | % See http://www.pserc.cornell.edu/matpower/ for more info. 48 | 49 | SelfRef = Start; 50 | Counter = 0; 51 | while Link(SelfRef)~=0 52 | Counter = Counter+1; % count how many linkage in this list 53 | LinkPos(Counter)=SelfRef; 54 | SelfRef = Link(SelfRef); 55 | LinkArray(Counter)=SelfRef; % create the array of the self referential link list 56 | end 57 | end -------------------------------------------------------------------------------- /library/matpower5.1/extras/reduction/TinneyOne.m: -------------------------------------------------------------------------------- 1 | function [PivOrd,PivInd] = TinneyOne(ERP,PivInd,PivOrd,ExBus) 2 | % Subroutine TinneyOne applied Tinney 1 optimal ordering to the input data 3 | % in order to reduce the fills generated in the partial LU factorization 4 | % process. 5 | % 6 | % [PivOrd,PivInd] = TinneyOne(ERP,PivInd,PivOrd,ExBus) 7 | % 8 | % INPUT DATA: 9 | % ERP: 1*n array, includes end of row pointer of input addmittance matrix 10 | % PivInd: 1*n array, includes bus ordering after pivotting 11 | % PivOrd: 1*n array, includes bus indices after pivotting 12 | % ExBus: 1*n array, includes bus indices of external buses 13 | % 14 | % OUTPUT DATA: 15 | % PivInd: 1*n array, includes bus ordering after pivotting by Tinney 1 16 | % ordering 17 | % PivOrd: 1*n array, includes bus indices after pivotting by Tinney 1 18 | % ordering 19 | % 20 | % NOTE: 21 | % This subroutine does not pivot any data but output an array includes 22 | % ordering of buses. Pivoting will be done in the subroutine PivotData. 23 | 24 | % MATPOWER 25 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 26 | % by Yujia Zhu, PSERC ASU 27 | % 28 | % $Id: TinneyOne.m 2655 2015-03-18 16:40:32Z ray $ 29 | % 30 | % This file is part of MATPOWER. 31 | % Covered by the 3-clause BSD License (see LICENSE file for details). 32 | % See http://www.pserc.cornell.edu/matpower/ for more info. 33 | 34 | %% Extract the external bus part 35 | ExLen = length(ExBus); 36 | ERP_E = ERP(1:ExLen+1); 37 | %% 38 | RowLen = ERP_E; 39 | for i = 1:ExLen 40 | RowLen(i)=ERP_E(i+1)-ERP_E(i); % calculate the number of non-zero entry in each row 41 | end 42 | RowLen(end)=[]; 43 | [RowLen,RowOrd] = sort(RowLen); 44 | for i =1:ExLen 45 | RowOrdO(RowOrd(i))=i; 46 | end 47 | PivInd(1:ExLen)=PivInd(RowOrdO); 48 | for i = 1:ExLen 49 | PivOrd(PivInd(i))=i; 50 | end 51 | 52 | end -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/case2local.m: -------------------------------------------------------------------------------- 1 | function mpc = case2local 2 | %CASE2LOCAL Power flow data for 2-bus system used in [1]. 3 | % Please see CASEFORMAT for details on the case file format. 4 | % 5 | % The semidefinite relaxation of the OPF problem fails to solve 6 | % case2local for upper limits on bus two voltage magnitude between 7 | % 0.985 and 1.04. See [1] for more details. 8 | % 9 | % [1] W. Bukhsh, A. Grothey, K. McKinnon, and P. Trodden, "Local 10 | % Solutions of Optimal power Flow," Tech. Report. ERGO-11-017, 11 | % University of Edinburgh School of Mathematics, Edinburgh Research 12 | % Group in Optimization, 2011. [Online]. Available: 13 | % http://www.maths.ed.ac.uk/ERGO/pubs/ERGO-11-017.html 14 | 15 | t = 17.625; 16 | 17 | %% MATPOWER Case Format : Version 2 18 | mpc.version = '2'; 19 | 20 | %%----- Power Flow Data -----%% 21 | %% system MVA base 22 | mpc.baseMVA = 100; 23 | 24 | %% bus data 25 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 26 | mpc.bus = [ 27 | 1 3 0 0 0 0 1 0.9703 0 345 1 1.05 0.95; 28 | 2 1 20*t -20.3121*t 0 0 1 1.03 -64.3755 345 1 1.03 0.95; 29 | ]; 30 | 31 | %% generator data 32 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 33 | mpc.gen = [ 34 | 1 447.67 153.55 900 -900 0.9703 100 1 900 0 0 0 0 0 0 0 0 0 0 0 0; 35 | ]; 36 | 37 | %% branch data 38 | % fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax 39 | mpc.branch = [ 40 | 1 2 0.04 0.20 0.0 900 900 900 0 0 1 -360 360; 41 | ]; 42 | 43 | %%----- OPF Data -----%% 44 | %% area data 45 | % area refbus 46 | mpc.areas = [ 47 | 1 1; 48 | ]; 49 | 50 | %% generator cost data 51 | % 1 startup shutdown n x1 y1 ... xn yn 52 | % 2 startup shutdown n c(n-1) ... c0 53 | mpc.gencost = [ 54 | 2 1500 0 3 0 1 0; 55 | ]; 56 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/case3sc.m: -------------------------------------------------------------------------------- 1 | function mpc = case3sc 2 | %CASE3SC Power flow data for 3-bus system used in [1]. 3 | % Please see CASEFORMAT for details on the case file format. 4 | % 5 | % The semidefinite relaxation of the OPF problem successfully solves 6 | % case3sc with a value of 60 MVA for the line-flow limit on the line from 7 | % bus 3 to bus 2. The semidefinite relaxation fails to give a physically 8 | % meaningful solution to case3sc with a value of 50 MVA for the line-flow 9 | % limit on this line. See [1] for further details. 10 | % 11 | % [1] B.C. Lesieutre, D.K. Molzahn, A.R. Borden, and C.L. DeMarco, 12 | % "Examining the Limits of the Application of Semidefinite 13 | % Programming to Power Flow Problems," In 49th Annual Allerton 14 | % Conference on Communication, Control, and Computing, 2011, 15 | % September 28-30 2011. 16 | 17 | mpc.version = '2'; 18 | 19 | %----- Power Flow Data -----%% 20 | % system MVA base 21 | mpc.baseMVA = 100; 22 | 23 | % bus data 24 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 25 | mpc.bus = [ 26 | 1 3 110 40 0 0 1 1 0 345 1 1.1 0.9; 27 | 2 2 110 40 0 0 1 1 0 345 1 1.1 0.9; 28 | 3 2 95 50 0 0 1 1 0 345 1 1.1 0.9; 29 | ]; 30 | 31 | % generator data 32 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 33 | mpc.gen = [ 34 | 1 0 0 300 -300 1 100 1 1e3 0 0 0 0 0 0 0 0 0 0 0 0; 35 | 2 0 0 300 -300 1 100 1 1e3 0 0 0 0 0 0 0 0 0 0 0 0; 36 | 3 0 0 300 -300 1 100 1 0.0001 -0.0001 0 0 0 0 0 0 0 0 0 0 0; % Synchronous condensor 37 | ]; 38 | 39 | % branch data 40 | % fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax 41 | mpc.branch = [ 42 | 1 3 0.065 0.62 0.45 250 250 250 0 0 1 -360 360; 43 | 3 2 0.025 0.75 0.7 50 300 300 0 0 1 -360 360; % <-- change this line-flow limit to change satisfaction of semidefinite rank constraint 44 | 1 2 0.042 0.900 0.3 250 250 250 0 0 1 -360 360; 45 | ]; 46 | 47 | % area data 48 | % area refbus 49 | mpc.areas = [ 50 | 1 1; 51 | ]; 52 | 53 | % generator cost data 54 | % 1 startup shutdown n x1 y1 ... xn yn 55 | % 2 startup shutdown n c(n-1) ... c0 56 | mpc.gencost = [ 57 | 2 1500 0 3 0.11 5 0; 58 | 2 2000 0 3 0.085 1.2 0; 59 | 2 2000 0 3 0 0 0; % Synchronous condensor 60 | ]; 61 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/combineCost.m: -------------------------------------------------------------------------------- 1 | function [cost] = combineCost(maxcliques,maxcliquesidx) 2 | %COMBINECOST Calculate the cost of combining two maximal cliques. 3 | % [COST] = COMBINECOST(MAXCLIQUES,MAXCLIQUEIDX) 4 | % 5 | % Calculate the cost of combining two maximal cliques in terms of the 6 | % number of scalar variables and linking constraints that will be 7 | % required after combining the maximal cliques specified in 8 | % maxcliquesidx. This is the clique combination heuristic described in 9 | % [1]. Negative costs indicate that the heuristic predicts 10 | % decreased computational costs after combining the specified maximal 11 | % cliques. 12 | % 13 | % Inputs: 14 | % MAXCLIQUES : Cell array containing the buses contained in each 15 | % maximal clique. 16 | % MAXCLIQUESIDX : Vector of length two with elements corresponding to 17 | % the candidate maximal cliques. 18 | % 19 | % Outputs: 20 | % COST : Scalar indicating the cost, as defined by the heuristic in 21 | % [1] of combining the specified maximal cliques. 22 | % 23 | % [1] D.K. Molzahn, J.T. Holzer, B.C. Lesieutre, and C.L. DeMarco, 24 | % "Implementation of a Large-Scale Optimal Power Flow Solver Based on 25 | % Semidefinite Programming," IEEE Transactions on Power Systems, 26 | % vol. 28, no. 4, pp. 3987-3998, November 2013. 27 | 28 | % MATPOWER 29 | % Copyright (c) 2013-2015 by Power System Engineering Research Center (PSERC) 30 | % by Daniel Molzahn, PSERC U of Wisc, Madison 31 | % 32 | % $Id: combineCost.m 2644 2015-03-11 19:34:22Z ray $ 33 | % 34 | % This file is part of MATPOWER. 35 | % Covered by the 3-clause BSD License (see LICENSE file for details). 36 | % See http://www.pserc.cornell.edu/matpower/ for more info. 37 | 38 | maxcliques1 = maxcliques{maxcliquesidx(1)}; 39 | maxcliques2 = maxcliques{maxcliquesidx(2)}; 40 | nintersect = sum(ismembc(maxcliques1, maxcliques2)); 41 | 42 | elimmaxcliques(1) = length(maxcliques1); 43 | elimmaxcliques(2) = length(maxcliques2); 44 | lnewmaxcliques = sum(elimmaxcliques) - nintersect; 45 | 46 | nvarafter = (lnewmaxcliques)*(2*lnewmaxcliques+1) - sum((elimmaxcliques).*(2*elimmaxcliques+1)); 47 | 48 | ocostbefore = (nintersect)*(2*nintersect+1); 49 | 50 | cost = nvarafter - ocostbefore; 51 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/documentation/lesieutre_molzahn_borden_demarco-allerton2011.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/extras/sdp_pf/documentation/lesieutre_molzahn_borden_demarco-allerton2011.pdf -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/documentation/molzahn_dawar_lesieutre_demarco-irep2013.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/extras/sdp_pf/documentation/molzahn_dawar_lesieutre_demarco-irep2013.pdf -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/documentation/molzahn_demarco_lesieutre-pfcondition_tech_report.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/extras/sdp_pf/documentation/molzahn_demarco_lesieutre-pfcondition_tech_report.pdf -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/documentation/molzahn_holzer_lesieutre_demarco-large_scale_sdp_opf.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/extras/sdp_pf/documentation/molzahn_holzer_lesieutre_demarco-large_scale_sdp_opf.pdf -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/documentation/molzahn_lesieutre_demarco-globaloptcond.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/extras/sdp_pf/documentation/molzahn_lesieutre_demarco-globaloptcond.pdf -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/documentation/molzahn_lesieutre_demarco-pfcondition.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/extras/sdp_pf/documentation/molzahn_lesieutre_demarco-pfcondition.pdf -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/documentation/sdp_pf_documentation.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/extras/sdp_pf/documentation/sdp_pf_documentation.pdf -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/makeIncidence.m: -------------------------------------------------------------------------------- 1 | function [Ainc] = makeIncidence(bus, branch) 2 | %MAKEINCIDENCE Builds the bus incidence matrix. 3 | % [Ainc] = MAKEINCIDENCE(MPC) 4 | % [Ainc] = MAKEINCIDENCE(BUS, BRANCH) 5 | % 6 | % Builds the bus incidence matrix. This matrix has size nline by nbus, 7 | % with each row having two nonzero elements: +1 in the entry for the 8 | % "from" bus of the corresponding line and -1 in the entry for the "to" 9 | % bus of the corresponding line. 10 | % 11 | % Inputs: 12 | % MPC : MATPOWER case variable with internal indexing. 13 | % 14 | % Outputs: 15 | % AINC : An nline by nbus size bus incidence matrix. 16 | 17 | % MATPOWER 18 | % Copyright (c) 2013-2015 by Power System Engineering Research Center (PSERC) 19 | % by Daniel Molzahn, PSERC U of Wisc, Madison 20 | % and Ray Zimmerman, PSERC Cornell 21 | % 22 | % $Id: makeIncidence.m 2644 2015-03-11 19:34:22Z ray $ 23 | % 24 | % This file is part of MATPOWER. 25 | % Covered by the 3-clause BSD License (see LICENSE file for details). 26 | % See http://www.pserc.cornell.edu/matpower/ for more info. 27 | 28 | if nargin < 2 29 | mpc = bus; 30 | bus = mpc.bus; 31 | branch = mpc.branch; 32 | end 33 | 34 | %% constants 35 | nb = size(bus, 1); %% number of buses 36 | nl = size(branch, 1); %% number of lines 37 | 38 | %% define named indices into bus, branch matrices 39 | [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 40 | VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 41 | [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ... 42 | TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ... 43 | ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch; 44 | 45 | %% check that bus numbers are equal to indices to bus (one set of bus numbers) 46 | if any(bus(:, BUS_I) ~= (1:nb)') 47 | error('makeIncidence: buses must appear in order by bus number') 48 | end 49 | 50 | %% build connection matrices 51 | f = branch(:, F_BUS); %% list of "from" buses 52 | t = branch(:, T_BUS); %% list of "to" buses 53 | Cf = sparse(1:nl, f, ones(nl, 1), nl, nb); %% connection matrix for line & from buses 54 | Ct = sparse(1:nl, t, ones(nl, 1), nl, nb); %% connection matrix for line & to buses 55 | 56 | Ainc = Cf - Ct; 57 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/mpoption_info_yalmip.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_yalmip(selector) 2 | %MPOPTION_INFO_YALMIP Returns MATPOWER option info for YALMIP. 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_YALMIP('D') 5 | % VALID_OPTS = MPOPTION_INFO_YALMIP('V') 6 | % EXCEPTIONS = MPOPTION_INFO_YALMIP('E') 7 | % 8 | % Returns a structure for YALMIP options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_yalmip.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | if have_fcn('yalmip') 34 | switch upper(selector) 35 | case {'D', 'V'} %% default and valid options 36 | opt = struct(... 37 | 'yalmip', struct(... 38 | 'opts', [], ... 39 | 'opt_fname', '' ... 40 | ) ... 41 | ); 42 | case 'E' %% exceptions used by nested_struct_copy() for applying 43 | opt = struct(... 44 | 'name', { 'yalmip.opts' }, ... 45 | 'check', 0 ... 46 | ); 47 | % 'copy_mode', { @yalmip_options } ... 48 | otherwise 49 | error('mpoption_info_yalmip: ''%s'' is not a valid input argument', selector); 50 | end 51 | else 52 | opt = struct([]); %% YALMIP is not available 53 | end 54 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/prim.m: -------------------------------------------------------------------------------- 1 | function [E] = prim(Aadj) 2 | %PRIM Prim's algorithm for calculating a minimal spanning tree. 3 | % [E] = PRIM(AADJ) 4 | % 5 | % Implementation of Prim's algorithm for calculating a minimal spanning 6 | % tree from a graph adjacency matrix. This implementation can incorporate 7 | % negative edge weights. Create a maximal spanning tree by specifying 8 | % the negative of the graph adjacency matrix. 9 | % 10 | % Inputs: 11 | % AADJ : A graph adjacency matrix, including the possibility of 12 | % negative edge weights. 13 | % 14 | % Outputs: 15 | % E : Matrix with two columns describing the resulting minimal weight 16 | % spanning tree. Each row gives the maximal cliques for a branch 17 | % of the tree. 18 | 19 | % MATPOWER 20 | % Copyright (c) 2013-2015 by Power System Engineering Research Center (PSERC) 21 | % by Daniel Molzahn, PSERC U of Wisc, Madison 22 | % 23 | % $Id: prim.m 2644 2015-03-11 19:34:22Z ray $ 24 | % 25 | % This file is part of MATPOWER. 26 | % Covered by the 3-clause BSD License (see LICENSE file for details). 27 | % See http://www.pserc.cornell.edu/matpower/ for more info. 28 | 29 | 30 | Vnew = 1; 31 | E = []; 32 | nnode = size(Aadj,1); 33 | cols(1).c = sparse(Aadj(Vnew(1),:)~=0); 34 | cols(1).c(Vnew) = 0; 35 | while length(Vnew) < nnode 36 | % Choose an edge (u,v) with minimal weight so that u is in Vnew and 37 | % v is not 38 | 39 | % Find the best available edge 40 | bestedge.value = inf; 41 | bestedge.row = []; 42 | bestedge.col = []; 43 | for i=1:length(Vnew) 44 | 45 | [tempMaxVal,tempMaxCol] = min(Aadj(Vnew(i),cols(i).c)); 46 | if tempMaxVal < bestedge.value 47 | bestedge.value = tempMaxVal; 48 | bestedge.row = Vnew(i); 49 | 50 | tempc = find(cols(i).c,tempMaxCol); 51 | bestedge.col = tempc(tempMaxCol); 52 | end 53 | end 54 | 55 | Vnew = [Vnew; bestedge.col]; 56 | cols(length(Vnew)).c = sparse(Aadj(Vnew(end),:) ~= 0); 57 | cols(length(Vnew)).c(Vnew) = 0; 58 | 59 | for i=1:length(Vnew)-1 60 | cols(i).c(Vnew(end)) = 0; 61 | end 62 | 63 | E = [E; bestedge.row bestedge.col]; 64 | 65 | if isempty(bestedge.row) || isempty(bestedge.col) 66 | error('prim: Error in Prim''s Algorithm. System is probably separated into multiple island. Ensure connected system and try again.'); 67 | end 68 | 69 | end 70 | V = Vnew; 71 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/sdp_pf_ver.m: -------------------------------------------------------------------------------- 1 | function rv = sdp_pf_ver(varargin) 2 | %SPD_PF_VER Prints or returns SDP_PF version info for current installation. 3 | % V = SDP_PF_VER returns the current SDP_PF version number. 4 | % V = SDP_PF_VER('all') returns a struct with the fields Name, Version, 5 | % Release and Date (all strings). Calling SDP_PF_VER without assigning the 6 | % return value prints the version and release date of the current 7 | % installation of SDP_PF. 8 | % 9 | % See also MPVER. 10 | 11 | % MATPOWER 12 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 13 | % by Ray Zimmerman, PSERC Cornell 14 | % 15 | % $Id: sdp_pf_ver.m 2644 2015-03-11 19:34:22Z ray $ 16 | % 17 | % This file is part of MATPOWER. 18 | % Covered by the 3-clause BSD License (see LICENSE file for details). 19 | % See http://www.pserc.cornell.edu/matpower/ for more info. 20 | 21 | v = struct( 'Name', 'SDP_PF', ... 22 | 'Version', '1.0', ... 23 | 'Release', '', ... 24 | 'Date', '17-Jan-2014' ); 25 | if nargout > 0 26 | if nargin > 0 27 | rv = v; 28 | else 29 | rv = v.Version; 30 | end 31 | else 32 | fprintf('%-22s Version %-9s %11s\n', v.Name, v.Version, v.Date); 33 | end 34 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/soln9mod_opf.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/extras/sdp_pf/soln9mod_opf.mat -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/soln9mod_opf_Plim.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/extras/sdp_pf/soln9mod_opf_Plim.mat -------------------------------------------------------------------------------- /library/matpower5.1/extras/sdp_pf/t_case9mod_opf.m: -------------------------------------------------------------------------------- 1 | function [baseMVA, bus, gen, branch, areas, gencost] = t_case9mod_opf 2 | %T_CASE9MOD_OPF Power flow data for 9 bus, 3 generator case, with OPF data. 3 | % This is the same as t_case9_opf except for a line-flow limit of 100 MVA 4 | % rather than 40 MVA for the line between buses 6 and 7. This less strict 5 | % line-flow limit results in an exact semidefinite relaxation for this 6 | % problem. Also all lines have minimum resistances of 1e-4 per unit. 7 | % Please see CASEFORMAT for details on the case file format. 8 | 9 | %% MATPOWER Case Format : Version 1 10 | 11 | %%----- Power Flow Data -----%% 12 | %% system MVA base 13 | baseMVA = 100; 14 | 15 | %% bus data 16 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 17 | bus = [ 18 | 1 3 0 0 0 0 1 1 0 345 1 1.1 0.9; 19 | 2 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 20 | 30 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 21 | 4 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 22 | 5 1 90 30 0 0 1 1 0 345 1 1.1 0.9; 23 | 6 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 24 | 7 1 100 35 0 0 1 1 0 345 1 1.1 0.9; 25 | 8 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 26 | 9 1 125 50 0 0 1 1 0 345 1 1.1 0.9; 27 | ]; 28 | 29 | %% generator data 30 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin 31 | gen = [ 32 | 1 0 0 300 -300 1 100 1 250 90; 33 | 2 163 0 300 -300 1 100 1 300 10; 34 | 30 85 0 300 -300 1 100 1 270 10; 35 | ]; 36 | 37 | %% branch data 38 | % fbus tbus r x b rateA rateB rateC ratio angle status 39 | branch = [ 40 | 1 4 0.0001 0.0576 0 0 250 250 0 0 1; 41 | 4 5 0.0170 0.0920 0.158 0 250 250 0 0 1; 42 | 5 6 0.0390 0.1700 0.358 150 150 150 0 0 1; 43 | 30 6 0.0001 0.0586 0 0 300 300 0 0 1; 44 | 6 7 0.0119 0.1008 0.209 100 150 150 0 0 1; 45 | 7 8 0.0085 0.0720 0.149 250 250 250 0 0 1; 46 | 8 2 0.0001 0.0625 0 250 250 250 0 0 1; 47 | 8 9 0.0320 0.1610 0.306 250 250 250 0 0 1; 48 | 9 4 0.0100 0.0850 0.176 250 250 250 0 0 1; 49 | ]; 50 | 51 | %%----- OPF Data -----%% 52 | %% area data 53 | % area refbus 54 | areas = [ 55 | 1 5; 56 | ]; 57 | 58 | %% generator cost data 59 | % 1 startup shutdown n x1 y1 ... xn yn 60 | % 2 startup shutdown n c(n-1) ... c0 61 | gencost = [ 62 | 1 0 0 4 0 0 100 2500 200 5500 250 7250; 63 | 2 0 0 2 24.035 -403.5 0 0 0 0 0 0; 64 | 1 0 0 3 0 0 200 3000 300 5000 0 0; 65 | ]; 66 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/se/case3bus_P6_6.m: -------------------------------------------------------------------------------- 1 | function [baseMVA, bus, gen, branch, areas, gencost] = case3bus_P6_6 2 | %CASE3BUS_P6_6 Case of 3 bus system. 3 | % From Problem 6.6 in book 'Computational 4 | % Methods for Electric Power Systems' by Mariesa Crow 5 | % created by Rui Bo on 2007/11/12 6 | 7 | % MATPOWER 8 | % $Id: case3bus_P6_6.m 1618 2010-04-19 14:40:46Z ray $ 9 | 10 | %%----- Power Flow Data -----%% 11 | %% system MVA base 12 | baseMVA = 1000; 13 | 14 | %% bus data 15 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 16 | bus = [ 17 | 1 3 350 100 0 0 1 1 0 230 1 1.00 1.00; 18 | 2 2 400 250 0 0 1 1 0 230 1 1.02 1.02; 19 | 3 2 250 100 0 0 1 1 0 230 1 1.02 1.02; 20 | ]; 21 | 22 | %% generator data 23 | % Note: 24 | % 1)It's better of gen to be in number order, otherwise gen and genbid 25 | % should be sorted to make the lp solution output clearly(in number order as well) 26 | % 2)set Pmax to nonzero. set to 999 if no limit 27 | % 3)If change the order of gen, then must change the order in genbid 28 | % accordingly 29 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin 30 | gen = [ 31 | 1 182.18 0 999 -999 1.00 100 1 600 0; 32 | 2 272.77 0 999 -999 1.02 100 1 400 0; 33 | 3 545.05 0 999 -999 1.02 100 1 100 0; 34 | ]; 35 | %gen(:, 9) = 999; % inactive the Pmax constraints 36 | 37 | %% branch data 38 | % fbus tbus r x b rateA rateB rateC ratio angle status 39 | branch = [ 40 | 1 2 0.01 0.1 0.050 999 100 100 0 0 1; 41 | 1 3 0.05 0.1 0.025 999 100 100 0 0 1; 42 | 2 3 0.05 0.1 0.025 999 100 100 0 0 1; 43 | ]; 44 | 45 | %%----- OPF Data -----%% 46 | %% area data 47 | areas = [ 48 | 1 1; 49 | ]; 50 | 51 | %% generator cost data 52 | % 2 startup shutdown n c(n-1) ... c0 53 | gencost = [ 54 | 2 0 0 3 1.5 1 0; 55 | 2 0 0 3 1 2 0; 56 | 2 0 0 3 0.5 2.5 0; 57 | ]; 58 | 59 | return; 60 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/se/getV0.m: -------------------------------------------------------------------------------- 1 | function V0 = getV0(bus, gen, type_initialguess, V0) 2 | %GETV0 Get initial voltage profile for power flow calculation. 3 | % Note: The pv bus voltage will remain at the given value even for 4 | % flat start. 5 | % type_initialguess: 1 - initial guess from case data 6 | % 2 - flat start 7 | % 3 - from input 8 | 9 | % MATPOWER 10 | % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 11 | % by Rui Bo 12 | % 13 | % $Id: getV0.m 2644 2015-03-11 19:34:22Z ray $ 14 | % 15 | % This file is part of MATPOWER. 16 | % Covered by the 3-clause BSD License (see LICENSE file for details). 17 | % See http://www.pserc.cornell.edu/matpower/ for more info. 18 | 19 | %% define named indices into bus, gen, branch matrices 20 | [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 21 | VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 22 | [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, ... 23 | RATE_C, TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST] = idx_brch; 24 | [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, ... 25 | GEN_STATUS, PMAX, PMIN, MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN] = idx_gen; 26 | 27 | %% generator info 28 | on = find(gen(:, GEN_STATUS) > 0); %% which generators are on? 29 | gbus = gen(on, GEN_BUS); %% what buses are they at? 30 | if type_initialguess == 1 % using previous value in case data 31 | % NOTE: angle is in degree in case data, but in radians in pf solver, 32 | % so conversion from degree to radians is needed here 33 | V0 = bus(:, VM) .* exp(sqrt(-1) * pi/180 * bus(:, VA)); 34 | elseif type_initialguess == 2 % using flat start 35 | V0 = ones(size(bus, 1), 1); 36 | elseif type_initialguess == 3 % using given initial voltage 37 | V0 = V0; 38 | else 39 | fprintf('Error: unknow ''type_initialguess''.\n'); 40 | pause 41 | end 42 | % set the voltages of PV bus and reference bus into the initial guess 43 | V0(gbus) = gen(on, VG) ./ abs(V0(gbus)).* V0(gbus); 44 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/se/getVarName.m: -------------------------------------------------------------------------------- 1 | function [varName] = getVarName(varIndex, pv, pq) 2 | %GETVARNAME Get variable name by variable index (as in H matrix). 3 | % [OUTPUT PARAMETERS] 4 | % varName: comprise both variable type ('Va', 'Vm') and the bus number of 5 | % the variable. For instance, Va8, Vm10, etc. 6 | % created by Rui Bo on Jan 9, 2010 7 | 8 | % MATPOWER 9 | % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 10 | % by Rui Bo 11 | % 12 | % $Id: getVarName.m 2644 2015-03-11 19:34:22Z ray $ 13 | % 14 | % This file is part of MATPOWER. 15 | % Covered by the 3-clause BSD License (see LICENSE file for details). 16 | % See http://www.pserc.cornell.edu/matpower/ for more info. 17 | 18 | %% get non reference buses 19 | nonref = [pv;pq]; 20 | 21 | if varIndex <= length(nonref) 22 | varType = 'Va'; 23 | newIdx = varIndex; 24 | else 25 | varType = 'Vm'; 26 | newIdx = varIndex - length(nonref); 27 | end 28 | varName = sprintf('%s%d', varType, nonref(newIdx)); 29 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/se/run_se.m: -------------------------------------------------------------------------------- 1 | function [baseMVA, bus, gen, branch, success, et, z, z_est, error_sqrsum] = run_se(casename, measure, idx, sigma, type_initialguess, V0) 2 | %RUN_SE Run state estimation. 3 | % [INPUT PARAMETERS] 4 | % measure: measurements 5 | % idx: measurement indices 6 | % sigma: measurement variances 7 | % [OUTPUT PARAMETERS] 8 | % z: Measurement Vector. In the order of PF, PT, PG, Va, QF, QT, QG, Vm (if 9 | % applicable), so it has ordered differently from original measurements 10 | % z_est: Estimated Vector. In the order of PF, PT, PG, Va, QF, QT, QG, Vm 11 | % (if applicable) 12 | % error_sqrsum: Weighted sum of error squares 13 | % created by Rui Bo on 2007/11/12 14 | 15 | % MATPOWER 16 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 17 | % by Rui Bo 18 | % and Ray Zimmerman, PSERC Cornell 19 | % 20 | % $Id: run_se.m 2644 2015-03-11 19:34:22Z ray $ 21 | % 22 | % This file is part of MATPOWER. 23 | % Covered by the 3-clause BSD License (see LICENSE file for details). 24 | % See http://www.pserc.cornell.edu/matpower/ for more info. 25 | 26 | %% read data & convert to internal bus numbering 27 | [baseMVA, bus, gen, branch] = loadcase(casename); 28 | [i2e, bus, gen, branch] = ext2int(bus, gen, branch); 29 | 30 | %% get bus index lists of each type of bus 31 | [ref, pv, pq] = bustypes(bus, gen); 32 | 33 | %% build admittance matrices 34 | [Ybus, Yf, Yt] = makeYbus(baseMVA, bus, branch); 35 | Ybus = full(Ybus); 36 | Yf = full(Yf); 37 | Yt = full(Yt); 38 | 39 | %% prepare initial guess 40 | if nargin < 6 41 | V0 = getV0(bus, gen, type_initialguess); 42 | else 43 | V0 = getV0(bus, gen, type_initialguess, V0); 44 | end 45 | 46 | %% run state estimation 47 | t0 = clock; 48 | [V, success, iterNum, z, z_est, error_sqrsum] = doSE(baseMVA, bus, gen, branch, Ybus, Yf, Yt, V0, ref, pv, pq, measure, idx, sigma); 49 | %% update data matrices with solution, ie, V 50 | % [bus, gen, branch] = updatepfsoln(baseMVA, bus, gen, branch, Ybus, V, ref, pv, pq); 51 | [bus, gen, branch] = pfsoln(baseMVA, bus, gen, branch, Ybus, Yf, Yt, V, ref, pv, pq); 52 | et = etime(clock, t0); 53 | 54 | %%----- output results ----- 55 | %% convert back to original bus numbering & print results 56 | [bus, gen, branch] = int2ext(i2e, bus, gen, branch); 57 | %% output power flow solution 58 | outputpfsoln(baseMVA, bus, gen, branch, success, et, 1, iterNum); 59 | %% output state estimation solution 60 | outputsesoln(idx, sigma, z, z_est, error_sqrsum); 61 | 62 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/se/se_intro.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/extras/se/se_intro.pdf -------------------------------------------------------------------------------- /library/matpower5.1/extras/se/test_se.m: -------------------------------------------------------------------------------- 1 | function test_se 2 | %TEST_SE Test state estimation. 3 | % created by Rui Bo on 2007/11/12 4 | 5 | % MATPOWER 6 | % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 7 | % by Rui Bo 8 | % 9 | % $Id: test_se.m 2644 2015-03-11 19:34:22Z ray $ 10 | % 11 | % This file is part of MATPOWER. 12 | % Covered by the 3-clause BSD License (see LICENSE file for details). 13 | % See http://www.pserc.cornell.edu/matpower/ for more info. 14 | 15 | %%------------------------------------------------------ 16 | % using data in Problem 6.7 in book 'Computational 17 | % Methods for Electric Power Systems' by Mariesa Crow 18 | %%------------------------------------------------------ 19 | %% which measurements are available 20 | idx.idx_zPF = [1;2]; 21 | idx.idx_zPT = [3]; 22 | idx.idx_zPG = [1;2;3]; 23 | idx.idx_zVa = []; 24 | idx.idx_zQF = []; 25 | idx.idx_zQT = []; 26 | idx.idx_zQG = []; 27 | idx.idx_zVm = [2;3]; 28 | 29 | %% specify measurements 30 | measure.PF = [0.12;0.10]; 31 | measure.PT = [-0.04]; 32 | measure.PG = [0.58;0.30;0.14]; 33 | measure.Va = []; 34 | measure.QF = []; 35 | measure.QT = []; 36 | measure.QG = []; 37 | measure.Vm = [1.04;0.98]; 38 | 39 | %% specify measurement variances 40 | sigma.sigma_PF = 0.02; 41 | sigma.sigma_PT = 0.02; 42 | sigma.sigma_PG = 0.015; 43 | sigma.sigma_Va = []; 44 | sigma.sigma_QF = []; 45 | sigma.sigma_QT = []; 46 | sigma.sigma_QG = []; 47 | sigma.sigma_Vm = 0.01; 48 | 49 | %% check input data integrity 50 | nbus = 3; 51 | [success, measure, idx, sigma] = checkDataIntegrity(measure, idx, sigma, nbus); 52 | if ~success 53 | error('State Estimation input data are not complete or sufficient!'); 54 | end 55 | 56 | %% run state estimation 57 | casename = 'case3bus_P6_6.m'; 58 | type_initialguess = 2; % flat start 59 | [baseMVA, bus, gen, branch, success, et, z, z_est, error_sqrsum] = run_se(casename, measure, idx, sigma, type_initialguess); 60 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/se/test_se_14bus.m: -------------------------------------------------------------------------------- 1 | function test_se_14bus 2 | %TEST_SE_14BUS Test state estimation on IEEE 14-bus system 3 | % created by Rui Bo on Jan 6, 2010 4 | 5 | % MATPOWER 6 | % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 7 | % by Rui Bo 8 | % 9 | % $Id: test_se_14bus.m 2644 2015-03-11 19:34:22Z ray $ 10 | % 11 | % This file is part of MATPOWER. 12 | % Covered by the 3-clause BSD License (see LICENSE file for details). 13 | % See http://www.pserc.cornell.edu/matpower/ for more info. 14 | 15 | %%------------------------------------------------------ 16 | % using data for IEEE 14-bus system 17 | %%------------------------------------------------------ 18 | % NOTE: 19 | % 1) all eight members of 'idx', 'measure' and 'sigma' must be 20 | % defined. They should be null vectors([]) if they do not have data 21 | % 2) all data used in this code are for testing purpose only 22 | %% which measurements are available 23 | idx.idx_zPF = [1;3;8;9;10;13;15;16;17;19]; 24 | idx.idx_zPT = [4;5;7;11]; 25 | idx.idx_zPG = [1;2;3;4;5]; 26 | idx.idx_zVa = []; 27 | idx.idx_zQF = [1;3;8;9;10;13;15;19]; 28 | idx.idx_zQT = [4;5;7;11]; 29 | idx.idx_zQG = [1;2]; 30 | idx.idx_zVm = [2;3;6;8;10;14]; 31 | 32 | %% specify measurements 33 | measure.PF = [1.5708;0.734;0.2707;0.1546;0.4589;0.1834;0.2707;0.0523;0.0943;0.0188]; 34 | measure.PT = [-0.5427;-0.4081;0.6006;-0.0816]; 35 | measure.PG = [2.32;0.4;0;0;0]; 36 | measure.Va = []; 37 | measure.QF = [-0.1748;0.0594;-0.154;-0.0264;-0.2084;0.0998;0.148;0.0141]; 38 | measure.QT = [0.0213;-0.0193;-0.1006;-0.0864]; 39 | measure.QG = [-0.169;0.424]; 40 | measure.Vm = [1;1;1;1;1;1]; 41 | 42 | %% specify measurement variances 43 | sigma.sigma_PF = 0.02; 44 | sigma.sigma_PT = 0.02; 45 | sigma.sigma_PG = 0.015; 46 | sigma.sigma_Va = []; 47 | sigma.sigma_QF = 0.02; 48 | sigma.sigma_QT = 0.02; 49 | sigma.sigma_QG = 0.015; 50 | sigma.sigma_Vm = 0.01; 51 | 52 | %% check input data integrity 53 | nbus = 14; 54 | [success, measure, idx, sigma] = checkDataIntegrity(measure, idx, sigma, nbus); 55 | if ~success 56 | error('State Estimation input data are not complete or sufficient!'); 57 | end 58 | 59 | %% run state estimation 60 | casename = 'case14.m'; 61 | type_initialguess = 2; % flat start 62 | [baseMVA, bus, gen, branch, success, et, z, z_est, error_sqrsum] = run_se(casename, measure, idx, sigma, type_initialguess); 63 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/se/test_se_14bus_err.m: -------------------------------------------------------------------------------- 1 | function test_se_14bus_err 2 | %TEST_SE_14BUS Test state estimation on IEEE 14-bus system. 3 | % NOTE: This test shows system can be not observable due to measurement 4 | % issues. 5 | % created by Rui Bo on Jan 6, 2010 6 | 7 | % MATPOWER 8 | % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 9 | % by Rui Bo 10 | % 11 | % $Id: test_se_14bus_err.m 2644 2015-03-11 19:34:22Z ray $ 12 | % 13 | % This file is part of MATPOWER. 14 | % Covered by the 3-clause BSD License (see LICENSE file for details). 15 | % See http://www.pserc.cornell.edu/matpower/ for more info. 16 | 17 | %%------------------------------------------------------ 18 | % for IEEE 14-bus system 19 | %%------------------------------------------------------ 20 | % NOTE: 21 | % 1) all eight members of 'idx', 'measure' and 'sigma' must be 22 | % defined. They should be null vectors([]) if they do not have data 23 | % 2) all data used in this code are for testing purpose only 24 | %% which measurements are available 25 | idx.idx_zPF = [1;3;8;9;10;13;15;19]; 26 | idx.idx_zPT = [4;5;7;11]; 27 | idx.idx_zPG = [1;2]; 28 | idx.idx_zVa = []; 29 | idx.idx_zQF = [1;3;8;9;10;13;15;19]; 30 | idx.idx_zQT = [4;5;7;11]; 31 | idx.idx_zQG = [1;2]; 32 | idx.idx_zVm = [2;3]; 33 | 34 | %% specify measurements 35 | measure.PF = [1.5708;0.734;0.2707;0.1546;0.4589;0.1834;0.2707;0.0188]; 36 | measure.PT = [-0.5427;-0.4081;0.6006;-0.0816]; 37 | measure.PG = [2.32;0.4]; 38 | measure.Va = []; 39 | measure.QF = [-0.1748;0.0594;-0.154;-0.0264;-0.2084;0.0998;0.148;0.0141]; 40 | measure.QT = [0.0213;-0.0193;-0.1006;-0.0864]; 41 | measure.QG = [-0.169;0.424]; 42 | measure.Vm = [1;1]; 43 | 44 | %% specify measurement variances 45 | sigma.sigma_PF = 0.02; 46 | sigma.sigma_PT = 0.02; 47 | sigma.sigma_PG = 0.015; 48 | sigma.sigma_Va = []; 49 | sigma.sigma_QF = 0.02; 50 | sigma.sigma_QT = 0.02; 51 | sigma.sigma_QG = 0.015; 52 | sigma.sigma_Vm = 0.01; 53 | 54 | %% check input data integrity 55 | nbus = 14; 56 | [success, measure, idx, sigma] = checkDataIntegrity(measure, idx, sigma, nbus); 57 | if ~success 58 | error('State Estimation input data are not complete or sufficient!'); 59 | end 60 | 61 | %% run state estimation 62 | casename = 'case14.m'; 63 | type_initialguess = 2; % flat start 64 | [baseMVA, bus, gen, branch, success, et, z, z_est, error_sqrsum] = run_se(casename, measure, idx, sigma, type_initialguess); 65 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/smartmarket/case2off.m: -------------------------------------------------------------------------------- 1 | function [q, p] = case2off(gen, gencost) 2 | %CASE2OFF Creates quantity & price offers from gen & gencost. 3 | % [Q, P] = CASE2OFF(GEN, GENCOST) creates quantity and price offers 4 | % from case variables GEN & GENCOST. 5 | % 6 | % See also OFF2CASE. 7 | 8 | % MATPOWER 9 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 10 | % by Ray Zimmerman, PSERC Cornell 11 | % 12 | % $Id: case2off.m 2644 2015-03-11 19:34:22Z ray $ 13 | % 14 | % This file is part of MATPOWER. 15 | % Covered by the 3-clause BSD License (see LICENSE file for details). 16 | % See http://www.pserc.cornell.edu/matpower/ for more info. 17 | 18 | %% define named indices into data matrices 19 | [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 20 | MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 21 | QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 22 | [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost; 23 | 24 | %% do conversion 25 | oldgencost = gencost; 26 | i_poly = find(gencost(:, MODEL) == POLYNOMIAL); 27 | npts = 6; %% 6 points => 5 blocks 28 | %% convert polynomials to piece-wise linear by evaluating at zero and then 29 | %% at evenly spaced points between Pmin and Pmax 30 | if any(i_poly) 31 | [m, n] = size(gencost(i_poly, :)); %% size of piece being changed 32 | gencost(i_poly, MODEL) = PW_LINEAR * ones(m, 1); %% change cost model 33 | gencost(i_poly, COST:n) = zeros(size(gencost(i_poly, COST:n))); %% zero out old data 34 | gencost(i_poly, NCOST) = npts * ones(m, 1); %% change number of data points 35 | 36 | for i = 1:m 37 | ig = i_poly(i); %% index to gen 38 | Pmin = gen(ig, PMIN); 39 | Pmax = gen(ig, PMAX); 40 | if Pmin == 0 41 | step = (Pmax - Pmin) / (npts - 1); 42 | xx = (Pmin:step:Pmax); 43 | else 44 | step = (Pmax - Pmin) / (npts - 2); 45 | xx = [0 Pmin:step:Pmax]; 46 | end 47 | yy = totcost(oldgencost(ig, :), xx); 48 | gencost(ig, COST:2:(COST + 2*(npts-1) )) = xx; 49 | gencost(ig, (COST+1):2:(COST + 2*(npts-1) + 1)) = yy; 50 | end 51 | end 52 | n = max(gencost(:, NCOST)); 53 | xx = gencost(:, COST:2:( COST + 2*n - 1 )); 54 | yy = gencost(:, (COST+1):2:( COST + 2*n )); 55 | i1 = 1:(n-1); 56 | i2 = 2:n; 57 | q = xx(:, i2) - xx(:, i1); 58 | p = ( yy(:, i2) - yy(:, i1) ) ./ q; 59 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/smartmarket/idx_disp.m: -------------------------------------------------------------------------------- 1 | function [QUANTITY, PRICE, FCOST, VCOST, SCOST, PENALTY] = idx_disp 2 | %IDX_DISP Defines constants for named column indices to dispatch matrix. 3 | % Example: 4 | % 5 | % [QUANTITY, PRICE, FCOST, VCOST, SCOST, PENALTY] = idx_disp; 6 | % 7 | % The index, name and meaning of each column of the dispatch matrix is given 8 | % below: 9 | % 10 | % columns 1-6 11 | % 1 QUANTITY quantity produced by generator in MW 12 | % 2 PRICE market price for power produced by generator in $/MWh 13 | % 3 FCOST fixed cost in $/MWh 14 | % 4 VCOST variable cost in $/MWh 15 | % 5 SCOST startup cost in $ 16 | % 6 PENALTY penalty cost in $ (not used) 17 | 18 | % MATPOWER 19 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 20 | % by Ray Zimmerman, PSERC Cornell 21 | % 22 | % $Id: idx_disp.m 2644 2015-03-11 19:34:22Z ray $ 23 | % 24 | % This file is part of MATPOWER. 25 | % Covered by the 3-clause BSD License (see LICENSE file for details). 26 | % See http://www.pserc.cornell.edu/matpower/ for more info. 27 | 28 | %% define the indices 29 | QUANTITY = 1; %% quantity produced by generator in MW 30 | PRICE = 2; %% market price for power produced by generator in $/MWh 31 | FCOST = 3; %% fixed cost in $/MWh 32 | VCOST = 4; %% variable cost in $/MWh 33 | SCOST = 5; %% startup cost in $ 34 | PENALTY = 6; %% penalty cost in $ (not used) 35 | -------------------------------------------------------------------------------- /library/matpower5.1/extras/smartmarket/pricelimits.m: -------------------------------------------------------------------------------- 1 | function lim = pricelimits(lim, haveQ) 2 | %PRICELIMITS Fills in a struct with default values for offer/bid limits. 3 | % LIM = PRICELIMITS(LIM, HAVEQ) 4 | % The final structure looks like: 5 | % LIM.P.min_bid - bids below this are withheld 6 | % .max_offer - offers above this are withheld 7 | % .min_cleared_bid - cleared bid prices below this are clipped 8 | % .max_cleared_offer - cleared offer prices above this are clipped 9 | % .Q (optional, same structure as P) 10 | 11 | % MATPOWER 12 | % Copyright (c) 2005-2015 by Power System Engineering Research Center (PSERC) 13 | % by Ray Zimmerman, PSERC Cornell 14 | % 15 | % $Id: pricelimits.m 2644 2015-03-11 19:34:22Z ray $ 16 | % 17 | % This file is part of MATPOWER. 18 | % Covered by the 3-clause BSD License (see LICENSE file for details). 19 | % See http://www.pserc.cornell.edu/matpower/ for more info. 20 | 21 | if isempty(lim) 22 | if haveQ 23 | lim = struct( 'P', fill_lim([]), 'Q', fill_lim([]) ); 24 | else 25 | lim = struct( 'P', fill_lim([]) ); 26 | end 27 | else 28 | if ~isfield(lim, 'P') 29 | lim.P = []; 30 | end 31 | lim.P = fill_lim(lim.P); 32 | if haveQ 33 | if ~isfield(lim, 'Q') 34 | lim.Q = []; 35 | end 36 | lim.Q = fill_lim(lim.Q); 37 | end 38 | end 39 | 40 | 41 | 42 | function lim = fill_lim(lim) 43 | if isempty(lim) 44 | lim = struct( 'max_offer', [], 'min_bid', [], ... 45 | 'max_cleared_offer', [], 'min_cleared_bid', [] ); 46 | else 47 | if ~isfield(lim, 'max_offer'), lim.max_offer = []; end 48 | if ~isfield(lim, 'min_bid'), lim.min_bid = []; end 49 | if ~isfield(lim, 'max_cleared_offer'), lim.max_cleared_offer = []; end 50 | if ~isfield(lim, 'min_cleared_bid'), lim.min_cleared_bid = []; end 51 | end 52 | -------------------------------------------------------------------------------- /library/matpower5.1/fairmax.m: -------------------------------------------------------------------------------- 1 | function [val, idx] = fairmax(x) 2 | %FAIRMAX Same as built-in MAX, except breaks ties randomly. 3 | % [VAL, IDX] = FAIRMAX(X) takes a vector as an argument and returns 4 | % the same output as the built-in function MAX with two output 5 | % parameters, except that where the maximum value occurs at more 6 | % than one position in the vector, the index is chosen randomly 7 | % from these positions as opposed to just choosing the first occurance. 8 | % 9 | % See also MAX. 10 | 11 | % MATPOWER 12 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 13 | % by Ray Zimmerman, PSERC Cornell 14 | % 15 | % $Id: fairmax.m 2644 2015-03-11 19:34:22Z ray $ 16 | % 17 | % This file is part of MATPOWER. 18 | % Covered by the 3-clause BSD License (see LICENSE file for details). 19 | % See http://www.pserc.cornell.edu/matpower/ for more info. 20 | 21 | val = max(x); %% find max value 22 | i = find(x == val); %% find all positions where this occurs 23 | n = length(i); %% number of occurences 24 | idx = i( fix(n*rand)+1 ); %% select index randomly among occurances 25 | -------------------------------------------------------------------------------- /library/matpower5.1/find_islands.m: -------------------------------------------------------------------------------- 1 | function [groups, isolated] = find_islands(mpc) 2 | %FIND_ISLANDS Finds islands in a network 3 | % GROUPS = FIND_ISLANDS(MPC) 4 | % [GROUPS, ISOLATED] = FIND_ISLANDS(MPC) 5 | % 6 | % Returns the islands in a network. The return value GROUPS 7 | % is a cell array of vectors of the bus indices for each island. 8 | % The second and optional return value ISOLATED is a vector of 9 | % indices of isolated buses that have no connecting branches. 10 | % 11 | % See also EXTRACT_ISLANDS, CONNECTED_COMPONENTS. 12 | 13 | % TODO: add handling of DC lines 14 | 15 | % MATPOWER 16 | % Copyright (c) 2012-2015 by Power System Engineering Research Center (PSERC) 17 | % by Ray Zimmerman, PSERC Cornell 18 | % 19 | % $Id: find_islands.m 2644 2015-03-11 19:34:22Z ray $ 20 | % 21 | % This file is part of MATPOWER. 22 | % Covered by the 3-clause BSD License (see LICENSE file for details). 23 | % See http://www.pserc.cornell.edu/matpower/ for more info. 24 | 25 | %% define named indices into data matrices 26 | [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 27 | VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 28 | [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ... 29 | TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ... 30 | ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch; 31 | 32 | %% find islands 33 | nb = size(mpc.bus, 1); %% number of buses 34 | nl = size(mpc.branch, 1); %% number of branches 35 | 36 | e2i = sparse(mpc.bus(:, BUS_I), ones(nb, 1), 1:nb, max(mpc.bus(:, BUS_I)), 1); 37 | C_on = sparse(1:nl, e2i(mpc.branch(:, F_BUS)), -mpc.branch(:, BR_STATUS), nl, nb) + ... 38 | sparse(1:nl, e2i(mpc.branch(:, T_BUS)), mpc.branch(:, BR_STATUS), nl, nb); 39 | 40 | if nnz(C_on) 41 | [groups, isolated] = connected_components(C_on); 42 | else 43 | groups = []; 44 | isolated = 1:nb; 45 | end 46 | -------------------------------------------------------------------------------- /library/matpower5.1/fmincopf.m: -------------------------------------------------------------------------------- 1 | function [varargout] = fmincopf(varargin) 2 | %FMINCOPF Solves an AC optimal power flow using FMINCON (Opt Tbx 2.x & later). 3 | % 4 | % Uses algorithm 520. Please see OPF for the details of input and 5 | % output arguments. 6 | 7 | % MATPOWER 8 | % Copyright (c) 2000-2015 by Power System Engineering Research Center (PSERC) 9 | % by Ray Zimmerman, PSERC Cornell 10 | % 11 | % $Id: fmincopf.m 2644 2015-03-11 19:34:22Z ray $ 12 | % 13 | % This file is part of MATPOWER. 14 | % Covered by the 3-clause BSD License (see LICENSE file for details). 15 | % See http://www.pserc.cornell.edu/matpower/ for more info. 16 | 17 | [mpc, mpopt] = opf_args(varargin{:}); 18 | mpopt = mpoption(mpopt, 'model', 'AC', 'opf.ac.solver', 'FMINCON'); 19 | [varargout{1:nargout}] = opf(mpc, mpopt); 20 | -------------------------------------------------------------------------------- /library/matpower5.1/get_reorder.m: -------------------------------------------------------------------------------- 1 | function B = get_reorder(A, idx, dim) 2 | %GET_REORDER Returns A with one of its dimensions indexed. 3 | % 4 | % B = GET_REORDER(A, IDX, DIM) 5 | % 6 | % Returns A(:, ..., :, IDX, :, ..., :), where DIM determines 7 | % in which dimension to place the IDX. 8 | % 9 | % See also SET_REORDER. 10 | 11 | % MATPOWER 12 | % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 13 | % by Ray Zimmerman, PSERC Cornell 14 | % 15 | % $Id: get_reorder.m 2644 2015-03-11 19:34:22Z ray $ 16 | % 17 | % This file is part of MATPOWER. 18 | % Covered by the 3-clause BSD License (see LICENSE file for details). 19 | % See http://www.pserc.cornell.edu/matpower/ for more info. 20 | 21 | ndim = ndims(A); 22 | s.type = '()'; 23 | s.subs = cell(1, ndim); 24 | for k = 1:ndim 25 | if k == dim 26 | s.subs{k} = idx; 27 | else 28 | s.subs{k} = ':'; 29 | end 30 | end 31 | B = subsref(A, s); 32 | -------------------------------------------------------------------------------- /library/matpower5.1/gurobiver.m: -------------------------------------------------------------------------------- 1 | function rv = gurobiver(varargin) 2 | %GUROBIVER Prints or returns GUROBI version info. 3 | % V = GUROBIVER returns the current GUROBI version numbers. 4 | % V = GUROBIVER('all') returns a struct with the fields Name, Version, 5 | % Release and Date (all strings). Calling GUROBIVER without assigning the 6 | % return value prints the version and release date of the current 7 | % installation of GUROBI. 8 | % 9 | % See also MPVER. 10 | 11 | % MATPOWER 12 | % Copyright (c) 2010-2015 by Power System Engineering Research Center (PSERC) 13 | % by Ray Zimmerman, PSERC Cornell 14 | % 15 | % $Id: gurobiver.m 2644 2015-03-11 19:34:22Z ray $ 16 | % 17 | % This file is part of MATPOWER. 18 | % Covered by the 3-clause BSD License (see LICENSE file for details). 19 | % See http://www.pserc.cornell.edu/matpower/ for more info. 20 | 21 | try 22 | model = struct( ... 23 | 'A', sparse(1), ... 24 | 'rhs', 1, ... 25 | 'sense', '=', ... 26 | 'vtype', 'C', ... 27 | 'obj', 1, ... 28 | 'modelsense', 'min' ... 29 | ); 30 | params = struct( ... 31 | 'outputflag', 0 ... 32 | ); 33 | result = gurobi(model, params); 34 | vn = sprintf('%d.%d.%d', result.versioninfo.major, result.versioninfo.minor, result.versioninfo.technical); 35 | catch gurobiError 36 | fprintf('Gurobi Error!\n'); 37 | disp(gurobiError.message); 38 | vn = ''; 39 | end 40 | 41 | v = struct( 'Name', 'Gurobi', ... 42 | 'Version', vn, ... 43 | 'Release', '', ... 44 | 'Date', '' ); 45 | if nargout > 0 46 | if nargin > 0 47 | rv = v; 48 | else 49 | rv = v.Version; 50 | end 51 | else 52 | fprintf('%-22s Version %-10s %-11s\n', v.Name, v.Version, v.Date); 53 | end 54 | -------------------------------------------------------------------------------- /library/matpower5.1/i2e_field.m: -------------------------------------------------------------------------------- 1 | function mpc = i2e_field(mpc, field, ordering, dim) 2 | %I2E_FIELD Converts fields of MPC from internal to external bus numbering. 3 | % 4 | % MPC = I2E_FIELD(MPC, FIELD, ORDERING) 5 | % MPC = I2E_FIELD(MPC, FIELD, ORDERING, DIM) 6 | % 7 | % For a case struct using internal indexing, this function can be 8 | % used to convert other data structures as well by passing in 2 or 3 9 | % extra parameters in addition to the case struct. 10 | % 11 | % The 2nd argument is a string or cell array of strings, specifying 12 | % a field in the case struct whose value should be converted by 13 | % a corresponding call to I2E_DATA. The field can contain either a 14 | % numeric or a cell array. The corresponding OLDVAL is taken from 15 | % where it was stored by EXT2INT in MPC.ORDER.EXT and the updated 16 | % case struct is returned. If FIELD is a cell array of strings, 17 | % they specify nested fields. 18 | % 19 | % The 3rd and optional 4th arguments are simply passed along to 20 | % the call to I2E_DATA. 21 | % 22 | % Examples: 23 | % mpc = i2e_field(mpc, {'reserves', 'cost'}, 'gen'); 24 | % 25 | % Reorders rows of mpc.reserves.cost to match external generator 26 | % ordering. 27 | % 28 | % mpc = i2e_field(mpc, {'reserves', 'zones'}, 'gen', 2); 29 | % 30 | % Reorders columns of mpc.reserves.zones to match external 31 | % generator ordering. 32 | % 33 | % See also E2I_FIELD, I2E_DATA, INT2EXT. 34 | 35 | % MATPOWER 36 | % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 37 | % by Ray Zimmerman, PSERC Cornell 38 | % 39 | % $Id: i2e_field.m 2644 2015-03-11 19:34:22Z ray $ 40 | % 41 | % This file is part of MATPOWER. 42 | % Covered by the 3-clause BSD License (see LICENSE file for details). 43 | % See http://www.pserc.cornell.edu/matpower/ for more info. 44 | 45 | if nargin < 4 46 | dim = 1; 47 | end 48 | if ischar(field) 49 | mpc.order.int.(field) = mpc.(field); 50 | mpc.(field) = i2e_data(mpc, mpc.(field), ... 51 | mpc.order.ext.(field), ordering, dim); 52 | else %% iscell(field) 53 | for k = 1:length(field) 54 | s(k).type = '.'; 55 | s(k).subs = field{k}; 56 | end 57 | if ~isfield(mpc.order, 'int') 58 | mpc.order.int = []; 59 | end 60 | mpc.order.int = subsasgn(mpc.order.int, s, subsref(mpc, s)); 61 | mpc = subsasgn(mpc, s, i2e_data(mpc, subsref(mpc, s), ... 62 | subsref(mpc.order.ext, s), ordering, dim)); 63 | end 64 | -------------------------------------------------------------------------------- /library/matpower5.1/isload.m: -------------------------------------------------------------------------------- 1 | function TorF = isload(gen) 2 | %ISLOAD Checks for dispatchable loads. 3 | % TORF = ISLOAD(GEN) returns a column vector of 1's and 0's. The 1's 4 | % correspond to rows of the GEN matrix which represent dispatchable loads. 5 | % The current test is Pmin < 0 AND Pmax == 0. 6 | % This may need to be revised to allow sensible specification 7 | % of both elastic demand and pumped storage units. 8 | 9 | % MATPOWER 10 | % Copyright (c) 2005-2015 by Power System Engineering Research Center (PSERC) 11 | % by Ray Zimmerman, PSERC Cornell 12 | % 13 | % $Id: isload.m 2644 2015-03-11 19:34:22Z ray $ 14 | % 15 | % This file is part of MATPOWER. 16 | % Covered by the 3-clause BSD License (see LICENSE file for details). 17 | % See http://www.pserc.cornell.edu/matpower/ for more info. 18 | 19 | [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 20 | MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 21 | QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 22 | 23 | TorF = gen(:, PMIN) < 0 & gen(:, PMAX) == 0; 24 | -------------------------------------------------------------------------------- /library/matpower5.1/makeAang.m: -------------------------------------------------------------------------------- 1 | function [Aang, lang, uang, iang] = makeAang(baseMVA, branch, nb, mpopt) 2 | %MAKEAANG Construct constraints for branch angle difference limits. 3 | % [AANG, LANG, UANG, IANG] = MAKEAANG(BASEMVA, BRANCH, NB, MPOPT) 4 | % 5 | % Constructs the parameters for the following linear constraint limiting 6 | % the voltage angle differences across branches, where Va is the vector 7 | % of bus voltage angles. NB is the number of buses. 8 | % 9 | % LANG <= AANG * Va <= UANG 10 | % 11 | % IANG is the vector of indices of branches with angle difference limits. 12 | % The limits are given in the ANGMIN and ANGMAX columns of the branch 13 | % matrix. Voltage angle differences are taken to be unbounded below if 14 | % ANGMIN < -360 and unbounded above if ANGMAX > 360. If both ANGMIN and 15 | % ANGMAX are zero, the angle difference is assumed to be unconstrained. 16 | % 17 | % Example: 18 | % [Aang, lang, uang, iang] = makeAang(baseMVA, branch, nb, mpopt); 19 | 20 | % MATPOWER 21 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales 24 | % 25 | % $Id: makeAang.m 2644 2015-03-11 19:34:22Z ray $ 26 | % 27 | % This file is part of MATPOWER. 28 | % Covered by the 3-clause BSD License (see LICENSE file for details). 29 | % See http://www.pserc.cornell.edu/matpower/ for more info. 30 | 31 | %% define named indices into data matrices 32 | [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ... 33 | TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ... 34 | ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch; 35 | 36 | if mpopt.opf.ignore_angle_lim 37 | Aang = sparse(0, nb); 38 | lang = []; 39 | uang = []; 40 | iang = []; 41 | else 42 | iang = find((branch(:, ANGMIN) & branch(:, ANGMIN) > -360) | ... 43 | (branch(:, ANGMAX) & branch(:, ANGMAX) < 360)); 44 | nang = length(iang); 45 | 46 | if nang > 0 47 | ii = [(1:nang)'; (1:nang)']; 48 | jj = [branch(iang, F_BUS); branch(iang, T_BUS)]; 49 | Aang = sparse(ii, jj, [ones(nang, 1); -ones(nang, 1)], nang, nb); 50 | lang = branch(iang, ANGMIN) * pi/180; 51 | uang = branch(iang, ANGMAX) * pi/180; 52 | else 53 | Aang = sparse(0, nb); 54 | lang =[]; 55 | uang =[]; 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /library/matpower5.1/makeLODF.m: -------------------------------------------------------------------------------- 1 | function LODF = makeLODF(branch, PTDF); 2 | %MAKELODF Builds the line outage distribution factor matrix. 3 | % LODF = MAKELODF(BRANCH, PTDF) returns the DC line outage 4 | % distribution factor matrix for a given PTDF. The matrix is nbr x nbr, 5 | % where nbr is the number of branches. 6 | % 7 | % Example: 8 | % H = makePTDF(baseMVA, bus, branch); 9 | % LODF = makeLODF(branch, H); 10 | % 11 | % See also MAKEPTDF. 12 | 13 | % MATPOWER 14 | % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 15 | % by Ray Zimmerman, PSERC Cornell 16 | % 17 | % $Id: makeLODF.m 2644 2015-03-11 19:34:22Z ray $ 18 | % 19 | % This file is part of MATPOWER. 20 | % Covered by the 3-clause BSD License (see LICENSE file for details). 21 | % See http://www.pserc.cornell.edu/matpower/ for more info. 22 | 23 | [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ... 24 | TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ... 25 | ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch; 26 | 27 | [nl, nb] = size(PTDF); 28 | f = branch(:, F_BUS); 29 | t = branch(:, T_BUS); 30 | Cft = sparse([f; t], [1:nl 1:nl]', [ones(nl, 1); -ones(nl, 1)], nb, nl); 31 | 32 | H = PTDF * Cft; 33 | h = diag(H, 0); 34 | LODF = H ./ (ones(nl, nl) - ones(nl, 1) * h'); 35 | LODF = LODF - diag(diag(LODF)) - eye(nl, nl); 36 | -------------------------------------------------------------------------------- /library/matpower5.1/makeSbus.m: -------------------------------------------------------------------------------- 1 | function Sbus = makeSbus(baseMVA, bus, gen) 2 | %MAKESBUS Builds the vector of complex bus power injections. 3 | % SBUS = MAKESBUS(BASEMVA, BUS, GEN) returns the vector of complex bus 4 | % power injections, that is, generation minus load. Power is expressed 5 | % in per unit. 6 | % 7 | % See also MAKEYBUS. 8 | 9 | % MATPOWER 10 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 11 | % by Ray Zimmerman, PSERC Cornell 12 | % 13 | % $Id: makeSbus.m 2644 2015-03-11 19:34:22Z ray $ 14 | % 15 | % This file is part of MATPOWER. 16 | % Covered by the 3-clause BSD License (see LICENSE file for details). 17 | % See http://www.pserc.cornell.edu/matpower/ for more info. 18 | 19 | %% define named indices into bus, gen matrices 20 | [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 21 | VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 22 | [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 23 | MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 24 | QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 25 | 26 | %% generator info 27 | on = find(gen(:, GEN_STATUS) > 0); %% which generators are on? 28 | gbus = gen(on, GEN_BUS); %% what buses are they at? 29 | 30 | %% form net complex bus power injection vector 31 | nb = size(bus, 1); 32 | ngon = size(on, 1); 33 | Cg = sparse(gbus, (1:ngon)', ones(ngon, 1), nb, ngon); %% connection matrix 34 | %% element i, j is 1 if 35 | %% gen on(j) at bus i is ON 36 | Sbus = ( Cg * (gen(on, PG) + 1j * gen(on, QG)) ... %% power injected by generators 37 | - (bus(:, PD) + 1j * bus(:, QD)) ) / ... %% plus power injected by loads 38 | baseMVA; %% converted to p.u. 39 | -------------------------------------------------------------------------------- /library/matpower5.1/margcost.m: -------------------------------------------------------------------------------- 1 | function marginalcost = margcost(gencost, Pg) 2 | %MARGCOST Computes marginal cost for generators at given output level. 3 | % MARGINALCOST = MARGCOST(GENCOST, PG) computes marginal cost for generators 4 | % given a matrix in gencost format and a column vector of generation levels. 5 | % The return value has the same dimensions as PG. Each row of GENCOST is 6 | % used to evaluate the cost at the points specified in the corresponding row 7 | % of PG. 8 | 9 | % MATPOWER 10 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 11 | % by Ray Zimmerman, PSERC Cornell 12 | % & Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales 13 | % 14 | % $Id: margcost.m 2644 2015-03-11 19:34:22Z ray $ 15 | % 16 | % This file is part of MATPOWER. 17 | % Covered by the 3-clause BSD License (see LICENSE file for details). 18 | % See http://www.pserc.cornell.edu/matpower/ for more info. 19 | 20 | [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost; 21 | 22 | [ng, m] = size(gencost); 23 | marginalcost = zeros(ng, 1); 24 | 25 | if ~isempty(gencost) 26 | ipwl = find(gencost(:, MODEL) == PW_LINEAR); 27 | ipol = find(gencost(:, MODEL) == POLYNOMIAL); 28 | if ~isempty(ipwl) 29 | x = gencost(:, COST:2:(m-1)); 30 | y = gencost(:, (COST+1):2:m); 31 | for i = ipwl' 32 | if gencost(i, NCOST) > 0 33 | c = diff(y(i,:)) ./ diff(x(i,:)); 34 | k = find(Pg(i,:) <= x(i,:), 1); 35 | if isempty(k) 36 | marginalcost(i,:) = c(end); 37 | elseif k == 1 38 | marginalcost(i,:) = c(1); 39 | else 40 | marginalcost(i,:) = c(k-1); 41 | end 42 | end 43 | end 44 | end 45 | for i = ipol' 46 | marginalcost(i,:) = polyval(polyder(gencost(i, COST:(COST+gencost(i, NCOST)-1) )), Pg(i,:) ); 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /library/matpower5.1/mipsver.m: -------------------------------------------------------------------------------- 1 | function rv = mipsver(varargin) 2 | %MIPSVER Prints or returns MIPS version info for current installation. 3 | % V = MIPSVER returns the current MIPS version number. 4 | % V = MIPSVER('all') returns a struct with the fields Name, Version, 5 | % Release and Date (all strings). Calling MIPSVER without assigning the 6 | % return value prints the version and release date of the current 7 | % installation of MIPS. 8 | % 9 | % See also MPVER. 10 | 11 | % MIPS 12 | % Copyright (c) 2010-2015 by Power System Engineering Research Center (PSERC) 13 | % by Ray Zimmerman, PSERC Cornell 14 | % 15 | % $Id: mipsver.m 2664 2015-03-20 21:31:02Z ray $ 16 | % 17 | % This file is part of MIPS. 18 | % Covered by the 3-clause BSD License (see LICENSE file for details). 19 | % See http://www.pserc.cornell.edu/matpower/ for more info. 20 | 21 | v = struct( 'Name', 'MIPS', ... 22 | 'Version', '1.2', ... 23 | 'Release', '', ... 24 | 'Date', '20-Mar-2015' ); 25 | if nargout > 0 26 | if nargin > 0 27 | rv = v; 28 | else 29 | rv = v.Version; 30 | end 31 | else 32 | fprintf('%-22s Version %-9s %11s\n', v.Name, v.Version, v.Date); 33 | end 34 | -------------------------------------------------------------------------------- /library/matpower5.1/mosek_symbcon.m: -------------------------------------------------------------------------------- 1 | function sc = mosek_symbcon 2 | %MOSEK_SYMBCON Returns struct containing MOSEK's symbolic constants 3 | % SC = MOSEK_SYMBCON 4 | % 5 | % Returns a stuct containing all of MOSEk's symbolic constants, such 6 | % as those used to select the optimizer algorithm. Since the values 7 | % of these constants are not necessarily the same from one version of 8 | % MOSEK to the next, it is safer to use the symbolic constant rather 9 | % than the value in your MATPOWER code. For example, the following code 10 | % 11 | % mpopt = mpoption('opf.dc.solver', 'MOSEK', 'mosek_lp_alg', 4); 12 | % 13 | % would select primal simplex solver in MOSEK v6.x, but dual-simplex in 14 | % MOSEK v7.x. The recommended way to select a dual-simplex solver that 15 | % should work regardless of MOSEK version is to use the following: 16 | % 17 | % sc = mosek_symbcon; 18 | % mpopt = mpoption('opf.dc.solver', 'MOSEK', ... 19 | % 'mosek_lp_alg', sc.MSK_OPTIMIZER_DUAL_SIMPLEX); 20 | 21 | % MATPOWER 22 | % Copyright (c) 2015-2015 by Power System Engineering Research Center (PSERC) 23 | % by Ray Zimmerman, PSERC Cornell 24 | % 25 | % $Id: mosek_symbcon.m 2644 2015-03-11 19:34:22Z ray $ 26 | % 27 | % This file is part of MATPOWER. 28 | % Covered by the 3-clause BSD License (see LICENSE file for details). 29 | % See http://www.pserc.cornell.edu/matpower/ for more info. 30 | 31 | [r, res] = mosekopt('symbcon echo(0)'); 32 | sc = res.symbcon; 33 | -------------------------------------------------------------------------------- /library/matpower5.1/mpoption_info_clp.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_clp(selector) 2 | %MPOPTION_INFO_CLP Returns MATPOWER option info for CLP. 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_CLP('D') 5 | % VALID_OPTS = MPOPTION_INFO_CLP('V') 6 | % EXCEPTIONS = MPOPTION_INFO_CLP('E') 7 | % 8 | % Returns a structure for CLP options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2014, 2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_clp.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | if have_fcn('clp') 34 | switch upper(selector) 35 | case {'D', 'V'} %% default and valid options 36 | opt = struct(... 37 | 'clp', struct(... 38 | 'opts', [], ... 39 | 'opt_fname', '' ... 40 | ) ... 41 | ); 42 | case 'E' %% exceptions used by nested_struct_copy() for applying 43 | opt = struct(... 44 | 'name', { 'clp.opts' }, ... 45 | 'check', 0 ... 46 | ); 47 | % 'copy_mode', { @clp_options } ... 48 | otherwise 49 | error('mpoption_info_clp: ''%s'' is not a valid input argument', selector); 50 | end 51 | else 52 | opt = struct([]); %% CLP is not available 53 | end 54 | -------------------------------------------------------------------------------- /library/matpower5.1/mpoption_info_cplex.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_cplex(selector) 2 | %MPOPTION_INFO_CPLEX Returns MATPOWER option info for CPLEX. 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_CPLEX('D') 5 | % VALID_OPTS = MPOPTION_INFO_CPLEX('V') 6 | % EXCEPTIONS = MPOPTION_INFO_CPLEX('E') 7 | % 8 | % Returns a structure for CPLEX options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_cplex.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | if have_fcn('cplex') 34 | switch upper(selector) 35 | case {'D', 'V'} %% default and valid options 36 | opt = struct(... 37 | 'cplex', struct(... 38 | 'lpmethod', 0, ... 39 | 'qpmethod', 0, ... 40 | 'opts', [], ... 41 | 'opt_fname', '', ... 42 | 'opt', 0 ... 43 | ) ... 44 | ); 45 | case 'E' %% exceptions used by nested_struct_copy() for applying 46 | opt = struct(... 47 | 'name', { 'cplex.opts' }, ... 48 | 'check', 0 ... 49 | ); 50 | % 'copy_mode', { @cplex_options } ... 51 | otherwise 52 | error('mpoption_info_cplex: ''%s'' is not a valid input argument', selector); 53 | end 54 | else 55 | opt = struct([]); %% CPLEX is not available 56 | end 57 | -------------------------------------------------------------------------------- /library/matpower5.1/mpoption_info_fmincon.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_fmincon(selector) 2 | %MPOPTION_INFO_FMINCON Returns MATPOWER option info for FMINCON. 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_FMINCON('D') 5 | % VALID_OPTS = MPOPTION_INFO_FMINCON('V') 6 | % EXCEPTIONS = MPOPTION_INFO_FMINCON('E') 7 | % 8 | % Returns a structure for FMINCON options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_fmincon.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | if have_fcn('fmincon') 34 | switch upper(selector) 35 | case {'D', 'V'} %% default and valid options 36 | opt = struct(... 37 | 'fmincon', struct(... 38 | 'alg', 4, ... 39 | 'tol_x', 1e-4, ... 40 | 'tol_f', 1e-4, ... 41 | 'max_it', 0 ... 42 | ) ... % 'opt_fname', '', 'opts', [] 43 | ); 44 | case 'E' %% exceptions used by nested_struct_copy() for applying 45 | opt = struct([]); %% no exceptions 46 | % opt = struct(... 47 | % 'name', { 'fmincon.opts' }, ... 48 | % 'check', 0, ... 49 | % 'copy_mode', { '' } ... 50 | % ); 51 | otherwise 52 | error('mpoption_info_fmincon: ''%s'' is not a valid input argument', selector); 53 | end 54 | else 55 | opt = struct([]); %% FMINCON is not available 56 | end 57 | -------------------------------------------------------------------------------- /library/matpower5.1/mpoption_info_glpk.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_glpk(selector) 2 | %MPOPTION_INFO_GLPK Returns MATPOWER option info for GLPK. 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_GLPK('D') 5 | % VALID_OPTS = MPOPTION_INFO_GLPK('V') 6 | % EXCEPTIONS = MPOPTION_INFO_GLPK('E') 7 | % 8 | % Returns a structure for GLPK options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_glpk.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | if have_fcn('glpk') 34 | switch upper(selector) 35 | case {'D', 'V'} %% default and valid options 36 | opt = struct(... 37 | 'glpk', struct(... 38 | 'opts', [], ... 39 | 'opt_fname', '' ... 40 | ) ... 41 | ); 42 | case 'E' %% exceptions used by nested_struct_copy() for applying 43 | opt = struct(... 44 | 'name', { 'glpk.opts' }, ... 45 | 'check', 0 ... 46 | ); 47 | % 'copy_mode', { @glpk_options } ... 48 | otherwise 49 | error('mpoption_info_glpk: ''%s'' is not a valid input argument', selector); 50 | end 51 | else 52 | opt = struct([]); %% GLPK is not available 53 | end 54 | -------------------------------------------------------------------------------- /library/matpower5.1/mpoption_info_gurobi.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_gurobi(selector) 2 | %MPOPTION_INFO_GUROBI Returns MATPOWER option info for Gurobi. 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_GUROBI('D') 5 | % VALID_OPTS = MPOPTION_INFO_GUROBI('V') 6 | % EXCEPTIONS = MPOPTION_INFO_GUROBI('E') 7 | % 8 | % Returns a structure for Gurobi options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_gurobi.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | if have_fcn('gurobi') 34 | switch upper(selector) 35 | case {'D', 'V'} %% default and valid options 36 | opt = struct(... 37 | 'gurobi', struct(... 38 | 'method', -1, ... 39 | 'timelimit', Inf, ... 40 | 'threads', 0, ... 41 | 'opts', [], ... 42 | 'opt_fname', '', ... 43 | 'opt', 0 ... 44 | ) ... 45 | ); 46 | case 'E' %% exceptions used by nested_struct_copy() for applying 47 | opt = struct(... 48 | 'name', { 'gurobi.opts' }, ... 49 | 'check', 0 ... 50 | ); 51 | % 'copy_mode', { @gurobi_options } ... 52 | otherwise 53 | error('mpoption_info_gurobi: ''%s'' is not a valid input argument', selector); 54 | end 55 | else 56 | opt = struct([]); %% Gurobi is not available 57 | end 58 | -------------------------------------------------------------------------------- /library/matpower5.1/mpoption_info_intlinprog.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_intlinprog(selector) 2 | %MPOPTION_INFO_INTLINPROG Returns MATPOWER option info for INTLINPROG. 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_INTLINPROG('D') 5 | % VALID_OPTS = MPOPTION_INFO_INTLINPROG('V') 6 | % EXCEPTIONS = MPOPTION_INFO_INTLINPROG('E') 7 | % 8 | % Returns a structure for INTLINPROG options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2015-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_intlinprog.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | if have_fcn('intlinprog') 34 | switch upper(selector) 35 | case {'D', 'V'} %% default and valid options 36 | opt = struct(... 37 | 'intlinprog', [] ... 38 | ); 39 | case 'E' %% exceptions used by nested_struct_copy() for applying 40 | opt = struct(... 41 | 'name', { 'intlinprog' }, ... 42 | 'check', 0, ... 43 | 'copy_mode', { '' } ... 44 | ); 45 | otherwise 46 | error('mpoption_info_intlinprog: ''%s'' is not a valid input argument', selector); 47 | end 48 | else 49 | opt = struct([]); %% INTLINPROG is not available 50 | end 51 | -------------------------------------------------------------------------------- /library/matpower5.1/mpoption_info_ipopt.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_ipopt(selector) 2 | %MPOPTION_INFO_IPOPT Returns MATPOWER option info for IPOPT. 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_IPOPT('D') 5 | % VALID_OPTS = MPOPTION_INFO_IPOPT('V') 6 | % EXCEPTIONS = MPOPTION_INFO_IPOPT('E') 7 | % 8 | % Returns a structure for IPOPT options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_ipopt.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | if have_fcn('ipopt') 34 | switch upper(selector) 35 | case {'D', 'V'} %% default and valid options 36 | opt = struct(... 37 | 'ipopt', struct(... 38 | 'opts', [], ... 39 | 'opt_fname', '', ... 40 | 'opt', 0 ... 41 | ) ... 42 | ); 43 | case 'E' %% exceptions used by nested_struct_copy() for applying 44 | opt = struct(... 45 | 'name', { 'ipopt.opts' }, ... 46 | 'check', 0 ... 47 | ); 48 | % 'copy_mode', { @ipopt_options } ... 49 | otherwise 50 | error('mpoption_info_ipopt: ''%s'' is not a valid input argument', selector); 51 | end 52 | else 53 | opt = struct([]); %% IPOPT is not available 54 | end 55 | -------------------------------------------------------------------------------- /library/matpower5.1/mpoption_info_knitro.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_knitro(selector) 2 | %MPOPTION_INFO_KNITRO Returns MATPOWER option info for KNITRO. 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_KNITRO('D') 5 | % VALID_OPTS = MPOPTION_INFO_KNITRO('V') 6 | % EXCEPTIONS = MPOPTION_INFO_KNITRO('E') 7 | % 8 | % Returns a structure for KNITRO options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_knitro.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | if have_fcn('knitro') 34 | switch upper(selector) 35 | case {'D', 'V'} %% default and valid options 36 | opt = struct(... 37 | 'knitro', struct(... 38 | 'tol_x', 1e-4, ... 39 | 'tol_f', 1e-4, ... 40 | 'opts', [], ... 41 | 'opt_fname', '', ... 42 | 'opt', 0 ... 43 | ) ... 44 | ); 45 | case 'E' %% exceptions used by nested_struct_copy() for applying 46 | opt = struct(... 47 | 'name', { 'knitro.opts' }, ... 48 | 'check', 0, ... 49 | 'copy_mode', { '' } ... 50 | ); 51 | otherwise 52 | error('mpoption_info_knitro: ''%s'' is not a valid input argument', selector); 53 | end 54 | else 55 | opt = struct([]); %% KNITRO is not available 56 | end 57 | -------------------------------------------------------------------------------- /library/matpower5.1/mpoption_info_linprog.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_linprog(selector) 2 | %MPOPTION_INFO_LINPROG Returns MATPOWER option info for LINPROG. 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_LINPROG('D') 5 | % VALID_OPTS = MPOPTION_INFO_LINPROG('V') 6 | % EXCEPTIONS = MPOPTION_INFO_LINPROG('E') 7 | % 8 | % Returns a structure for LINPROG options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_linprog.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | if have_fcn('linprog') 34 | switch upper(selector) 35 | case {'D', 'V'} %% default and valid options 36 | opt = struct(... 37 | 'linprog', [] ... 38 | ); 39 | case 'E' %% exceptions used by nested_struct_copy() for applying 40 | opt = struct(... 41 | 'name', { 'linprog' }, ... 42 | 'check', 0, ... 43 | 'copy_mode', { '' } ... 44 | ); 45 | otherwise 46 | error('mpoption_info_linprog: ''%s'' is not a valid input argument', selector); 47 | end 48 | else 49 | opt = struct([]); %% LINPROG is not available 50 | end 51 | -------------------------------------------------------------------------------- /library/matpower5.1/mpoption_info_mips.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_mips(selector) 2 | %MPOPTION_INFO_MIPS Returns MATPOWER option info for MIPS (optional fields). 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_MIPS('D') 5 | % VALID_OPTS = MPOPTION_INFO_MIPS('V') 6 | % EXCEPTIONS = MPOPTION_INFO_MIPS('E') 7 | % 8 | % Returns a structure for MIPS options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_mips.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | switch upper(selector) 34 | case 'D' %% default options 35 | opt = struct([]); %% no default options 36 | case 'V' %% valid options 37 | opt = struct(... 38 | 'mips', struct(... 39 | 'xi', 0.99995, ... 40 | 'sigma', 0.1, ... 41 | 'z0', 1, ... 42 | 'alpha_min', 1e-8, ... 43 | 'rho_min', 0.95, ... 44 | 'rho_max', 1.05, ... 45 | 'mu_threshold', 1e-5, ... 46 | 'max_stepsize', 1e10 ... 47 | ) ... 48 | ); 49 | case 'E' %% exceptions used by nested_struct_copy() for applying 50 | opt = struct([]); %% no exceptions 51 | otherwise 52 | error('mpoption_info_mips: ''%s'' is not a valid input argument', selector); 53 | end 54 | -------------------------------------------------------------------------------- /library/matpower5.1/mpoption_info_mosek.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_mosek(selector) 2 | %MPOPTION_INFO_MOSEK Returns MATPOWER option info for MOSEK. 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_MOSEK('D') 5 | % VALID_OPTS = MPOPTION_INFO_MOSEK('V') 6 | % EXCEPTIONS = MPOPTION_INFO_MOSEK('E') 7 | % 8 | % Returns a structure for MOSEK options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_mosek.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | if have_fcn('mosek') 34 | switch upper(selector) 35 | case {'D', 'V'} %% default and valid options 36 | opt = struct(... 37 | 'mosek', struct(... 38 | 'lp_alg', 0, ... 39 | 'max_it', 0, ... 40 | 'gap_tol', 0, ... 41 | 'max_time', 0, ... 42 | 'num_threads', 0, ... 43 | 'opts', [], ... 44 | 'opt_fname', '', ... 45 | 'opt', 0 ... 46 | ) ... 47 | ); 48 | case 'E' %% exceptions used by nested_struct_copy() for applying 49 | opt = struct(... 50 | 'name', { 'mosek.opts' }, ... 51 | 'check', 0 ... 52 | ); 53 | % 'copy_mode', { @mosek_options } ... 54 | otherwise 55 | error('mpoption_info_mosek: ''%s'' is not a valid input argument', selector); 56 | end 57 | else 58 | opt = struct([]); %% MOSEK is not available 59 | end 60 | -------------------------------------------------------------------------------- /library/matpower5.1/mpoption_info_quadprog.m: -------------------------------------------------------------------------------- 1 | function opt = mpoption_info_quadprog(selector) 2 | %MPOPTION_INFO_QUADPROG Returns MATPOWER option info for QUADPROG. 3 | % 4 | % DEFAULT_OPTS = MPOPTION_INFO_QUADPROG('D') 5 | % VALID_OPTS = MPOPTION_INFO_QUADPROG('V') 6 | % EXCEPTIONS = MPOPTION_INFO_QUADPROG('E') 7 | % 8 | % Returns a structure for QUADPROG options for MATPOWER containing ... 9 | % (1) default options, 10 | % (2) valid options, or 11 | % (3) NESTED_STRUCT_COPY exceptions for setting options 12 | % ... depending on the value of the input argument. 13 | % 14 | % This function is used by MPOPTION to set default options, check validity 15 | % of option names or modify option setting/copying behavior for this 16 | % subset of optional MATPOWER options. 17 | % 18 | % See also MPOPTION. 19 | 20 | % MATPOWER 21 | % Copyright (c) 2014-2015 by Power System Engineering Research Center (PSERC) 22 | % by Ray Zimmerman, PSERC Cornell 23 | % 24 | % $Id: mpoption_info_quadprog.m 2644 2015-03-11 19:34:22Z ray $ 25 | % 26 | % This file is part of MATPOWER. 27 | % Covered by the 3-clause BSD License (see LICENSE file for details). 28 | % See http://www.pserc.cornell.edu/matpower/ for more info. 29 | 30 | if nargin < 1 31 | selector = 'D'; 32 | end 33 | if have_fcn('quadprog') 34 | switch upper(selector) 35 | case {'D', 'V'} %% default and valid options 36 | opt = struct(... 37 | 'quadprog', [] ... 38 | ); 39 | case 'E' %% exceptions used by nested_struct_copy() for applying 40 | opt = struct(... 41 | 'name', { 'quadprog' }, ... 42 | 'check', 0, ... 43 | 'copy_mode', { '' } ... 44 | ); 45 | otherwise 46 | error('mpoption_info_quadprog: ''%s'' is not a valid input argument', selector); 47 | end 48 | else 49 | opt = struct([]); %% QUADPROG is not available 50 | end 51 | -------------------------------------------------------------------------------- /library/matpower5.1/poly2pwl.m: -------------------------------------------------------------------------------- 1 | function pwlcost = poly2pwl(polycost, Pmin, Pmax, npts) 2 | %POLY2PWL Converts polynomial cost variable to piecewise linear. 3 | % PWLCOST = POLY2PWL(POLYCOST, PMIN, PMAX, NPTS) converts the polynomial 4 | % cost variable POLYCOST into a piece-wise linear cost by evaluating at 5 | % NPTS evenly spaced points between PMIN and PMAX. If the range does not 6 | % include 0, then it is evaluated at 0 and NPTS-1 evenly spaced points 7 | % between PMIN and PMAX. 8 | 9 | % MATPOWER 10 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 11 | % by Ray Zimmerman, PSERC Cornell 12 | % 13 | % $Id: poly2pwl.m 2644 2015-03-11 19:34:22Z ray $ 14 | % 15 | % This file is part of MATPOWER. 16 | % Covered by the 3-clause BSD License (see LICENSE file for details). 17 | % See http://www.pserc.cornell.edu/matpower/ for more info. 18 | 19 | [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost; 20 | 21 | pwlcost = polycost; 22 | [m, n] = size(polycost); %% size of piece being changed 23 | pwlcost(:, MODEL) = PW_LINEAR; %% change cost model 24 | pwlcost(:, COST:n) = 0; %% zero out old data 25 | pwlcost(:, NCOST) = npts; %% change number of data points 26 | pwlcost(1, COST+2*(npts-1)+1) = 0; %% expand as needed 27 | 28 | for i = 1:m 29 | if Pmin(i) > 0 30 | step = (Pmax(i) - Pmin(i)) / (npts - 2); 31 | xx = [0 Pmin(i):step:Pmax(i)]; 32 | elseif Pmax(i) < 0 33 | step = (Pmax(i) - Pmin(i)) / (npts - 2); 34 | xx = [Pmin(i):step:Pmax(i) 0]; 35 | else 36 | step = (Pmax(i) - Pmin(i)) / (npts - 1); 37 | xx = (Pmin(i):step:Pmax(i)); 38 | end 39 | yy = totcost(polycost(i, :), xx); 40 | pwlcost(i, COST:2:(COST + 2*(npts-1) )) = xx; 41 | pwlcost(i, (COST+1):2:(COST + 2*(npts-1) + 1)) = yy; 42 | end 43 | -------------------------------------------------------------------------------- /library/matpower5.1/polycost.m: -------------------------------------------------------------------------------- 1 | function f = polycost(gencost, Pg, der) 2 | %POLYCOST Evaluates polynomial generator cost & derivatives. 3 | % F = POLYCOST(GENCOST, PG) returns the vector of costs evaluated at PG 4 | % 5 | % DF = POLYCOST(GENCOST, PG, 1) returns the vector of first derivatives 6 | % of costs evaluated at PG 7 | % 8 | % D2F = POLYCOST(GENCOST, PG, 2) returns the vector of second derivatives 9 | % of costs evaluated at PG 10 | % 11 | % GENCOST must contain only polynomial costs 12 | % PG is in MW, not p.u. (works for QG too) 13 | % 14 | % This is a more effecient implementation that what can be done with 15 | % MATLAB's built-in POLYVAL and POLYDER functions. 16 | 17 | % MATPOWER 18 | % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 19 | % by Ray Zimmerman, PSERC Cornell 20 | % 21 | % $Id: polycost.m 2644 2015-03-11 19:34:22Z ray $ 22 | % 23 | % This file is part of MATPOWER. 24 | % Covered by the 3-clause BSD License (see LICENSE file for details). 25 | % See http://www.pserc.cornell.edu/matpower/ for more info. 26 | 27 | %%----- initialize ----- 28 | %% define named indices into data matrices 29 | [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost; 30 | 31 | if nargin < 3 32 | der = 0; 33 | end 34 | 35 | if any(gencost(:, MODEL) == PW_LINEAR) 36 | error('polycost: all costs must be polynomial'); 37 | end 38 | 39 | ng = length(Pg); 40 | maxN = max(gencost(:, NCOST)); 41 | minN = min(gencost(:, NCOST)); 42 | 43 | %% form coefficient matrix where 1st column is constant term, 2nd linear, etc. 44 | c = zeros(ng, maxN); 45 | for n = minN:maxN 46 | k = find(gencost(:, NCOST) == n); %% cost with n coefficients 47 | c(k, 1:n) = gencost(k, (COST+n-1):-1:COST); 48 | end 49 | 50 | %% do derivatives 51 | for d = 1:der 52 | if size(c, 2) >= 2 53 | c = c(:, 2:maxN-d+1); 54 | else 55 | c = zeros(ng, 1); 56 | break; 57 | end 58 | for k = 2:maxN-d 59 | c(:, k) = k * c(:, k); 60 | end 61 | end 62 | 63 | %% evaluate polynomial 64 | if isempty(c) 65 | f = zeros(size(Pg)); 66 | else 67 | f = c(:, 1); %% constant term 68 | for k = 2:size(c, 2) 69 | f = f + c(:, k) .* Pg .^ (k-1); 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /library/matpower5.1/pqcost.m: -------------------------------------------------------------------------------- 1 | function [pcost, qcost] = pqcost(gencost, ng, on) 2 | %PQCOST Splits the gencost variable into two pieces if costs are given for Qg. 3 | % [PCOST, QCOST] = PQCOST(GENCOST, NG, ON) checks whether GENCOST has 4 | % cost information for reactive power generation (rows ng+1 to 2*ng). 5 | % If so, it returns the first NG rows in PCOST and the last NG rows in 6 | % QCOST. Otherwise, leaves QCOST empty. Also does some error checking. 7 | % If ON is specified (list of indices of generators which are on line) 8 | % it only returns the rows corresponding to these generators. 9 | 10 | % MATPOWER 11 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 12 | % by Ray Zimmerman, PSERC Cornell 13 | % 14 | % $Id: pqcost.m 2644 2015-03-11 19:34:22Z ray $ 15 | % 16 | % This file is part of MATPOWER. 17 | % Covered by the 3-clause BSD License (see LICENSE file for details). 18 | % See http://www.pserc.cornell.edu/matpower/ for more info. 19 | 20 | if nargin < 3 21 | on = (1:ng)'; 22 | end 23 | 24 | if size(gencost, 1) == ng 25 | pcost = gencost(on, :); 26 | qcost = []; 27 | elseif size(gencost, 1) == 2 * ng 28 | pcost = gencost(on, :); 29 | qcost = gencost(on+ng, :); 30 | else 31 | error('pqcost: gencost has wrong number of rows'); 32 | end 33 | -------------------------------------------------------------------------------- /library/matpower5.1/remove_userfcn.m: -------------------------------------------------------------------------------- 1 | function mpc = remove_userfcn(mpc, stage, fcn) 2 | %REMOVE_USERFCN Removes a userfcn from the list to be called for a case. 3 | % MPC = REMOVE_USERFCN(MPC, STAGE, FCN) 4 | % 5 | % A userfcn is a callback function that can be called automatically by 6 | % MATPOWER at one of various stages in a simulation. This function removes 7 | % the last instance of the userfcn for the given STAGE with the function 8 | % handle specified by FCN. 9 | % 10 | % See also ADD_USERFCN, RUN_USERFCN, TOGGLE_RESERVES, TOGGLE_IFLIMS, 11 | % RUNOPF_W_RES. 12 | 13 | % MATPOWER 14 | % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 15 | % by Ray Zimmerman, PSERC Cornell 16 | % 17 | % $Id: remove_userfcn.m 2644 2015-03-11 19:34:22Z ray $ 18 | % 19 | % This file is part of MATPOWER. 20 | % Covered by the 3-clause BSD License (see LICENSE file for details). 21 | % See http://www.pserc.cornell.edu/matpower/ for more info. 22 | 23 | n = length(mpc.userfcn.(stage)); 24 | 25 | if have_fcn('octave') 26 | fcn_info = functions(fcn); 27 | for k = n:-1:1 28 | cb_info = functions(mpc.userfcn.(stage)(k).fcn); 29 | if strcmp(cb_info.function, fcn_info.function) 30 | mpc.userfcn.(stage)(k) = []; 31 | break; 32 | end 33 | end 34 | else 35 | for k = n:-1:1 36 | if isequal(mpc.userfcn.(stage)(k).fcn, fcn) 37 | mpc.userfcn.(stage)(k) = []; 38 | break; 39 | end 40 | end 41 | end -------------------------------------------------------------------------------- /library/matpower5.1/run_userfcn.m: -------------------------------------------------------------------------------- 1 | function rv = run_userfcn(userfcn, stage, varargin) 2 | %RUN_USERFCN Runs the userfcn callbacks for a given stage. 3 | % RV = RUN_USERFCN(USERFCN, STAGE, VARARGIN) 4 | % 5 | % USERFCN : the 'userfcn' field of mpc, populated by ADD_USERFCN 6 | % STAGE : the name of the callback stage begin executed 7 | % (additional arguments) some stages require additional arguments. 8 | % 9 | % Example: 10 | % mpc = get_mpc(om); 11 | % om = run_userfcn(mpc.userfcn, 'formulation', om); 12 | % 13 | % See also ADD_USERFCN, REMOVE_USERFCN, TOGGLE_RESERVES, TOGGLE_IFLIMS, 14 | % RUNOPF_W_RES. 15 | 16 | % MATPOWER 17 | % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 18 | % by Ray Zimmerman, PSERC Cornell 19 | % 20 | % $Id: run_userfcn.m 2644 2015-03-11 19:34:22Z ray $ 21 | % 22 | % This file is part of MATPOWER. 23 | % Covered by the 3-clause BSD License (see LICENSE file for details). 24 | % See http://www.pserc.cornell.edu/matpower/ for more info. 25 | 26 | rv = varargin{1}; 27 | if ~isempty(userfcn) && isfield(userfcn, stage) 28 | for k = 1:length(userfcn.(stage)) 29 | if isfield(userfcn.(stage)(k), 'args') 30 | args = userfcn.(stage)(k).args; 31 | else 32 | args = []; 33 | end 34 | switch stage 35 | case {'ext2int', 'formulation', 'int2ext'} 36 | % mpc = userfcn_*_ext2int(mpc, args); 37 | % om = userfcn_*_formulation(om, args); 38 | % results = userfcn_*_int2ext(results, args); 39 | rv = feval(userfcn.(stage)(k).fcn, rv, args); 40 | case {'printpf', 'savecase'} 41 | % results = userfcn_*_printpf(results, fd, mpopt, args); 42 | % mpc = userfcn_*_savecase(mpc, fd, prefix, args); 43 | rv = feval(userfcn.(stage)(k).fcn, rv, varargin{2}, varargin{3}, args); 44 | end 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /library/matpower5.1/set_reorder.m: -------------------------------------------------------------------------------- 1 | function A = set_reorder(A, B, idx, dim) 2 | %SET_REORDER Assigns B to A with one of the dimensions of A indexed. 3 | % 4 | % A = SET_REORDER(A, B, IDX, DIM) 5 | % 6 | % Returns A after doing A(:, ..., :, IDX, :, ..., :) = B 7 | % where DIM determines in which dimension to place the IDX. 8 | % 9 | % If any dimension of B is smaller than the corresponding dimension 10 | % of A, the "extra" elements in A are untouched. If any dimension of 11 | % B is larger than the corresponding dimension of A, then A is padded 12 | % with zeros (if numeric) or empty matrices (if cell array) before 13 | % performing the assignment. 14 | % 15 | % See also GET_REORDER. 16 | 17 | % MATPOWER 18 | % Copyright (c) 2009-2015 by Power System Engineering Research Center (PSERC) 19 | % by Ray Zimmerman, PSERC Cornell 20 | % 21 | % $Id: set_reorder.m 2644 2015-03-11 19:34:22Z ray $ 22 | % 23 | % This file is part of MATPOWER. 24 | % Covered by the 3-clause BSD License (see LICENSE file for details). 25 | % See http://www.pserc.cornell.edu/matpower/ for more info. 26 | 27 | %% check dimensions 28 | ndim = ndims(A); 29 | sA = size(A); 30 | sB = size(B); 31 | d = (1:length(sA)); 32 | d(dim) = []; %% indices of all dimensions other than DIM 33 | 34 | %% pad A with zeros (numeric) or empty matrices (cell), if necessary 35 | s.subs = cell(1, ndim); 36 | if any(sA(d) < sB(d)) 37 | s.subs = num2cell(max(sA, sB)); 38 | if iscell(A) 39 | s.type = '{}'; 40 | A = subsasgn(A, s, []); 41 | else 42 | s.type = '()'; 43 | A = subsasgn(A, s, 0); 44 | end 45 | end 46 | 47 | %% set up indexing 48 | s.type = '()'; 49 | for k = 1:ndim 50 | if k == dim 51 | s.subs{k} = idx; 52 | else 53 | if sA(k) == sB(k) 54 | s.subs{k} = ':'; %% indexes of all elements in this dimension 55 | else %% sA(k) > sB(k) 56 | s.subs{k} = (1:sB(k)); %% limit indexes to smaller size of B 57 | end 58 | end 59 | end 60 | 61 | %% do the assignment 62 | A = subsasgn(A, s, B); 63 | -------------------------------------------------------------------------------- /library/matpower5.1/t/soln9_dcopf.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/t/soln9_dcopf.mat -------------------------------------------------------------------------------- /library/matpower5.1/t/soln9_dcpf.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/t/soln9_dcpf.mat -------------------------------------------------------------------------------- /library/matpower5.1/t/soln9_opf.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/t/soln9_opf.mat -------------------------------------------------------------------------------- /library/matpower5.1/t/soln9_opf_PQcap.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/t/soln9_opf_PQcap.mat -------------------------------------------------------------------------------- /library/matpower5.1/t/soln9_opf_Plim.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/t/soln9_opf_Plim.mat -------------------------------------------------------------------------------- /library/matpower5.1/t/soln9_opf_ang.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/t/soln9_opf_ang.mat -------------------------------------------------------------------------------- /library/matpower5.1/t/soln9_opf_extras1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/t/soln9_opf_extras1.mat -------------------------------------------------------------------------------- /library/matpower5.1/t/soln9_pf.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yangyangangela/continuous_cascade_model/7292c2e97ede5d60551be25a7ed97412f6976f25/library/matpower5.1/t/soln9_pf.mat -------------------------------------------------------------------------------- /library/matpower5.1/t/t_begin.m: -------------------------------------------------------------------------------- 1 | function t_begin(num_of_tests, quiet) 2 | %T_BEGIN Begin running tests. 3 | % T_BEGIN(NUM_OF_TESTS, QUIET) initializes the global test counters, 4 | % setting everything up to execute NUM_OF_TESTS tests using T_OK 5 | % and T_IS. If QUIET is true, it will not print anything for the 6 | % individual tests, only a summary when T_END is called. 7 | % 8 | % Example: 9 | % quiet = 0; 10 | % t_begin(5, quiet); 11 | % t_ok(pi > 3, 'size of pi'); 12 | % t_skip(3, 'not yet written'); 13 | % t_is(2+2, 4, 12, '2+2 still equals 4'); 14 | % t_end; 15 | % 16 | % See also T_END, T_OK, T_IS, T_SKIP, T_RUN_TESTS. 17 | 18 | % MATPOWER 19 | % Copyright (c) 2004-2015 by Power System Engineering Research Center (PSERC) 20 | % by Ray Zimmerman, PSERC Cornell 21 | % 22 | % $Id: t_begin.m 2644 2015-03-11 19:34:22Z ray $ 23 | % 24 | % This file is part of MATPOWER. 25 | % Covered by the 3-clause BSD License (see LICENSE file for details). 26 | % See http://www.pserc.cornell.edu/matpower/ for more info. 27 | 28 | global t_quiet; 29 | global t_num_of_tests; 30 | global t_counter; 31 | global t_ok_cnt; 32 | global t_not_ok_cnt; 33 | global t_skip_cnt; 34 | global t_clock; 35 | 36 | if nargin < 2 37 | quiet = 0; 38 | end 39 | 40 | t_quiet = quiet; 41 | t_num_of_tests = num_of_tests; 42 | t_counter = 1; 43 | t_ok_cnt = 0; 44 | t_not_ok_cnt = 0; 45 | t_skip_cnt = 0; 46 | t_clock = clock; 47 | 48 | if ~t_quiet 49 | fprintf('1..%d\n', num_of_tests); 50 | end 51 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_case9_opf.m: -------------------------------------------------------------------------------- 1 | function [baseMVA, bus, gen, branch, areas, gencost] = t_case9_opf 2 | %T_CASE9_OPF Power flow data for 9 bus, 3 generator case, with OPF data. 3 | % Please see CASEFORMAT for details on the case file format. 4 | 5 | % MATPOWER 6 | % $Id: t_case9_opf.m 1717 2010-11-09 16:45:00Z cvs $ 7 | 8 | %% MATPOWER Case Format : Version 1 9 | 10 | %%----- Power Flow Data -----%% 11 | %% system MVA base 12 | baseMVA = 100; 13 | 14 | %% bus data 15 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 16 | bus = [ 17 | 1 3 0 0 0 0 1 1 0 345 1 1.1 0.9; 18 | 2 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 19 | 30 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 20 | 4 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 21 | 5 1 90 30 0 0 1 1 0 345 1 1.1 0.9; 22 | 6 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 23 | 7 1 100 35 0 0 1 1 0 345 1 1.1 0.9; 24 | 8 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 25 | 9 1 125 50 0 0 1 1 0 345 1 1.1 0.9; 26 | ]; 27 | 28 | %% generator data 29 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin 30 | gen = [ 31 | 1 0 0 300 -300 1 100 1 250 90; 32 | 2 163 0 300 -300 1 100 1 300 10; 33 | 30 85 0 300 -300 1 100 1 270 10; 34 | ]; 35 | 36 | %% branch data 37 | % fbus tbus r x b rateA rateB rateC ratio angle status 38 | branch = [ 39 | 1 4 0 0.0576 0 0 250 250 0 0 1; 40 | 4 5 0.017 0.092 0.158 0 250 250 0 0 1; 41 | 5 6 0.039 0.17 0.358 150 150 150 0 0 1; 42 | 30 6 0 0.0586 0 0 300 300 0 0 1; 43 | 6 7 0.0119 0.1008 0.209 40 150 150 0 0 1; 44 | 7 8 0.0085 0.072 0.149 250 250 250 0 0 1; 45 | 8 2 0 0.0625 0 250 250 250 0 0 1; 46 | 8 9 0.032 0.161 0.306 250 250 250 0 0 1; 47 | 9 4 0.01 0.085 0.176 250 250 250 0 0 1; 48 | ]; 49 | 50 | %%----- OPF Data -----%% 51 | %% area data 52 | % area refbus 53 | areas = [ 54 | 1 5; 55 | ]; 56 | 57 | %% generator cost data 58 | % 1 startup shutdown n x1 y1 ... xn yn 59 | % 2 startup shutdown n c(n-1) ... c0 60 | gencost = [ 61 | 1 0 0 4 0 0 100 2500 200 5500 250 7250; 62 | 2 0 0 2 24.035 -403.5 0 0 0 0 0 0; 63 | 1 0 0 3 0 0 200 3000 300 5000 0 0; 64 | ]; 65 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_case9_opfv2.m: -------------------------------------------------------------------------------- 1 | function mpc = t_case9_opfv2 2 | %T_CASE9_OPFV2 Power flow data for 9 bus, 3 generator case, with OPF data. 3 | % Please see CASEFORMAT for details on the case file format. 4 | 5 | % MATPOWER 6 | % $Id: t_case9_opfv2.m 2408 2014-10-22 20:41:33Z ray $ 7 | 8 | %% MATPOWER Case Format : Version 2 9 | mpc.version = '2'; 10 | 11 | %%----- Power Flow Data -----%% 12 | %% system MVA base 13 | mpc.baseMVA = 100; 14 | 15 | %% bus data 16 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 17 | mpc.bus = [ 18 | 1 3 0 0 0 0 1 1 0 345 1 1.1 0.9; 19 | 2 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 20 | 30 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 21 | 4 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 22 | 5 1 90 30 0 0 1 1 0 345 1 1.1 0.9; 23 | 6 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 24 | 7 1 100 35 0 0 1 1 0 345 1 1.1 0.9; 25 | 8 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 26 | 9 1 125 50 0 0 1 1 0 345 1 1.1 0.9; 27 | ]; 28 | 29 | %% generator data 30 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 31 | mpc.gen = [ 32 | 1 0 0 300 -300 1 100 1 250 90 0 0 0 0 0 0 0 0 0 0 0; 33 | 2 163 0 300 -300 1 100 1 300 10 0 200 -20 20 -10 10 0 0 0 0 0; 34 | 30 85 0 300 -300 1 100 1 270 10 0 200 -30 30 -15 15 0 0 0 0 0; 35 | ]; 36 | 37 | %% branch data 38 | % fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax 39 | mpc.branch = [ 40 | 1 4 0 0.0576 0 0 250 250 0 0 1 -360 2.48; 41 | 4 5 0.017 0.092 0.158 0 250 250 0 0 1 -360 360; 42 | 5 6 0.039 0.17 0.358 150 150 150 0 0 1 -360 360; 43 | 30 6 0 0.0586 0 0 300 300 0 0 1 -360 360; 44 | 6 7 0.0119 0.1008 0.209 40 150 150 0 0 1 -360 360; 45 | 7 8 0.0085 0.072 0.149 250 250 250 0 0 1 -360 360; 46 | 8 2 0 0.0625 0 250 250 250 0 0 1 -360 360; 47 | 8 9 0.032 0.161 0.306 250 250 250 0 0 1 -360 360; 48 | 9 4 0.01 0.085 0.176 250 250 250 0 0 1 -2 360; 49 | ]; 50 | 51 | %%----- OPF Data -----%% 52 | %% generator cost data 53 | % 1 startup shutdown n x1 y1 ... xn yn 54 | % 2 startup shutdown n c(n-1) ... c0 55 | mpc.gencost = [ 56 | 1 0 0 4 0 0 100 2500 200 5500 250 7250; 57 | 2 0 0 2 24.035 -403.5 0 0 0 0 0 0; 58 | 1 0 0 3 0 0 200 3000 300 5000 0 0; 59 | ]; 60 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_case9_pf.m: -------------------------------------------------------------------------------- 1 | function [baseMVA, bus, gen, branch] = t_case9_pf 2 | %T_CASE9_PF Power flow data for 9 bus, 3 generator case, no OPF data. 3 | % Please see CASEFORMAT for details on the case file format. 4 | 5 | % MATPOWER 6 | % $Id: t_case9_pf.m 1559 2010-03-10 18:08:32Z ray $ 7 | 8 | %% MATPOWER Case Format : Version 1 9 | 10 | %%----- Power Flow Data -----%% 11 | %% system MVA base 12 | baseMVA = 100; 13 | 14 | %% bus data 15 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 16 | bus = [ 17 | 1 3 0 0 0 0 1 1 0 345 1 1.1 0.9; 18 | 2 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 19 | 30 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 20 | 4 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 21 | 5 1 90 30 0 0 1 1 0 345 1 1.1 0.9; 22 | 6 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 23 | 7 1 100 35 0 0 1 1 0 345 1 1.1 0.9; 24 | 8 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 25 | 9 1 125 50 0 0 1 1 0 345 1 1.1 0.9; 26 | ]; 27 | 28 | %% generator data 29 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin 30 | gen = [ 31 | 1 0 0 300 -300 1 100 1 250 90; 32 | 2 163 0 300 -300 1 100 1 300 10; 33 | 30 85 0 300 -300 1 100 1 270 10; 34 | ]; 35 | 36 | %% branch data 37 | % fbus tbus r x b rateA rateB rateC ratio angle status 38 | branch = [ 39 | 1 4 0 0.0576 0 250 250 250 0 0 1; 40 | 4 5 0.017 0.092 0.158 250 250 250 0 0 1; 41 | 5 6 0.039 0.17 0.358 150 150 150 0 0 1; 42 | 30 6 0 0.0586 0 300 300 300 0 0 1; 43 | 6 7 0.0119 0.1008 0.209 40 150 150 0 0 1; 44 | 7 8 0.0085 0.072 0.149 250 250 250 0 0 1; 45 | 8 2 0 0.0625 0 250 250 250 0 0 1; 46 | 8 9 0.032 0.161 0.306 250 250 250 0 0 1; 47 | 9 4 0.01 0.085 0.176 250 250 250 0 0 1; 48 | ]; 49 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_case9_pfv2.m: -------------------------------------------------------------------------------- 1 | function mpc = t_case9_pfv2 2 | %T_CASE9_PFV2 Power flow data for 9 bus, 3 generator case, no OPF data. 3 | % Please see CASEFORMAT for details on the case file format. 4 | 5 | % MATPOWER 6 | % $Id: t_case9_pfv2.m 1559 2010-03-10 18:08:32Z ray $ 7 | 8 | %% MATPOWER Case Version 2 9 | mpc.version = '2'; 10 | 11 | %%----- Power Flow Data -----%% 12 | %% system MVA base 13 | mpc.baseMVA = 100; 14 | 15 | %% bus data 16 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 17 | mpc.bus = [ 18 | 1 3 0 0 0 0 1 1 0 345 1 1.1 0.9; 19 | 2 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 20 | 30 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 21 | 4 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 22 | 5 1 90 30 0 0 1 1 0 345 1 1.1 0.9; 23 | 6 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 24 | 7 1 100 35 0 0 1 1 0 345 1 1.1 0.9; 25 | 8 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 26 | 9 1 125 50 0 0 1 1 0 345 1 1.1 0.9; 27 | ]; 28 | 29 | %% generator data 30 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 31 | mpc.gen = [ 32 | 1 0 0 300 -300 1 100 1 250 90 0 0 0 0 0 0 0 0 0 0 0; 33 | 2 163 0 300 -300 1 100 1 300 10 0 0 0 0 0 0 0 0 0 0 0; 34 | 30 85 0 300 -300 1 100 1 270 10 0 0 0 0 0 0 0 0 0 0 0; 35 | ]; 36 | 37 | %% branch data 38 | % fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax 39 | mpc.branch = [ 40 | 1 4 0 0.0576 0 250 250 250 0 0 1 -360 360; 41 | 4 5 0.017 0.092 0.158 250 250 250 0 0 1 -360 360; 42 | 5 6 0.039 0.17 0.358 150 150 150 0 0 1 -360 360; 43 | 30 6 0 0.0586 0 300 300 300 0 0 1 -360 360; 44 | 6 7 0.0119 0.1008 0.209 40 150 150 0 0 1 -360 360; 45 | 7 8 0.0085 0.072 0.149 250 250 250 0 0 1 -360 360; 46 | 8 2 0 0.0625 0 250 250 250 0 0 1 -360 360; 47 | 8 9 0.032 0.161 0.306 250 250 250 0 0 1 -360 360; 48 | 9 4 0.01 0.085 0.176 250 250 250 0 0 1 -360 360; 49 | ]; 50 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_case_int.m: -------------------------------------------------------------------------------- 1 | function mpc = t_case_int 2 | %T_CASE_INT Case data in internal format used to test EXT2INT and INT2EXT. 3 | 4 | % MATPOWER 5 | % $Id: t_case_int.m 2408 2014-10-22 20:41:33Z ray $ 6 | 7 | %% MATPOWER Case Format : Version 2 8 | mpc.version = '2'; 9 | 10 | %%----- Power Flow Data -----%% 11 | %% system MVA base 12 | mpc.baseMVA = 100; 13 | 14 | %% bus data 15 | % bus_i type Pd Qd Gs Bs area Vm Va baseKV zone Vmax Vmin 16 | mpc.bus = [ 17 | 1 3 0 0 0 0 1 1 0 345 1 1.1 0.9; 18 | 2 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 19 | 3 2 0 0 0 0 1 1 0 345 1 1.1 0.9; 20 | 4 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 21 | 5 1 90 30 0 0 1 1 0 345 1 1.1 0.9; 22 | 6 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 23 | 7 1 100 35 0 0 1 1 0 345 1 1.1 0.9; 24 | 8 1 0 0 0 0 1 1 0 345 1 1.1 0.9; 25 | 9 1 125 50 0 0 1 1 0 345 1 1.1 0.9; 26 | ]; 27 | 28 | %% generator data 29 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 30 | mpc.gen = [ 31 | 1 0 0 300 -300 1 100 1 250 90 0 0 0 0 0 0 0 0 0 0 0; 32 | 2 163 0 300 -300 1 100 1 300 10 0 0 0 0 0 0 0 0 0 0 0; 33 | 3 85 0 300 -300 1 100 1 270 10 0 0 0 0 0 0 0 0 0 0 0; 34 | ]; 35 | 36 | %% branch data 37 | % fbus tbus r x b rateA rateB rateC ratio angle status angmin angmax 38 | mpc.branch = [ 39 | 1 4 0 0.0576 0 0 250 250 0 0 1 -360 360; 40 | 4 5 0.017 0.092 0.158 0 250 250 0 0 1 -360 360; 41 | 5 6 0.039 0.17 0.358 150 150 150 0 0 1 -360 360; 42 | 3 6 0 0.0586 0 0 300 300 0 0 1 -360 360; 43 | 6 7 0.0119 0.1008 0.209 40 150 150 0 0 1 -360 360; 44 | 7 8 0.0085 0.072 0.149 250 250 250 0 0 1 -360 360; 45 | 8 2 0 0.0625 0 250 250 250 0 0 1 -360 360; 46 | 8 9 0.032 0.161 0.306 250 250 250 0 0 1 -360 360; 47 | 9 4 0.01 0.085 0.176 250 250 250 0 0 1 -360 360; 48 | ]; 49 | 50 | %%----- OPF Data -----%% 51 | %% generator cost data 52 | % 1 startup shutdown n x1 y1 ... xn yn 53 | % 2 startup shutdown n c(n-1) ... c0 54 | mpc.gencost = [ 55 | 1 0 0 4 0 0 100 2000 200 4403.5 270 6363.5; 56 | 1 0 0 4 0 0 100 2500 200 5500 250 7250; 57 | 2 0 0 2 15 0 0 0 0 0 0 0; 58 | ]; 59 | 60 | mpc.A = [ 61 | 1 2 3 4 5 7 8 9 10 11 12 13 14 15 17 18 19 20 24 22 21 28 26 25 29 30; 62 | 2 4 6 8 10 14 16 18 20 22 24 26 28 30 34 36 38 40 48 44 42 56 52 50 58 60; 63 | ]; 64 | 65 | mpc.N = [ 66 | 30 29 28 27 26 24 23 22 21 20 19 18 17 16 14 13 12 11 7 9 10 3 5 6 2 1; 67 | 60 58 56 54 52 48 46 44 42 40 38 36 34 32 28 26 24 22 14 18 20 6 10 12 4 2; 68 | ]; 69 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_cpf_cb1.m: -------------------------------------------------------------------------------- 1 | function [cb_state, results] = t_cpf_cb1(k, V_c, lam_c, V_p, lam_p, ... 2 | cb_data, cb_state, cb_args, results) 3 | %T_CPF_CB1 User callback function 1 for continuation power flow testing. 4 | 5 | % MATPOWER 6 | % Copyright (c) 2013-2015 by Power System Engineering Research Center (PSERC) 7 | % by Ray Zimmerman, PSERC Cornell 8 | % 9 | % $Id: t_cpf_cb1.m 2644 2015-03-11 19:34:22Z ray $ 10 | % 11 | % This file is part of MATPOWER. 12 | % Covered by the 3-clause BSD License (see LICENSE file for details). 13 | % See http://www.pserc.cornell.edu/matpower/ for more info. 14 | 15 | 16 | %%----- INITIAL call ----- 17 | if k == 0 18 | cb_state.cb1.initial = 1; 19 | cb_state.cb1.iteration = 0; 20 | cb_state.cb1.final = 0; 21 | %%----- FINAL call ----- 22 | elseif nargout == 2 23 | results.cb1.final = 1; 24 | %%----- ITERATION call ----- 25 | else 26 | cb_state.cb1.iteration = cb_state.cb1.iteration + 1; 27 | end 28 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_cpf_cb2.m: -------------------------------------------------------------------------------- 1 | function [cb_state, results] = t_cpf_cb2(k, V_c, lam_c, V_p, lam_p, ... 2 | cb_data, cb_state, cb_args, results) 3 | %T_CPF_CB2 User callback function 2 for continuation power flow testing. 4 | 5 | % MATPOWER 6 | % Copyright (c) 2013-2015 by Power System Engineering Research Center (PSERC) 7 | % by Ray Zimmerman, PSERC Cornell 8 | % 9 | % $Id: t_cpf_cb2.m 2644 2015-03-11 19:34:22Z ray $ 10 | % 11 | % This file is part of MATPOWER. 12 | % Covered by the 3-clause BSD License (see LICENSE file for details). 13 | % See http://www.pserc.cornell.edu/matpower/ for more info. 14 | 15 | %%----- INITIAL call ----- 16 | if k == 0 17 | cb_state.cb2.initial = cb_args.cb2.initial; 18 | cb_state.cb2.iteration = 0; 19 | cb_state.cb2.final = 0; 20 | %%----- FINAL call ----- 21 | elseif nargout == 2 22 | results.cb2.final = cb_args.cb2.final; 23 | %%----- ITERATION call ----- 24 | else 25 | cb_state.cb2.iteration = cb_state.cb2.iteration + cb_args.cb2.iteration; 26 | end 27 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_end.m: -------------------------------------------------------------------------------- 1 | function t_end 2 | %T_END Finish running tests and print statistics. 3 | % T_END checks the global counters that were updated by calls to 4 | % T_OK and T_IS and prints out a summary of the test results. 5 | % 6 | % Example: 7 | % quiet = 0; 8 | % t_begin(5, quiet); 9 | % t_ok(pi > 3, 'size of pi'); 10 | % t_skip(3, 'not yet written'); 11 | % t_is(2+2, 4, 12, '2+2 still equals 4'); 12 | % t_end; 13 | % 14 | % See also T_BEGIN, T_OK, T_IS, T_SKIP, T_RUN_TESTS. 15 | 16 | % MATPOWER 17 | % Copyright (c) 2004-2015 by Power System Engineering Research Center (PSERC) 18 | % by Ray Zimmerman, PSERC Cornell 19 | % 20 | % $Id: t_end.m 2644 2015-03-11 19:34:22Z ray $ 21 | % 22 | % This file is part of MATPOWER. 23 | % Covered by the 3-clause BSD License (see LICENSE file for details). 24 | % See http://www.pserc.cornell.edu/matpower/ for more info. 25 | 26 | global t_quiet; 27 | global t_num_of_tests; 28 | global t_counter; 29 | global t_ok_cnt; 30 | global t_not_ok_cnt; 31 | global t_skip_cnt; 32 | global t_clock; 33 | 34 | t_counter = t_counter - 1; 35 | 36 | if t_counter == t_num_of_tests && ... 37 | t_counter == t_ok_cnt + t_skip_cnt && ... 38 | t_not_ok_cnt == 0 39 | all_ok = 1; 40 | else 41 | all_ok = 0; 42 | end 43 | 44 | if t_quiet 45 | if all_ok 46 | fprintf('ok'); 47 | if t_skip_cnt 48 | fprintf(' (%d of %d skipped)', t_skip_cnt, t_num_of_tests); 49 | end 50 | else 51 | fprintf('not ok\n'); 52 | fprintf('\t##### Ran %d of %d tests: %d passed, %d failed', ... 53 | t_counter, t_num_of_tests, t_ok_cnt, t_not_ok_cnt); 54 | if t_skip_cnt 55 | fprintf(', %d skipped', t_skip_cnt); 56 | end 57 | end 58 | fprintf('\n'); 59 | else 60 | if all_ok 61 | if t_skip_cnt 62 | fprintf('All tests successful (%d passed, %d skipped of %d)', ... 63 | t_ok_cnt, t_skip_cnt, t_num_of_tests); 64 | else 65 | fprintf('All tests successful (%d of %d)', t_ok_cnt, t_num_of_tests); 66 | end 67 | else 68 | fprintf('Ran %d of %d tests: %d passed, %d failed', ... 69 | t_counter, t_num_of_tests, t_ok_cnt, t_not_ok_cnt); 70 | if t_skip_cnt 71 | fprintf(', %d skipped', t_skip_cnt); 72 | end 73 | end 74 | fprintf('\nElapsed time %.2f seconds.\n', etime(clock, t_clock)); 75 | end 76 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_hasPQcap.m: -------------------------------------------------------------------------------- 1 | function t_hasPQcap(quiet) 2 | %T_HASPQCAP Tests for HASPQCAP. 3 | 4 | % MATPOWER 5 | % Copyright (c) 2005-2015 by Power System Engineering Research Center (PSERC) 6 | % by Ray Zimmerman, PSERC Cornell 7 | % 8 | % $Id: t_hasPQcap.m 2644 2015-03-11 19:34:22Z ray $ 9 | % 10 | % This file is part of MATPOWER. 11 | % Covered by the 3-clause BSD License (see LICENSE file for details). 12 | % See http://www.pserc.cornell.edu/matpower/ for more info. 13 | 14 | if nargin < 1 15 | quiet = 0; 16 | end 17 | 18 | t_begin(4, quiet); 19 | 20 | %% generator data 21 | % bus Pg Qg Qmax Qmin Vg mBase status Pmax Pmin Pc1 Pc2 Qc1min Qc1max Qc2min Qc2max ramp_agc ramp_10 ramp_30 ramp_q apf 22 | gen = [ 23 | 1 10 0 10 -10 1 100 1 10 2 0 0 0 0 0 0 0 0 0 0 0; 24 | 1 10 0 10 -10 1 100 1 10 2 0 20 0 12 0 2 0 0 0 0 0; 25 | 1 10 0 10 -10 1 100 1 10 2 0 20 -15 12 -15 2 0 0 0 0 0; 26 | 1 10 0 10 -10 1 100 1 10 2 0 20 -12 0 -2 0 0 0 0 0 0; 27 | 1 10 0 10 -10 1 100 1 10 2 0 20 -12 15 -2 15 0 0 0 0 0; 28 | 1 10 0 10 -10 1 100 1 10 2 0 20 -12 12 -2 2 0 0 0 0 0; 29 | 1 10 0 10 -10 1 100 1 10 2 0 20 0 12 0 8 0 0 0 0 0; 30 | 1 10 0 10 -10 1 100 1 10 2 0 20 -15 12 -15 8 0 0 0 0 0; 31 | 1 10 0 10 -10 1 100 1 10 2 0 20 -12 0 -8 0 0 0 0 0 0; 32 | 1 10 0 10 -10 1 100 1 10 2 0 20 -12 15 -8 15 0 0 0 0 0; 33 | 1 10 0 10 -10 1 100 1 10 2 0 20 -12 12 -8 8 0 0 0 0 0; 34 | 1 10 0 10 -10 1 100 1 10 2 0 20 0 0 -20 20 0 0 0 0 0; 35 | 1 10 0 10 -10 1 100 1 10 2 0 20 0 0 -22 18 0 0 0 0 0; 36 | 1 10 0 10 -10 1 100 1 10 2 0 20 0 0 -18 22 0 0 0 0 0; 37 | ]; 38 | 39 | t = 'hasPQcap(gen)'; 40 | t_is(hasPQcap(gen), [0;1;1;1;1;1;1;0;1;0;0;1;1;1], 12, t); 41 | 42 | t = 'hasPQcap(gen, ''B'')'; 43 | t_is(hasPQcap(gen, 'B'), [0;1;1;1;1;1;1;0;1;0;0;1;1;1], 12, t); 44 | 45 | t = 'hasPQcap(gen, ''U'')'; 46 | t_is(hasPQcap(gen, 'U'), [0;1;1;1;0;1;0;0;1;0;0;1;1;1], 12, t); 47 | 48 | t = 'hasPQcap(gen, ''L'')'; 49 | t_is(hasPQcap(gen, 'L'), [0;1;0;1;1;1;1;0;0;0;0;1;1;1], 12, t); 50 | 51 | t_end; 52 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_makeLODF.m: -------------------------------------------------------------------------------- 1 | function t_makeLODF(quiet) 2 | %T_MAKELODF Tests for MAKELODF. 3 | 4 | % MATPOWER 5 | % Copyright (c) 2008-2015 by Power System Engineering Research Center (PSERC) 6 | % by Ray Zimmerman, PSERC Cornell 7 | % 8 | % $Id: t_makeLODF.m 2644 2015-03-11 19:34:22Z ray $ 9 | % 10 | % This file is part of MATPOWER. 11 | % Covered by the 3-clause BSD License (see LICENSE file for details). 12 | % See http://www.pserc.cornell.edu/matpower/ for more info. 13 | 14 | if nargin < 1 15 | quiet = 0; 16 | end 17 | 18 | ntests = 31; 19 | t_begin(ntests, quiet); 20 | 21 | casefile = 't_auction_case'; 22 | if quiet 23 | verbose = 0; 24 | else 25 | verbose = 0; 26 | end 27 | 28 | [PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ... 29 | VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus; 30 | [F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ... 31 | TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ... 32 | ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch; 33 | [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 34 | MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 35 | QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 36 | 37 | %% load case 38 | mpc = loadcase(casefile); 39 | mpopt = mpoption('out.all', 0, 'verbose', verbose); 40 | [baseMVA, bus, gen, gencost, branch, f, success, et] = ... 41 | rundcopf(mpc, mpopt); 42 | [i2e, bus, gen, branch] = ext2int(bus, gen, branch); 43 | 44 | %% compute injections and flows 45 | F0 = branch(:, PF); 46 | 47 | %% create some PTDF matrices 48 | H = makePTDF(baseMVA, bus, branch, 1); 49 | 50 | %% create some PTDF matrices 51 | s = warning('query', 'MATLAB:divideByZero'); 52 | warning('off', 'MATLAB:divideByZero'); 53 | LODF = makeLODF(branch, H); 54 | warning(s.state, 'MATLAB:divideByZero'); 55 | 56 | %% take out non-essential lines one-by-one and see what happens 57 | mpc.bus = bus; 58 | mpc.gen = gen; 59 | branch0 = branch; 60 | outages = [1:12 14:15 17:18 20 27:33 35:41]; 61 | for k = outages 62 | mpc.branch = branch0; 63 | mpc.branch(k, BR_STATUS) = 0; 64 | [baseMVA, bus, gen, branch, success, et] = rundcpf(mpc, mpopt); 65 | F = branch(:, PF); 66 | 67 | t_is(LODF(:, k), (F - F0) / F0(k), 6, sprintf('LODF(:, %d)', k)); 68 | end 69 | 70 | t_end; 71 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_mpoption_ov.m: -------------------------------------------------------------------------------- 1 | function ov = t_mpoption_ov() 2 | %T_MPOPTION_OV Example of option overrides from file. 3 | 4 | % MATPOWER 5 | % Copyright (c) 2013-2015 by Power System Engineering Research Center (PSERC) 6 | % by Ray Zimmerman, PSERC Cornell 7 | % 8 | % $Id: t_mpoption_ov.m 2644 2015-03-11 19:34:22Z ray $ 9 | % 10 | % This file is part of MATPOWER. 11 | % Covered by the 3-clause BSD License (see LICENSE file for details). 12 | % See http://www.pserc.cornell.edu/matpower/ for more info. 13 | 14 | ov = struct('verbose', 2, 'model', 'DC', 'opf', struct('dc', struct('solver', 'CPLEX'))); 15 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_ok.m: -------------------------------------------------------------------------------- 1 | function ok = t_ok(cond, msg) 2 | %T_OK Tests if a condition is true. 3 | % T_OK(EXPR, MSG) increments the global test count and if the EXPR 4 | % is true it increments the passed tests count, otherwise increments 5 | % the failed tests count. Prints 'ok' or 'not ok' followed by the 6 | % MSG, unless the global variable t_quiet is true. Intended to be 7 | % called between calls to T_BEGIN and T_END. 8 | % 9 | % Optionally returns a true or false value indicating whether or 10 | % not the test succeeded. 11 | % 12 | % Example: 13 | % quiet = 0; 14 | % t_begin(5, quiet); 15 | % t_ok(pi > 3, 'size of pi'); 16 | % t_skip(3, 'not yet written'); 17 | % t_is(2+2, 4, 12, '2+2 still equals 4'); 18 | % t_end; 19 | % 20 | % See also T_IS, T_SKIP, T_BEGIN, T_END, T_RUN_TESTS. 21 | 22 | % MATPOWER 23 | % Copyright (c) 2004-2015 by Power System Engineering Research Center (PSERC) 24 | % by Ray Zimmerman, PSERC Cornell 25 | % 26 | % $Id: t_ok.m 2644 2015-03-11 19:34:22Z ray $ 27 | % 28 | % This file is part of MATPOWER. 29 | % Covered by the 3-clause BSD License (see LICENSE file for details). 30 | % See http://www.pserc.cornell.edu/matpower/ for more info. 31 | 32 | global t_quiet; 33 | global t_counter; 34 | global t_ok_cnt; 35 | global t_not_ok_cnt; 36 | 37 | if nargin < 2 || strcmp(msg, '') 38 | msg = ''; 39 | else 40 | msg = [' - ', msg]; 41 | end 42 | if cond 43 | t_ok_cnt = t_ok_cnt + 1; 44 | else 45 | t_not_ok_cnt = t_not_ok_cnt + 1; 46 | if ~t_quiet 47 | fprintf('not '); 48 | end 49 | end 50 | if ~t_quiet 51 | fprintf('ok %d%s\n', t_counter, msg); 52 | end 53 | t_counter = t_counter + 1; 54 | if nargout 55 | ok = cond; 56 | end 57 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_psse_case.raw: -------------------------------------------------------------------------------- 1 | Header 1 2 | Header 2 3 | Header 3 4 | 1 'Line 1 ' 1.1000 -.1 1.1e-2 '1' '1.1' A,, 'A' /, "comment 1" 5 | 2,'Line, "2"', 2.2000 , -0.2 , 0.022, '2 ' ,' 2.2',B , , 'B' / comment, '2' 6 | 3 "Line, '3'" 3.3000 -0.3 33E-3 ' 3 ' ' 3.3' C , , 'C' / 'comment 3' 7 | 4 'Line 4' 44e-1 -0.4 0.44E-1 '4' '4.4' D , , 'D' ///comment,4 8 | 0 / END OF TEST1 DATA, BEGIN TEST2 DATA 9 | 1 'Line 1 ' 1.1000 -.1 1.1e-2 '1' '1.1' A,, 'A' /, "comment 1" 10 | 2,'Line, "2"', 2.2000 , -0.2 , 0.022, '2 ' ,' 2.2',B , , 'B' / comment, '2' 11 | Q 12 | 3 "Line, '3'" 3.3000 -0.3 33E-3 ' 3 ' ' 3.3' C , , 'C' / 'comment 3' 13 | 4 'Line 4' 44e-1 -0.4 0.44E-1 '4' '4.4' D , , 'D' ///comment,4 14 | 0 / END OF TEST2 DATA 15 | -------------------------------------------------------------------------------- /library/matpower5.1/t/t_skip.m: -------------------------------------------------------------------------------- 1 | function t_skip(cnt, msg) 2 | %T_SKIP Skips a number of tests. 3 | % T_SKIP(CNT, MSG) increments the global test count and skipped tests 4 | % count. Prints 'skipped tests x..y : ' followed by the MSG, unless the 5 | % global variable t_quiet is true. Intended to be called between calls to 6 | % T_BEGIN and T_END. 7 | % 8 | % Example: 9 | % quiet = 0; 10 | % t_begin(5, quiet); 11 | % t_ok(pi > 3, 'size of pi'); 12 | % t_skip(3, 'not yet written'); 13 | % t_is(2+2, 4, 12, '2+2 still equals 4'); 14 | % t_end; 15 | % 16 | % See also T_OK, T_IS, T_BEGIN, T_END, T_RUN_TESTS. 17 | 18 | 19 | % MATPOWER 20 | % Copyright (c) 2004-2015 by Power System Engineering Research Center (PSERC) 21 | % by Ray Zimmerman, PSERC Cornell 22 | % 23 | % $Id: t_skip.m 2644 2015-03-11 19:34:22Z ray $ 24 | % 25 | % This file is part of MATPOWER. 26 | % Covered by the 3-clause BSD License (see LICENSE file for details). 27 | % See http://www.pserc.cornell.edu/matpower/ for more info. 28 | 29 | global t_quiet; 30 | global t_counter; 31 | global t_skip_cnt; 32 | 33 | if nargin < 2 || strcmp(msg, '') 34 | msg = ''; 35 | else 36 | msg = [' : ', msg]; 37 | end 38 | 39 | t_skip_cnt = t_skip_cnt + cnt; 40 | if ~t_quiet 41 | fprintf('skipped tests %d..%d%s\n', t_counter, t_counter+cnt-1, msg); 42 | end 43 | t_counter = t_counter + cnt; 44 | -------------------------------------------------------------------------------- /library/matpower5.1/totcost.m: -------------------------------------------------------------------------------- 1 | function totalcost = totcost(gencost, Pg) 2 | %TOTCOST Computes total cost for generators at given output level. 3 | % TOTALCOST = TOTCOST(GENCOST, PG) computes total cost for generators given 4 | % a matrix in gencost format and a column vector or matrix of generation 5 | % levels. The return value has the same dimensions as PG. Each row 6 | % of GENCOST is used to evaluate the cost at the points specified in the 7 | % corresponding row of PG. 8 | 9 | % MATPOWER 10 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 11 | % by Ray Zimmerman, PSERC Cornell 12 | % & Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales 13 | % 14 | % $Id: totcost.m 2644 2015-03-11 19:34:22Z ray $ 15 | % 16 | % This file is part of MATPOWER. 17 | % Covered by the 3-clause BSD License (see LICENSE file for details). 18 | % See http://www.pserc.cornell.edu/matpower/ for more info. 19 | 20 | [PW_LINEAR, POLYNOMIAL, MODEL, STARTUP, SHUTDOWN, NCOST, COST] = idx_cost; 21 | 22 | [ng, m] = size(gencost); 23 | totalcost = zeros(ng, size(Pg, 2)); 24 | 25 | if ~isempty(gencost) 26 | ipwl = find(gencost(:, MODEL) == PW_LINEAR); 27 | ipol = find(gencost(:, MODEL) == POLYNOMIAL); 28 | if ~isempty(ipwl) 29 | x = gencost(:, COST:2:(m-1)); 30 | y = gencost(:, (COST+1):2:m); 31 | for i = ipwl' 32 | if gencost(i, NCOST) > 0 33 | % totalcost(i,:) = interp1(x(i, 1:gencost(i, NCOST)), ... 34 | % y(i, 1:gencost(i, NCOST)), ... 35 | % Pg(i,:), 'linear', 'extrap'); 36 | j1 = 1:(gencost(i, NCOST) - 1); j2 = 2:gencost(i, NCOST); 37 | pp = mkpp(x(i, 1:gencost(i, NCOST))', [(y(i,j2) - y(i,j1)) ./ (x(i,j2) - x(i,j1)); y(i,j1)]'); 38 | totalcost(i,:) = ppval(pp, Pg(i,:)); 39 | end 40 | end 41 | end 42 | for i = 1:size(totalcost, 2) 43 | totalcost(ipol, i) = polycost(gencost(ipol, :), Pg(ipol, i)); 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /library/matpower5.1/update_mupq.m: -------------------------------------------------------------------------------- 1 | function gen = update_mupq(baseMVA, gen, mu_PQh, mu_PQl, data) 2 | %UPDATE_MUPQ Updates values of generator limit shadow prices. 3 | % GEN = UPDATE_MUPQ(BASEMVA, GEN, MU_PQH, MU_PQL, DATA) 4 | % 5 | % Updates the values of MU_PMIN, MU_PMAX, MU_QMIN, MU_QMAX based 6 | % on any shadow prices on the sloped portions of the generator 7 | % capability curve constraints. 8 | % 9 | % MU_PQH - shadow prices on upper sloped portion of capability curves 10 | % MU_PQL - shadow prices on lower sloped portion of capability curves 11 | % DATA - "data" struct returned by MAKEAPQ 12 | % 13 | % See also MAKEAPQ. 14 | 15 | % MATPOWER 16 | % Copyright (c) 1996-2015 by Power System Engineering Research Center (PSERC) 17 | % by Ray Zimmerman, PSERC Cornell 18 | % and Carlos E. Murillo-Sanchez, PSERC Cornell & Universidad Autonoma de Manizales 19 | % 20 | % $Id: update_mupq.m 2644 2015-03-11 19:34:22Z ray $ 21 | % 22 | % This file is part of MATPOWER. 23 | % Covered by the 3-clause BSD License (see LICENSE file for details). 24 | % See http://www.pserc.cornell.edu/matpower/ for more info. 25 | 26 | %% extract the constraint parameters 27 | [ipqh, ipql, Apqhdata, Apqldata] = ... 28 | deal(data.ipqh, data.ipql, data.h, data.l); 29 | 30 | %% define named indices into data matrices 31 | [GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ... 32 | MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ... 33 | QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen; 34 | 35 | %% combine original limit multipliers into single value 36 | muP = gen(:, MU_PMAX) - gen(:, MU_PMIN); 37 | muQ = gen(:, MU_QMAX) - gen(:, MU_QMIN); 38 | 39 | %% add P and Q components of multipliers on upper sloped constraint 40 | muP(ipqh) = muP(ipqh) - mu_PQh .* Apqhdata(:,1)/baseMVA; 41 | muQ(ipqh) = muQ(ipqh) - mu_PQh .* Apqhdata(:,2)/baseMVA; 42 | 43 | %% add P and Q components of multipliers on lower sloped constraint 44 | muP(ipql) = muP(ipql) - mu_PQl .* Apqldata(:,1)/baseMVA; 45 | muQ(ipql) = muQ(ipql) - mu_PQl .* Apqldata(:,2)/baseMVA; 46 | 47 | %% split back into upper and lower multipliers based on sign 48 | gen(:, MU_PMAX) = (muP > 0) .* muP; 49 | gen(:, MU_PMIN) = (muP < 0) .* -muP; 50 | gen(:, MU_QMAX) = (muQ > 0) .* muQ; 51 | gen(:, MU_QMIN) = (muQ < 0) .* -muQ; 52 | -------------------------------------------------------------------------------- /readme.txt: -------------------------------------------------------------------------------- 1 | ——————————————————————————————————————————————————————————————————————————————————— 2 | Cascading failures as continuous phase-space transitions——————————————————————————————————————————————————————————————————————————————————— 3 | 4 | Copyright (C) 2016 Yang Yang 5 | 6 | This program is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by the 8 | Free Software Foundation; either version 2 of the License, or (at your 9 | option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 14 | Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License along 17 | with this program; if not, write to the Free Software Foundation, Inc., 18 | 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | 20 | The full text of the GNU General Public License can be found in the file 21 | “license.txt". 22 | 23 | 24 | Folders 25 | ——————— 26 | 27 | The code used for simulations described in the paper 28 | 29 | Yang Yang and Adilson Motter 30 | 31 | Cascading failures as continuous phase-space transitions 32 | 33 | For instructions on how to use them, see the comments in the corresponding folders. --------------------------------------------------------------------------------