forked from MATPOWER/matpower
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscopf_execute.m
75 lines (63 loc) · 2.54 KB
/
scopf_execute.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
function [results, success, raw] = scopf_execute(om, model, mpopt)
%SCOPF_EXECUTE Executes the SCOPF specified by an OPF model object.
% [RESULTS, SUCCESS, RAW] = SCOPF_EXECUTE(OM, MPOPT)
%
% RESULTS are returned with internal indexing, all equipment
% in-service, etc.
%
% See also OPF, OPF_SETUP.
% MATPOWER
% Copyright (c) 2009-2016, Power Systems Engineering Research Center (PSERC)
% by Ray Zimmerman, PSERC Cornell
%
% This file is part of MATPOWER.
% Covered by the 3-clause BSD License (see LICENSE file for details).
% See http://www.pserc.cornell.edu/matpower/ for more info.
%% define named indices into data matrices
[PQ, PV, REF, NONE, BUS_I, BUS_TYPE, PD, QD, GS, BS, BUS_AREA, VM, ...
VA, BASE_KV, ZONE, VMAX, VMIN, LAM_P, LAM_Q, MU_VMAX, MU_VMIN] = idx_bus;
[GEN_BUS, PG, QG, QMAX, QMIN, VG, MBASE, GEN_STATUS, PMAX, PMIN, ...
MU_PMAX, MU_PMIN, MU_QMAX, MU_QMIN, PC1, PC2, QC1MIN, QC1MAX, ...
QC2MIN, QC2MAX, RAMP_AGC, RAMP_10, RAMP_30, RAMP_Q, APF] = idx_gen;
[F_BUS, T_BUS, BR_R, BR_X, BR_B, RATE_A, RATE_B, RATE_C, ...
TAP, SHIFT, BR_STATUS, PF, QF, PT, QT, MU_SF, MU_ST, ...
ANGMIN, ANGMAX, MU_ANGMIN, MU_ANGMAX] = idx_brch;
%%----- setup -----
%% options
dc = strcmp(upper(mpopt.model), 'DC');
alg = upper(mpopt.opf.ac.solver);
sdp = strcmp(alg, 'SDPOPF');
%% build user-defined costs
om = build_cost_params(om); %for some reason it is necessary
%% get indexing
[vv, ll, nn] = om.get_idx();
if mpopt.verbose > 0
v = mpver('all');
fprintf('\nMATPOWER Version %s, %s', v.Version, v.Date);
end
%%----- run AC OPF solver -----
if mpopt.verbose > 0
fprintf(' -- AC Security Constrainted Optimal Power Flow\n');
end
%% if opf.ac.solver not set, choose best available option
if strcmp(alg, 'DEFAULT')
alg = 'MIPS'; %% MIPS
mpopt = mpoption(mpopt, 'opf.ac.solver', alg);
end
%% run specific AC OPF solver
switch alg
case 'MIPS'
[results, success, raw] = mipsscopf_solver(om, model, mpopt);
case 'OPTIZELLE'
[results, success, raw] = optizellescopf_solver(om, model, mpopt);
case 'IPOPT'
if ~have_fcn('ipopt')
error('opf_execute: MPOPT.opf.ac.solver = ''%s'' requires IPOPT (see http://www.coin-or.org/projects/Ipopt.xml)', alg);
end
[results, success, raw] = ipoptscopf_solver(om, model, mpopt);
otherwise
error('opf_execute: MPOPT.opf.ac.solver = ''%s'' is not a valid AC OPF solver selection', alg);
end
if ~isfield(raw, 'output') || ~isfield(raw.output, 'alg') || isempty(raw.output.alg)
raw.output.alg = alg;
end