source: trunk/test/pyomo/unit/test_preprocess.py @ 1768

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

Rework of Coopr to use the new PyUtilib? package decomposition.

NOTE: to use Coopr with this update, we need to work with a new version of coopr_install.

File size: 1.3 KB
Line 
1#
2# Unit Tests for model preprocessing
3#
4
5import unittest
6import os
7import sys
8from os.path import abspath, dirname
9sys.path.insert(0, dirname(dirname(abspath(__file__)))+"/../..")
10currdir = dirname(abspath(__file__))+os.sep
11
12import pyutilib.th
13from coopr.pyomo import *
14from nose.tools import nottest
15
16
17class TestPreprocess(pyutilib.th.TestCase):
18
19    def test_label1(self):
20        model = Model()
21        model.A = Set(initialize=[1,2,3])
22        model.B = Param(model.A,initialize={1:100,2:200,3:300})
23        model.x = Var(model.A)
24        model.y = Var(model.A)
25        instance=model.create()
26        instance.presolve()
27        self.failUnlessEqual(instance.num_used_variables(),0)
28
29    def test_label1(self):
30        model = Model()
31        model.A = Set(initialize=[1,2,3])
32        model.B = Param(model.A,initialize={1:100,2:200,3:300})
33        model.x = Var(model.A)
34        model.y = Var(model.A)
35        model.obj = Objective(rule=lambda inst: inst.x[1])
36        instance=model.create()
37        instance.presolve()
38        self.failUnlessEqual(instance.num_used_variables(),1)
39        self.failUnlessEqual(instance.x[1].label,"x[1]")
40        self.failUnlessEqual(instance.x[2].label,"x[2]")
41        self.failUnlessEqual(instance.y[1].label,"y[1]")
42
43if __name__ == "__main__":
44   unittest.main()
Note: See TracBrowser for help on using the repository browser.