@@ -1481,7 +1481,6 @@ def test_presolve_almost_lower_triangular_nonlinear(self):
1481
1481
# Note: bounds on x[1] are:
1482
1482
# min(22/3, 82/17, 23/4, -39/-6) == 4.823529411764706
1483
1483
# max(2/3, 62/17, 3/4, -19/-6) == 3.6470588235294117
1484
- print (OUT .getvalue ())
1485
1484
self .assertEqual (
1486
1485
* nl_diff (
1487
1486
"""g3 1 1 0 # problem unknown
@@ -1558,6 +1557,83 @@ def test_presolve_lower_triangular_out_of_bounds(self):
1558
1557
nlinfo = nl_writer .NLWriter ().write (m , OUT , linear_presolve = True )
1559
1558
self .assertEqual (LOG .getvalue (), "" )
1560
1559
1560
+ def test_presolve_named_expressions (self ):
1561
+ # Test from #3055
1562
+ m = pyo .ConcreteModel ()
1563
+ m .x = pyo .Var ([1 , 2 , 3 ], initialize = 1 , bounds = (0 , 10 ))
1564
+ m .subexpr = pyo .Expression (pyo .Integers )
1565
+ m .subexpr [1 ] = m .x [1 ] + m .x [2 ]
1566
+ m .eq = pyo .Constraint (pyo .Integers )
1567
+ m .eq [1 ] = m .x [1 ] == 7
1568
+ m .eq [2 ] = m .x [3 ] == 0.1 * m .subexpr [1 ] * m .x [2 ]
1569
+ m .obj = pyo .Objective (expr = m .x [1 ] ** 2 + m .x [2 ] ** 2 + m .x [3 ] ** 3 )
1570
+
1571
+ OUT = io .StringIO ()
1572
+ with LoggingIntercept () as LOG :
1573
+ nlinfo = nl_writer .NLWriter ().write (
1574
+ m , OUT , symbolic_solver_labels = True , linear_presolve = True
1575
+ )
1576
+ self .assertEqual (LOG .getvalue (), "" )
1577
+
1578
+ self .assertEqual (
1579
+ nlinfo .eliminated_vars , [(m .x [1 ], nl_writer .AMPLRepn (7 , {}, None ))]
1580
+ )
1581
+
1582
+ self .assertEqual (
1583
+ * nl_diff (
1584
+ """g3 1 1 0 # problem unknown
1585
+ 2 1 1 0 1 # vars, constraints, objectives, ranges, eqns
1586
+ 1 1 0 0 0 0 # nonlinear constrs, objs; ccons: lin, nonlin, nd, nzlb
1587
+ 0 0 # network constraints: nonlinear, linear
1588
+ 1 2 1 # nonlinear vars in constraints, objectives, both
1589
+ 0 0 0 1 # linear network variables; functions; arith, flags
1590
+ 0 0 0 0 0 # discrete variables: binary, integer, nonlinear (b,c,o)
1591
+ 2 2 # nonzeros in Jacobian, obj. gradient
1592
+ 5 4 # max name lengths: constraints, variables
1593
+ 0 0 0 1 0 # common exprs: b,c,o,c1,o1
1594
+ V2 1 1 #subexpr[1]
1595
+ 0 1
1596
+ n7.0
1597
+ C0 #eq[2]
1598
+ o16 #-
1599
+ o2 #*
1600
+ o2 #*
1601
+ n0.1
1602
+ v2 #subexpr[1]
1603
+ v0 #x[2]
1604
+ O0 0 #obj
1605
+ o54 # sumlist
1606
+ 3 # (n)
1607
+ o5 #^
1608
+ n7.0
1609
+ n2
1610
+ o5 #^
1611
+ v0 #x[2]
1612
+ n2
1613
+ o5 #^
1614
+ v1 #x[3]
1615
+ n3
1616
+ x2 # initial guess
1617
+ 0 1 #x[2]
1618
+ 1 1 #x[3]
1619
+ r #1 ranges (rhs's)
1620
+ 4 0 #eq[2]
1621
+ b #2 bounds (on variables)
1622
+ 0 0 10 #x[2]
1623
+ 0 0 10 #x[3]
1624
+ k1 #intermediate Jacobian column lengths
1625
+ 1
1626
+ J0 2 #eq[2]
1627
+ 0 0
1628
+ 1 1
1629
+ G0 2 #obj
1630
+ 0 0
1631
+ 1 0
1632
+ """ ,
1633
+ OUT .getvalue (),
1634
+ )
1635
+ )
1636
+
1561
1637
def test_scaling (self ):
1562
1638
m = pyo .ConcreteModel ()
1563
1639
m .x = pyo .Var (initialize = 0 )
@@ -1665,7 +1741,7 @@ def test_scaling(self):
1665
1741
self .assertEqual (LOG .getvalue (), "" )
1666
1742
1667
1743
nl2 = OUT .getvalue ()
1668
- print ( nl2 )
1744
+
1669
1745
self .assertEqual (
1670
1746
* nl_diff (
1671
1747
"""g3 1 1 0 # problem unknown
@@ -1759,7 +1835,7 @@ def test_named_expressions(self):
1759
1835
1760
1836
OUT = io .StringIO ()
1761
1837
nl_writer .NLWriter ().write (m , OUT , symbolic_solver_labels = True )
1762
- print ( OUT . getvalue ())
1838
+
1763
1839
self .assertEqual (
1764
1840
* nl_diff (
1765
1841
"""g3 1 1 0 # problem unknown
0 commit comments