source: coopr.pyomo/stable/2.3/coopr/pyomo/tests/unit/test_transform.py @ 2433

Last change on this file since 2433 was 2433, checked in by wehart, 11 years ago

Merged revisions 2388-2432 via svnmerge from
https://software.sandia.gov/svn/public/coopr/coopr.pyomo/trunk

........

r2399 | wehart | 2010-02-24 11:36:56 -0700 (Wed, 24 Feb 2010) | 2 lines


Adding a work-around when pstats cannot be imported.

........

r2400 | wehart | 2010-02-24 14:51:08 -0700 (Wed, 24 Feb 2010) | 2 lines


Misc documentation updates.

........

r2408 | wehart | 2010-02-28 05:41:04 -0700 (Sun, 28 Feb 2010) | 3 lines


Allow an earlier version of Python. I'm still not sure this is a good idea,
but it's necessary for Jython.

........

r2409 | wehart | 2010-02-28 05:42:33 -0700 (Sun, 28 Feb 2010) | 7 lines


Rework of profiling imports.


Refinement of Pyomo command-line parsing, which is more
specific now.


Adding automatic import of pyomo to package.

........

r2415 | jwatson | 2010-03-08 20:53:13 -0700 (Mon, 08 Mar 2010) | 3 lines


Significantly improved performance of PyomoModel? _clear_attribute method, mainly by eliminate unnecessary calls to it through _setattr_exec_.

........

r2416 | jwatson | 2010-03-09 16:45:22 -0700 (Tue, 09 Mar 2010) | 5 lines


Modified the AMPL dat file parser to instantiate the lexer and yaccer objects only once, for the lifetime of the module.


They were being inadvertently created at each invocation, which pyomo users wouldn't notice. But PySP users, who can be creating 1K or more instances, do!

........

r2422 | wehart | 2010-03-11 16:01:09 -0700 (Thu, 11 Mar 2010) | 3 lines


Rework of unit tests to (a) import pyutilib.th as 'unittest' and
(b) employ test skipping.

........

r2430 | wehart | 2010-03-11 23:38:22 -0700 (Thu, 11 Mar 2010) | 2 lines


Reworking class decorators.

........

File size: 2.4 KB
Line 
1#
2# Unit Tests for model transformations
3#
4
5import os
6import sys
7from os.path import abspath, dirname
8sys.path.insert(0, dirname(dirname(abspath(__file__)))+os.sep+".."+os.sep+"..")
9currdir = dirname(abspath(__file__))+os.sep
10
11from coopr.pyomo import *
12from coopr.opt import *
13import pyutilib.th as unittest
14import pyutilib.services
15from pyutilib.component.core import Plugin
16
17class Test(unittest.TestCase):
18
19    def setUp(self):
20        self.model = Model()
21
22    def tearDown(self):
23        if os.path.exists("unknown.lp"):
24           os.unlink("unknown.lp")
25        pyutilib.services.TempfileManager.clear_tempfiles()
26
27    def test_relax_integrality1(self):
28        """ Coverage of the _clear_attribute method """
29        self.model.A = RangeSet(1,4)
30        self.model.a = Var()
31        self.model.b = Var(within=self.model.A)
32        self.model.c = Var(within=NonNegativeIntegers)
33        self.model.d = Var(within=Integers, bounds=(-2,3))
34        self.model.e = Var(within=Boolean)
35        self.model.f = Var(domain=Boolean)
36        instance=self.model.create()
37        rinst = apply_transformation('relax_integrality',instance)
38        self.failUnlessEqual(type(rinst.a.domain), type(Reals))
39        self.failUnlessEqual(type(rinst.b.domain), type(Reals))
40        self.failUnlessEqual(type(rinst.c.domain), type(Reals))
41        self.failUnlessEqual(type(rinst.d.domain), type(Reals))
42        self.failUnlessEqual(type(rinst.e.domain), type(Reals))
43        self.failUnlessEqual(type(rinst.f.domain), type(Reals))
44        self.failUnlessEqual(rinst.a.bounds, instance.a.bounds)
45        self.failUnlessEqual(rinst.b.bounds, instance.b.bounds)
46        self.failUnlessEqual(rinst.c.bounds, instance.c.bounds)
47        self.failUnlessEqual(rinst.d.bounds, instance.d.bounds)
48        self.failUnlessEqual(rinst.e.bounds, instance.e.bounds)
49        self.failUnlessEqual(rinst.f.bounds, instance.f.bounds)
50
51    def test_apply_transformation1(self):
52        self.failUnless('relax_integrality' in apply_transformation())
53
54    def test_apply_transformation2(self):
55        self.failUnlessEqual(apply_transformation('foo'),None)
56        self.failUnless(isinstance(apply_transformation('relax_integrality'),Plugin))
57        self.failUnless(isinstance(apply_transformation('relax_integrality'),Plugin))
58        self.failUnlessEqual(apply_transformation('foo', self.model),None)
59
60if __name__ == "__main__":
61   unittest.main()
62
Note: See TracBrowser for help on using the repository browser.