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

Last change on this file since 5842 was 5842, checked in by jwatson, 8 years ago

Adding alternative baseline for PySP test - encountered when moving some tests to carr.sandia.gov.

File size: 106.0 KB
RevLine 
[1339]1#
[1340]2# Get the directory where this script is defined, and where the baseline
3# files are located.
[1339]4#
5import os
6import sys
[2271]7import string
[1339]8from os.path import abspath, dirname
9sys.path.insert(0, dirname(dirname(abspath(__file__)))+"/../..")
[2267]10
[3346]11this_test_file_directory = dirname(abspath(__file__))+os.sep
[2275]12
[2267]13pysp_examples_dir = dirname(dirname(dirname(dirname(dirname(abspath(__file__))))))+os.sep+"examples"+os.sep+"pysp"+os.sep
14
[2269]15coopr_bin_dir = dirname(dirname(dirname(dirname(dirname(dirname(dirname(abspath(__file__))))))))+os.sep+"bin"+os.sep
16
[1340]17#
18# Import the testing packages
19#
[1768]20import pyutilib.misc
[2423]21import pyutilib.th as unittest
[2267]22import pyutilib.subprocess
[4941]23from pyutilib.component.executables import *
[2267]24import coopr.pysp
[4890]25import coopr.plugins.solvers
[2271]26import coopr.pysp.phinit
[3264]27import coopr.pysp.ef_writer_script
[1339]28
[3349]29def filter_time_and_data_dirs(line):
[3698]30    return "seconds" in line or line.startswith("Output file written to") or "filename" in line or "directory" in line or "file" in line
[2267]31
[5227]32# pyro output filtering is complex, due to asynchronous behaviors - filter all blather regarding what Pyro components are doing.
[4941]33def filter_pyro(line):
[5788]34    if line.startswith("URI") or line.startswith("Object URI") or line.startswith("Dispatcher Object URI") or line.startswith("Dispatcher is ready"):
[4941]35       return True
36    elif line.startswith("Applying solver"):
37       return True
[5178]38    elif line.startswith("Attempting to find Pyro dispatcher object"):
39       return True   
[5151]40    elif line.startswith("Getting work from"):
41       return True
[5438]42    elif line.startswith("Name Server gracefully stopped."):
43       return True   
[5268]44    elif line.startswith("Listening for work from"):
45       return True
[5427]46    elif line.startswith("Error loading coopr.opt entry point"): # supressing weird error that occasionally pops up when loading plugins
47       return True
[5227]48    elif line.startswith("Broadcast server"):
49       return True
[5175]50    elif line.startswith("Failed to locate nameserver - trying again"):
51       return True
[5171]52    elif line.startswith("Failed to find dispatcher object from name server - trying again"):
53       return True   
[5151]54    elif line.startswith("Lost connection to"): # happens when shutting down pyro objects
55       return True     
[5266]56    elif line.startswith("WARNING: daemon bound on hostname that resolves"): # happens when not connected to a network.
57       return True     
[5120]58    elif line.startswith("This is worker") or line.startswith("This is client") or line.startswith("Finding Pyro"):
[5079]59       return True
60    elif line.find("Applying solver") != -1:
61       return True
62    elif line.find("Solve completed") != -1:
[5147]63       return True
[5529]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
[5149]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
[5218]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               
[4941]76    return filter_time_and_data_dirs(line)
77
[2267]78cplex = None
79cplex_available = False
80try:
[4890]81    cplex = coopr.plugins.solvers.CPLEX(keepFiles=True)
[2267]82    cplex_available = (not cplex.executable() is None) and cplex.available(False)
83except pyutilib.common.ApplicationError:
84    cplex_available=False
85
[4660]86cplex_direct = None
87cplex_direct_available = False
88try:
[4890]89    cplex_direct = coopr.plugins.solvers.CPLEXDirect()
[4911]90    cplex_direct_available = cplex_direct.available(False)
[4660]91except pyutilib.common.ApplicationError:
92    cplex_direct_available=False
93
[3608]94gurobi = None
95gurobi_available = False
96try:
[4890]97    gurobi = coopr.plugins.solvers.GUROBI(keepFiles=True)
[3608]98    gurobi_available = (not gurobi.executable() is None) and gurobi.available(False)
99except pyutilib.common.ApplicationError:
100    gurobi_available=False
101
[4898]102gurobi_direct = None
103gurobi_direct_available = False
104try:
[4900]105    gurobi_direct = coopr.plugins.solvers.gurobi_direct()
[4911]106    gurobi_direct_available = gurobi_direct.available(False)
[4898]107except pyutilib.common.ApplicationError:
108    gurobi_direct_available=False
109
[2267]110glpk = None
111glpk_available = False
112try:
[4890]113    glpk = coopr.plugins.solvers.GLPK(keepFiles=True)
[2267]114    glpk_available = (not glpk.executable() is None) and glpk.available(False)
115except pyutilib.common.ApplicationError:
116    glpk_available=False
117
[4667]118ipopt = None
119ipopt_available = False
120try:
[4890]121    ipopt = coopr.plugins.solvers.ASL(keepFiles=True, options={'solver':'ipopt'})
[4667]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
[5407]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
[4941]137mpirun_executable = ExternalExecutable(name="mpirun")
138mpirun_available = mpirun_executable.enabled()
139
[1340]140#
[2423]141# Define a testing class, using the unittest.TestCase class.
[1340]142#
[2931]143
[2423]144class TestPH(unittest.TestCase):
[1339]145
[2275]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:
[4162]153            del sys.modules["ReferenceModel"]
[2275]154
[2423]155    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
[3608]156    def test_farmer_quadratic_cplex(self):
[2275]157        farmer_examples_dir = pysp_examples_dir + "farmer"
[2267]158        model_dir = farmer_examples_dir + os.sep + "models"
[4162]159        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
[2271]160        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
[4801]161        print "Testing command: " + argstring
162
163        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_cplex.out")
[2271]164        args = string.split(argstring)
[3823]165        coopr.pysp.phinit.main(args=args)
[2275]166        pyutilib.misc.reset_redirect()
[4162]167        self.cleanup()
[3745]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)
[3561]169
[5065]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
[4898]185    @unittest.skipIf(not cplex_direct_available, "The 'cplex' python solver is not available")
[4660]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
[4801]191        print "Testing command: " + argstring
192
193        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_cplex_direct.out")
[4660]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
[4898]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
[3608]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"
[4162]219        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
[3608]220        argstring = "runph --solver=gurobi --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
[4801]221        print "Testing command: " + argstring
222
223        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_gurobi.out")
[3608]224        args = string.split(argstring)
[3823]225        coopr.pysp.phinit.main(args=args)
[3608]226        pyutilib.misc.reset_redirect()
[4162]227        self.cleanup()
[3745]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)
[3608]229
[4932]230    @unittest.skipIf(not gurobi_available, "The 'gurobi' executable is not available")
[5063]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")
[4932]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
[4929]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()
[5721]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)
[4929]274
[4898]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
[3561]290    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
[4842]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
[4846]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
[4866]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:
[5077]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)
[4866]323
[4842]324    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
[3614]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"
[4162]328        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
[3614]329        argstring = "runph --solver=cplex --solver-manager=serial --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir
[4801]330        print "Testing command: " + argstring
331
332        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_verbose_cplex.out")
[3614]333        args = string.split(argstring)
[3823]334        coopr.pysp.phinit.main(args=args)
[3614]335        pyutilib.misc.reset_redirect()
[4162]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)
[3614]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"
[4162]343        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
[3614]344        argstring = "runph --solver=gurobi --solver-manager=serial --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir
[4801]345        print "Testing command: " + argstring
346
347        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_verbose_gurobi.out")
[3614]348        args = string.split(argstring)
[3823]349        coopr.pysp.phinit.main(args=args)
[3614]350        pyutilib.misc.reset_redirect()
[4162]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)
[3614]353
[4855]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       
[4682]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
[4801]375        print "Testing command: " + argstring
376
377        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_quadratic_trivial_bundling_gurobi.out")
[4682]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
[5116]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()
[5721]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)
[5116]398
[3614]399    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
[4855]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")
[3608]430    def test_farmer_with_rent_quadratic_cplex(self):
[3561]431        farmer_examples_dir = pysp_examples_dir + "farmerWrent"
432        model_dir = farmer_examples_dir + os.sep + "models"
[4162]433        instance_dir = farmer_examples_dir + os.sep + "nodedata"
[3561]434        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
[4801]435        print "Testing command: " + argstring
436
437        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_with_rent_quadratic_cplex.out")
[3561]438        args = string.split(argstring)
[3823]439        coopr.pysp.phinit.main(args=args)
[3561]440        pyutilib.misc.reset_redirect()
[4162]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)
[3608]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"
[4162]448        instance_dir = farmer_examples_dir + os.sep + "nodedata"
[3608]449        argstring = "runph --solver=gurobi --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
[4801]450        print "Testing command: " + argstring
451
452        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_with_rent_quadratic_gurobi.out")
[3608]453        args = string.split(argstring)
[3823]454        coopr.pysp.phinit.main(args=args)
[3608]455        pyutilib.misc.reset_redirect()
[4162]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
[2423]459    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
[3608]460    def test_linearized_farmer_cplex(self):
[2364]461        if cplex_available:
[2370]462            solver_string="cplex"
[2275]463        farmer_examples_dir = pysp_examples_dir + "farmer"
[2267]464        model_dir = farmer_examples_dir + os.sep + "models"
[4162]465        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
[2370]466        argstring = "runph --solver="+solver_string+" --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
[4801]467        print "Testing command: " + argstring
468
469        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_linearized_cplex.out")
[2271]470        args = string.split(argstring)
[4162]471        coopr.pysp.phinit.main(args=args)
[2275]472        pyutilib.misc.reset_redirect()
[4162]473        self.cleanup()
[3745]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)
[2267]475
[5407]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
[5202]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
[3608]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"
[4162]516        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
[3608]517        argstring = "runph --solver="+solver_string+" --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
[4801]518        print "Testing command: " + argstring
519
520        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_linearized_gurobi.out")
[3608]521        args = string.split(argstring)
[4162]522        coopr.pysp.phinit.main(args=args)
[3608]523        pyutilib.misc.reset_redirect()
[4162]524        self.cleanup()
[3745]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)
[3608]526
[5203]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
[2423]544    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
[3608]545    def test_linearized_farmer_nodedata_cplex(self):
[2372]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"
[4162]550        instance_dir = farmer_examples_dir + os.sep + "nodedata"
[2372]551        argstring = "runph --solver="+solver_string+" --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
[4801]552        print "Testing command: " + argstring
553
554        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_linearized_nodedata_cplex.out")
[2372]555        args = string.split(argstring)
[4162]556        coopr.pysp.phinit.main(args=args)
[2372]557        pyutilib.misc.reset_redirect()
[4162]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)
[2372]560
[3608]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"
[4162]567        instance_dir = farmer_examples_dir + os.sep + "nodedata"
[3608]568        argstring = "runph --solver="+solver_string+" --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
[4801]569        print "Testing command: " + argstring
570
571        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_linearized_nodedata_gurobi.out")
[3608]572        args = string.split(argstring)
[4162]573        coopr.pysp.phinit.main(args=args)
[3608]574        pyutilib.misc.reset_redirect()
[4162]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)
[3608]577
[2423]578    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
[3613]579    def test_quadratic_sizes3_cplex(self):
[2275]580        sizes_example_dir = pysp_examples_dir + "sizes"
[2269]581        model_dir = sizes_example_dir + os.sep + "models"
[4162]582        instance_dir = sizes_example_dir + os.sep + "SIZES3"
[2271]583        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
[4216]584                    " --max-iterations=40"+ \
[2271]585                    " --rho-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
[2275]586                    " --scenario-solver-options=mip_tolerances_integrality=1e-7"+ \
[2271]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"
[4801]590        print "Testing command: " + argstring
591
592        pyutilib.misc.setup_redirect(this_test_file_directory+"sizes3_quadratic_cplex.out")
[2271]593        args = string.split(argstring)
[4162]594        coopr.pysp.phinit.main(args=args)
[2271]595        pyutilib.misc.reset_redirect()
[4162]596        self.cleanup()
[2269]597
[5471]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
[4911]603    @unittest.skipIf(not cplex_direct_available, "The 'cplex' python solver is not available")
[4660]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"
[4801]615        print "Testing command: " + argstring
616
617        pyutilib.misc.setup_redirect(this_test_file_directory+"sizes3_quadratic_cplex_direct.out")
[4660]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
[3612]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"
[4162]628        instance_dir = sizes_example_dir + os.sep + "SIZES3"
[3612]629        argstring = "runph --solver=gurobi --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
[4216]630                    " --max-iterations=40"+ \
[3612]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"
[4801]636        print "Testing command: " + argstring
637
638        pyutilib.misc.setup_redirect(this_test_file_directory+"sizes3_quadratic_gurobi.out")
[3612]639        args = string.split(argstring)
[4162]640        coopr.pysp.phinit.main(args=args)
[3612]641        pyutilib.misc.reset_redirect()
[3689]642        self.cleanup()
[3612]643
[4007]644        if os.sys.platform == "darwin":
[5470]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")               
[4007]649        else:
[5472]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
[3623]656    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
[4862]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()
[4904]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
[4862]691    @unittest.skipIf(not cplex_available, "The 'cplex' executable is not available")
[3623]692    def test_quadratic_networkflow1ef10_cplex(self):
693        networkflow_example_dir = pysp_examples_dir + "networkflow"
694        model_dir = networkflow_example_dir + os.sep + "models"
[4162]695        instance_dir = networkflow_example_dir + os.sep + "1ef10"
[3623]696        argstring = "runph --solver=cplex --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
697                    " --max-iterations=100"+ \
[4994]698                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
[3623]699                    " --enable-ww-extensions"+ \
700                    " --ww-extension-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph-immediatefixing.cfg"
[4801]701        print "Testing command: " + argstring
702
703        pyutilib.misc.setup_redirect(this_test_file_directory+"networkflow1ef10_quadratic_cplex.out")
[3623]704        args = string.split(argstring)
[4162]705        coopr.pysp.phinit.main(args=args)
[3623]706        pyutilib.misc.reset_redirect()
[4162]707        self.cleanup()
[3623]708
[5786]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:
[5790]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")               
[5786]716
[3622]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"
[4162]721        instance_dir = networkflow_example_dir + os.sep + "1ef10"
[3622]722        argstring = "runph --solver=gurobi --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
723                    " --max-iterations=100"+ \
[4994]724                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
[3622]725                    " --enable-ww-extensions"+ \
726                    " --ww-extension-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph-immediatefixing.cfg"
[4801]727        print "Testing command: " + argstring
728
729        pyutilib.misc.setup_redirect(this_test_file_directory+"networkflow1ef10_quadratic_gurobi.out")
[3622]730        args = string.split(argstring)
[4162]731        coopr.pysp.phinit.main(args=args)
[3622]732        pyutilib.misc.reset_redirect()
[4162]733        self.cleanup()
[5786]734
[4096]735        if os.sys.platform == "darwin":
[4162]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)
[4096]737        else:
[4162]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)
[3622]739
[3917]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"
[4162]744        instance_dir = networkflow_example_dir + os.sep + "1ef10"
[3917]745        argstring = "runph --solver=cplex --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
746                    " --max-iterations=10"+ \
[4994]747                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
[3917]748                    " --linearize-nonbinary-penalty-terms=8"+ \
749                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg"
[4801]750        print "Testing command: " + argstring
751
752        pyutilib.misc.setup_redirect(this_test_file_directory+"networkflow1ef10_linearized_cplex.out")
[3917]753        args = string.split(argstring)
[4162]754        coopr.pysp.phinit.main(args=args)
[3917]755        pyutilib.misc.reset_redirect()
[4162]756        self.cleanup()
[3917]757
[5786]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
[3918]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"
[4162]767        instance_dir = networkflow_example_dir + os.sep + "1ef10"
[3918]768        argstring = "runph --solver=gurobi --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
769                    " --max-iterations=10"+ \
[4994]770                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
[3918]771                    " --linearize-nonbinary-penalty-terms=8"+ \
772                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg"
[4801]773        print "Testing command: " + argstring
774
775        pyutilib.misc.setup_redirect(this_test_file_directory+"networkflow1ef10_linearized_gurobi.out")
[3918]776        args = string.split(argstring)
[4162]777        coopr.pysp.phinit.main(args=args)
[3918]778        pyutilib.misc.reset_redirect()
[4162]779        self.cleanup()
[3918]780
[4007]781        if os.sys.platform == "darwin":
[4162]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)
[4007]783        else:
[4162]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)
[4007]785
[4189]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"
[4801]799        print "Testing command: " + argstring
800
801        pyutilib.misc.setup_redirect(this_test_file_directory+"forestry_linearized_cplex.out")
[4189]802        args = string.split(argstring)
803        coopr.pysp.phinit.main(args=args)
804        pyutilib.misc.reset_redirect()
805        self.cleanup()
[4193]806
[5786]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:
[5790]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")               
[4189]814
[4215]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"
[4801]828        print "Testing command: " + argstring
829
830        pyutilib.misc.setup_redirect(this_test_file_directory+"forestry_linearized_gurobi.out")
[4215]831        args = string.split(argstring)
832        coopr.pysp.phinit.main(args=args)
833        pyutilib.misc.reset_redirect()
834        self.cleanup()
[4188]835
[4215]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
[3264]841    def test_farmer_ef(self):
842        farmer_examples_dir = pysp_examples_dir + "farmer"
843        model_dir = farmer_examples_dir + os.sep + "models"
[4162]844        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
[3421]845        ef_output_file = this_test_file_directory+"test_farmer_ef.lp"
[3349]846        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file
[4801]847        print "Testing command: " + argstring
848
849        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_ef.out")
[3264]850        args = string.split(argstring)
[4162]851        coopr.pysp.ef_writer_script.main(args=args)
[3264]852        pyutilib.misc.reset_redirect()
[4162]853        self.cleanup()
[3745]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")
[3264]856
[5200]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
[4932]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
[5666]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"
[5691]893        ef_output_file = this_test_file_directory+"test_farmer_piecewise_ef.lp"
[5666]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
[4862]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()
[5077]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)
[4862]920
[5201]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
[4862]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()
[4931]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)
[4862]952
[5201]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
[4931]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
[4997]984        if os.sys.platform == "darwin":
[5721]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)               
[4997]986        else:
[5721]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)               
[4997]988
[3348]989    def test_hydro_ef(self):
990        hydro_examples_dir = pysp_examples_dir + "hydro"
991        model_dir = hydro_examples_dir + os.sep + "models"
[4162]992        instance_dir = hydro_examples_dir + os.sep + "scenariodata"
[3421]993        ef_output_file = this_test_file_directory+"test_hydro_ef.lp"
[3349]994        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file
[4801]995        print "Testing command: " + argstring
996
997        pyutilib.misc.setup_redirect(this_test_file_directory+"hydro_ef.out")
[3348]998        args = string.split(argstring)
[4162]999        coopr.pysp.ef_writer_script.main(args=args)
[3348]1000        pyutilib.misc.reset_redirect()
[4162]1001        self.cleanup()
[3745]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")
[3346]1004
[3350]1005    def test_sizes3_ef(self):
1006        sizes3_examples_dir = pysp_examples_dir + "sizes"
1007        model_dir = sizes3_examples_dir + os.sep + "models"
[4162]1008        instance_dir = sizes3_examples_dir + os.sep + "SIZES3"
[3421]1009        ef_output_file = this_test_file_directory+"test_sizes3_ef.lp"
[3350]1010        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file
[4801]1011        print "Testing command: " + argstring
1012
1013        pyutilib.misc.setup_redirect(this_test_file_directory+"sizes3_ef.out")
[3350]1014        args = string.split(argstring)
[4162]1015        coopr.pysp.ef_writer_script.main(args=args)
[3350]1016        pyutilib.misc.reset_redirect()
[4162]1017        self.cleanup()
[3745]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")
[3350]1020
[4862]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
[5786]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:
[5790]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)               
[5786]1040
[4862]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
[4865]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
[4182]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
[4801]1067        print "Testing command: " + argstring
1068
1069        pyutilib.misc.setup_redirect(this_test_file_directory+"forestry_ef.out")
[4182]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
[3355]1077    def test_networkflow1ef10_ef(self):
1078        networkflow1ef10_examples_dir = pysp_examples_dir + "networkflow"
1079        model_dir = networkflow1ef10_examples_dir + os.sep + "models"
[4162]1080        instance_dir = networkflow1ef10_examples_dir + os.sep + "1ef10"
[3421]1081        ef_output_file = this_test_file_directory+"test_networkflow1ef10_ef.lp"
[3355]1082        argstring = "runef --verbose --model-directory="+model_dir+" --instance-directory="+instance_dir+" --output-file="+ef_output_file
[4801]1083        print "Testing command: " + argstring
1084
1085        pyutilib.misc.setup_redirect(this_test_file_directory+"networkflow1ef10_ef.out")
[3355]1086        args = string.split(argstring)
[4162]1087        coopr.pysp.ef_writer_script.main(args=args)
[3355]1088        pyutilib.misc.reset_redirect()
[4162]1089        self.cleanup()
[3745]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")
[3355]1092
[3264]1093    def test_farmer_ef_cvar(self):
1094        farmer_examples_dir = pysp_examples_dir + "farmer"
1095        model_dir = farmer_examples_dir + os.sep + "models"
[4162]1096        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
[4928]1097        ef_output_file = this_test_file_directory+"test_farmer_ef_cvar.lp"
[3349]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
[4801]1099        print "Testing command: " + argstring
1100
1101        pyutilib.misc.setup_redirect(this_test_file_directory+"farmer_ef_cvar.out")
[3264]1102        args = string.split(argstring)
[4162]1103        coopr.pysp.ef_writer_script.main(args=args)
[3264]1104        pyutilib.misc.reset_redirect()
[4162]1105        self.cleanup()
[3745]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")
[3264]1108
[5263]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"
[5389]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"
[5263]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"
[5389]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"
[5263]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
[5389]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
[5263]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()
[5721]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)
[5263]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"
[5389]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"
[5263]1198        print "Testing command: " + argstring
1199
1200        os.system(argstring)
1201        self.cleanup()
[5721]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)
[5263]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")
[5389]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()
[5721]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)
[5389]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")
[5263]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"
[5389]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"
[5263]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"
[5389]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"
[5263]1234        print "Testing command: " + argstring
1235
1236        os.system(argstring)
1237        self.cleanup()
[5721]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)
[5263]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"       
[5402]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"
[5263]1254        print "Testing command: " + argstring
1255
1256        os.system(argstring)       
1257        self.cleanup()
1258
[5786]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            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)
1263
[5429]1264    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
[5789]1265    def test_farmer_with_integers_quadratic_cplex_with_pyro_with_postef_solve(self):
1266        farmer_examples_dir = pysp_examples_dir + "farmerWintegers"
1267        model_dir = farmer_examples_dir + os.sep + "models"
1268        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1269        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"
1270        print "Testing command: " + argstring
1271
1272        os.system(argstring)
1273        self.cleanup()
1274        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)                   
1275
1276    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
[5429]1277    def test_linearized_sizes3_cplex_with_phpyro(self):
1278        sizes_example_dir = pysp_examples_dir + "sizes"
1279        model_dir = sizes_example_dir + os.sep + "models"
1280        instance_dir = sizes_example_dir + os.sep + "SIZES3"       
1281        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : " + \
1282                    " -np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1283                    " --max-iterations=10"+ \
1284                    " --rho-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
1285                    " --scenario-solver-options=mip_tolerances_integrality=1e-7"+ \
1286                    " --enable-ww-extensions"+ \
1287                    " --ww-extension-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.cfg"+ \
1288                    " --ww-extension-suffixfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"+ \
1289                    " --linearize-nonbinary-penalty-terms=4" + \
1290                    " >& "+this_test_file_directory+"sizes3_linearized_cplex_with_phpyro.out"
1291        print "Testing command: " + argstring
1292
1293        os.system(argstring)       
1294        self.cleanup()
1295
[5786]1296        if os.sys.platform == "darwin":
1297            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)       
1298        else:
[5842]1299            [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)
1300            [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)
1301            if (not flag_a) and (not flag_b):
1302                self.fail("Differences identified relative to all baseline output file alternatives")               
[5786]1303
[5402]1304    @unittest.skipIf(not gurobi_available or not mpirun_available, "Either the 'gurobi' executable is not available or the 'mpirun' executable is not available")
1305    def test_quadratic_sizes3_gurobi_with_phpyro(self):
1306        sizes_example_dir = pysp_examples_dir + "sizes"
1307        model_dir = sizes_example_dir + os.sep + "models"
1308        instance_dir = sizes_example_dir + os.sep + "SIZES3"       
1309        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : " + \
1310                    " -np 1 runph --solver=gurobi --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1311                    " --max-iterations=40"+ \
1312                    " --rho-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
1313                    " --scenario-solver-options=mip_tolerances_integrality=1e-7"+ \
1314                    " --enable-ww-extensions"+ \
1315                    " --ww-extension-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.cfg"+ \
1316                    " --ww-extension-suffixfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"+ \
1317                    " >& "+this_test_file_directory+"sizes3_quadratic_gurobi_with_phpyro.out"
1318        print "Testing command: " + argstring
1319
1320        os.system(argstring)       
1321        self.cleanup()
1322
[5470]1323        if os.sys.platform == "darwin":
1324            [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)
1325            # TBD: We should see different baselines here (on darwin)       
1326            if (not flag_a):
1327                self.fail("Differences identified relative to all baseline output file alternatives")               
1328        else:
[5473]1329            [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)
1330            [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)
1331            if (not flag_a) and (not flag_b):
1332                self.fail("Differences identified relative to all baseline output file alternatives")               
[5470]1333
[5263]1334    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1335    def test_farmer_ef_with_solve_cplex_with_pyro(self):
1336        farmer_examples_dir = pysp_examples_dir + "farmer"
1337        model_dir = farmer_examples_dir + os.sep + "models"
1338        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1339        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"
1340        print "Testing command: " + argstring
1341
1342        os.system(argstring)
1343        self.cleanup()
1344        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)               
1345
[5368]1346    # async PH with one pyro solver server should yield the same behavior as serial PH.
[5366]1347    @unittest.skipIf(not ipopt_available or not mpirun_available, "Either the 'ipopt' executable is not available or the 'mpirun' executable is not available")
1348    def test_farmer_quadratic_async_ipopt_with_pyro(self):
1349        farmer_examples_dir = pysp_examples_dir + "farmer"
1350        model_dir = farmer_examples_dir + os.sep + "models"
1351        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1352        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"
1353        print "Testing command: " + argstring
1354
1355        os.system(argstring)
1356        self.cleanup()
[5721]1357        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)
[5366]1358
[5368]1359    # async PH with one pyro solver server should yield the same behavior as serial PH.
[5366]1360    @unittest.skipIf(not gurobi_available or not mpirun_available, "Either the 'gurobi' executable is not available or the 'mpirun' executable is not available")
1361    def test_farmer_quadratic_async_gurobi_with_pyro(self):
1362        farmer_examples_dir = pysp_examples_dir + "farmer"
1363        model_dir = farmer_examples_dir + os.sep + "models"
1364        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1365        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"
1366        print "Testing command: " + argstring
1367
1368        os.system(argstring)
1369        self.cleanup()
1370        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)
1371
[5368]1372    # async PH with one pyro solver server should yield the same behavior as serial PH.
1373    @unittest.skipIf(not gurobi_available or not mpirun_available, "Either the 'gurobi' executable is not available or the 'mpirun' executable is not available")
1374    def test_farmer_linearized_async_gurobi_with_pyro(self):
1375        farmer_examples_dir = pysp_examples_dir + "farmer"
1376        model_dir = farmer_examples_dir + os.sep + "models"
1377        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1378        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"
1379        print "Testing command: " + argstring
1380
1381        os.system(argstring)
1382        self.cleanup()
1383        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)
1384
1385    # async PH with one pyro solver server should yield the same behavior as serial PH.
1386    @unittest.skipIf(not ipopt_available or not mpirun_available, "Either the 'ipopt' executable is not available or the 'mpirun' executable is not available")
1387    def test_farmer_linearized_async_ipopt_with_pyro(self):
1388        farmer_examples_dir = pysp_examples_dir + "farmer"
1389        model_dir = farmer_examples_dir + os.sep + "models"
1390        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1391        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"
1392        print "Testing command: " + argstring
1393
1394        os.system(argstring)
1395        self.cleanup()
[5740]1396        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)
[5368]1397
[5444]1398    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
1399    def test_farmer_with_integers_linearized_cplex_with_phpyro(self):
1400        farmer_examples_dir = pysp_examples_dir + "farmerWintegers"
1401        model_dir = farmer_examples_dir + os.sep + "models"
1402        instance_dir = farmer_examples_dir + os.sep + "scenariodata"
1403        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"
1404        print "Testing command: " + argstring
1405
1406        os.system(argstring)
1407        self.cleanup()
[5740]1408        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)       
[5444]1409
[5439]1410    # the primary objective of this test is to validate the bare minimum level of functionality on the PH solver server
1411    # end (solves and rho setting) - obviously should yield the same results as serial PH.
[5787]1412    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")   
[5439]1413    def test_simple_quadratic_networkflow1ef10_cplex_with_phpyro(self):
1414        networkflow_example_dir = pysp_examples_dir + "networkflow"
1415        model_dir = networkflow_example_dir + os.sep + "models"
1416        instance_dir = networkflow_example_dir + os.sep + "1ef10"
1417        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 10 phsolverserver : " + \
1418                    "-np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1419                    " --max-iterations=5"+ \
1420                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1421                    " >& "+this_test_file_directory+"networkflow1ef10_simple_quadratic_cplex_with_phpyro.out"
1422        print "Testing command: " + argstring
1423
1424        os.system(argstring)
1425        self.cleanup()
1426
1427        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)
1428
1429    # builds on the above test, to validate warm-start capabilities; by imposing a migap,
1430    # executions with and without warm-starts will arrive at different solutions.
[5787]1431    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")   
[5439]1432    def test_advanced_quadratic_networkflow1ef10_cplex_with_phpyro(self):
1433        networkflow_example_dir = pysp_examples_dir + "networkflow"
1434        model_dir = networkflow_example_dir + os.sep + "models"
1435        instance_dir = networkflow_example_dir + os.sep + "1ef10"
1436        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 10 phsolverserver : " + \
1437                    "-np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1438                    " --max-iterations=5"+ \
1439                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1440                    " --enable-ww-extensions"+ \
1441                    " --ww-extension-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph-mipgaponly.cfg" + \
1442                    " >& "+this_test_file_directory+"networkflow1ef10_advanced_quadratic_cplex_with_phpyro.out"
1443        print "Testing command: " + argstring
1444
1445        os.system(argstring)
1446        self.cleanup()
1447
[5786]1448        if os.sys.platform == "darwin":
1449            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)
1450        else:
1451            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)
[5439]1452
[5838]1453    @unittest.skipIf(not gurobi_available or not mpirun_available, "Either the 'gurobi' executable is not available or the 'mpirun' executable is not available")
[5406]1454    def test_linearized_networkflow1ef10_gurobi_with_phpyro(self):
1455        networkflow_example_dir = pysp_examples_dir + "networkflow"
1456        model_dir = networkflow_example_dir + os.sep + "models"
1457        instance_dir = networkflow_example_dir + os.sep + "1ef10"
1458        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 10 phsolverserver : " + \
1459                    "-np 1 runph --solver=gurobi --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1460                    " --max-iterations=10"+ \
[5408]1461                    " --enable-termdiff-convergence --termdiff-threshold=0.01" + \
1462                    " --enable-ww-extensions"+ \
1463                    " --ww-extension-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph-aggressivefixing.cfg"+ \
1464                    " --ww-extension-suffixfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"+ \
[5406]1465                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1466                    " --linearize-nonbinary-penalty-terms=8"+ \
[5408]1467                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg" + \
[5420]1468                    " >& "+this_test_file_directory+"networkflow1ef10_linearized_gurobi_with_phpyro.out"
[5406]1469        print "Testing command: " + argstring
1470
[5408]1471        os.system(argstring)
[5406]1472        self.cleanup()
1473
1474        if os.sys.platform == "darwin":
[5438]1475            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)
[5406]1476        else:
[5438]1477            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)
[5406]1478
[5787]1479    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
[5447]1480    def test_simple_linearized_networkflow1ef3_cplex_with_phpyro(self):
1481        networkflow_example_dir = pysp_examples_dir + "networkflow"
1482        model_dir = networkflow_example_dir + os.sep + "models"
1483        instance_dir = networkflow_example_dir + os.sep + "1ef3"
1484        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 3 phsolverserver : " + \
1485                    "-np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1486                    " --max-iterations=10"+ \
1487                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1488                    " --linearize-nonbinary-penalty-terms=4"+ \
1489                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg" + \
1490                    " >& "+this_test_file_directory+"networkflow1ef3_simple_linearized_cplex_with_phpyro.out"
1491        print "Testing command: " + argstring
1492
1493        os.system(argstring)
1494        self.cleanup()
1495
[5786]1496        if os.sys.platform == "darwin":
1497            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)   
1498        else:
1499            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)
[5447]1500           
1501
[5787]1502    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
[5437]1503    def test_simple_linearized_networkflow1ef10_cplex_with_phpyro(self):
1504        networkflow_example_dir = pysp_examples_dir + "networkflow"
1505        model_dir = networkflow_example_dir + os.sep + "models"
1506        instance_dir = networkflow_example_dir + os.sep + "1ef10"
1507        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 10 phsolverserver : " + \
1508                    "-np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1509                    " --max-iterations=10"+ \
1510                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1511                    " --linearize-nonbinary-penalty-terms=8"+ \
1512                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg" + \
1513                    " >& "+this_test_file_directory+"networkflow1ef10_simple_linearized_cplex_with_phpyro.out"
1514        print "Testing command: " + argstring
1515
1516        os.system(argstring)
1517        self.cleanup()
1518
[5438]1519        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)
1520       
[5787]1521    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
[5437]1522    def test_advanced_linearized_networkflow1ef10_cplex_with_phpyro(self):
1523        networkflow_example_dir = pysp_examples_dir + "networkflow"
1524        model_dir = networkflow_example_dir + os.sep + "models"
1525        instance_dir = networkflow_example_dir + os.sep + "1ef10"
1526        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 10 phsolverserver : " + \
1527                    "-np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1528                    " --max-iterations=10"+ \
1529                    " --enable-termdiff-convergence --termdiff-threshold=0.01" + \
1530                    " --enable-ww-extensions"+ \
1531                    " --ww-extension-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph-aggressivefixing.cfg"+ \
1532                    " --ww-extension-suffixfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"+ \
1533                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1534                    " --linearize-nonbinary-penalty-terms=8"+ \
1535                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg" + \
1536                    " >& "+this_test_file_directory+"networkflow1ef10_advanced_linearized_cplex_with_phpyro.out"
1537        print "Testing command: " + argstring
1538
1539        os.system(argstring)
1540        self.cleanup()
1541
[5786]1542        if os.sys.platform == "darwin":
1543            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)
1544        else:
1545            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)
[5437]1546
[5787]1547    @unittest.skipIf(not cplex_available or not mpirun_available, "Either the 'cplex' executable is not available or the 'mpirun' executable is not available")
[5451]1548    def test_linearized_networkflow1ef10_cplex_with_bundles_with_phpyro(self):
1549        networkflow_example_dir = pysp_examples_dir + "networkflow"
1550        model_dir = networkflow_example_dir + os.sep + "models"
1551        instance_dir = networkflow_example_dir + os.sep + "1ef10"
1552        argstring = "mpirun -np 1 coopr_ns : -np 1 dispatch_srvr : -np 5 phsolverserver : " + \
1553                    "-np 1 runph --solver=cplex --solver-manager=phpyro --shutdown-pyro --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
1554                    " --scenario-bundle-specification="+networkflow_example_dir+os.sep+"10scenario-bundle-specs/FiveBundles.dat" + \
1555                    " --max-iterations=10"+ \
1556                    " --enable-termdiff-convergence --termdiff-threshold=0.01" + \
1557                    " --enable-ww-extensions"+ \
1558                    " --ww-extension-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph-aggressivefixing.cfg"+ \
1559                    " --ww-extension-suffixfile="+networkflow_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"+ \
1560                    " --rho-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"rhosettermixed.cfg"+ \
1561                    " --linearize-nonbinary-penalty-terms=8"+ \
1562                    " --bounds-cfgfile="+networkflow_example_dir+os.sep+"config"+os.sep+"xboundsetter.cfg" + \
1563                    " >& "+this_test_file_directory+"networkflow1ef10_linearized_cplex_with_bundles_with_phpyro.out"
1564        print "Testing command: " + argstring
1565
1566        os.system(argstring)
1567        self.cleanup()
1568
1569        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)                   
1570
[3485]1571TestPH = unittest.category('nightly', 'performance')(TestPH)
[2931]1572
[5264]1573TestPHParallel = unittest.category('parallel', 'performance')(TestPHParallel)
[5263]1574
[1339]1575if __name__ == "__main__":
[2423]1576    unittest.main()
Note: See TracBrowser for help on using the repository browser.