1# ___________________________________________________________________________ 2# 3# Pyomo: Python Optimization Modeling Objects 4# Copyright 2017 National Technology and Engineering Solutions of Sandia, LLC 5# Under the terms of Contract DE-NA0003525 with National Technology and 6# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain 7# rights in this software. 8# This software is distributed under the 3-clause BSD License. 9# ___________________________________________________________________________ 10 11import pyomo.common.unittest as unittest 12 13from pyomo.core import ConcreteModel, Var, Param, Constraint, Objective, exp 14from pyomo.repn.standard_repn import generate_standard_repn as gar 15 16 17class AmplRepnTests(unittest.TestCase): 18 19 def test_divide_by_mutable(self): 20 # 21 # Test from https://github.com/Pyomo/pyomo/issues/153 22 # 23 m = ConcreteModel() 24 m.x = Var(bounds=(1,5)) 25 m.p = Param(initialize=100, mutable=True) 26 m.con = Constraint(expr=exp(5*(1/m.x - 1/m.p))<=10) 27 m.obj = Objective(expr=m.x**2) 28 29 test = gar(m.con.body) 30 self.assertEqual(test.constant, 0) 31 self.assertEqual(test.linear_vars, tuple()) 32 self.assertEqual(test.linear_coefs, tuple()) 33 self.assertEqual(set(id(v) for v in test.nonlinear_vars), set([id(m.x)])) 34 self.assertIs(test.nonlinear_expr, m.con.body) 35 36if __name__ == "__main__": 37 unittest.main() 38