27
27
28
28
import logging
29
29
30
- logger = logging .getLogger (' pyomo.solvers' )
30
+ logger = logging .getLogger (" pyomo.solvers" )
31
31
32
32
33
33
@SolverFactory .register (
34
- ' asl' , doc = ' Interface for solvers using the AMPL Solver Library'
34
+ " asl" , doc = " Interface for solvers using the AMPL Solver Library"
35
35
)
36
36
class ASL (SystemCallSolver ):
37
37
"""A generic optimizer that uses the AMPL Solver Library to interface with applications."""
@@ -40,7 +40,7 @@ def __init__(self, **kwds):
40
40
#
41
41
# Call base constructor
42
42
#
43
- if not ' type' in kwds :
43
+ if not " type" in kwds :
44
44
kwds ["type" ] = "asl"
45
45
SystemCallSolver .__init__ (self , ** kwds )
46
46
self ._metasolver = True
@@ -93,7 +93,7 @@ def _get_version(self):
93
93
"""
94
94
solver_exec = self .executable ()
95
95
if solver_exec is None :
96
- return _extract_version ('' )
96
+ return _extract_version ("" )
97
97
try :
98
98
results = subprocess .run (
99
99
[solver_exec , "-v" ],
@@ -105,8 +105,8 @@ def _get_version(self):
105
105
ver = _extract_version (results .stdout )
106
106
if ver is None :
107
107
# Some ASL solvers do not export a version number
108
- if results .stdout .strip ().split ()[- 1 ].startswith (' ASL(' ):
109
- return ' 0.0.0'
108
+ if results .stdout .strip ().split ()[- 1 ].startswith (" ASL(" ):
109
+ return " 0.0.0"
110
110
return ver
111
111
except OSError :
112
112
pass
@@ -139,9 +139,9 @@ def create_command_line(self, executable, problem_files):
139
139
"The 'soln_file' keyword will be ignored for solver=" + self .type
140
140
)
141
141
fname = problem_files [0 ]
142
- if '.' in fname :
143
- tmp = fname .split ('.' )
144
- fname = '.' .join (tmp [:- 1 ])
142
+ if "." in fname :
143
+ tmp = fname .split ("." )
144
+ fname = "." .join (tmp [:- 1 ])
145
145
self ._soln_file = fname + ".sol"
146
146
147
147
#
@@ -158,15 +158,15 @@ def create_command_line(self, executable, problem_files):
158
158
# Pyomo/Pyomo) with any user-specified external function
159
159
# libraries
160
160
#
161
- if ' PYOMO_AMPLFUNC' in env :
162
- if ' AMPLFUNC' in env :
163
- for line in env [' PYOMO_AMPLFUNC' ].split (' \n ' ):
164
- if line not in env [' AMPLFUNC' ]:
165
- env [' AMPLFUNC' ] += "\n " + line
161
+ if " PYOMO_AMPLFUNC" in env :
162
+ if " AMPLFUNC" in env :
163
+ for line in env [" PYOMO_AMPLFUNC" ].split (" \n " ):
164
+ if line not in env [" AMPLFUNC" ]:
165
+ env [" AMPLFUNC" ] += "\n " + line
166
166
else :
167
- env [' AMPLFUNC' ] = env [' PYOMO_AMPLFUNC' ]
167
+ env [" AMPLFUNC" ] = env [" PYOMO_AMPLFUNC" ]
168
168
169
- cmd = [executable , problem_files [0 ], ' -AMPL' ]
169
+ cmd = [executable , problem_files [0 ], " -AMPL" ]
170
170
if self ._timer :
171
171
cmd .insert (0 , self ._timer )
172
172
#
@@ -181,12 +181,12 @@ def create_command_line(self, executable, problem_files):
181
181
#
182
182
opt = []
183
183
for key in self .options :
184
- if key == ' solver' :
184
+ if key == " solver" :
185
185
continue
186
- if isinstance (self .options [key ], str ) and (' ' in self .options [key ]):
187
- opt .append (key + "= \" " + str (self .options [key ]) + " \" " )
186
+ if isinstance (self .options [key ], str ) and (" " in self .options [key ]):
187
+ opt .append (key + '="' + str (self .options [key ]) + '"' )
188
188
cmd .append (str (key ) + "=" + str (self .options [key ]))
189
- elif key == ' subsolver' :
189
+ elif key == " subsolver" :
190
190
opt .append ("solver=" + str (self .options [key ]))
191
191
cmd .append (str (key ) + "=" + str (self .options [key ]))
192
192
else :
@@ -202,9 +202,9 @@ def create_command_line(self, executable, problem_files):
202
202
def _presolve (self , * args , ** kwds ):
203
203
if (not isinstance (args [0 ], str )) and (not isinstance (args [0 ], IBlock )):
204
204
self ._instance = args [0 ]
205
- xfrm = TransformationFactory (' mpec.nl' )
205
+ xfrm = TransformationFactory (" mpec.nl" )
206
206
xfrm .apply_to (self ._instance )
207
- if len (self ._instance ._transformation_data [' mpec.nl' ].compl_cuids ) == 0 :
207
+ if len (self ._instance ._transformation_data [" mpec.nl" ].compl_cuids ) == 0 :
208
208
# There were no complementarity conditions
209
209
# so we don't hold onto the instance
210
210
self ._instance = None
@@ -223,7 +223,7 @@ def _postsolve(self):
223
223
if not self ._instance is None :
224
224
from pyomo .mpec import Complementarity
225
225
226
- for cuid in self ._instance ._transformation_data [' mpec.nl' ].compl_cuids :
226
+ for cuid in self ._instance ._transformation_data [" mpec.nl" ].compl_cuids :
227
227
mpec = True
228
228
cobj = cuid .find_component_on (self ._instance )
229
229
cobj .parent_block ().reclassify_component_type (cobj , Complementarity )
@@ -232,7 +232,7 @@ def _postsolve(self):
232
232
return SystemCallSolver ._postsolve (self )
233
233
234
234
235
- @SolverFactory .register (' _mock_asl' )
235
+ @SolverFactory .register (" _mock_asl" )
236
236
class MockASL (ASL , MockMIP ):
237
237
"""A Mock ASL solver used for testing"""
238
238
0 commit comments