Skip to content

Commit

Permalink
Merge branch 'main' into gurobipy_addconstr_deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
blnicho authored Aug 20, 2024
2 parents cf23302 + 5a5b13a commit eee27c4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pyomo/repn/ampl.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class TextNLDebugTemplate(object):
# NOTE: to support scaling and substitutions, we do NOT include the
# 'v' or the EOL here:
var = '%s'
const = 'n%r\n'
const = 'n%s\n'
string = 'h%d:%s\n'
monomial = product + const + var.replace('%', '%%')
multiplier = product + const
Expand Down
32 changes: 32 additions & 0 deletions pyomo/repn/tests/ampl/test_nlv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -2761,6 +2761,38 @@ def test_nested_external_expressions(self):
0 0
1 0
2 0
""",
OUT.getvalue(),
)
)

@unittest.skipUnless(numpy_available, "test requires numpy")
def test_objective_numpy_const(self):
# This tests issue #3352
m = ConcreteModel()
m.e = Expression(expr=numpy.float64(0))
m.obj = Objective(expr=m.e)

OUT = io.StringIO()
nl_writer.NLWriter().write(m, OUT, linear_presolve=False, scale_model=True)
self.assertEqual(
*nl_diff(
"""g3 1 1 0 #problem unknown
0 0 1 0 0 #vars, constraints, objectives, ranges, eqns
0 0 0 0 0 0 #nonlinear constrs, objs; ccons: lin, nonlin, nd, nzlb
0 0 #network constraints: nonlinear, linear
0 0 0 #nonlinear vars in constraints, objectives, both
0 0 0 1 #linear network variables; functions; arith, flags
0 0 0 0 0 #discrete variables: binary, integer, nonlinear (b,c,o)
0 0 #nonzeros in Jacobian, obj. gradient
0 0 #max name lengths: constraints, variables
0 0 0 0 0 #common exprs: b,c,o,c1,o1
O0 0
n0
x0
r
b
k-1
""",
OUT.getvalue(),
)
Expand Down

0 comments on commit eee27c4

Please sign in to comment.