1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """Sets options for MOSEK.
18 """
19
20 try:
21 from pymosek import mosekopt
22 except ImportError:
23
24 pass
25
26 from pypower.util import feval
27
28
30 """Sets options for MOSEK.
31
32 Inputs are all optional, second argument must be either a string
33 (C{fname}) or a dict (C{ppopt}):
34
35 - C{overrides}
36 - dict containing values to override the defaults
37 - C{fname} name of user-supplied function called after default
38 options are set to modify them. Calling syntax is::
39 modified_opt = fname(default_opt)
40 - C{ppopt} PYPOWER options vector, uses the following entries:
41 - C{OPF_VIOLATION} used to set opt.MSK_DPAR_INTPNT_TOL_PFEAS
42 - C{VERBOSE} not currently used here
43 - C{MOSEK_MAX_IT} used to set opt.MSK_IPAR_INTPNT_MAX_ITERATIONS
44 - C{MOSEK_GAP_TOL} used to set opt.MSK_DPAR_INTPNT_TOL_REL_GAP
45 - C{MOSEK_MAX_TIME} used to set opt.MSK_DPAR_OPTIMIZER_MAX_TIME
46 - C{MOSEK_NUM_THREADS} used to set opt.MSK_IPAR_INTPNT_NUM_THREADS
47 - C{MOSEK_OPT} user option file, if ppopt['MOSEK_OPT'] is non-zero
48 non-zero it is apped to 'mosek_user_options_' to form
49 the name of a user-supplied function used as C{fname}
50 described above, except with calling syntax::
51 modified_opt = fname(default_opt, ppopt)
52
53 Output is a param dict to pass to MOSEKOPT.
54
55 Example:
56
57 If PPOPT['MOSEK_OPT'] = 3, then after setting the default MOSEK options,
58 L{mosek_options} will execute the following user-defined function
59 to allow option overrides::
60
61 opt = mosek_user_options_3(opt, ppopt)
62
63 The contents of mosek_user_options_3.py, could be something like::
64
65 def mosek_user_options_3(opt, ppopt):
66 opt = {}
67 opt.MSK_DPAR_INTPNT_TOL_DFEAS = 1e-9
68 opt.MSK_IPAR_SIM_MAX_ITERATIONS = 5000000
69 return opt
70
71 See the Parameters reference in Appix E of "The MOSEK
72 optimization toolbox for MATLAB manaul" for
73 details on the available options.
74
75 U{http://www.mosek.com/documentation/}
76
77 @see: C{mosekopt}, L{ppoption}.
78
79 @author: Ray Zimmerman (PSERC Cornell)
80 @author: Richard Lincoln
81 """
82
83
84 verbose = 2
85 gaptol = 0
86 fname = ''
87
88
89 r, res = mosekopt('symbcon echo(0)')
90 sc = res['symbcon']
91
92
93 if ppopt == None:
94 if isinstance(ppopt, basestring):
95 fname = ppopt
96 have_ppopt = False
97 else:
98 have_ppopt = True
99
100 verbose = ppopt['VERBOSE']
101 if ppopt['MOSEK_OPT']:
102 fname = 'mosek_user_options_#d'
103 else:
104 have_ppopt = False
105
106 opt = {}
107
108
109 if have_ppopt:
110 alg = ppopt['MOSEK_LP_ALG']
111 if alg == sc['MSK_OPTIMIZER_FREE'] or \
112 alg == sc['MSK_OPTIMIZER_INTPNT'] or \
113 alg == sc['MSK_OPTIMIZER_PRIMAL_SIMPLEX'] or \
114 alg == sc['MSK_OPTIMIZER_DUAL_SIMPLEX'] or \
115 alg == sc['MSK_OPTIMIZER_PRIMAL_DUAL_SIMPLEX'] or \
116 alg == sc['MSK_OPTIMIZER_FREE_SIMPLEX'] or \
117 alg == sc['MSK_OPTIMIZER_CONCURRENT']:
118 opt['MSK_IPAR_OPTIMIZER'] = alg
119 else:
120 opt['MSK_IPAR_OPTIMIZER'] = sc['MSK_OPTIMIZER_FREE'];
121
122
123 opt['MSK_DPAR_INTPNT_TOL_PFEAS'] = ppopt['OPF_VIOLATION'] / 500
124 if ppopt['MOSEK_MAX_IT']:
125 opt['MSK_IPAR_INTPNT_MAX_ITERATIONS'] = ppopt['MOSEK_MAX_IT']
126
127 if ppopt['MOSEK_GAP_TOL']:
128 opt['MSK_DPAR_INTPNT_TOL_REL_GAP'] = ppopt['MOSEK_GAP_TOL']
129
130 if ppopt['MOSEK_MAX_TIME']:
131 opt['MSK_DPAR_OPTIMIZER_MAX_TIME'] = ppopt['MOSEK_MAX_TIME']
132
133 if ppopt['MOSEK_NUM_THREADS']:
134 opt['MSK_IPAR_INTPNT_NUM_THREADS'] = ppopt['MOSEK_NUM_THREADS']
135 else:
136 opt['MSK_IPAR_OPTIMIZER'] = sc['MSK_OPTIMIZER_FREE']
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153 if len(fname) > 0:
154 if have_ppopt:
155 opt = feval(fname, opt, ppopt)
156 else:
157 opt = feval(fname, opt)
158
159
160 if overrides is not None:
161 names = overrides.keys()
162 for k in range(len(names)):
163 opt[names[k]] = overrides[names[k]]
164