source: coopr.pysp/stable/2.3/coopr/pysp/tests/unit/test_ph.py @ 2317

Last change on this file since 2317 was 2317, checked in by wehart, 10 years ago

Merged revisions 2246-2316 via svnmerge from
https://software.sandia.gov/svn/public/coopr/coopr.pysp/trunk

........

r2246 | wehart | 2010-02-01 21:10:48 -0700 (Mon, 01 Feb 2010) | 2 lines


Tagging coopr.pysp release 2.2

........

r2247 | wehart | 2010-02-01 21:46:08 -0700 (Mon, 01 Feb 2010) | 2 lines


Documentation fix.

........

r2248 | jwatson | 2010-02-03 08:44:59 -0700 (Wed, 03 Feb 2010) | 3 lines


Adding os.path.expanduser wrappers around all directory/filenames, to facilitate correct processing of ~ characters.

........

r2249 | jwatson | 2010-02-03 09:28:25 -0700 (Wed, 03 Feb 2010) | 3 lines


Misc fixes.

........

r2254 | jwatson | 2010-02-03 21:09:38 -0700 (Wed, 03 Feb 2010) | 3 lines


Changed PyomoModelData? call from add_data_mumble() to add().

........

r2255 | jwatson | 2010-02-03 21:38:35 -0700 (Wed, 03 Feb 2010) | 3 lines


Re-factoring of PH options parser code to accomodate MRP work being done by DLW.

........

r2256 | jwatson | 2010-02-03 22:18:11 -0700 (Wed, 03 Feb 2010) | 3 lines


Major speed improvements in the EF writer by avoiding Python deep-copes - saves a few orders of magnitude of run-time.

........

r2260 | jwatson | 2010-02-04 21:44:29 -0700 (Thu, 04 Feb 2010) | 3 lines


Refactoring of ph initialization routines to support sampling and bundling.

........

r2261 | jwatson | 2010-02-04 21:46:37 -0700 (Thu, 04 Feb 2010) | 3 lines


Renaming ph_script module to phinit, which is more accurate with the newly factored, library-like functionality.

........

r2262 | jwatson | 2010-02-04 21:54:50 -0700 (Thu, 04 Feb 2010) | 3 lines


Minor improvement to phinit functionality.

........

r2267 | jwatson | 2010-02-05 15:09:02 -0700 (Fri, 05 Feb 2010) | 3 lines


Initial PySP unit tests!!!

........

r2268 | wehart | 2010-02-05 15:25:52 -0700 (Fri, 05 Feb 2010) | 2 lines


A fix to the tests.

........

r2269 | jwatson | 2010-02-05 15:46:35 -0700 (Fri, 05 Feb 2010) | 3 lines


Added SIZES3 PySP test and added absolute paths to "runph" script.

........

r2270 | jwatson | 2010-02-05 16:01:08 -0700 (Fri, 05 Feb 2010) | 3 lines


PySP tests need absolute output paths!

........

r2271 | jwatson | 2010-02-05 16:20:01 -0700 (Fri, 05 Feb 2010) | 3 lines


Making unit tests for PySP compatible with coverage utilities. Farmer examples work, SIZES3 doesn't for some reason.

........

r2272 | jwatson | 2010-02-05 16:59:46 -0700 (Fri, 05 Feb 2010) | 3 lines


Various fixes to PySP unit tests. Changing name of testphextension to examplephextension - with the test prefix, coverage tests import the module, which causes all kinds of issues.

........

r2275 | jwatson | 2010-02-06 13:45:11 -0700 (Sat, 06 Feb 2010) | 3 lines


Testing improvements. From lpython, the tests run individually just fine. In aggregate, only the first run passes - independent of what test that might be! Something to stare at later....

........

r2277 | jwatson | 2010-02-06 23:30:13 -0700 (Sat, 06 Feb 2010) | 3 lines


Fixed problem with runph --profile option, broken by my recent factoring of phinit.py.

........

r2288 | jwatson | 2010-02-08 13:32:41 -0700 (Mon, 08 Feb 2010) | 3 lines


Significant initialization speed reductions in the WW PH extension for PySP.

........

r2290 | jwatson | 2010-02-08 19:22:32 -0700 (Mon, 08 Feb 2010) | 1 line


Initial commit of multi-stage capacity expansion problem in PySP

........

r2291 | jwatson | 2010-02-08 19:23:24 -0700 (Mon, 08 Feb 2010) | 1 line


Miscellaneous fix to ef writer involving indexed cost variables

........

r2296 | jwatson | 2010-02-09 18:56:48 -0700 (Tue, 09 Feb 2010) | 3 lines


Removing monster-sized LP file from the PySP forestry examples directory.

........

r2297 | jwatson | 2010-02-09 18:59:05 -0700 (Tue, 09 Feb 2010) | 3 lines


The extensive forms in the PySP forestry example were massive - and are now gone.

........

r2298 | jwatson | 2010-02-09 19:03:09 -0700 (Tue, 09 Feb 2010) | 1 line


Removing output logs for PySP network flow example

........

r2299 | jwatson | 2010-02-09 19:04:12 -0700 (Tue, 09 Feb 2010) | 1 line


Removing a big network flow EF

........

r2300 | jwatson | 2010-02-09 19:05:08 -0700 (Tue, 09 Feb 2010) | 3 lines


Removing PySP cap example EF to free up space.

........

r2301 | jwatson | 2010-02-09 19:14:26 -0700 (Tue, 09 Feb 2010) | 1 line


Performance improvements to PH obtained by processing scenario sub-problem results as they come in, instead of waiting for them after a solver barrier sync

........

File size: 5.0 KB
Line 
1#
2# Get the directory where this script is defined, and where the baseline
3# files are located.
4#
5import os
6import sys
7import string
8from os.path import abspath, dirname
9sys.path.insert(0, dirname(dirname(abspath(__file__)))+"/../..")
10
11current_directory = dirname(abspath(__file__))+os.sep
12
13pysp_examples_dir = dirname(dirname(dirname(dirname(dirname(abspath(__file__))))))+os.sep+"examples"+os.sep+"pysp"+os.sep
14
15coopr_bin_dir = dirname(dirname(dirname(dirname(dirname(dirname(dirname(abspath(__file__))))))))+os.sep+"bin"+os.sep
16
17#
18# Import the testing packages
19#
20import unittest
21import pyutilib.misc
22import pyutilib.th
23import pyutilib.subprocess
24import coopr.pysp
25import coopr.plugins.mip
26import coopr.pysp.phinit
27
28def filter_time(line):
29   return "seconds" in line
30
31cplex = None
32cplex_available = False
33try:
34    cplex = coopr.plugins.mip.CPLEX(keepFiles=True)
35    cplex_available = (not cplex.executable() is None) and cplex.available(False)
36except pyutilib.common.ApplicationError:
37    cplex_available=False
38
39glpk = None
40glpk_available = False
41try:
42    glpk = coopr.plugins.mip.GLPK(keepFiles=True)
43    glpk_available = (not glpk.executable() is None) and glpk.available(False)
44except pyutilib.common.ApplicationError:
45    glpk_available=False
46
47#
48# Define a testing class, using the pyutilib.th.TestCase class.  This is
49# an extension of the unittest.TestCase class that adds additional testing
50# functions.
51#
52class TestPH(pyutilib.th.TestCase):
53
54    def cleanup(self):
55
56        # IMPT: This step is key, as Python keys off the name of the module, not the location.
57        #       So, different reference models in different directories won't be detected.
58        #       If you don't do this, the symptom is a model that doesn't have the attributes
59        #       that the data file expects.
60        if "ReferenceModel" in sys.modules:
61           del sys.modules["ReferenceModel"]
62
63    def test_quadratic_farmer(self):
64
65        if cplex_available is False:
66           return
67
68        pyutilib.misc.setup_redirect(current_directory+"farmer_quadratic.out")
69        farmer_examples_dir = pysp_examples_dir + "farmer"
70        model_dir = farmer_examples_dir + os.sep + "models"
71        instance_dir = farmer_examples_dir + os.sep + "scenariodata"       
72        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir
73        args = string.split(argstring)
74        coopr.pysp.phinit.run(args=args)
75        pyutilib.misc.reset_redirect()
76        self.cleanup()       
77        self.failUnlessFileEqualsBaseline(current_directory+"farmer_quadratic.out",current_directory+"farmer_quadratic.baseline", filter=filter_time)
78       
79    def test_linearized_farmer(self):
80
81        if cplex_available is False:
82           return       
83
84        pyutilib.misc.setup_redirect(current_directory+"farmer_linearized.out")
85        farmer_examples_dir = pysp_examples_dir + "farmer"
86        model_dir = farmer_examples_dir + os.sep + "models"
87        instance_dir = farmer_examples_dir + os.sep + "scenariodata"       
88        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+" --linearize-nonbinary-penalty-terms=10"
89        args = string.split(argstring)
90        coopr.pysp.phinit.run(args=args)       
91        pyutilib.misc.reset_redirect()
92        self.cleanup()               
93        self.failUnlessFileEqualsBaseline(current_directory+"farmer_linearized.out",current_directory+"farmer_linearized.baseline", filter=filter_time)
94
95    def test_quadratic_sizes3(self):
96
97        if cplex_available is False:
98           return
99       
100        pyutilib.misc.setup_redirect(current_directory+"sizes3_quadratic.out")
101
102        sizes_example_dir = pysp_examples_dir + "sizes"
103        model_dir = sizes_example_dir + os.sep + "models"
104        instance_dir = sizes_example_dir + os.sep + "SIZES3"       
105        argstring = "runph --solver=cplex --solver-manager=serial --model-directory="+model_dir+" --instance-directory="+instance_dir+ \
106                    " --max-iterations=200"+ \
107                    " --rho-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"rhosetter.cfg"+ \
108                    " --scenario-solver-options=mip_tolerances_integrality=1e-7"+ \
109                    " --enable-ww-extensions"+ \
110                    " --ww-extension-cfgfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.cfg"+ \
111                    " --ww-extension-suffixfile="+sizes_example_dir+os.sep+"config"+os.sep+"wwph.suffixes"
112        args = string.split(argstring)
113        coopr.pysp.phinit.run(args=args)               
114        pyutilib.misc.reset_redirect()
115        self.failUnlessFileEqualsBaseline(current_directory+"sizes3_quadratic.out",current_directory+"sizes3_quadratic.baseline", filter=filter_time)
116        self.cleanup()       
117
118    def run(self, result=None):
119       global cplex_available
120       if not cplex_available:
121          return
122       pyutilib.th.TestCase.run(self,result)
123
124if __name__ == "__main__":
125   unittest.main()
Note: See TracBrowser for help on using the repository browser.