source: coopr.pysp/trunk/coopr/pysp/tests/unit/test_ph.py @ 5843

Last change on this file since 5843 was 5843, checked in by jwatson, 7 years ago

More alternative baseline updates, triggered by carr migration.

File size: 106.6 KB
Line 
1#
2# Get the directory where this script is defined, and where the baseline
3# files are located.
4#
5import os
6import sys
7import string
8from os.path import abspath, dirname
9sys.path.insert(0, dirname(dirname(abspath(__file__)))+"/../..")
10
11this_test_file_directory = dirname(abspath(__file__))+os.sep
12
13pysp_examples_dir = dirname(dirname(dirname(dirname(dirname(abspath(__file__))))))+os.sep+"examples"+os.sep+"pysp"+os.sep
14
15coopr_bin_dir = dirname(dirname(dirname(dirname(dirname(dirname(dirname(abspath(__file__))))))))+os.sep+"bin"+os.sep
16
17#
18# Import the testing packages
19#
20import pyutilib.misc
21import pyutilib.th as unittest
22import pyutilib.subprocess
23from pyutilib.component.executables import *
24import coopr.pysp
25import coopr.plugins.solvers
26import coopr.pysp.phinit
27import coopr.pysp.ef_writer_script
28
29def filter_time_and_data_dirs(line):
30    return "seconds" in line or line.startswith("Output file written to") or "filename" in line or "directory" in line or "file" in line
31
32# pyro output filtering is complex, due to asynchronous behaviors - filter all blather regarding what Pyro components are doing.
33def filter_pyro(line):
34    if line.startswith("URI") or line.startswith("Object URI") or line.startswith("Dispatcher Object URI") or line.startswith("Dispatcher is ready"):
35       return True
36    elif line.startswith("Applying solver"):
37       return True
38    elif line.startswith("Attempting to find Pyro dispatcher object"):
39       return True   
40    elif line.startswith("Getting work from"):
41       return True
42    elif line.startswith("Name Server gracefully stopped."):
43       return True   
44    elif line.startswith("Listening for work from"):
45       return True
46    elif line.startswith("Error loading coopr.opt entry point"): # supressing weird error that occasionally pops up when loading plugins
47       return True
48    elif line.startswith("Broadcast server"):
49       return True
50    elif line.startswith("Failed to locate nameserver - trying again"):
51       return True
52    elif line.startswith("Failed to find dispatcher object from name server - trying again"):
53       return True   
54    elif line.startswith("Lost connection to"): # happens when shutting down pyro objects
55       return True     
56    elif line.startswith("WARNING: daemon bound on hostname that resolves"): # happens when not connected to a network.
57       return True     
58    elif line.startswith("This is worker") or line.startswith("This is client") or line.startswith("Finding Pyro"):
59       return True
60    elif line.find("Applying solver") != -1:
61       return True
62    elif line.find("Solve completed") != -1:
63       return True
64    elif line.find("Freeing MIP data") != -1: # CPLEX 12.4 python interface idiocy
65       return True
66    elif line.find("Warning: integer solution") != -1: # CPLEX 12.4 python interface idiocy
67       return True
68    elif line.startswith("Creating instance"): # non-deterministic order for PH Pyro solver manager
69       return True
70    elif line.startswith("Exception in thread"): # occasionally raised during Pyro component shutdown
71       return True
72    elif line.startswith("Traceback"): # occasionally raised during Pyro component shutdown
73       return True
74    elif line.startswith("File"): # occasionally raised during Pyro component shutdown
75       return True               
76    return filter_time_and_data_dirs(line)
77
78cplex = None
79cplex_available = False
80try:
81    cplex = coopr.plugins.solvers.CPLEX(keepFiles=True)
82    cplex_available = (not cplex.executable() is None) and cplex.available(False)
83except pyutilib.common.ApplicationError:
84    cplex_available=False
85
86cplex_direct = None
87cplex_direct_available = False
88try:
89    cplex_direct = coopr.plugins.solvers.CPLEXDirect()
90    cplex_direct_available = cplex_direct.available(False)
91except pyutilib.common.ApplicationError:
92    cplex_direct_available=False
93
94gurobi = None
95gurobi_available = False
96try:
97    gurobi = coopr.plugins.solvers.GUROBI(keepFiles=True)
98    gurobi_available = (not gurobi.executable() is None) and gurobi.available(False)
99except pyutilib.common.ApplicationError:
100    gurobi_available=False
101
102gurobi_direct = None
103gurobi_direct_available = False
104try:
105    gurobi_direct = coopr.plugins.solvers.gurobi_direct()
106    gurobi_direct_available = gurobi_direct.available(False)
107except pyutilib.common.ApplicationError:
108    gurobi_direct_available=False
109
110glpk = None
111glpk_available = False
112try:
113    glpk = coopr.plugins.solvers.GLPK(keepFiles=True)
114    glpk_available = (not glpk.executable() is None) and glpk.available(False)
115except pyutilib.common.ApplicationError:
116    glpk_available=False
117
118ipopt = None
119ipopt_available = False
120try:
121    ipopt = coopr.plugins.solvers.ASL(keepFiles=True, options={'solver':'ipopt'})
122    if (ipopt.executable() is not None) and (ipopt.available(False) is True):
123        ipopt_available = True
124    else:
125        ipopt_available = False
126except pyutilib.common.ApplicationError:
127    ipopt_available=False
128
129cbc = None
130cbc_available = False
131try:
132    cbc = coopr.plugins.solvers.CBC(keepFiles=True)
133    cbc_available = (not cbc.executable() is None) and cbc.available(False)
134except pyutilib.common.ApplicationError:
135    cbc_available=False
136
137mpirun_executable = ExternalExecutable(name="mpirun")
138mpirun_available = mpirun_executable.enabled()
139
140#
141# Define a testing class, using the unittest.TestCase class.
142#
143
144class TestPH(unittest.TestCase):
145
146    def cleanup(self):
147
148        # IMPT: This step is key, as Python keys off the name of the module, not the location.
149        #       So, different reference models in different directories won't be detected.
150        #       If you don't do this, the symptom is a model that doesn't have the attributes
151        #       that the data file expects.
152        if "ReferenceModel" in sys.modules:
153            del sys.modules["ReferenceModel"]
154
155    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
156    def test_farmer_quadratic_cplex(self):
157        farmer_examples_dir = pysp_examples_dir + "farmer"
158        model_dir = farmer_examples_dir + os.sep + "models"
159        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
160        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
161        print "Testing command: " + argstring
162
163        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_cplex.out")
164        args = string.split(argstring)
165        coopr.pysp.phinit.main(args=args)
166        pyutilib.misc.reset_redirect()
167        self.cleanup()
168        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_cplex.out",this_test_file_directory+"farmer_quadratic_cplex.baseline", filter=filter_time_and_data_dirs)
169
170    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
171    def test_farmer_quadratic_nonnormalized_termdiff_cplex(self):
172        farmer_examples_dir = pysp_examples_dir + "farmer"
173        model_dir = farmer_examples_dir + os.sep + "models"
174        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
175        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --enable-termdiff-convergence --termdiff-threshold=0.01"
176        print "Testing command: " + argstring
177
178        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_nonnormalized_termdiff_cplex.out")
179        args = string.split(argstring)
180        coopr.pysp.phinit.main(args=args)
181        pyutilib.misc.reset_redirect()
182        self.cleanup()
183        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_nonnormalized_termdiff_cplex.out",this_test_file_directory+"farmer_quadratic_nonnormalized_termdiff_cplex.baseline", filter=filter_time_and_data_dirs)       
184
185    @unittest.skipIf(not cplex_direct_available, "The 'cplex' python solver is not available")
186    def test_farmer_quadratic_cplex_direct(self):
187        farmer_examples_dir = pysp_examples_dir + "farmer"
188        model_dir = farmer_examples_dir + os.sep + "models"
189        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
190        argstring = "runph --solver=cplex --solver-io=python --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
191        print "Testing command: " + argstring
192
193        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_cplex_direct.out")
194        args = string.split(argstring)
195        coopr.pysp.phinit.main(args=args)
196        pyutilib.misc.reset_redirect()
197        self.cleanup()
198        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_cplex_direct.out",this_test_file_directory+"farmer_quadratic_cplex_direct.baseline", filter=filter_time_and_data_dirs)       
199
200    @unittest.skipIf(not gurobi_direct_available, "The 'gurobi' python solver is not available")
201    def test_farmer_quadratic_gurobi_direct(self):
202        farmer_examples_dir = pysp_examples_dir + "farmer"
203        model_dir = farmer_examples_dir + os.sep + "models"
204        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
205        argstring = "runph --solver=gurobi --solver-io=python --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
206        print "Testing command: " + argstring
207
208        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_gurobi_direct.out")
209        args = string.split(argstring)
210        coopr.pysp.phinit.main(args=args)
211        pyutilib.misc.reset_redirect()
212        self.cleanup()
213        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_gurobi_direct.out",this_test_file_directory+"farmer_quadratic_gurobi_direct.baseline", filter=filter_time_and_data_dirs)       
214
215    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
216    def test_farmer_quadratic_gurobi(self):
217        farmer_examples_dir = pysp_examples_dir + "farmer"
218        model_dir = farmer_examples_dir + os.sep + "models"
219        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
220        argstring = "runph --solver=gurobi --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
221        print "Testing command: " + argstring
222
223        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_gurobi.out")
224        args = string.split(argstring)
225        coopr.pysp.phinit.main(args=args)
226        pyutilib.misc.reset_redirect()
227        self.cleanup()
228        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_gurobi.out",this_test_file_directory+"farmer_quadratic_gurobi.baseline", filter=filter_time_and_data_dirs)
229
230    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
231    def test_farmer_quadratic_nonnormalized_termdiff_gurobi(self):
232        farmer_examples_dir = pysp_examples_dir + "farmer"
233        model_dir = farmer_examples_dir + os.sep + "models"
234        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
235        argstring = "runph --solver=gurobi --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --enable-termdiff-convergence --termdiff-threshold=0.01"
236        print "Testing command: " + argstring
237
238        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_nonnormalized_termdiff_gurobi.out")
239        args = string.split(argstring)
240        coopr.pysp.phinit.main(args=args)
241        pyutilib.misc.reset_redirect()
242        self.cleanup()
243        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_nonnormalized_termdiff_gurobi.out",this_test_file_directory+"farmer_quadratic_nonnormalized_termdiff_gurobi.baseline", filter=filter_time_and_data_dirs)
244
245    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
246    def test_farmer_quadratic_gurobi_with_flattening(self):
247        farmer_examples_dir = pysp_examples_dir + "farmer"
248        model_dir = farmer_examples_dir + os.sep + "models"
249        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
250        argstring = "runph --solver=gurobi --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --flatten-expressions"
251        print "Testing command: " + argstring
252
253        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_gurobi_with_flattening.out")
254        args = string.split(argstring)
255        coopr.pysp.phinit.main(args=args)
256        pyutilib.misc.reset_redirect()
257        self.cleanup()
258        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_gurobi_with_flattening.out",this_test_file_directory+"farmer_quadratic_gurobi_with_flattening.baseline", filter=filter_time_and_data_dirs)
259
260    @unittest.skipIf(not ipopt_available, "The 'ipopt' executable is not available")
261    def test_farmer_quadratic_ipopt(self):
262        farmer_examples_dir = pysp_examples_dir + "farmer"
263        model_dir = farmer_examples_dir + os.sep + "models"
264        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
265        argstring = "runph --solver=ipopt --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
266        print "Testing command: " + argstring
267
268        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_ipopt.out")
269        args = string.split(argstring)
270        coopr.pysp.phinit.main(args=args)
271        pyutilib.misc.reset_redirect()
272        self.cleanup()
273        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_ipopt.out",this_test_file_directory+"farmer_quadratic_ipopt.baseline", filter=filter_time_and_data_dirs, tolerance=1e-4)
274
275    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
276    def test_farmer_maximize_quadratic_gurobi(self):
277        farmer_examples_dir = pysp_examples_dir + "farmer"
278        model_dir = farmer_examples_dir + os.sep + "maxmodels"
279        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
280        argstring = "runph --solver=gurobi --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
281        print "Testing command: " + argstring
282
283        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_maximize_quadratic_gurobi.out")
284        args = string.split(argstring)
285        coopr.pysp.phinit.main(args=args)
286        pyutilib.misc.reset_redirect()
287        self.cleanup()
288        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_maximize_quadratic_gurobi.out",this_test_file_directory+"farmer_maximize_quadratic_gurobi.baseline", filter=filter_time_and_data_dirs)
289
290    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
291    def test_farmer_with_integers_quadratic_cplex(self):
292        farmer_examples_dir = pysp_examples_dir + "farmerWintegers"
293        model_dir = farmer_examples_dir + os.sep + "models"
294        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
295        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --default-rho=10"
296        print "Testing command: " + argstring
297
298        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_with_integers_quadratic_cplex.out")
299        args = string.split(argstring)
300        coopr.pysp.phinit.main(args=args)
301        pyutilib.misc.reset_redirect()
302        self.cleanup()
303        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_with_integers_quadratic_cplex.out",this_test_file_directory+"farmer_with_integers_quadratic_cplex.baseline", filter=filter_time_and_data_dirs)       
304
305    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
306    def test_farmer_with_integers_quadratic_gurobi(self):
307        farmer_examples_dir = pysp_examples_dir + "farmerWintegers"
308        model_dir = farmer_examples_dir + os.sep + "models"
309        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
310        argstring = "runph --solver=gurobi --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --default-rho=10"
311        print "Testing command: " + argstring
312
313        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_with_integers_quadratic_gurobi.out")
314        args = string.split(argstring)
315        coopr.pysp.phinit.main(args=args)
316        pyutilib.misc.reset_redirect()
317        self.cleanup()
318
319        if os.sys.platform == "darwin":
320           self.assertFileEqualsBaseline(this_test_file_directory+"farmer_with_integers_quadratic_gurobi.out",this_test_file_directory+"farmer_with_integers_quadratic_gurobi_darwin.baseline", filter=filter_time_and_data_dirs)       
321        else:
322           self.assertFileEqualsBaseline(this_test_file_directory+"farmer_with_integers_quadratic_gurobi.out",this_test_file_directory+"farmer_with_integers_quadratic_gurobi.baseline", filter=filter_time_and_data_dirs)
323
324    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
325    def test_farmer_quadratic_verbose_cplex(self):
326        farmer_examples_dir = pysp_examples_dir + "farmer"
327        model_dir = farmer_examples_dir + os.sep + "models"
328        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
329        argstring = "runph --solver=cplex --solver-manager=serial --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir
330        print "Testing command: " + argstring
331
332        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_verbose_cplex.out")
333        args = string.split(argstring)
334        coopr.pysp.phinit.main(args=args)
335        pyutilib.misc.reset_redirect()
336        self.cleanup()
337        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_verbose_cplex.out",this_test_file_directory+"farmer_quadratic_verbose_cplex.baseline", filter=filter_time_and_data_dirs)
338
339    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
340    def test_farmer_quadratic_verbose_gurobi(self):
341        farmer_examples_dir = pysp_examples_dir + "farmer"
342        model_dir = farmer_examples_dir + os.sep + "models"
343        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
344        argstring = "runph --solver=gurobi --solver-manager=serial --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir
345        print "Testing command: " + argstring
346
347        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_verbose_gurobi.out")
348        args = string.split(argstring)
349        coopr.pysp.phinit.main(args=args)
350        pyutilib.misc.reset_redirect()
351        self.cleanup()
352        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_verbose_gurobi.out",this_test_file_directory+"farmer_quadratic_verbose_gurobi.baseline", filter=filter_time_and_data_dirs)
353
354    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
355    def test_farmer_quadratic_trivial_bundling_cplex(self):
356        farmer_examples_dir = pysp_examples_dir + "farmer"
357        model_dir = farmer_examples_dir + os.sep + "models"
358        instance_dir = farmer_examples_dir + os.sep + "scenariodataWithTrivialBundles"
359        argstring = "runph --solver=cplex --solver-manager=serial --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir
360        print "Testing command: " + argstring
361
362        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_trivial_bundling_cplex.out")       
363        args = string.split(argstring)
364        coopr.pysp.phinit.main(args=args)
365        pyutilib.misc.reset_redirect()
366        self.cleanup()
367        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_trivial_bundling_cplex.out",this_test_file_directory+"farmer_quadratic_trivial_bundling_cplex.baseline", filter=filter_time_and_data_dirs)
368       
369    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
370    def test_farmer_quadratic_trivial_bundling_gurobi(self):
371        farmer_examples_dir = pysp_examples_dir + "farmer"
372        model_dir = farmer_examples_dir + os.sep + "models"
373        instance_dir = farmer_examples_dir + os.sep + "scenariodataWithTrivialBundles"
374        argstring = "runph --solver=gurobi --solver-manager=serial --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir
375        print "Testing command: " + argstring
376
377        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_trivial_bundling_gurobi.out")
378        args = string.split(argstring)
379        coopr.pysp.phinit.main(args=args)
380        pyutilib.misc.reset_redirect()
381        self.cleanup()
382        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_trivial_bundling_gurobi.out",this_test_file_directory+"farmer_quadratic_trivial_bundling_gurobi.baseline", filter=filter_time_and_data_dirs)
383
384    @unittest.skipIf(not ipopt_available, "The 'ipopt' executable is not available")
385    def test_farmer_quadratic_trivial_bundling_ipopt(self):
386        farmer_examples_dir = pysp_examples_dir + "farmer"
387        model_dir = farmer_examples_dir + os.sep + "models"
388        instance_dir = farmer_examples_dir + os.sep + "scenariodataWithTrivialBundles"
389        argstring = "runph --solver=ipopt --solver-manager=serial --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir
390        print "Testing command: " + argstring
391
392        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_trivial_bundling_ipopt.out")       
393        args = string.split(argstring)
394        coopr.pysp.phinit.main(args=args)
395        pyutilib.misc.reset_redirect()
396        self.cleanup()
397        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_trivial_bundling_ipopt.out",this_test_file_directory+"farmer_quadratic_trivial_bundling_ipopt.baseline", filter=filter_time_and_data_dirs, tolerance=1e-4)
398
399    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
400    def test_farmer_quadratic_basic_bundling_cplex(self):
401        farmer_examples_dir = pysp_examples_dir + "farmer"
402        model_dir = farmer_examples_dir + os.sep + "models"
403        instance_dir = farmer_examples_dir + os.sep + "scenariodataWithTwoBundles"
404        argstring = "runph --solver=cplex --solver-manager=serial --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir
405        print "Testing command: " + argstring
406
407        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_basic_bundling_cplex.out")
408        args = string.split(argstring)
409        coopr.pysp.phinit.main(args=args)
410        pyutilib.misc.reset_redirect()
411        self.cleanup()
412        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_basic_bundling_cplex.out",this_test_file_directory+"farmer_quadratic_basic_bundling_cplex.baseline", filter=filter_time_and_data_dirs)       
413
414    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
415    def test_farmer_quadratic_basic_bundling_gurobi(self):
416        farmer_examples_dir = pysp_examples_dir + "farmer"
417        model_dir = farmer_examples_dir + os.sep + "models"
418        instance_dir = farmer_examples_dir + os.sep + "scenariodataWithTwoBundles"
419        argstring = "runph --solver=gurobi --solver-manager=serial --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir
420        print "Testing command: " + argstring
421
422        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_basic_bundling_gurobi.out")       
423        args = string.split(argstring)
424        coopr.pysp.phinit.main(args=args)
425        pyutilib.misc.reset_redirect()
426        self.cleanup()
427        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_basic_bundling_gurobi.out",this_test_file_directory+"farmer_quadratic_basic_bundling_gurobi.baseline", filter=filter_time_and_data_dirs)       
428
429    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
430    def test_farmer_with_rent_quadratic_cplex(self):
431        farmer_examples_dir = pysp_examples_dir + "farmerWrent"
432        model_dir = farmer_examples_dir + os.sep + "models"
433        instance_dir = farmer_examples_dir + os.sep + "nodedata"
434        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
435        print "Testing command: " + argstring
436
437        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_with_rent_quadratic_cplex.out")
438        args = string.split(argstring)
439        coopr.pysp.phinit.main(args=args)
440        pyutilib.misc.reset_redirect()
441        self.cleanup()
442        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_with_rent_quadratic_cplex.out",this_test_file_directory+"farmer_with_rent_quadratic_cplex.baseline", filter=filter_time_and_data_dirs)
443
444    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
445    def test_farmer_with_rent_quadratic_gurobi(self):
446        farmer_examples_dir = pysp_examples_dir + "farmerWrent"
447        model_dir = farmer_examples_dir + os.sep + "models"
448        instance_dir = farmer_examples_dir + os.sep + "nodedata"
449        argstring = "runph --solver=gurobi --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
450        print "Testing command: " + argstring
451
452        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_with_rent_quadratic_gurobi.out")
453        args = string.split(argstring)
454        coopr.pysp.phinit.main(args=args)
455        pyutilib.misc.reset_redirect()
456        self.cleanup()
457        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_with_rent_quadratic_gurobi.out",this_test_file_directory+"farmer_with_rent_quadratic_gurobi.baseline", filter=filter_time_and_data_dirs)
458
459    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
460    def test_linearized_farmer_cplex(self):
461        if cplex_available:
462            solver_string="cplex"
463        farmer_examples_dir = pysp_examples_dir + "farmer"
464        model_dir = farmer_examples_dir + os.sep + "models"
465        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
466        argstring = "runph --solver="+solver_string+" --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
467        print "Testing command: " + argstring
468
469        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_linearized_cplex.out")
470        args = string.split(argstring)
471        coopr.pysp.phinit.main(args=args)
472        pyutilib.misc.reset_redirect()
473        self.cleanup()
474        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_linearized_cplex.out",this_test_file_directory+"farmer_linearized_cplex.baseline", filter=filter_time_and_data_dirs)
475
476    @unittest.skipIf(not cbc_available, "The 'cbc' executable is not available")
477    def test_linearized_farmer_cbc(self):
478        if cbc_available:
479            solver_string="cbc"
480        farmer_examples_dir = pysp_examples_dir + "farmer"
481        model_dir = farmer_examples_dir + os.sep + "models"
482        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
483        argstring = "runph --solver="+solver_string+" --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
484        print "Testing command: " + argstring
485
486        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_linearized_cbc.out")
487        args = string.split(argstring)
488        coopr.pysp.phinit.main(args=args)
489        pyutilib.misc.reset_redirect()
490        self.cleanup()
491        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_linearized_cbc.out",this_test_file_directory+"farmer_linearized_cbc.baseline", filter=filter_time_and_data_dirs)
492
493    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
494    def test_linearized_farmer_maximize_cplex(self):
495        if cplex_available:
496            solver_string="cplex"
497        farmer_examples_dir = pysp_examples_dir + "farmer"
498        model_dir = farmer_examples_dir + os.sep + "maxmodels"
499        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
500        argstring = "runph --solver="+solver_string+" --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
501        print "Testing command: " + argstring
502
503        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_maximize_linearized_cplex.out")
504        args = string.split(argstring)
505        coopr.pysp.phinit.main(args=args)
506        pyutilib.misc.reset_redirect()
507        self.cleanup()
508        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_maximize_linearized_cplex.out",this_test_file_directory+"farmer_maximize_linearized_cplex.baseline", filter=filter_time_and_data_dirs)       
509
510    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
511    def test_linearized_farmer_gurobi(self):
512        if gurobi_available:
513            solver_string="gurobi"
514        farmer_examples_dir = pysp_examples_dir + "farmer"
515        model_dir = farmer_examples_dir + os.sep + "models"
516        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
517        argstring = "runph --solver="+solver_string+" --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
518        print "Testing command: " + argstring
519
520        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_linearized_gurobi.out")
521        args = string.split(argstring)
522        coopr.pysp.phinit.main(args=args)
523        pyutilib.misc.reset_redirect()
524        self.cleanup()
525        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_linearized_gurobi.out",this_test_file_directory+"farmer_linearized_gurobi.baseline", filter=filter_time_and_data_dirs)
526
527    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
528    def test_linearized_farmer_maximize_gurobi(self):
529        if gurobi_available:
530            solver_string="gurobi"
531        farmer_examples_dir = pysp_examples_dir + "farmer"
532        model_dir = farmer_examples_dir + os.sep + "maxmodels"
533        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
534        argstring = "runph --solver="+solver_string+" --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
535        print "Testing command: " + argstring
536
537        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_maximize_linearized_gurobi.out")
538        args = string.split(argstring)
539        coopr.pysp.phinit.main(args=args)
540        pyutilib.misc.reset_redirect()
541        self.cleanup()
542        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_maximize_linearized_gurobi.out",this_test_file_directory+"farmer_maximize_linearized_gurobi.baseline", filter=filter_time_and_data_dirs)       
543
544    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
545    def test_linearized_farmer_nodedata_cplex(self):
546        if cplex_available:
547            solver_string="cplex"
548        farmer_examples_dir = pysp_examples_dir + "farmer"
549        model_dir = farmer_examples_dir + os.sep + "models"
550        instance_dir = farmer_examples_dir + os.sep + "nodedata"
551        argstring = "runph --solver="+solver_string+" --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
552        print "Testing command: " + argstring
553
554        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_linearized_nodedata_cplex.out")
555        args = string.split(argstring)
556        coopr.pysp.phinit.main(args=args)
557        pyutilib.misc.reset_redirect()
558        self.cleanup()
559        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_linearized_nodedata_cplex.out",this_test_file_directory+"farmer_linearized_nodedata_cplex.baseline", filter=filter_time_and_data_dirs)
560
561    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
562    def test_linearized_farmer_nodedata_gurobi(self):
563        if gurobi_available:
564            solver_string="gurobi"
565        farmer_examples_dir = pysp_examples_dir + "farmer"
566        model_dir = farmer_examples_dir + os.sep + "models"
567        instance_dir = farmer_examples_dir + os.sep + "nodedata"
568        argstring = "runph --solver="+solver_string+" --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
569        print "Testing command: " + argstring
570
571        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_linearized_nodedata_gurobi.out")
572        args = string.split(argstring)
573        coopr.pysp.phinit.main(args=args)
574        pyutilib.misc.reset_redirect()
575        self.cleanup()
576        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_linearized_nodedata_gurobi.out",this_test_file_directory+"farmer_linearized_nodedata_gurobi.baseline", filter=filter_time_and_data_dirs)
577
578    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
579    def test_quadratic_sizes3_cplex(self):
580        sizes_example_dir = pysp_examples_dir + "sizes"
581        model_dir = sizes_example_dir + os.sep + "models"
582        instance_dir = sizes_example_dir + os.sep + "SIZES3"
583        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
584                    " --max-iterations=40"+ \
585                    " --rho-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
586                    " --scenario-solver-options=mip_tolerances_integrality=1e-7"+ \
587                    " --enable-ww-extensions"+ \
588                    " --ww-extension-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.cfg"+ \
589                    " --ww-extension-suffixfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"
590        print "Testing command: " + argstring
591
592        pyutilib.misc.setup_redirect(this_test_file_directory+"sizes3_quadratic_cplex.out")
593        args = string.split(argstring)
594        coopr.pysp.phinit.main(args=args)
595        pyutilib.misc.reset_redirect()
596        self.cleanup()
597
598        [flag_a,lineno_a,diffs_a] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_quadratic_cplex.out", this_test_file_directory+"sizes3_quadratic_cplex.baseline-a", filter=filter_time_and_data_dirs)
599        [flag_b,lineno_b,diffs_b] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_quadratic_cplex.out", this_test_file_directory+"sizes3_quadratic_cplex.baseline-b", filter=filter_time_and_data_dirs)
600        if (not flag_a) and (not flag_b):
601            self.fail("Differences identified relative to all baseline output file alternatives")               
602
603    @unittest.skipIf(not cplex_direct_available, "The 'cplex' python solver is not available")
604    def test_quadratic_sizes3_cplex_direct(self):
605        sizes_example_dir = pysp_examples_dir + "sizes"
606        model_dir = sizes_example_dir + os.sep + "models"
607        instance_dir = sizes_example_dir + os.sep + "SIZES3"
608        argstring = "runph --solver=cplex --solver-io=python --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
609                    " --max-iterations=40"+ \
610                    " --rho-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
611                    " --scenario-solver-options=mip_tolerances_integrality=1e-7"+ \
612                    " --enable-ww-extensions"+ \
613                    " --ww-extension-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.cfg"+ \
614                    " --ww-extension-suffixfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"
615        print "Testing command: " + argstring
616
617        pyutilib.misc.setup_redirect(this_test_file_directory+"sizes3_quadratic_cplex_direct.out")
618        args = string.split(argstring)
619        coopr.pysp.phinit.main(args=args)
620        pyutilib.misc.reset_redirect()
621        self.cleanup()
622        self.assertFileEqualsBaseline(this_test_file_directory+"sizes3_quadratic_cplex_direct.out",this_test_file_directory+"sizes3_quadratic_cplex_direct.baseline", filter=filter_time_and_data_dirs)       
623
624    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
625    def test_quadratic_sizes3_gurobi(self):
626        sizes_example_dir = pysp_examples_dir + "sizes"
627        model_dir = sizes_example_dir + os.sep + "models"
628        instance_dir = sizes_example_dir + os.sep + "SIZES3"
629        argstring = "runph --solver=gurobi --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
630                    " --max-iterations=40"+ \
631                    " --rho-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
632                    " --scenario-solver-options=mip_tolerances_integrality=1e-7"+ \
633                    " --enable-ww-extensions"+ \
634                    " --ww-extension-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.cfg"+ \
635                    " --ww-extension-suffixfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"
636        print "Testing command: " + argstring
637
638        pyutilib.misc.setup_redirect(this_test_file_directory+"sizes3_quadratic_gurobi.out")
639        args = string.split(argstring)
640        coopr.pysp.phinit.main(args=args)
641        pyutilib.misc.reset_redirect()
642        self.cleanup()
643
644        if os.sys.platform == "darwin":
645            [flag_a,lineno_a,diffs_a] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_quadratic_gurobi.out", this_test_file_directory+"sizes3_quadratic_gurobi_darwin.baseline-a", filter=filter_time_and_data_dirs)
646            [flag_b,lineno_b,diffs_b] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_quadratic_gurobi.out", this_test_file_directory+"sizes3_quadratic_gurobi_darwin.baseline-b", filter=filter_time_and_data_dirs)
647            if (not flag_a) and (not flag_b):
648                self.fail("Differences identified relative to all baseline output file alternatives")               
649        else:
650
651            [flag_a,lineno_a,diffs_a] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_quadratic_gurobi.out", this_test_file_directory+"sizes3_quadratic_gurobi.baseline-a", filter=filter_time_and_data_dirs)
652            [flag_b,lineno_b,diffs_b] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_quadratic_gurobi.out", this_test_file_directory+"sizes3_quadratic_gurobi.baseline-b", filter=filter_time_and_data_dirs)
653            if (not flag_a) and (not flag_b):
654                self.fail("Differences identified relative to all baseline output file alternatives")               
655
656    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
657    def test_sizes10_quadratic_twobundles_cplex(self):
658        sizes_example_dir = pysp_examples_dir + "sizes"
659        model_dir = sizes_example_dir + os.sep + "models"
660        instance_dir = sizes_example_dir + os.sep + "SIZES10WithTwoBundles"
661        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
662                    " --max-iterations=10"
663        print "Testing command: " + argstring       
664
665        pyutilib.misc.setup_redirect(this_test_file_directory+"sizes10_quadratic_twobundles_cplex.out")       
666        args = string.split(argstring)
667        coopr.pysp.phinit.main(args=args)
668        pyutilib.misc.reset_redirect()
669        self.cleanup()
670        self.assertFileEqualsBaseline(this_test_file_directory+"sizes10_quadratic_twobundles_cplex.out",this_test_file_directory+"sizes10_quadratic_twobundles_cplex.baseline", filter=filter_time_and_data_dirs)           
671
672    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
673    def test_sizes10_quadratic_twobundles_gurobi(self):
674        sizes_example_dir = pysp_examples_dir + "sizes"
675        model_dir = sizes_example_dir + os.sep + "models"
676        instance_dir = sizes_example_dir + os.sep + "SIZES10WithTwoBundles"
677        argstring = "runph --solver=gurobi --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
678                    " --max-iterations=10"
679        print "Testing command: " + argstring               
680
681        pyutilib.misc.setup_redirect(this_test_file_directory+"sizes10_quadratic_twobundles_gurobi.out")       
682        args = string.split(argstring)
683        coopr.pysp.phinit.main(args=args)
684        pyutilib.misc.reset_redirect()
685        self.cleanup()
686        if os.sys.platform == "darwin":
687            self.assertFileEqualsBaseline(this_test_file_directory+"sizes10_quadratic_twobundles_gurobi.out",this_test_file_directory+"sizes10_quadratic_twobundles_gurobi_darwin.baseline", filter=filter_time_and_data_dirs)                       
688        else:
689            self.assertFileEqualsBaseline(this_test_file_directory+"sizes10_quadratic_twobundles_gurobi.out",this_test_file_directory+"sizes10_quadratic_twobundles_gurobi.baseline", filter=filter_time_and_data_dirs)                       
690
691    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
692    def test_quadratic_networkflow1ef10_cplex(self):
693        networkflow_example_dir = pysp_examples_dir + "networkflow"
694        model_dir = networkflow_example_dir + os.sep + "models"
695        instance_dir = networkflow_example_dir + os.sep + "1ef10"
696        argstring = "runph --solver=cplex --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
697                    " --max-iterations=100"+ \
698                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
699                    " --enable-ww-extensions"+ \
700                    " --ww-extension-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph-immediatefixing.cfg"
701        print "Testing command: " + argstring
702
703        pyutilib.misc.setup_redirect(this_test_file_directory+"networkflow1ef10_quadratic_cplex.out")
704        args = string.split(argstring)
705        coopr.pysp.phinit.main(args=args)
706        pyutilib.misc.reset_redirect()
707        self.cleanup()
708
709        if os.sys.platform == "darwin":
710            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_quadratic_cplex.out",this_test_file_directory+"networkflow1ef10_quadratic_cplex_darwin.baseline", filter=filter_time_and_data_dirs)
711        else:
712            [flag_a,lineno_a,diffs_a] = pyutilib.misc.compare_file(this_test_file_directory+"networkflow1ef10_quadratic_cplex.out", this_test_file_directory+"networkflow1ef10_quadratic_cplex.baseline-a", filter=filter_time_and_data_dirs)
713            [flag_b,lineno_b,diffs_b] = pyutilib.misc.compare_file(this_test_file_directory+"networkflow1ef10_quadratic_cplex.out", this_test_file_directory+"networkflow1ef10_quadratic_cplex.baseline-b", filter=filter_time_and_data_dirs)
714            if (not flag_a) and (not flag_b):
715                self.fail("Differences identified relative to all baseline output file alternatives")               
716
717    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
718    def test_quadratic_networkflow1ef10_gurobi(self):
719        networkflow_example_dir = pysp_examples_dir + "networkflow"
720        model_dir = networkflow_example_dir + os.sep + "models"
721        instance_dir = networkflow_example_dir + os.sep + "1ef10"
722        argstring = "runph --solver=gurobi --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
723                    " --max-iterations=100"+ \
724                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
725                    " --enable-ww-extensions"+ \
726                    " --ww-extension-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph-immediatefixing.cfg"
727        print "Testing command: " + argstring
728
729        pyutilib.misc.setup_redirect(this_test_file_directory+"networkflow1ef10_quadratic_gurobi.out")
730        args = string.split(argstring)
731        coopr.pysp.phinit.main(args=args)
732        pyutilib.misc.reset_redirect()
733        self.cleanup()
734
735        if os.sys.platform == "darwin":
736            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_quadratic_gurobi.out",this_test_file_directory+"networkflow1ef10_quadratic_gurobi_darwin.baseline", filter=filter_time_and_data_dirs)
737        else:
738            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_quadratic_gurobi.out",this_test_file_directory+"networkflow1ef10_quadratic_gurobi.baseline", filter=filter_time_and_data_dirs)
739
740    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
741    def test_linearized_networkflow1ef10_cplex(self):
742        networkflow_example_dir = pysp_examples_dir + "networkflow"
743        model_dir = networkflow_example_dir + os.sep + "models"
744        instance_dir = networkflow_example_dir + os.sep + "1ef10"
745        argstring = "runph --solver=cplex --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
746                    " --max-iterations=10"+ \
747                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
748                    " --linearize-nonbinary-penalty-terms=8"+ \
749                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg"
750        print "Testing command: " + argstring
751
752        pyutilib.misc.setup_redirect(this_test_file_directory+"networkflow1ef10_linearized_cplex.out")
753        args = string.split(argstring)
754        coopr.pysp.phinit.main(args=args)
755        pyutilib.misc.reset_redirect()
756        self.cleanup()
757
758        if os.sys.platform == "darwin":
759            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_linearized_cplex.out",this_test_file_directory+"networkflow1ef10_linearized_cplex_darwin.baseline", filter=filter_time_and_data_dirs)
760        else:
761            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_linearized_cplex.out",this_test_file_directory+"networkflow1ef10_linearized_cplex.baseline", filter=filter_time_and_data_dirs)
762
763    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
764    def test_linearized_networkflow1ef10_gurobi(self):
765        networkflow_example_dir = pysp_examples_dir + "networkflow"
766        model_dir = networkflow_example_dir + os.sep + "models"
767        instance_dir = networkflow_example_dir + os.sep + "1ef10"
768        argstring = "runph --solver=gurobi --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
769                    " --max-iterations=10"+ \
770                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
771                    " --linearize-nonbinary-penalty-terms=8"+ \
772                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg"
773        print "Testing command: " + argstring
774
775        pyutilib.misc.setup_redirect(this_test_file_directory+"networkflow1ef10_linearized_gurobi.out")
776        args = string.split(argstring)
777        coopr.pysp.phinit.main(args=args)
778        pyutilib.misc.reset_redirect()
779        self.cleanup()
780
781        if os.sys.platform == "darwin":
782            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_linearized_gurobi.out",this_test_file_directory+"networkflow1ef10_linearized_gurobi_darwin.baseline", filter=filter_time_and_data_dirs)
783        else:
784            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_linearized_gurobi.out",this_test_file_directory+"networkflow1ef10_linearized_gurobi.baseline", filter=filter_time_and_data_dirs)
785
786    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
787    def test_linearized_forestry_cplex(self):
788        forestry_example_dir = pysp_examples_dir + "forestry"
789        model_dir = forestry_example_dir + os.sep + "models-nb-yr"
790        instance_dir = forestry_example_dir + os.sep + "18scenarios"
791        argstring = "runph --solver=cplex --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
792                    " --max-iterations=10" + " --scenario-mipgap=0.05" + " --default-rho=0.001" + \
793                    " --rho-cfgfile="+forestry_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
794                    " --linearize-nonbinary-penalty-terms=2"+ \
795                    " --bounds-cfgfile="+forestry_example_dir+os.sep+"config"+os.sep+"boundsetter.cfg" + \
796                    " --enable-ww-extension" + " --ww-extension-cfgfile="+forestry_example_dir+os.sep+"config"+os.sep+"wwph.cfg" + \
797                    " --ww-extension-suffixfile="+forestry_example_dir+os.sep+"config"+os.sep+"wwph-nb.suffixes" + \
798                    " --solve-ef"
799        print "Testing command: " + argstring
800
801        pyutilib.misc.setup_redirect(this_test_file_directory+"forestry_linearized_cplex.out")
802        args = string.split(argstring)
803        coopr.pysp.phinit.main(args=args)
804        pyutilib.misc.reset_redirect()
805        self.cleanup()
806
807        if os.sys.platform == "darwin":
808            self.assertFileEqualsBaseline(this_test_file_directory+"forestry_linearized_cplex.out",this_test_file_directory+"forestry_linearized_cplex_darwin.baseline", filter=filter_time_and_data_dirs)           
809        else:
810            [flag_a,lineno_a,diffs_a] = pyutilib.misc.compare_file(this_test_file_directory+"forestry_linearized_cplex.out", this_test_file_directory+"forestry_linearized_cplex.baseline-a", filter=filter_time_and_data_dirs)
811            [flag_b,lineno_b,diffs_b] = pyutilib.misc.compare_file(this_test_file_directory+"forestry_linearized_cplex.out", this_test_file_directory+"forestry_linearized_cplex.baseline-b", filter=filter_time_and_data_dirs)
812            if (not flag_a) and (not flag_b):
813                self.fail("Differences identified relative to all baseline output file alternatives")               
814
815    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
816    def test_linearized_forestry_gurobi(self):
817        forestry_example_dir = pysp_examples_dir + "forestry"
818        model_dir = forestry_example_dir + os.sep + "models-nb-yr"
819        instance_dir = forestry_example_dir + os.sep + "18scenarios"
820        argstring = "runph --solver=gurobi --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
821                    " --max-iterations=10" + " --scenario-mipgap=0.05" + " --default-rho=0.001" + \
822                    " --rho-cfgfile="+forestry_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
823                    " --linearize-nonbinary-penalty-terms=2"+ \
824                    " --bounds-cfgfile="+forestry_example_dir+os.sep+"config"+os.sep+"boundsetter.cfg" + \
825                    " --enable-ww-extension" + " --ww-extension-cfgfile="+forestry_example_dir+os.sep+"config"+os.sep+"wwph.cfg" + \
826                    " --ww-extension-suffixfile="+forestry_example_dir+os.sep+"config"+os.sep+"wwph-nb.suffixes" + \
827                    " --solve-ef"
828        print "Testing command: " + argstring
829
830        pyutilib.misc.setup_redirect(this_test_file_directory+"forestry_linearized_gurobi.out")
831        args = string.split(argstring)
832        coopr.pysp.phinit.main(args=args)
833        pyutilib.misc.reset_redirect()
834        self.cleanup()
835
836        if os.sys.platform == "darwin":
837            self.assertFileEqualsBaseline(this_test_file_directory+"forestry_linearized_gurobi.out",this_test_file_directory+"forestry_linearized_gurobi_darwin.baseline", filter=filter_time_and_data_dirs)
838        else:
839            self.assertFileEqualsBaseline(this_test_file_directory+"forestry_linearized_gurobi.out",this_test_file_directory+"forestry_linearized_gurobi.baseline", filter=filter_time_and_data_dirs)
840
841    def test_farmer_ef(self):
842        farmer_examples_dir = pysp_examples_dir + "farmer"
843        model_dir = farmer_examples_dir + os.sep + "models"
844        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
845        ef_output_file = this_test_file_directory+"test_farmer_ef.lp"
846        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file
847        print "Testing command: " + argstring
848
849        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_ef.out")
850        args = string.split(argstring)
851        coopr.pysp.ef_writer_script.main(args=args)
852        pyutilib.misc.reset_redirect()
853        self.cleanup()
854        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_ef.out",this_test_file_directory+"farmer_ef.baseline.out", filter=filter_time_and_data_dirs)
855        self.assertFileEqualsBaseline(ef_output_file,this_test_file_directory+"farmer_ef.baseline.lp")
856
857    def test_farmer_maximize_ef(self):
858        farmer_examples_dir = pysp_examples_dir + "farmer"
859        model_dir = farmer_examples_dir + os.sep + "maxmodels"
860        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
861        ef_output_file = this_test_file_directory+"farmer_maximize_ef.lp"
862        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file
863        print "Testing command: " + argstring
864
865        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_maximize_ef.out")
866        args = string.split(argstring)
867        coopr.pysp.ef_writer_script.main(args=args)
868        pyutilib.misc.reset_redirect()
869        self.cleanup()
870        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_maximize_ef.out",this_test_file_directory+"farmer_maximize_ef.baseline.out", filter=filter_time_and_data_dirs)
871        self.assertFileEqualsBaseline(ef_output_file,this_test_file_directory+"farmer_maximize_ef.baseline.lp")
872
873    def test_farmer_ef_with_flattened_expressions(self):
874        farmer_examples_dir = pysp_examples_dir + "farmer"
875        model_dir = farmer_examples_dir + os.sep + "models"
876        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
877        ef_output_file = this_test_file_directory+"test_farmer_ef_with_flattening.lp"
878        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file+" --flatten-expressions"
879        print "Testing command: " + argstring
880
881        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_ef_with_flattening.out")
882        args = string.split(argstring)
883        coopr.pysp.ef_writer_script.main(args=args)
884        pyutilib.misc.reset_redirect()
885        self.cleanup()
886        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_ef_with_flattening.out",this_test_file_directory+"farmer_ef_with_flattening.baseline.out", filter=filter_time_and_data_dirs)
887        self.assertFileEqualsBaseline(ef_output_file,this_test_file_directory+"farmer_ef_with_flattening.baseline.lp")
888
889    def test_farmer_piecewise_ef(self):
890        farmer_examples_dir = pysp_examples_dir + "farmerWpiecewise"
891        model_dir = farmer_examples_dir + os.sep + "models"
892        instance_dir = farmer_examples_dir + os.sep + "nodedata"
893        ef_output_file = this_test_file_directory+"test_farmer_piecewise_ef.lp"
894        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file
895        print "Testing command: " + argstring
896
897        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_piecewise_ef.out")
898        args = string.split(argstring)
899        coopr.pysp.ef_writer_script.main(args=args)
900        pyutilib.misc.reset_redirect()
901        self.cleanup()
902        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_piecewise_ef.out",this_test_file_directory+"farmer_piecewise_ef.baseline.out", filter=filter_time_and_data_dirs)
903        self.assertFileEqualsBaseline(ef_output_file,this_test_file_directory+"farmer_piecewise_ef.baseline.lp")
904
905    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
906    def test_farmer_ef_with_solve_cplex(self):
907        farmer_examples_dir = pysp_examples_dir + "farmer"
908        model_dir = farmer_examples_dir + os.sep + "models"
909        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
910        ef_output_file = this_test_file_directory+"test_farmer_with_solve_cplex.lp"
911        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file+" --solver=cplex --solve"
912        print "Testing command: " + argstring
913       
914        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_ef_with_solve_cplex.out")       
915        args = string.split(argstring)
916        coopr.pysp.ef_writer_script.main(args=args)
917        pyutilib.misc.reset_redirect()
918        self.cleanup()
919        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_ef_with_solve_cplex.out",this_test_file_directory+"farmer_ef_with_solve_cplex.baseline", filter=filter_time_and_data_dirs)
920
921    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
922    def test_farmer_maximize_ef_with_solve_cplex(self):
923        farmer_examples_dir = pysp_examples_dir + "farmer"
924        model_dir = farmer_examples_dir + os.sep + "maxmodels"
925        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
926        ef_output_file = this_test_file_directory+"test_farmer_maximize_with_solve_cplex.lp"
927        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file+" --solver=cplex --solve"
928        print "Testing command: " + argstring
929       
930        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_maximize_ef_with_solve_cplex.out")       
931        args = string.split(argstring)
932        coopr.pysp.ef_writer_script.main(args=args)
933        pyutilib.misc.reset_redirect()
934        self.cleanup()
935        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_maximize_ef_with_solve_cplex.out",this_test_file_directory+"farmer_maximize_ef_with_solve_cplex.baseline", filter=filter_time_and_data_dirs)
936
937    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
938    def test_farmer_ef_with_solve_gurobi(self):
939        farmer_examples_dir = pysp_examples_dir + "farmer"
940        model_dir = farmer_examples_dir + os.sep + "models"
941        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
942        ef_output_file = this_test_file_directory+"test_farmer_with_solve_gurobi.lp"
943        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file+" --solver=gurobi --solve"
944        print "Testing command: " + argstring
945       
946        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_ef_with_solve_gurobi.out")       
947        args = string.split(argstring)
948        coopr.pysp.ef_writer_script.main(args=args)
949        pyutilib.misc.reset_redirect()
950        self.cleanup()
951        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_ef_with_solve_gurobi.out",this_test_file_directory+"farmer_ef_with_solve_gurobi.baseline", filter=filter_time_and_data_dirs)
952
953    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
954    def test_farmer_maximize_ef_with_solve_gurobi(self):
955        farmer_examples_dir = pysp_examples_dir + "farmer"
956        model_dir = farmer_examples_dir + os.sep + "maxmodels"
957        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
958        ef_output_file = this_test_file_directory+"test_farmer_maximize_with_solve_gurobi.lp"
959        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file+" --solver=gurobi --solve"
960        print "Testing command: " + argstring
961       
962        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_maximize_ef_with_solve_gurobi.out")       
963        args = string.split(argstring)
964        coopr.pysp.ef_writer_script.main(args=args)
965        pyutilib.misc.reset_redirect()
966        self.cleanup()
967        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_maximize_ef_with_solve_gurobi.out",this_test_file_directory+"farmer_maximize_ef_with_solve_gurobi.baseline", filter=filter_time_and_data_dirs)
968
969    @unittest.skipIf(not ipopt_available, "The 'ipopt' executable is not available")
970    def test_farmer_ef_with_solve_ipopt(self):
971        farmer_examples_dir = pysp_examples_dir + "farmer"
972        model_dir = farmer_examples_dir + os.sep + "models"
973        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
974        ef_output_file = this_test_file_directory+"test_farmer_with_solve_ipopt.nl"
975        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file+" --solver=ipopt --solve"
976        print "Testing command: " + argstring
977       
978        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_ef_with_solve_ipopt.out")       
979        args = string.split(argstring)
980        coopr.pysp.ef_writer_script.main(args=args)
981        pyutilib.misc.reset_redirect()
982        self.cleanup()
983
984        if os.sys.platform == "darwin":
985           self.assertFileEqualsBaseline(this_test_file_directory+"farmer_ef_with_solve_ipopt.out",this_test_file_directory+"farmer_ef_with_solve_ipopt_darwin.baseline", filter=filter_time_and_data_dirs, tolerance=1e-4)               
986        else:
987           self.assertFileEqualsBaseline(this_test_file_directory+"farmer_ef_with_solve_ipopt.out",this_test_file_directory+"farmer_ef_with_solve_ipopt.baseline", filter=filter_time_and_data_dirs, tolerance=1e-4)               
988
989    def test_hydro_ef(self):
990        hydro_examples_dir = pysp_examples_dir + "hydro"
991        model_dir = hydro_examples_dir + os.sep + "models"
992        instance_dir = hydro_examples_dir + os.sep + "scenariodata"
993        ef_output_file = this_test_file_directory+"test_hydro_ef.lp"
994        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file
995        print "Testing command: " + argstring
996
997        pyutilib.misc.setup_redirect(this_test_file_directory+"hydro_ef.out")
998        args = string.split(argstring)
999        coopr.pysp.ef_writer_script.main(args=args)
1000        pyutilib.misc.reset_redirect()
1001        self.cleanup()
1002        self.assertFileEqualsBaseline(this_test_file_directory+"hydro_ef.out",this_test_file_directory+"hydro_ef.baseline.out", filter=filter_time_and_data_dirs)
1003        self.assertFileEqualsBaseline(ef_output_file,this_test_file_directory+"hydro_ef.baseline.lp")
1004
1005    def test_sizes3_ef(self):
1006        sizes3_examples_dir = pysp_examples_dir + "sizes"
1007        model_dir = sizes3_examples_dir + os.sep + "models"
1008        instance_dir = sizes3_examples_dir + os.sep + "SIZES3"
1009        ef_output_file = this_test_file_directory+"test_sizes3_ef.lp"
1010        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file
1011        print "Testing command: " + argstring
1012
1013        pyutilib.misc.setup_redirect(this_test_file_directory+"sizes3_ef.out")
1014        args = string.split(argstring)
1015        coopr.pysp.ef_writer_script.main(args=args)
1016        pyutilib.misc.reset_redirect()
1017        self.cleanup()
1018        self.assertFileEqualsBaseline(this_test_file_directory+"sizes3_ef.out",this_test_file_directory+"sizes3_ef.baseline.out", filter=filter_time_and_data_dirs)
1019        self.assertFileEqualsBaseline(ef_output_file,this_test_file_directory+"sizes3_ef.baseline.lp.gz")
1020
1021    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
1022    def test_sizes3_ef_with_solve_cplex(self):
1023        sizes3_examples_dir = pysp_examples_dir + "sizes"
1024        model_dir = sizes3_examples_dir + os.sep + "models"
1025        instance_dir = sizes3_examples_dir + os.sep + "SIZES3"
1026        ef_output_file = this_test_file_directory+"test_sizes3_ef.lp"
1027        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file+" --solver=cplex --solve"
1028        print "Testing command: " + argstring       
1029
1030        pyutilib.misc.setup_redirect(this_test_file_directory+"sizes3_ef_with_solve_cplex.out")       
1031        args = string.split(argstring)
1032        coopr.pysp.ef_writer_script.main(args=args)
1033        pyutilib.misc.reset_redirect()
1034        self.cleanup()
1035
1036        if os.sys.platform == "darwin":
1037            self.assertFileEqualsBaseline(this_test_file_directory+"sizes3_ef_with_solve_cplex.out",this_test_file_directory+"sizes3_ef_with_solve_cplex_darwin.baseline", filter=filter_time_and_data_dirs)               
1038        else:
1039            self.assertFileEqualsBaseline(this_test_file_directory+"sizes3_ef_with_solve_cplex.out",this_test_file_directory+"sizes3_ef_with_solve_cplex.baseline", filter=filter_time_and_data_dirs, tolerance=1e-4)               
1040
1041    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
1042    def test_sizes3_ef_with_solve_gurobi(self):
1043        sizes3_examples_dir = pysp_examples_dir + "sizes"
1044        model_dir = sizes3_examples_dir + os.sep + "models"
1045        instance_dir = sizes3_examples_dir + os.sep + "SIZES3"
1046        ef_output_file = this_test_file_directory+"test_sizes3_ef.lp"
1047        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file+" --solver=gurobi --solve"
1048        print "Testing command: " + argstring       
1049
1050        pyutilib.misc.setup_redirect(this_test_file_directory+"sizes3_ef_with_solve_gurobi.out")       
1051        args = string.split(argstring)
1052        coopr.pysp.ef_writer_script.main(args=args)
1053        pyutilib.misc.reset_redirect()
1054        self.cleanup()
1055
1056        if os.sys.platform == "darwin":
1057           self.assertFileEqualsBaseline(this_test_file_directory+"sizes3_ef_with_solve_gurobi.out",this_test_file_directory+"sizes3_ef_with_solve_gurobi_darwin.baseline", filter=filter_time_and_data_dirs)       
1058        else:
1059           self.assertFileEqualsBaseline(this_test_file_directory+"sizes3_ef_with_solve_gurobi.out",this_test_file_directory+"sizes3_ef_with_solve_gurobi.baseline", filter=filter_time_and_data_dirs)       
1060
1061    def test_forestry_ef(self):
1062        forestry_examples_dir = pysp_examples_dir + "forestry"
1063        model_dir = forestry_examples_dir + os.sep + "models-nb-yr"
1064        instance_dir = forestry_examples_dir + os.sep + "18scenarios"
1065        ef_output_file = this_test_file_directory+"test_forestry_ef.lp"
1066        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file
1067        print "Testing command: " + argstring
1068
1069        pyutilib.misc.setup_redirect(this_test_file_directory+"forestry_ef.out")
1070        args = string.split(argstring)
1071        coopr.pysp.ef_writer_script.main(args=args)
1072        pyutilib.misc.reset_redirect()
1073        self.cleanup()
1074        self.assertFileEqualsBaseline(this_test_file_directory+"forestry_ef.out",this_test_file_directory+"forestry_ef.baseline.out", filter=filter_time_and_data_dirs)
1075        self.assertFileEqualsBaseline(ef_output_file,this_test_file_directory+"forestry_ef.baseline.lp.gz")
1076
1077    def test_networkflow1ef10_ef(self):
1078        networkflow1ef10_examples_dir = pysp_examples_dir + "networkflow"
1079        model_dir = networkflow1ef10_examples_dir + os.sep + "models"
1080        instance_dir = networkflow1ef10_examples_dir + os.sep + "1ef10"
1081        ef_output_file = this_test_file_directory+"test_networkflow1ef10_ef.lp"
1082        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file
1083        print "Testing command: " + argstring
1084
1085        pyutilib.misc.setup_redirect(this_test_file_directory+"networkflow1ef10_ef.out")
1086        args = string.split(argstring)
1087        coopr.pysp.ef_writer_script.main(args=args)
1088        pyutilib.misc.reset_redirect()
1089        self.cleanup()
1090        self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_ef.out",this_test_file_directory+"networkflow1ef10_ef.baseline.out", filter=filter_time_and_data_dirs)
1091        self.assertFileEqualsBaseline(ef_output_file,this_test_file_directory+"networkflow1ef10_ef.baseline.lp.gz")
1092
1093    def test_farmer_ef_cvar(self):
1094        farmer_examples_dir = pysp_examples_dir + "farmer"
1095        model_dir = farmer_examples_dir + os.sep + "models"
1096        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1097        ef_output_file = this_test_file_directory+"test_farmer_ef_cvar.lp"
1098        argstring = "runef --verbose --generate-weighted-cvar --risk-alpha=0.90 --cvar-weight=0.0 --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file
1099        print "Testing command: " + argstring
1100
1101        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_ef_cvar.out")
1102        args = string.split(argstring)
1103        coopr.pysp.ef_writer_script.main(args=args)
1104        pyutilib.misc.reset_redirect()
1105        self.cleanup()
1106        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_ef_cvar.out",this_test_file_directory+"farmer_ef_cvar.baseline.out", filter=filter_time_and_data_dirs)
1107        self.assertFileEqualsBaseline(ef_output_file,this_test_file_directory+"farmer_ef_cvar.baseline.lp")
1108
1109class TestPHParallel(unittest.TestCase):
1110
1111    def cleanup(self):
1112
1113        # IMPT: This step is key, as Python keys off the name of the module, not the location.
1114        #       So, different reference models in different directories won't be detected.
1115        #       If you don't do this, the symptom is a model that doesn't have the attributes
1116        #       that the data file expects.
1117        if "ReferenceModel" in sys.modules:
1118            del sys.modules["ReferenceModel"]
1119
1120    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1121    def test_farmer_quadratic_cplex_with_pyro(self):
1122        farmer_examples_dir = pysp_examples_dir + "farmer"
1123        model_dir = farmer_examples_dir + os.sep + "models"
1124        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1125        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 1 pyro_mip_server : -np 1 runph --solver=cplex --solver-manager=pyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_quadratic_cplex_with_pyro.out"
1126        print "Testing command: " + argstring
1127
1128        os.system(argstring)
1129        self.cleanup()
1130        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_cplex_with_pyro.out",this_test_file_directory+"farmer_quadratic_cplex_with_pyro.baseline", filter=filter_pyro)
1131
1132    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1133    def test_farmer_quadratic_cplex_with_phpyro(self):
1134        farmer_examples_dir = pysp_examples_dir + "farmer"
1135        model_dir = farmer_examples_dir + os.sep + "models"
1136        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1137        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : -np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_quadratic_cplex_with_phpyro.out"
1138        print "Testing command: " + argstring
1139
1140        os.system(argstring)
1141        self.cleanup()
1142        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_cplex_with_phpyro.out",this_test_file_directory+"farmer_quadratic_cplex_with_phpyro.baseline", filter=filter_pyro)
1143
1144    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1145    def test_farmer_quadratic_with_bundles_cplex_with_pyro(self):
1146        farmer_examples_dir = pysp_examples_dir + "farmer"
1147        model_dir = farmer_examples_dir + os.sep + "models"
1148        instance_dir = farmer_examples_dir + os.sep + "scenariodataWithTwoBundles"
1149        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 1 pyro_mip_server : -np 1 runph --solver=cplex --solver-manager=pyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_quadratic_with_bundles_cplex_with_pyro.out"
1150        print "Testing command: " + argstring
1151
1152        os.system(argstring)
1153        self.cleanup()
1154        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_with_bundles_cplex_with_pyro.out",this_test_file_directory+"farmer_quadratic_with_bundles_cplex_with_pyro.baseline", filter=filter_pyro)
1155
1156    @unittest.skipIf(not gurobi_available or not mpirun_available, "Either the 'gurobi' executable is not available or the 'mpirun' executable is not available")
1157    def test_farmer_quadratic_gurobi_with_phpyro(self):
1158        farmer_examples_dir = pysp_examples_dir + "farmer"
1159        model_dir = farmer_examples_dir + os.sep + "models"
1160        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1161        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : -np 1 runph --solver=gurobi --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_quadratic_gurobi_with_phpyro.out"
1162        print "Testing command: " + argstring
1163
1164        os.system(argstring)
1165        self.cleanup()
1166        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_gurobi_with_phpyro.out",this_test_file_directory+"farmer_quadratic_gurobi_with_phpyro.baseline", filter=filter_pyro)
1167
1168    @unittest.skipIf(not gurobi_available or not mpirun_available, "Either the 'gurobi' executable is not available or the 'mpirun' executable is not available")
1169    def test_farmer_linearized_gurobi_with_phpyro(self):
1170        farmer_examples_dir = pysp_examples_dir + "farmer"
1171        model_dir = farmer_examples_dir + os.sep + "models"
1172        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1173        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : -np 1 runph --linearize-nonbinary-penalty-terms=10 --solver=gurobi --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_linearized_gurobi_with_phpyro.out"
1174        print "Testing command: " + argstring
1175
1176        os.system(argstring)
1177        self.cleanup()
1178        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_linearized_gurobi_with_phpyro.out",this_test_file_directory+"farmer_linearized_gurobi_with_phpyro.baseline", filter=filter_pyro)
1179
1180    @unittest.skipIf(not ipopt_available or not mpirun_available, "Either the 'ipopt' executable is not available or the 'mpirun' executable is not available")
1181    def test_farmer_quadratic_ipopt_with_pyro(self):
1182        farmer_examples_dir = pysp_examples_dir + "farmer"
1183        model_dir = farmer_examples_dir + os.sep + "models"
1184        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1185        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 1 pyro_mip_server : -np 1 runph --solver=ipopt --solver-manager=pyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_quadratic_ipopt_with_pyro.out"
1186        print "Testing command: " + argstring
1187
1188        os.system(argstring)
1189        self.cleanup()
1190        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_ipopt_with_pyro.out",this_test_file_directory+"farmer_quadratic_ipopt_with_pyro.baseline", filter=filter_pyro, tolerance=1e-4)
1191
1192    @unittest.skipIf(not ipopt_available or not mpirun_available, "Either the 'ipopt' executable is not available or the 'mpirun' executable is not available")
1193    def test_farmer_quadratic_ipopt_with_phpyro(self):
1194        farmer_examples_dir = pysp_examples_dir + "farmer"
1195        model_dir = farmer_examples_dir + os.sep + "models"
1196        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1197        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : -np 1 runph --solver=ipopt --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_quadratic_ipopt_with_phpyro.out"
1198        print "Testing command: " + argstring
1199
1200        os.system(argstring)
1201        self.cleanup()
1202        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_ipopt_with_phpyro.out",this_test_file_directory+"farmer_quadratic_ipopt_with_phpyro.baseline", filter=filter_pyro, tolerance=1e-4)
1203
1204    @unittest.skipIf(not ipopt_available or not mpirun_available, "Either the 'ipopt' executable is not available or the 'mpirun' executable is not available")
1205    def test_farmer_linearized_ipopt_with_phpyro(self):
1206        farmer_examples_dir = pysp_examples_dir + "farmer"
1207        model_dir = farmer_examples_dir + os.sep + "models"
1208        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1209        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : -np 1 runph --linearize-nonbinary-penalty-terms=10 --solver=ipopt --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_linearized_ipopt_with_phpyro.out"
1210        print "Testing command: " + argstring
1211
1212        os.system(argstring)
1213        self.cleanup()
1214        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_linearized_ipopt_with_phpyro.out",this_test_file_directory+"farmer_linearized_ipopt_with_phpyro.baseline", filter=filter_pyro, tolerance=1e-4)
1215
1216    @unittest.skipIf(not ipopt_available or not mpirun_available, "Either the 'ipopt' executable is not available or the 'mpirun' executable is not available")
1217    def test_farmer_quadratic_trivial_bundling_ipopt_with_phpyro(self):
1218        farmer_examples_dir = pysp_examples_dir + "farmer"
1219        model_dir = farmer_examples_dir + os.sep + "models"
1220        instance_dir = farmer_examples_dir + os.sep + "scenariodataWithTrivialBundles"
1221        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : -np 1 runph --solver=ipopt --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_quadratic_trivial_bundling_ipopt_with_phpyro.out"
1222        print "Testing command: " + argstring
1223
1224        os.system(argstring)
1225        self.cleanup()
1226        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_trivial_bundling_ipopt_with_phpyro.out",this_test_file_directory+"farmer_quadratic_trivial_bundling_ipopt_with_phpyro.baseline", filter=filter_pyro)
1227
1228    @unittest.skipIf(not ipopt_available or not mpirun_available, "Either the 'ipopt' executable is not available or the 'mpirun' executable is not available")
1229    def test_farmer_quadratic_bundling_ipopt_with_phpyro(self):
1230        farmer_examples_dir = pysp_examples_dir + "farmer"
1231        model_dir = farmer_examples_dir + os.sep + "models"
1232        instance_dir = farmer_examples_dir + os.sep + "scenariodataWithTwoBundles"
1233        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 2 phsolverserver : -np 1 runph --solver=ipopt --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_quadratic_bundling_ipopt_with_phpyro.out"
1234        print "Testing command: " + argstring
1235
1236        os.system(argstring)
1237        self.cleanup()
1238        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_bundling_ipopt_with_phpyro.out",this_test_file_directory+"farmer_quadratic_bundling_ipopt_with_phpyro.baseline", filter=filter_pyro, tolerance=1e-4)
1239
1240    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1241    def test_quadratic_sizes3_cplex_with_phpyro(self):
1242        sizes_example_dir = pysp_examples_dir + "sizes"
1243        model_dir = sizes_example_dir + os.sep + "models"
1244        instance_dir = sizes_example_dir + os.sep + "SIZES3"       
1245        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : " + \
1246                    " -np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1247                    " --max-iterations=40"+ \
1248                    " --rho-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
1249                    " --scenario-solver-options=mip_tolerances_integrality=1e-7"+ \
1250                    " --enable-ww-extensions"+ \
1251                    " --ww-extension-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.cfg"+ \
1252                    " --ww-extension-suffixfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"+ \
1253                    " >& "+this_test_file_directory+"sizes3_quadratic_cplex_with_phpyro.out"
1254        print "Testing command: " + argstring
1255
1256        os.system(argstring)       
1257        self.cleanup()
1258
1259        if os.sys.platform == "darwin":
1260            self.assertFileEqualsBaseline(this_test_file_directory+"sizes3_quadratic_cplex_with_phpyro.out",this_test_file_directory+"sizes3_quadratic_cplex_with_phpyro_darwin.baseline", filter=filter_pyro)
1261        else:
1262            [flag_a,lineno_a,diffs_a] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_quadratic_cplex_with_phpyro.out", this_test_file_directory+"sizes3_quadratic_cplex_with_phpyro.baseline-a", filter=filter_pyro)
1263            [flag_b,lineno_b,diffs_b] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_quadratic_cplex_with_phpyro.out", this_test_file_directory+"sizes3_quadratic_cplex_with_phpyro.baseline-b", filter=filter_pyro)
1264            if (not flag_a) and (not flag_b):
1265                self.fail("Differences identified relative to all baseline output file alternatives")               
1266           
1267            self.assertFileEqualsBaseline(this_test_file_directory+"sizes3_quadratic_cplex_with_phpyro.out",this_test_file_directory+"sizes3_quadratic_cplex_with_phpyro.baseline", filter=filter_pyro)
1268
1269    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1270    def test_farmer_with_integers_quadratic_cplex_with_pyro_with_postef_solve(self):
1271        farmer_examples_dir = pysp_examples_dir + "farmerWintegers"
1272        model_dir = farmer_examples_dir + os.sep + "models"
1273        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1274        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 1 pyro_mip_server : -np 1 runph --max-iterations=10 --solve-ef --solver=cplex --solver-manager=pyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_with_integers_quadratic_cplex_with_pyro_with_postef_solve.out"
1275        print "Testing command: " + argstring
1276
1277        os.system(argstring)
1278        self.cleanup()
1279        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_with_integers_quadratic_cplex_with_pyro_with_postef_solve.out",this_test_file_directory+"farmer_with_integers_quadratic_cplex_with_pyro_with_postef_solve.baseline", filter=filter_pyro)                   
1280
1281    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1282    def test_linearized_sizes3_cplex_with_phpyro(self):
1283        sizes_example_dir = pysp_examples_dir + "sizes"
1284        model_dir = sizes_example_dir + os.sep + "models"
1285        instance_dir = sizes_example_dir + os.sep + "SIZES3"       
1286        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : " + \
1287                    " -np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1288                    " --max-iterations=10"+ \
1289                    " --rho-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
1290                    " --scenario-solver-options=mip_tolerances_integrality=1e-7"+ \
1291                    " --enable-ww-extensions"+ \
1292                    " --ww-extension-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.cfg"+ \
1293                    " --ww-extension-suffixfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"+ \
1294                    " --linearize-nonbinary-penalty-terms=4" + \
1295                    " >& "+this_test_file_directory+"sizes3_linearized_cplex_with_phpyro.out"
1296        print "Testing command: " + argstring
1297
1298        os.system(argstring)       
1299        self.cleanup()
1300
1301        if os.sys.platform == "darwin":
1302            self.assertFileEqualsBaseline(this_test_file_directory+"sizes3_linearized_cplex_with_phpyro.out",this_test_file_directory+"sizes3_linearized_cplex_with_phpyro_darwin.baseline", filter=filter_pyro)       
1303        else:
1304            [flag_a,lineno_a,diffs_a] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_linearized_cplex_with_phpyro.out", this_test_file_directory+"sizes3_linearized_cplex_with_phpyro.baseline-a", filter=filter_pyro)
1305            [flag_b,lineno_b,diffs_b] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_linearized_cplex_with_phpyro.out", this_test_file_directory+"sizes3_linearized_cplex_with_phpyro.baseline-b", filter=filter_pyro)
1306            if (not flag_a) and (not flag_b):
1307                self.fail("Differences identified relative to all baseline output file alternatives")               
1308    @unittest.skipIf(not gurobi_available or not mpirun_available, "Either the 'gurobi' executable is not available or the 'mpirun' executable is not available")
1309    def test_quadratic_sizes3_gurobi_with_phpyro(self):
1310        sizes_example_dir = pysp_examples_dir + "sizes"
1311        model_dir = sizes_example_dir + os.sep + "models"
1312        instance_dir = sizes_example_dir + os.sep + "SIZES3"       
1313        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : " + \
1314                    " -np 1 runph --solver=gurobi --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1315                    " --max-iterations=40"+ \
1316                    " --rho-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
1317                    " --scenario-solver-options=mip_tolerances_integrality=1e-7"+ \
1318                    " --enable-ww-extensions"+ \
1319                    " --ww-extension-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.cfg"+ \
1320                    " --ww-extension-suffixfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"+ \
1321                    " >& "+this_test_file_directory+"sizes3_quadratic_gurobi_with_phpyro.out"
1322        print "Testing command: " + argstring
1323
1324        os.system(argstring)       
1325        self.cleanup()
1326
1327        if os.sys.platform == "darwin":
1328            [flag_a,lineno_a,diffs_a] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_quadratic_gurobi_with_phpyro.out", this_test_file_directory+"sizes3_quadratic_gurobi_with_phpyro_darwin.baseline-a", filter=filter_time_and_data_dirs)
1329            # TBD: We should see different baselines here (on darwin)       
1330            if (not flag_a):
1331                self.fail("Differences identified relative to all baseline output file alternatives")               
1332        else:
1333            [flag_a,lineno_a,diffs_a] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_quadratic_gurobi_with_phpyro.out", this_test_file_directory+"sizes3_quadratic_gurobi_with_phpyro.baseline-a", filter=filter_time_and_data_dirs)
1334            [flag_b,lineno_b,diffs_b] = pyutilib.misc.compare_file(this_test_file_directory+"sizes3_quadratic_gurobi_with_phpyro.out", this_test_file_directory+"sizes3_quadratic_gurobi_with_phpyro.baseline-b", filter=filter_time_and_data_dirs)
1335            if (not flag_a) and (not flag_b):
1336                self.fail("Differences identified relative to all baseline output file alternatives")               
1337
1338    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1339    def test_farmer_ef_with_solve_cplex_with_pyro(self):
1340        farmer_examples_dir = pysp_examples_dir + "farmer"
1341        model_dir = farmer_examples_dir + os.sep + "models"
1342        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1343        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 1 pyro_mip_server : -np 1 runef --verbose --solver=cplex --solver-manager=pyro --solve --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_ef_with_solve_cplex_with_pyro.out"
1344        print "Testing command: " + argstring
1345
1346        os.system(argstring)
1347        self.cleanup()
1348        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_ef_with_solve_cplex_with_pyro.out",this_test_file_directory+"farmer_ef_with_solve_cplex_with_pyro.baseline", filter=filter_pyro)               
1349
1350    # async PH with one pyro solver server should yield the same behavior as serial PH.
1351    @unittest.skipIf(not ipopt_available or not mpirun_available, "Either the 'ipopt' executable is not available or the 'mpirun' executable is not available")
1352    def test_farmer_quadratic_async_ipopt_with_pyro(self):
1353        farmer_examples_dir = pysp_examples_dir + "farmer"
1354        model_dir = farmer_examples_dir + os.sep + "models"
1355        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1356        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 1 pyro_mip_server : -np 1 runph --solver=ipopt --solver-manager=pyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_quadratic_async_ipopt_with_pyro.out"
1357        print "Testing command: " + argstring
1358
1359        os.system(argstring)
1360        self.cleanup()
1361        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_async_ipopt_with_pyro.out",this_test_file_directory+"farmer_quadratic_async_ipopt_with_pyro.baseline", filter=filter_pyro, tolerance=1e-4)
1362
1363    # async PH with one pyro solver server should yield the same behavior as serial PH.
1364    @unittest.skipIf(not gurobi_available or not mpirun_available, "Either the 'gurobi' executable is not available or the 'mpirun' executable is not available")
1365    def test_farmer_quadratic_async_gurobi_with_pyro(self):
1366        farmer_examples_dir = pysp_examples_dir + "farmer"
1367        model_dir = farmer_examples_dir + os.sep + "models"
1368        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1369        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 1 pyro_mip_server : -np 1 runph --solver=gurobi --solver-manager=pyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_quadratic_async_gurobi_with_pyro.out"
1370        print "Testing command: " + argstring
1371
1372        os.system(argstring)
1373        self.cleanup()
1374        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_quadratic_async_gurobi_with_pyro.out",this_test_file_directory+"farmer_quadratic_async_gurobi_with_pyro.baseline", filter=filter_pyro)
1375
1376    # async PH with one pyro solver server should yield the same behavior as serial PH.
1377    @unittest.skipIf(not gurobi_available or not mpirun_available, "Either the 'gurobi' executable is not available or the 'mpirun' executable is not available")
1378    def test_farmer_linearized_async_gurobi_with_pyro(self):
1379        farmer_examples_dir = pysp_examples_dir + "farmer"
1380        model_dir = farmer_examples_dir + os.sep + "models"
1381        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1382        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 1 pyro_mip_server : -np 1 runph --solver=gurobi --solver-manager=pyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10  "+" >& "+this_test_file_directory+"farmer_linearized_async_gurobi_with_pyro.out"
1383        print "Testing command: " + argstring
1384
1385        os.system(argstring)
1386        self.cleanup()
1387        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_linearized_async_gurobi_with_pyro.out",this_test_file_directory+"farmer_linearized_async_gurobi_with_pyro.baseline", filter=filter_pyro)
1388
1389    # async PH with one pyro solver server should yield the same behavior as serial PH.
1390    @unittest.skipIf(not ipopt_available or not mpirun_available, "Either the 'ipopt' executable is not available or the 'mpirun' executable is not available")
1391    def test_farmer_linearized_async_ipopt_with_pyro(self):
1392        farmer_examples_dir = pysp_examples_dir + "farmer"
1393        model_dir = farmer_examples_dir + os.sep + "models"
1394        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1395        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 1 pyro_mip_server : -np 1 runph --solver=ipopt --solver-manager=pyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10  "+" >& "+this_test_file_directory+"farmer_linearized_async_ipopt_with_pyro.out"
1396        print "Testing command: " + argstring
1397
1398        os.system(argstring)
1399        self.cleanup()
1400        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_linearized_async_ipopt_with_pyro.out",this_test_file_directory+"farmer_linearized_async_ipopt_with_pyro.baseline", filter=filter_pyro, tolerance=1e-4)
1401
1402    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1403    def test_farmer_with_integers_linearized_cplex_with_phpyro(self):
1404        farmer_examples_dir = pysp_examples_dir + "farmerWintegers"
1405        model_dir = farmer_examples_dir + os.sep + "models"
1406        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1407        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : -np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --linearize-nonbinary-penalty-terms=8 --model-directory="+model_dir+" --instance-directory="+instance_dir+" >& "+this_test_file_directory+"farmer_with_integers_linearized_cplex_with_phpyro.out"
1408        print "Testing command: " + argstring
1409
1410        os.system(argstring)
1411        self.cleanup()
1412        self.assertFileEqualsBaseline(this_test_file_directory+"farmer_with_integers_linearized_cplex_with_phpyro.out",this_test_file_directory+"farmer_with_integers_linearized_cplex_with_phpyro.baseline", filter=filter_pyro, tolerance=1e-4)       
1413
1414    # the primary objective of this test is to validate the bare minimum level of functionality on the PH solver server
1415    # end (solves and rho setting) - obviously should yield the same results as serial PH.
1416    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")   
1417    def test_simple_quadratic_networkflow1ef10_cplex_with_phpyro(self):
1418        networkflow_example_dir = pysp_examples_dir + "networkflow"
1419        model_dir = networkflow_example_dir + os.sep + "models"
1420        instance_dir = networkflow_example_dir + os.sep + "1ef10"
1421        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 10 phsolverserver : " + \
1422                    "-np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1423                    " --max-iterations=5"+ \
1424                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1425                    " >& "+this_test_file_directory+"networkflow1ef10_simple_quadratic_cplex_with_phpyro.out"
1426        print "Testing command: " + argstring
1427
1428        os.system(argstring)
1429        self.cleanup()
1430
1431        self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_simple_quadratic_cplex_with_phpyro.out",this_test_file_directory+"networkflow1ef10_simple_quadratic_cplex_with_phpyro.baseline", filter=filter_pyro)
1432
1433    # builds on the above test, to validate warm-start capabilities; by imposing a migap,
1434    # executions with and without warm-starts will arrive at different solutions.
1435    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")   
1436    def test_advanced_quadratic_networkflow1ef10_cplex_with_phpyro(self):
1437        networkflow_example_dir = pysp_examples_dir + "networkflow"
1438        model_dir = networkflow_example_dir + os.sep + "models"
1439        instance_dir = networkflow_example_dir + os.sep + "1ef10"
1440        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 10 phsolverserver : " + \
1441                    "-np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1442                    " --max-iterations=5"+ \
1443                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1444                    " --enable-ww-extensions"+ \
1445                    " --ww-extension-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph-mipgaponly.cfg" + \
1446                    " >& "+this_test_file_directory+"networkflow1ef10_advanced_quadratic_cplex_with_phpyro.out"
1447        print "Testing command: " + argstring
1448
1449        os.system(argstring)
1450        self.cleanup()
1451
1452        if os.sys.platform == "darwin":
1453            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_advanced_quadratic_cplex_with_phpyro.out",this_test_file_directory+"networkflow1ef10_advanced_quadratic_cplex_with_phpyro_darwin.baseline", filter=filter_pyro)
1454        else:
1455            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_advanced_quadratic_cplex_with_phpyro.out",this_test_file_directory+"networkflow1ef10_advanced_quadratic_cplex_with_phpyro.baseline", filter=filter_pyro)
1456
1457    @unittest.skipIf(not gurobi_available or not mpirun_available, "Either the 'gurobi' executable is not available or the 'mpirun' executable is not available")
1458    def test_linearized_networkflow1ef10_gurobi_with_phpyro(self):
1459        networkflow_example_dir = pysp_examples_dir + "networkflow"
1460        model_dir = networkflow_example_dir + os.sep + "models"
1461        instance_dir = networkflow_example_dir + os.sep + "1ef10"
1462        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 10 phsolverserver : " + \
1463                    "-np 1 runph --solver=gurobi --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1464                    " --max-iterations=10"+ \
1465                    " --enable-termdiff-convergence --termdiff-threshold=0.01" + \
1466                    " --enable-ww-extensions"+ \
1467                    " --ww-extension-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph-aggressivefixing.cfg"+ \
1468                    " --ww-extension-suffixfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"+ \
1469                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1470                    " --linearize-nonbinary-penalty-terms=8"+ \
1471                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg" + \
1472                    " >& "+this_test_file_directory+"networkflow1ef10_linearized_gurobi_with_phpyro.out"
1473        print "Testing command: " + argstring
1474
1475        os.system(argstring)
1476        self.cleanup()
1477
1478        if os.sys.platform == "darwin":
1479            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_linearized_gurobi_with_phpyro.out",this_test_file_directory+"networkflow1ef10_linearized_gurobi_with_phpyro_darwin.baseline", filter=filter_pyro)
1480        else:
1481            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_linearized_gurobi_with_phpyro.out",this_test_file_directory+"networkflow1ef10_linearized_gurobi_with_phpyro.baseline", filter=filter_pyro)
1482
1483    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1484    def test_simple_linearized_networkflow1ef3_cplex_with_phpyro(self):
1485        networkflow_example_dir = pysp_examples_dir + "networkflow"
1486        model_dir = networkflow_example_dir + os.sep + "models"
1487        instance_dir = networkflow_example_dir + os.sep + "1ef3"
1488        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : " + \
1489                    "-np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1490                    " --max-iterations=10"+ \
1491                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1492                    " --linearize-nonbinary-penalty-terms=4"+ \
1493                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg" + \
1494                    " >& "+this_test_file_directory+"networkflow1ef3_simple_linearized_cplex_with_phpyro.out"
1495        print "Testing command: " + argstring
1496
1497        os.system(argstring)
1498        self.cleanup()
1499
1500        if os.sys.platform == "darwin":
1501            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef3_simple_linearized_cplex_with_phpyro.out",this_test_file_directory+"networkflow1ef3_simple_linearized_cplex_with_phpyro_darwin.baseline", filter=filter_pyro)   
1502        else:
1503            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef3_simple_linearized_cplex_with_phpyro.out",this_test_file_directory+"networkflow1ef3_simple_linearized_cplex_with_phpyro.baseline", filter=filter_pyro)
1504           
1505
1506    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1507    def test_simple_linearized_networkflow1ef10_cplex_with_phpyro(self):
1508        networkflow_example_dir = pysp_examples_dir + "networkflow"
1509        model_dir = networkflow_example_dir + os.sep + "models"
1510        instance_dir = networkflow_example_dir + os.sep + "1ef10"
1511        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 10 phsolverserver : " + \
1512                    "-np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1513                    " --max-iterations=10"+ \
1514                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1515                    " --linearize-nonbinary-penalty-terms=8"+ \
1516                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg" + \
1517                    " >& "+this_test_file_directory+"networkflow1ef10_simple_linearized_cplex_with_phpyro.out"
1518        print "Testing command: " + argstring
1519
1520        os.system(argstring)
1521        self.cleanup()
1522
1523        self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_simple_linearized_cplex_with_phpyro.out",this_test_file_directory+"networkflow1ef10_simple_linearized_cplex_with_phpyro.baseline", filter=filter_pyro)
1524       
1525    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1526    def test_advanced_linearized_networkflow1ef10_cplex_with_phpyro(self):
1527        networkflow_example_dir = pysp_examples_dir + "networkflow"
1528        model_dir = networkflow_example_dir + os.sep + "models"
1529        instance_dir = networkflow_example_dir + os.sep + "1ef10"
1530        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 10 phsolverserver : " + \
1531                    "-np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1532                    " --max-iterations=10"+ \
1533                    " --enable-termdiff-convergence --termdiff-threshold=0.01" + \
1534                    " --enable-ww-extensions"+ \
1535                    " --ww-extension-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph-aggressivefixing.cfg"+ \
1536                    " --ww-extension-suffixfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"+ \
1537                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1538                    " --linearize-nonbinary-penalty-terms=8"+ \
1539                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg" + \
1540                    " >& "+this_test_file_directory+"networkflow1ef10_advanced_linearized_cplex_with_phpyro.out"
1541        print "Testing command: " + argstring
1542
1543        os.system(argstring)
1544        self.cleanup()
1545
1546        if os.sys.platform == "darwin":
1547            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_advanced_linearized_cplex_with_phpyro.out",this_test_file_directory+"networkflow1ef10_advanced_linearized_cplex_with_phpyro_darwin.baseline", filter=filter_pyro)
1548        else:
1549            self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_advanced_linearized_cplex_with_phpyro.out",this_test_file_directory+"networkflow1ef10_advanced_linearized_cplex_with_phpyro.baseline", filter=filter_pyro)
1550
1551    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1552    def test_linearized_networkflow1ef10_cplex_with_bundles_with_phpyro(self):
1553        networkflow_example_dir = pysp_examples_dir + "networkflow"
1554        model_dir = networkflow_example_dir + os.sep + "models"
1555        instance_dir = networkflow_example_dir + os.sep + "1ef10"
1556        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 5 phsolverserver : " + \
1557                    "-np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1558                    " --scenario-bundle-specification="+networkflow_example_dir+os.sep+"10scenario-bundle-specs/FiveBundles.dat" + \
1559                    " --max-iterations=10"+ \
1560                    " --enable-termdiff-convergence --termdiff-threshold=0.01" + \
1561                    " --enable-ww-extensions"+ \
1562                    " --ww-extension-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph-aggressivefixing.cfg"+ \
1563                    " --ww-extension-suffixfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"+ \
1564                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1565                    " --linearize-nonbinary-penalty-terms=8"+ \
1566                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg" + \
1567                    " >& "+this_test_file_directory+"networkflow1ef10_linearized_cplex_with_bundles_with_phpyro.out"
1568        print "Testing command: " + argstring
1569
1570        os.system(argstring)
1571        self.cleanup()
1572
1573        self.assertFileEqualsBaseline(this_test_file_directory+"networkflow1ef10_linearized_cplex_with_bundles_with_phpyro.out",this_test_file_directory+"networkflow1ef10_linearized_cplex_with_bundles_with_phpyro.baseline", filter=filter_pyro)                   
1574
1575TestPH = unittest.category('nightly', 'performance')(TestPH)
1576
1577TestPHParallel = unittest.category('parallel', 'performance')(TestPHParallel)
1578
1579if __name__ == "__main__":
1580    unittest.main()
Note: See TracBrowser for help on using the repository browser.