forked from MATPOWER/matpower
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmpoption.m
1641 lines (1580 loc) · 73.6 KB
/
mpoption.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function opt = mpoption(varargin)
%MPOPTION Used to set and retrieve a MATPOWER options struct.
%
% OPT = MPOPTION
% Returns the default options struct.
%
% OPT = MPOPTION(OVERRIDES)
% Returns the default options struct, with some fields overridden
% by values from OVERRIDES, which can be a struct or the name of
% a function that returns a struct.
%
% OPT = MPOPTION(NAME1, VALUE1, NAME2, VALUE2, ...)
% Same as previous, except override options are specified by NAME,
% VALUE pairs. This can be used to set any part of the options
% struct. The names can be individual fields or multi-level field
% names with embedded periods. The values can be scalars or structs.
%
% For backward compatibility, the NAMES and VALUES may correspond
% to old-style MATPOWER option names (elements in the old-style
% options vector) as well.
%
% OPT = MPOPTION(OPT0)
% Converts an old-style options vector OPT0 into the corresponding
% options struct. If OPT0 is an options struct it does nothing.
%
% OPT = MPOPTION(OPT0, OVERRIDES)
% Applies overrides to an existing set of options, OPT0, which
% can be an old-style options vector or an options struct.
%
% OPT = MPOPTION(OPT0, NAME1, VALUE1, NAME2, VALUE2, ...)
% Same as above except it uses the old-style options vector OPT0
% as a base instead of the old default options vector.
%
% OPT_VECTOR = MPOPTION(OPT, [])
% Creates and returns an old-style options vector from an
% options struct OPT.
%
% Note: The use of old-style MATPOWER options vectors and their
% names and values has been deprecated and will be removed
% in a future version of MATPOWER. Until then, all uppercase
% option names are not permitted for new top-level options.
%
% Examples:
% mpopt = mpoption('pf.alg', 'FDXB', 'pf.tol', 1e-4);
% mpopt = mpoption(mpopt, 'opf.dc.solver', 'CPLEX', 'verbose', 2);
%
%The currently defined options are as follows:
%
% name default description [options]
%---------------------- --------- ----------------------------------
%Model options:
% model 'AC' AC vs. DC power flow model
% [ 'AC' - use nonlinear AC model & corresponding algorithms/options ]
% [ 'DC' - use linear DC model & corresponding algorithms/options ]
%
%Power Flow options:
% pf.alg 'NR' AC power flow algorithm
% [ 'NR' - Newton's method ]
% [ 'FDXB' - Fast-Decoupled (XB version) ]
% [ 'FDBX' - Fast-Decoupled (BX version) ]
% [ 'GS' - Gauss-Seidel ]
% [ 'PQSUM'- Power Summation method (radial networks only) ]
% [ 'ISUM' - Current Summation method (radial networks only) ]
% [ 'YSUM' - Admittance Summation method (radial networks only) ]
% pf.tol 1e-8 termination tolerance on per unit
% P & Q mismatch
% pf.nr.max_it 10 maximum number of iterations for
% Newton's method
% pf.nr.lin_solver '' linear solver passed to MPLINSOLVE to
% solve Newton update step
% [ '' - default to '\' for small systems, 'LU3' for larger ones ]
% [ '\' - built-in backslash operator ]
% [ 'LU' - explicit default LU decomposition and back substitution ]
% [ 'LU3' - 3 output arg form of LU, Gilbert-Peierls algorithm with ]
% [ approximate minimum degree (AMD) reordering ]
% [ 'LU4' - 4 output arg form of LU, UMFPACK solver (same as 'LU') ]
% [ 'LU5' - 5 output arg form of LU, UMFPACK solver, w/row scaling ]
% [ (see MPLINSOLVE for complete list of all options) ]
% pf.fd.max_it 30 maximum number of iterations for
% fast decoupled method
% pf.gs.max_it 1000 maximum number of iterations for
% Gauss-Seidel method
% pf.radial.max_it 20 maximum number of iterations for
% radial power flow methods
% pf.radial.vcorr 0 perform voltage correction procedure
% in distribution power flow
% [ 0 - do NOT perform voltage correction ]
% [ 1 - perform voltage correction ]
% pf.enforce_q_lims 0 enforce gen reactive power limits at
% expense of |V|
% [ 0 - do NOT enforce limits ]
% [ 1 - enforce limits, simultaneous bus type conversion ]
% [ 2 - enforce limits, one-at-a-time bus type conversion ]
%
%Continuation Power Flow options:
% cpf.parameterization 3 choice of parameterization
% [ 1 - natural ]
% [ 2 - arc length ]
% [ 3 - pseudo arc length ]
% cpf.stop_at 'NOSE' determins stopping criterion
% [ 'NOSE' - stop when nose point is reached ]
% [ 'FULL' - trace full nose curve ]
% [ <lam_stop> - stop upon reaching specified target lambda value ]
% cpf.enforce_p_lims 0 enforce gen active power limits
% [ 0 - do NOT enforce limits ]
% [ 1 - enforce limits, simultaneous bus type conversion ]
% cpf.enforce_q_lims 0 enforce gen reactive power limits at
% expense of |V|
% [ 0 - do NOT enforce limits ]
% [ 1 - enforce limits, simultaneous bus type conversion ]
% cpf.enforce_v_lims 0 enforce bus voltage magnitude limits
% [ 0 - do NOT enforce limits ]
% [ 1 - enforce limits, termination on detection ]
% cpf.enforce_flow_lims 0 enforce branch flow MVA limits
% [ 0 - do NOT enforce limits ]
% [ 1 - enforce limits, termination on detection ]
% cpf.step 0.05 continuation power flow step size
% cpf.adapt_step 0 toggle adaptive step size feature
% [ 0 - adaptive step size disabled ]
% [ 1 - adaptive step size enabled ]
% cpf.step_min 1e-4 minimum allowed step size
% cpf.step_max 0.2 maximum allowed step size
% cpf.adapt_step_damping 0.7 damping factor for adaptive step
% sizing
% cpf.adapt_step_tol 1e-3 tolerance for adaptive step sizing
% cpf.target_lam_tol 1e-5 tolerance for target lambda detection
% cpf.nose_tol 1e-5 tolerance for nose point detection (pu)
% cpf.p_lims_tol 0.01 tolerance for generator active
% power limit enforcement (MW)
% cpf.q_lims_tol 0.01 tolerance for generator reactive
% power limit enforcement (MVAR)
% cpf.v_lims_tol 1e-4 tolerance for bus voltage
% magnitude enforcement (p.u)
% cpf.flow_lims_tol 0.01 tolerance for line MVA flow
% enforcement (MVA)
% cpf.plot.level 0 control plotting of noze curve
% [ 0 - do not plot nose curve ]
% [ 1 - plot when completed ]
% [ 2 - plot incrementally at each iteration ]
% [ 3 - same as 2, with 'pause' at each iteration ]
% cpf.plot.bus <empty> index of bus whose voltage is to be
% plotted
% cpf.user_callback <empty> string containing the name of a user
% callback function, or struct with
% function name, and optional priority
% and/or args, or cell array of such
% strings and/or structs, see
% 'help cpf_default_callback' for details
%
%Optimal Power Flow options:
% name default description [options]
%---------------------- --------- ----------------------------------
% opf.ac.solver 'DEFAULT' AC optimal power flow solver
% [ 'DEFAULT' - choose default solver, i.e. 'MIPS' ]
% [ 'MIPS' - MIPS, MATPOWER Interior Point Solver, primal/dual ]
% [ interior point method (pure MATLAB/Octave) ]
% [ 'FMINCON' - MATLAB Optimization Toolbox, FMINCON ]
% [ 'IPOPT' - IPOPT, requires MEX interface to IPOPT solver ]
% [ available from: ]
% [ http://www.coin-or.org/projects/Ipopt.xml ]
% [ 'KNITRO' - KNITRO, requires MATLAB Optimization Toolbox and ]
% [ KNITRO libraries available from: http://www.ziena.com/]
% [ 'MINOPF' - MINOPF, MINOS-based solver, requires optional ]
% [ MEX-based MINOPF package, available from: ]
% [ http://www.pserc.cornell.edu/minopf/ ]
% [ 'PDIPM' - PDIPM, primal/dual interior point method, requires ]
% [ optional MEX-based TSPOPF package, available from: ]
% [ http://www.pserc.cornell.edu/tspopf/ ]
% [ 'SDPOPF' - SDPOPF, solver based on semidefinite relaxation of ]
% [ OPF problem, requires optional packages: ]
% [ SDP_PF, available in extras/sdp_pf ]
% [ YALMIP, available from: ]
% [ http://users.isy.liu.se/johanl/yalmip/ ]
% [ SDP solver such as SeDuMi, available from: ]
% [ http://sedumi.ie.lehigh.edu/ ]
% [ 'TRALM' - TRALM, trust region based augmented Langrangian ]
% [ method, requires TSPOPF (see 'PDIPM') ]
% opf.dc.solver 'DEFAULT' DC optimal power flow solver
% [ 'DEFAULT' - choose solver based on availability in the following ]
% [ order: 'GUROBI', 'CPLEX', 'MOSEK', 'OT', ]
% [ 'GLPK' (linear costs only), 'BPMPD', 'MIPS' ]
% [ 'MIPS' - MIPS, MATPOWER Interior Point Solver, primal/dual ]
% [ interior point method (pure MATLAB/Octave) ]
% [ 'BPMPD' - BPMPD, requires optional MEX-based BPMPD_MEX package ]
% [ available from: http://www.pserc.cornell.edu/bpmpd/ ]
% [ 'CLP' - CLP, requires interface to COIN-OP LP solver ]
% [ available from:http://www.coin-or.org/projects/Clp.xml]
% [ 'CPLEX' - CPLEX, requires CPLEX solver available from: ]
% [ http://www.ibm.com/software/integration/ ... ]
% [ ... optimization/cplex-optimizer/ ]
% [ 'GLPK' - GLPK, requires interface to GLPK solver ]
% [ available from: http://www.gnu.org/software/glpk/ ]
% [ (GLPK does not work with quadratic cost functions) ]
% [ 'GUROBI' - GUROBI, requires Gurobi optimizer (v. 5+) ]
% [ available from: http://www.gurobi.com/ ]
% [ 'IPOPT' - IPOPT, requires MEX interface to IPOPT solver ]
% [ available from: ]
% [ http://www.coin-or.org/projects/Ipopt.xml ]
% [ 'MOSEK' - MOSEK, requires MATLAB interface to MOSEK solver ]
% [ available from: http://www.mosek.com/ ]
% [ 'OT' - MATLAB Optimization Toolbox, QUADPROG, LINPROG ]
% opf.violation 5e-6 constraint violation tolerance
% opf.use_vg 0 respect gen voltage setpt [ 0-1 ]
% [ 0 - use specified bus Vmin & Vmax, and ignore gen Vg ]
% [ 1 - replace specified bus Vmin & Vmax by corresponding gen Vg ]
% [ between 0 and 1 - use a weighted average of the 2 options ]
% opf.flow_lim 'S' quantity limited by branch flow
% constraints
% [ 'S' - apparent power flow (limit in MVA) ]
% [ 'P' - active power flow, implemented using P (limit in MW) ]
% [ '2' - active power flow, implemented using P^2 (limit in MW) ]
% [ 'I' - current magnitude (limit in MVA at 1 p.u. voltage) ]
% opf.ignore_angle_lim 0 angle diff limits for branches
% [ 0 - include angle difference limits, if specified ]
% [ 1 - ignore angle difference limits even if specified ]
% opf.init_from_mpc -1 (DEPRECATED: use opf.start instead)
% specify whether to use current state
% in MATPOWER case to initialize OPF
% (currently only supported by fmincon,
% Ipopt, Knitro and MIPS solvers,
% others always use mpc)
% [ -1 - MATPOWER decides, based on solver/algorithm ]
% [ 0 - ignore current state when initializing OPF ]
% [ 1 - use current state to initialize OPF ]
% opf.start 0 specify how to set OPF starting point
% [ 0 - default, use interior point estimate for fmincon, Ipopt, ]
% [ Knitro and MIPS; use current state for other solvers ]
% [ 1 - ignore current state when initializing OPF (only applies to ]
% [ fmincon, Ipopt, Knitro and MIPS), currently identical to 0 ]
% [ 2 - use current state to initialize OPF ]
% [ 3 - attempt to solve power flow to initialize OPF ]
% opf.return_raw_der 0 for AC OPF, return constraint and
% derivative info in results.raw
% (in fields g, dg, df, d2f) [ 0 or 1 ]
%
%Output options:
% name default description [options]
%---------------------- --------- ----------------------------------
% verbose 1 amount of progress info printed
% [ 0 - print no progress info ]
% [ 1 - print a little progress info ]
% [ 2 - print a lot of progress info ]
% [ 3 - print all progress info ]
% out.all -1 controls pretty-printing of results
% [ -1 - individual flags control what prints ]
% [ 0 - do not print anything (overrides individual flags, ignored ]
% [ for files specified as FNAME arg to runpf(), runopf(), etc.)]
% [ 1 - print everything (overrides individual flags) ]
% out.sys_sum 1 print system summary [ 0 or 1 ]
% out.area_sum 0 print area summaries [ 0 or 1 ]
% out.bus 1 print bus detail [ 0 or 1 ]
% out.branch 1 print branch detail [ 0 or 1 ]
% out.gen 0 print generator detail [ 0 or 1 ]
% out.lim.all -1 controls constraint info output
% [ -1 - individual flags control what constraint info prints ]
% [ 0 - no constraint info (overrides individual flags) ]
% [ 1 - binding constraint info (overrides individual flags) ]
% [ 2 - all constraint info (overrides individual flags) ]
% out.lim.v 1 control voltage limit info
% [ 0 - do not print ]
% [ 1 - print binding constraints only ]
% [ 2 - print all constraints ]
% [ (same options for OUT_LINE_LIM, OUT_PG_LIM, OUT_QG_LIM) ]
% out.lim.line 1 control line flow limit info
% out.lim.pg 1 control gen active power limit info
% out.lim.qg 1 control gen reactive pwr limit info
% out.force 0 print results even if success
% flag = 0 [ 0 or 1 ]
% out.suppress_detail -1 suppress all output but system summary
% [ -1 - suppress details for large systems (> 500 buses) ]
% [ 0 - do not suppress any output specified by other flags ]
% [ 1 - suppress all output except system summary section ]
% [ (overrides individual flags, but not out.all = 1) ]
%
%Solver specific options:
% name default description [options]
% ----------------------- --------- ----------------------------------
% MIPS:
% mips.linsolver '' linear system solver
% [ '' or '\' build-in backslash \ operator (e.g. x = A \ b) ]
% [ 'PARDISO' PARDISO solver (if available) ]
% mips.feastol 0 feasibility (equality) tolerance
% (set to opf.violation by default)
% mips.gradtol 1e-6 gradient tolerance
% mips.comptol 1e-6 complementary condition
% (inequality) tolerance
% mips.costtol 1e-6 optimality tolerance
% mips.max_it 150 maximum number of iterations
% mips.step_control 0 enable step-size cntrl [ 0 or 1 ]
% mips.sc.red_it 20 maximum number of reductions per
% iteration with step control
% mips.xi 0.99995 constant used in alpha updates*
% mips.sigma 0.1 centering parameter*
% mips.z0 1 used to initialize slack variables*
% mips.alpha_min 1e-8 returns "Numerically Failed" if
% either alpha parameter becomes
% smaller than this value*
% mips.rho_min 0.95 lower bound on rho_t*
% mips.rho_max 1.05 upper bound on rho_t*
% mips.mu_threshold 1e-5 KT multipliers smaller than this
% value for non-binding constraints
% are forced to zero
% mips.max_stepsize 1e10 returns "Numerically Failed" if the
% 2-norm of the reduced Newton step
% exceeds this value*
% * See the corresponding Appendix in the manual for details.
%
% CPLEX:
% cplex.lpmethod 0 solution algorithm for LP problems
% [ 0 - automatic: let CPLEX choose ]
% [ 1 - primal simplex ]
% [ 2 - dual simplex ]
% [ 3 - network simplex ]
% [ 4 - barrier ]
% [ 5 - sifting ]
% [ 6 - concurrent (dual, barrier, and primal) ]
% cplex.qpmethod 0 solution algorithm for QP problems
% [ 0 - automatic: let CPLEX choose ]
% [ 1 - primal simplex optimizer ]
% [ 2 - dual simplex optimizer ]
% [ 3 - network optimizer ]
% [ 4 - barrier optimizer ]
% cplex.opts <empty> see CPLEX_OPTIONS for details
% cplex.opt_fname <empty> see CPLEX_OPTIONS for details
% cplex.opt 0 see CPLEX_OPTIONS for details
%
% FMINCON:
% fmincon.alg 4 algorithm used by fmincon() for OPF
% for Opt Toolbox 4 and later
% [ 1 - active-set (not suitable for large problems) ]
% [ 2 - interior-point, w/default 'bfgs' Hessian approx ]
% [ 3 - interior-point, w/ 'lbfgs' Hessian approx ]
% [ 4 - interior-point, w/exact user-supplied Hessian ]
% [ 5 - interior-point, w/Hessian via finite differences ]
% [ 6 - sqp (not suitable for large problems) ]
% fmincon.tol_x 1e-4 termination tol on x
% fmincon.tol_f 1e-4 termination tol on f
% fmincon.max_it 0 maximum number of iterations
% [ 0 => default ]
%
% GUROBI:
% gurobi.method 0 solution algorithm (Method)
% [ -1 - automatic, let Gurobi decide ]
% [ 0 - primal simplex ]
% [ 1 - dual simplex ]
% [ 2 - barrier ]
% [ 3 - concurrent (LP only) ]
% [ 4 - deterministic concurrent (LP only) ]
% gurobi.timelimit Inf maximum time allowed (TimeLimit)
% gurobi.threads 0 max number of threads (Threads)
% gurobi.opts <empty> see GUROBI_OPTIONS for details
% gurobi.opt_fname <empty> see GUROBI_OPTIONS for details
% gurobi.opt 0 see GUROBI_OPTIONS for details
%
% IPOPT:
% ipopt.opts <empty> see IPOPT_OPTIONS for details
% ipopt.opt_fname <empty> see IPOPT_OPTIONS for details
% ipopt.opt 0 see IPOPT_OPTIONS for details
%
% KNITRO:
% knitro.tol_x 1e-4 termination tol on x
% knitro.tol_f 1e-4 termination tol on f
% knitro.opt_fname <empty> name of user-supplied native
% KNITRO options file that overrides
% all other options
% knitro.opt 0 if knitro.opt_fname is empty and
% knitro.opt is a non-zero integer N
% then knitro.opt_fname is auto-
% generated as:
% 'knitro_user_options_N.txt'
%
% LINPROG:
% linprog <empty> LINPROG options passed to
% OPTIMOPTIONS or OPTIMSET.
% see LINPROG in the Optimization
% Toolbox for details
%
% MINOPF:
% minopf.feastol 0 (1e-3) primal feasibility tolerance
% (set to opf.violation by default)
% minopf.rowtol 0 (1e-3) row tolerance
% minopf.xtol 0 (1e-4) x tolerance
% minopf.majdamp 0 (0.5) major damping parameter
% minopf.mindamp 0 (2.0) minor damping parameter
% minopf.penalty 0 (1.0) penalty parameter
% minopf.major_it 0 (200) major iterations
% minopf.minor_it 0 (2500) minor iterations
% minopf.max_it 0 (2500) iterations limit
% minopf.verbosity -1 amount of progress info printed
% [ -1 - controlled by 'verbose' option ]
% [ 0 - print nothing ]
% [ 1 - print only termination status message ]
% [ 2 - print termination status and screen progress ]
% [ 3 - print screen progress, report file (usually fort.9) ]
% minopf.core 0 (1200*nb + 2*(nb+ng)^2) memory allocation
% minopf.supbasic_lim 0 (2*nb + 2*ng) superbasics limit
% minopf.mult_price 0 (30) multiple price
%
% MOSEK:
% mosek.lp_alg 0 solution algorithm
% (MSK_IPAR_OPTIMIZER)
% for MOSEK 8.x ... (see MOSEK_SYMBCON for a "better way")
% [ 0 - automatic: let MOSEK choose ]
% [ 1 - dual simplex ]
% [ 2 - automatic: let MOSEK choose ]
% [ 3 - automatic simplex (MOSEK chooses which simplex method) ]
% [ 4 - interior point ]
% [ 6 - primal simplex ]
% mosek.max_it 0 (400) interior point max iterations
% (MSK_IPAR_INTPNT_MAX_ITERATIONS)
% mosek.gap_tol 0 (1e-8) interior point relative gap tol
% (MSK_DPAR_INTPNT_TOL_REL_GAP)
% mosek.max_time 0 (-1) maximum time allowed
% (MSK_DPAR_OPTIMIZER_MAX_TIME)
% mosek.num_threads 0 (1) max number of threads
% (MSK_IPAR_INTPNT_NUM_THREADS)
% mosek.opts <empty> see MOSEK_OPTIONS for details
% mosek.opt_fname <empty> see MOSEK_OPTIONS for details
% mosek.opt 0 see MOSEK_OPTIONS for details
%
% QUADPROG:
% quadprog <empty> QUADPROG options passed to
% OPTIMOPTIONS or OPTIMSET.
% see QUADPROG in the Optimization
% Toolbox for details
%
% TSPOPF:
% pdipm.feastol 0 feasibility (equality) tolerance
% (set to opf.violation by default)
% pdipm.gradtol 1e-6 gradient tolerance
% pdipm.comptol 1e-6 complementary condition
% (inequality) tolerance
% pdipm.costtol 1e-6 optimality tolerance
% pdipm.max_it 150 maximum number of iterations
% pdipm.step_control 0 enable step-size cntrl [ 0 or 1 ]
% pdipm.sc.red_it 20 maximum number of reductions per
% iteration with step control
% pdipm.sc.smooth_ratio 0.04 piecewise linear curve smoothing
% ratio
%
% tralm.feastol 0 feasibility tolerance
% (set to opf.violation by default)
% tralm.primaltol 5e-4 primal variable tolerance
% tralm.dualtol 5e-4 dual variable tolerance
% tralm.costtol 1e-5 optimality tolerance
% tralm.major_it 40 maximum number of major iterations
% tralm.minor_it 40 maximum number of minor iterations
% tralm.smooth_ratio 0.04 piecewise linear curve smoothing
% ratio
%
%Experimental Options:
% exp.sys_wide_zip_loads.pw <empty> 1 x 3 vector of active load fraction
% to be modeled as constant power,
% constant current and constant
% impedance, respectively, where
% <empty> means use [1 0 0]
% exp.sys_wide_zip_loads.qw <empty> same for reactive power, where
% <empty> means use same value as
% for 'pw'
% MATPOWER
% Copyright (c) 2013-2017, Power Systems Engineering Research Center (PSERC)
% by Ray Zimmerman, PSERC Cornell
% and Shrirang Abhyankar, Argonne National Laboratory
%
% 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.
%% some constants
N = 124; %% number of options in old-style vector (MATPOWER 4.1)
N40 = 116; %% dimension of MATPOWER 4.0 options vector
N32 = 93; %% dimension of MATPOWER 3.2 options vector
v = mpoption_version; %% version number of MATPOWER options struct
%% initialize flags and arg counter
have_opt0 = 0; %% existing options struct or vector provided?
have_old_style_ov = 0; %% override options using old-style names?
return_old_style = 0; %% return value as old-style vector?
k = 1;
if nargin > 0
opt0 = varargin{k};
if isstruct(opt0) && isfield(opt0, 'v') %% options struct
have_opt0 = 1;
k = k + 1;
elseif isnumeric(opt0) && size(opt0, 2) == 1 %% options vector
nn = size(opt0, 1);
if ismember(nn, [N N40 N32]) %% of valid size
%% expand smaller option vectors (from before MATPOWER 4.1)
if nn < N
optv = mpoption_old();
opt0(nn+1:N) = optv(nn+1:N);
end
have_opt0 = 1;
k = k + 1;
end
end
end
%% create base options vector to which overrides are made
if have_opt0
if isstruct(opt0) %% it's already a valid options struct
if DEBUG, fprintf('OPT0 is a valid options struct\n'); end
if opt0.v < v
%% convert older version to current version
opt_d = mpoption_default();
if opt0.v == 1 %% convert version 1 to 2
if isfield(opt_d, 'linprog')
opt0.lingprog = opt_d.linprog;
end
if isfield(opt_d, 'quadprog')
opt0.quadprog = opt_d.quadprog;
end
end
if opt0.v <= 2 %% convert version 2 to 3
opt0.out.suppress_detail = opt_d.out.suppress_detail;
end
%if opt0.v <= 3 %% convert version 3 to 4
%% new mips options were all optional, no conversion needed
%end
if opt0.v <= 4 %% convert version 4 to 5
opt0.opf.init_from_mpc = opt_d.opf.init_from_mpc;
end
if opt0.v <= 5 %% convert version 5 to 6
if isfield(opt_d, 'clp')
opt0.clp = opt_d.clp;
end
end
if opt0.v <= 6 %% convert version 6 to 7
if isfield(opt_d, 'intlinprog')
opt0.intlinprog = opt_d.intlinprog;
end
end
if opt0.v <= 7 %% convert version 7 to 8
opt0.mips.linsolver = opt_d.mips.linsolver;
end
if opt0.v <= 8 %% convert version 8 to 9
opt0.exp.sys_wide_zip_loads = opt_d.exp.sys_wide_zip_loads;
end
if opt0.v <= 9 %% convert version 9 to 10
opt0.most = opt_d.most;
end
if opt0.v <= 10 %% convert version 10 to 11
opt0.cpf.enforce_p_lims = opt_d.cpf.enforce_p_lims;
opt0.cpf.enforce_q_lims = opt_d.cpf.enforce_q_lims;
opt0.cpf.adapt_step_damping = opt_d.cpf.adapt_step_damping;
opt0.cpf.target_lam_tol = opt_d.cpf.target_lam_tol;
opt0.cpf.nose_tol = opt_d.cpf.nose_tol;
opt0.cpf.p_lims_tol = opt_d.cpf.p_lims_tol;
opt0.cpf.q_lims_tol = opt_d.cpf.q_lims_tol;
if (~isempty(opt0.cpf.user_callback_args) && ...
~isstruct(opt0.cpf.user_callback_args)) || ...
(isstruct(opt0.cpf.user_callback_args) && ...
~isempty(fields(opt0.cpf.user_callback_args)))
warning('The ''cpf.user_callback_args'' option has been removed. Please include the args in a struct in ''cpf.user_callback'' instead.')
end
opt0.cpf = rmfield(opt0.cpf, 'user_callback_args');
end
if opt0.v <= 11 %% convert version 11 to 12
opt0.opf.use_vg = opt_d.opf.use_vg;
end
if opt0.v <= 12 %% convert version 12 to 13
opt0.pf.radial.max_it = opt_d.pf.radial.max_it;
opt0.pf.radial.vcorr = opt_d.pf.radial.vcorr;
end
if opt0.v <= 13 %% convert version 13 to 14
opt0.pf.nr.lin_solver = opt_d.pf.nr.lin_solver;
end
if opt0.v <= 14 %% convert version 14 to 15
opt0.cpf.enforce_v_lims = opt_d.cpf.enforce_v_lims;
opt0.cpf.enforce_flow_lims = opt_d.cpf.enforce_flow_lims;
opt0.cpf.v_lims_tol = opt_d.cpf.v_lims_tol;
opt0.cpf.flow_lims_tol = opt_d.cpf.flow_lims_tol;
end
if opt0.v <= 15 %% convert version 15 to 16
opt0.opf.start = opt_d.opf.start;
end
opt0.v = v;
end
opt = opt0;
else %% convert from old-style options vector
if DEBUG, fprintf('OPT0 is a old-style options vector\n'); end
opt = mpoption_v2s(opt0);
end
else %% use default options struct as base
if DEBUG, fprintf('no OPT0, starting with default options struct\n'); end
opt = mpoption_default();
end
%% do we have OVERRIDES or NAME/VALUE pairs
ov = [];
if nargin - k == 0 %% looking at last arg, must be OVERRIDES
if isstruct(varargin{k}) %% OVERRIDES provided as struct
if DEBUG, fprintf('OVERRIDES struct\n'); end
ov = varargin{k};
elseif ischar(varargin{k}) %% OVERRIDES provided as file/function name
if DEBUG, fprintf('OVERRIDES file/function name\n'); end
try
ov = feval(varargin{k});
catch
error('mpoption: Unable to load MATPOWER options from ''%s''', varargin{k});
end
if ~isstruct(ov)
error('mpoption: calling ''%s'' did not return a struct', varargin{k});
end
elseif isempty(varargin{k})
return_old_style = 1;
else
error('mpoption: OVERRIDES must be a struct or the name of a function that returns a struct');
end
elseif nargin - k > 0 && mod(nargin-k, 2) %% even number of remaining args
if DEBUG, fprintf('NAME/VALUE pairs override defaults\n'); end
%% process NAME/VALUE pairs
if strcmp(varargin{k}, upper(varargin{k})) %% old-style, all UPPERCASE option pairs
%% NOTE: new top-level option fields cannot be all uppercase
if ~have_opt0
opt_v = mpoption_old(varargin{:}); %% create modified vector ...
opt = mpoption_v2s(opt_v); %% ... then convert
else
have_old_style_ov = 1;
%% convert pairs to struct
while k < nargin
name = varargin{k};
val = varargin{k+1};
k = k + 2;
ov.(name) = val;
end
end
else %% new option pairs
%% convert pairs to struct
while k < nargin
name = varargin{k};
val = varargin{k+1};
k = k + 2;
c = regexp(name, '([^\.]*)', 'tokens');
s = struct();
for i = 1:length(c)
s(i).type = '.';
s(i).subs = c{i}{1};
end
ov = subsasgn(ov, s, val);
end
end
elseif nargin == 0 || nargin == 1
if DEBUG, fprintf('no OVERRIDES, return default options struct or converted OPT0 vector\n'); end
else
error('mpoption: invalid calling syntax, see ''help mpoption'' to double-check the valid options');
end
%% apply overrides
if ~isempty(ov)
if have_old_style_ov
opt = apply_old_mpoption_overrides(opt, ov);
else
persistent nsc_opt; %% cache this to speed things up
if ~isstruct(nsc_opt)
vf = nested_struct_copy(mpoption_default(), mpoption_info_mips('V'));
vf = nested_struct_copy(vf, mpoption_optional_fields());
ex = struct(...
'name', {}, ...
'check', {}, ...
'copy_mode', {} ...
);
%% add exceptions for optional packages
opt_pkgs = mpoption_optional_pkgs();
n = length(ex);
for k = 1:length(opt_pkgs)
fname = ['mpoption_info_' opt_pkgs{k}];
if exist(fname, 'file') == 2
opt_ex = feval(fname, 'E');
nex = length(opt_ex);
if ~isempty(opt_ex)
for j = 1:nex
ex(n+j).name = opt_ex(j).name;
end
if isfield(opt_ex, 'check')
for j = 1:nex
ex(n+j).check = opt_ex(j).check;
end
end
if isfield(opt_ex, 'copy_mode')
for j = 1:nex
ex(n+j).copy_mode = opt_ex(j).copy_mode;
end
end
if isfield(opt_ex, 'valid_fields')
for j = 1:nex
ex(n+j).valid_fields = opt_ex(j).valid_fields;
end
end
n = n + nex;
end
end
end
nsc_opt = struct('check', 1, 'valid_fields', vf, 'exceptions', ex);
end
% if have_fcn('catchme')
% try
% opt = nested_struct_copy(opt, ov, nsc_opt);
% catch me
% str = strrep(me.message, 'field', 'option');
% str = strrep(str, 'nested_struct_copy', 'mpoption');
% error(str);
% end
% else
try
opt = nested_struct_copy(opt, ov, nsc_opt);
catch
me = lasterr;
str = strrep(me, 'field', 'option');
str = strrep(str, 'nested_struct_copy', 'mpoption');
error(str);
end
% end
end
end
if return_old_style
opt = mpoption_s2v(opt);
end
%%-------------------------------------------------------------------
function opt = apply_old_mpoption_overrides(opt0, ov)
%
% OPT0 is assumed to already have all of the fields and sub-fields found
% in the default options struct.
%% initialize output
opt = opt0;
errstr = 'mpoption: %g is not a valid value for the old-style ''%s'' option';
fields = fieldnames(ov);
for f = 1:length(fields)
ff = fields{f};
switch ff
case 'PF_ALG'
switch ov.(ff)
case 1
opt.pf.alg = 'NR'; %% Newton's method
case 2
opt.pf.alg = 'FDXB'; %% fast-decoupled (XB version)
case 3
opt.pf.alg = 'FDBX'; %% fast-decoupled (BX version)
case 4
opt.pf.alg = 'GS'; %% Gauss-Seidel
otherwise
error(errstr, ov.(ff), ff);
end
case 'PF_TOL'
opt.pf.tol = ov.(ff);
case 'PF_MAX_IT'
opt.pf.nr.max_it = ov.(ff);
case 'PF_MAX_IT_FD'
opt.pf.fd.max_it = ov.(ff);
case 'PF_MAX_IT_GS'
opt.pf.gs.max_it = ov.(ff);
case 'ENFORCE_Q_LIMS'
opt.pf.enforce_q_lims = ov.(ff);
case 'PF_DC'
switch ov.(ff)
case 0
opt.model = 'AC';
case 1
opt.model = 'DC';
otherwise
error(errstr, ov.(ff), ff);
end
case 'OPF_ALG'
switch ov.(ff)
case 0
opt.opf.ac.solver = 'DEFAULT';
case 500
opt.opf.ac.solver = 'MINOPF';
case 520
opt.opf.ac.solver = 'FMINCON';
case {540, 545}
opt.opf.ac.solver = 'PDIPM';
if ov.(ff) == 545
opt.pdipm.step_control = 1;
else
opt.pdipm.step_control = 0;
end
case 550
opt.opf.ac.solver = 'TRALM';
case {560, 565}
opt.opf.ac.solver = 'MIPS';
if ov.(ff) == 565
opt.mips.step_control = 1;
else
opt.mips.step_control = 0;
end
case 580
opt.opf.ac.solver = 'IPOPT';
case 600
opt.opf.ac.solver = 'KNITRO';
otherwise
error(errstr, ov.(ff), ff);
end
case 'OPF_VIOLATION'
opt.opf.violation = ov.(ff);
case 'CONSTR_TOL_X'
opt.fmincon.tol_x = ov.(ff);
opt.knitro.tol_x = ov.(ff);
case 'CONSTR_TOL_F'
opt.fmincon.tol_f = ov.(ff);
opt.knitro.tol_f = ov.(ff);
case 'CONSTR_MAX_IT'
opt.fmincon.max_it = ov.(ff);
case 'OPF_FLOW_LIM'
switch ov.(ff)
case 0
opt.opf.flow_lim = 'S'; %% apparent power (MVA)
case 1
opt.opf.flow_lim = 'P'; %% real power (MW)
case 2
opt.opf.flow_lim = 'I'; %% current magnitude (MVA @ 1 p.u. voltage)
otherwise
error(errstr, ov.(ff), ff);
end
case 'OPF_IGNORE_ANG_LIM'
opt.opf.ignore_angle_lim = ov.(ff);
case 'OPF_ALG_DC'
switch ov.(ff)
case 0
opt.opf.dc.solver = 'DEFAULT';
case 100
opt.opf.dc.solver = 'BPMPD';
case {200, 250}
opt.opf.dc.solver = 'MIPS';
if ov.(ff) == 250
opt.mips.step_control = 1;
else
opt.mips.step_control = 0;
end
case 300
opt.opf.dc.solver = 'OT'; %% QUADPROG, LINPROG
case 400
opt.opf.dc.solver = 'IPOPT';
case 500
opt.opf.dc.solver = 'CPLEX';
case 600
opt.opf.dc.solver = 'MOSEK';
case 700
opt.opf.dc.solver = 'GUROBI';
otherwise
error(errstr, ov.(ff), ff);
end
case 'VERBOSE'
opt.verbose = ov.(ff);
case 'OUT_ALL'
opt.out.all = ov.(ff);
case 'OUT_SYS_SUM'
opt.out.sys_sum = ov.(ff);
case 'OUT_AREA_SUM'
opt.out.area_sum = ov.(ff);
case 'OUT_BUS'
opt.out.bus = ov.(ff);
case 'OUT_BRANCH'
opt.out.branch = ov.(ff);
case 'OUT_GEN'
opt.out.gen = ov.(ff);
case 'OUT_ALL_LIM'
opt.out.lim.all = ov.(ff);
case 'OUT_V_LIM'
opt.out.lim.v = ov.(ff);
case 'OUT_LINE_LIM'
opt.out.lim.line = ov.(ff);
case 'OUT_PG_LIM'
opt.out.lim.pg = ov.(ff);
case 'OUT_QG_LIM'
opt.out.lim.qg = ov.(ff);
case 'OUT_FORCE'
opt.out.force = ov.(ff);
case 'RETURN_RAW_DER'
opt.opf.return_raw_der = ov.(ff);
case 'FMC_ALG'
opt.fmincon.alg = ov.(ff);
case 'KNITRO_OPT'
opt.knitro.opt = ov.(ff);
case 'IPOPT_OPT'
opt.ipopt.opt = ov.(ff);
case 'MNS_FEASTOL'
opt.minopf.feastol = ov.(ff);
case 'MNS_ROWTOL'
opt.minopf.rowtol = ov.(ff);
case 'MNS_XTOL'
opt.minopf.xtol = ov.(ff);
case 'MNS_MAJDAMP'
opt.minopf.majdamp = ov.(ff);
case 'MNS_MINDAMP'
opt.minopf.mindamp = ov.(ff);
case 'MNS_PENALTY_PARM'
opt.minopf.penalty = ov.(ff);
case 'MNS_MAJOR_IT'
opt.minopf.major_it = ov.(ff);
case 'MNS_MINOR_IT'
opt.minopf.minor_it = ov.(ff);
case 'MNS_MAX_IT'
opt.minopf.max_it = ov.(ff);
case 'MNS_VERBOSITY'
opt.minopf.verbosity = ov.(ff);
case 'MNS_CORE'
opt.minopf.core = ov.(ff);
case 'MNS_SUPBASIC_LIM'
opt.minopf.supbasic_lim = ov.(ff);
case 'MNS_MULT_PRICE'
opt.minopf.mult_price = ov.(ff);
case 'FORCE_PC_EQ_P0'
opt.sopf.force_Pc_eq_P0 = ov.(ff);
case 'PDIPM_FEASTOL'
opt.mips.feastol = ov.(ff);
opt.pdipm.feastol = ov.(ff);
case 'PDIPM_GRADTOL'
opt.mips.gradtol = ov.(ff);
opt.pdipm.gradtol = ov.(ff);
case 'PDIPM_COMPTOL'
opt.mips.comptol = ov.(ff);
opt.pdipm.comptol = ov.(ff);
case 'PDIPM_COSTTOL'
opt.mips.costtol = ov.(ff);
opt.pdipm.costtol = ov.(ff);
case 'PDIPM_MAX_IT'
opt.mips.max_it = ov.(ff);
opt.pdipm.max_it = ov.(ff);
case 'SCPDIPM_RED_IT'
opt.mips.sc.red_it = ov.(ff);
opt.pdipm.sc.red_it = ov.(ff);
case 'TRALM_FEASTOL'
opt.tralm.feastol = ov.(ff);
case 'TRALM_PRIMETOL'
opt.tralm.primaltol = ov.(ff);
case 'TRALM_DUALTOL'
opt.tralm.dualtol = ov.(ff);
case 'TRALM_COSTTOL'
opt.tralm.costtol = ov.(ff);
case 'TRALM_MAJOR_IT'
opt.tralm.major_it = ov.(ff);
case 'TRALM_MINOR_IT'
opt.tralm.minor_it = ov.(ff);
case 'SMOOTHING_RATIO'
opt.pdipm.sc.smooth_ratio = ov.(ff);
opt.tralm.smooth_ratio = ov.(ff);
case 'CPLEX_LPMETHOD'
opt.cplex.lpmethod = ov.(ff);
case 'CPLEX_QPMETHOD'
opt.cplex.qpmethod = ov.(ff);
case 'CPLEX_OPT'
opt.cplex.opt = ov.(ff);
case 'MOSEK_LP_ALG'
opt.mosek.lp_alg = ov.(ff);
case 'MOSEK_MAX_IT'
opt.mosek.max_it = ov.(ff);
case 'MOSEK_GAP_TOL'
opt.mosek.gap_tol = ov.(ff);
case 'MOSEK_MAX_TIME'
opt.mosek.max_time = ov.(ff);
case 'MOSEK_NUM_THREADS'
opt.mosek.num_threads = ov.(ff);
case 'MOSEK_OPT'
opt.mosek.opt = ov.(ff);
case 'GRB_METHOD'
opt.gurobi.method = ov.(ff);
case 'GRB_TIMELIMIT'
opt.gurobi.timelimit = ov.(ff);
case 'GRB_THREADS'
opt.gurobi.threads = ov.(ff);
case 'GRB_OPT'
opt.gurobi.opt = ov.(ff);
otherwise
error('mpoption: ''%s'' is not a valid old-style option name', ff);
end
end
% ov
%%-------------------------------------------------------------------
function opt_s = mpoption_v2s(opt_v)
if DEBUG, fprintf('mpoption_v2s()\n'); end
opt_s = mpoption_default();
errstr = 'mpoption: %g is not a valid value for the old-style ''%s'' option';
switch opt_v(1) %% PF_ALG
case 1
opt_s.pf.alg = 'NR'; %% Newton's method
case 2
opt_s.pf.alg = 'FDXB'; %% fast-decoupled (XB version)
case 3
opt_s.pf.alg = 'FDBX'; %% fast-decoupled (BX version)
case 4
opt_s.pf.alg = 'GS'; %% Gauss-Seidel
otherwise
error(errstr, opt_v(1), 'PF_ALG');
end
opt_s.pf.tol = opt_v(2); %% PF_TOL
opt_s.pf.nr.max_it = opt_v(3); %% PF_MAX_IT
opt_s.pf.fd.max_it = opt_v(4); %% PF_MAX_IT_FD
opt_s.pf.gs.max_it = opt_v(5); %% PF_MAX_IT_GS
opt_s.pf.enforce_q_lims = opt_v(6); %% ENFORCE_Q_LIMS
switch opt_v(10) %% PF_DC
case 0