Esempio n. 1
0
 def test_gams_expanded_connectors(self):
     m = ConcreteModel()
     m.x = Var()
     m.y = Var()
     m.CON1 = Connector()
     m.CON1.add(m.x, 'v')
     m.CON2 = Connector()
     m.CON2.add(m.y, 'v')
     m.c = Constraint(expr=m.CON1 + m.CON2 >= 10)
     TransformationFactory("core.expand_connectors").apply_to(m)
     m.o = Objective(expr=m.x)
     os = StringIO()
     io_options = dict(symbolic_solver_labels=True)
     m.write(os, format="gams", io_options=io_options)
     # no error if we're here, but check for some identifying string
     self.assertIn("x + y", os.getvalue())
Esempio n. 2
0
 def test_gams_expanded_arcs(self):
     m = ConcreteModel()
     m.x = Var()
     m.y = Var()
     m.CON1 = Port()
     m.CON1.add(m.x, 'v')
     m.CON2 = Port()
     m.CON2.add(m.y, 'v')
     m.c = Arc(source=m.CON1, destination=m.CON2)
     TransformationFactory("network.expand_arcs").apply_to(m)
     m.o = Objective(expr=m.x)
     outs = StringIO()
     io_options = dict(symbolic_solver_labels=True)
     m.write(outs, format="gams", io_options=io_options)
     # no error if we're here, but check for some identifying string
     self.assertIn("x - y", outs.getvalue())
Esempio n. 3
0
 def test_gams_expanded_connectors(self):
     m = ConcreteModel()
     m.x = Var()
     m.y = Var()
     m.CON1 = Connector()
     m.CON1.add(m.x, 'v')
     m.CON2 = Connector()
     m.CON2.add(m.y, 'v')
     m.c = Constraint(expr=m.CON1 + m.CON2 >= 10)
     TransformationFactory("core.expand_connectors").apply_to(m)
     m.o = Objective(expr=m.x)
     os = StringIO()
     io_options = dict(symbolic_solver_labels=True)
     m.write(os, format="gams", io_options=io_options)
     # no error if we're here, but check for some identifying string
     self.assertIn("x + y", os.getvalue())
Esempio n. 4
0
#  ___________________________________________________________________________
#
#  Pyomo: Python Optimization Modeling Objects
#  Copyright (c) 2008-2022
#  National Technology and Engineering Solutions of Sandia, LLC
#  Under the terms of Contract DE-NA0003525 with National Technology and
#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
#  rights in this software.
#  This software is distributed under the 3-clause BSD License.
#  ___________________________________________________________________________
#
# Author:  Gabe Hackebeil
# Purpose: For regression testing to ensure that the Pyomo
#          NL writer properly reports the values corresponding
#          to the nl file header line with the label
#          '# nonlinear vars in constraints, objectives, both'
#

from pyomo.environ import ConcreteModel, Var, Objective, Constraint

model = ConcreteModel()

model.x = Var(initialize=1.0)
model.y = Var(initialize=1.0)

model.OBJ = Objective(expr=model.y**2)

model.CON1 = Constraint(expr=model.y * model.x == 4)
Esempio n. 5
0
#          The ASL differentiation routines seem to have a
#          bug that causes the lagrangian hessian to become
#          dense unless this constant term in moved to the
#          numerator.
#
#          This test model relies on the gjh_asl_json executable. It
#          will not solve if sent to a real optimizer.
#

from pyomo.environ import ConcreteModel, Var, Objective, Constraint

model = ConcreteModel()
model.x = Var(bounds=(-1.0, 1.0), initialize=1.0)
model.y = Var(bounds=(-1.0, 1.0), initialize=2.0)
model.v = Var(bounds=(-1.0, 1.0), initialize=3.0)
model.p = Var(initialize=2.0)
model.p.fixed = True

model.OBJ = Objective(expr=model.x)
model.CON1 = Constraint(
    rule=lambda model: (2.0, 1.0 / model.p * model.v * (model.x - model.y)))
model.CON2 = Constraint(expr=model.v * 1.0 / model.p *
                        (model.x - model.y) == 2.0)
model.CON3 = Constraint(expr=model.v * (model.x - model.y) / model.p == 2.0)
model.CON4 = Constraint(expr=model.v *
                        (model.x / model.p - model.y / model.p) == 2.0)
model.CON5 = Constraint(expr=model.v * (model.x - model.y) *
                        (1.0 / model.p) == 2.0)
model.CON6 = Constraint(expr=model.v * (model.x - model.y) -
                        2.0 * model.p == 0)
Esempio n. 6
0
#  ___________________________________________________________________________
#
#  Pyomo: Python Optimization Modeling Objects
#  Copyright (c) 2008-2022
#  National Technology and Engineering Solutions of Sandia, LLC
#  Under the terms of Contract DE-NA0003525 with National Technology and
#  Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
#  rights in this software.
#  This software is distributed under the 3-clause BSD License.
#  ___________________________________________________________________________
#
# Author:  Gabe Hackebeil
# Purpose: For regression testing to ensure that the Pyomo
#          NL writer properly reports the values corresponding
#          to the nl file header line with the label
#          '# nonlinear vars in constraints, objectives, both'
#

from pyomo.environ import ConcreteModel, Var, Objective, Constraint

model = ConcreteModel()

model.x = Var(initialize=1.0)
model.y = Var(initialize=1.0)

model.OBJ = Objective(expr=model.x)

model.CON1 = Constraint(expr=model.y**2 == 4)
Esempio n. 7
0
#          dense unless this constant term in moved to the
#          numerator.
#
#          This test model relies on the gjh_asl_json executable. It
#          will not solve if sent to a real optimizer.
#

from pyomo.environ import ConcreteModel, Var, Param, Objective, Constraint

model = ConcreteModel()
model.x = Var(bounds=(-1.0,1.0),initialize=1.0)
model.y = Var(bounds=(-1.0,1.0),initialize=2.0)
model.v = Var(bounds=(-1.0,1.0),initialize=3.0)
model.p = Param(initialize=2.0)
model.q = Param(initialize=2.0,mutable=True)

model.OBJ = Objective(expr=model.x**2/model.p + model.x**2/model.q)
model.CON1 = Constraint(expr=1.0/model.p*model.v*(model.x-model.y) == 2.0)
model.CON2 = Constraint(expr=model.v*1.0/model.p*(model.x-model.y) == 2.0)
model.CON3 = Constraint(expr=model.v*(model.x-model.y)/model.p == 2.0)
model.CON4 = Constraint(expr=model.v*(model.x/model.p-model.y/model.p) == 2.0)
model.CON5 = Constraint(expr=model.v*(model.x-model.y)*(1.0/model.p) == 2.0)
model.CON6 = Constraint(expr=model.v*(model.x-model.y) == 2.0*model.p)

model.CON7 = Constraint(expr=1.0/model.q*model.v*(model.x-model.y) == 2.0)
model.CON8 = Constraint(expr=model.v*1.0/model.q*(model.x-model.y) == 2.0)
model.CON9 = Constraint(expr=model.v*(model.x-model.y)/model.q == 2.0)
model.CON10 = Constraint(expr=model.v*(model.x/model.q-model.y/model.q) == 2.0)
model.CON11 = Constraint(expr=model.v*(model.x-model.y)*(1.0/model.q) == 2.0)
model.CON12 = Constraint(expr=model.v*(model.x-model.y) == 2.0*model.q)