@@ -1812,6 +1812,78 @@ def test_presolve_zero_coef(self):
18121812 )
18131813 )
18141814
1815+ def test_presolve_independent_subsystem (self ):
1816+ # This is derived from the example in #3192
1817+ m = ConcreteModel ()
1818+ m .x = Var ()
1819+ m .y = Var ()
1820+ m .z = Var ()
1821+ m .d = Constraint (expr = m .z == m .y )
1822+ m .c = Constraint (expr = m .y == m .x )
1823+ m .o = Objective (expr = 0 )
1824+
1825+ ref = """g3 1 1 0 #problem unknown
1826+ 0 0 1 0 0 #vars, constraints, objectives, ranges, eqns
1827+ 0 0 0 0 0 0 #nonlinear constrs, objs; ccons: lin, nonlin, nd, nzlb
1828+ 0 0 #network constraints: nonlinear, linear
1829+ 0 0 0 #nonlinear vars in constraints, objectives, both
1830+ 0 0 0 1 #linear network variables; functions; arith, flags
1831+ 0 0 0 0 0 #discrete variables: binary, integer, nonlinear (b,c,o)
1832+ 0 0 #nonzeros in Jacobian, obj. gradient
1833+ 1 0 #max name lengths: constraints, variables
1834+ 0 0 0 0 0 #common exprs: b,c,o,c1,o1
1835+ O0 0 #o
1836+ n0
1837+ x0 #initial guess
1838+ r #0 ranges (rhs's)
1839+ b #0 bounds (on variables)
1840+ k-1 #intermediate Jacobian column lengths
1841+ """
1842+
1843+ OUT = io .StringIO ()
1844+ with LoggingIntercept () as LOG :
1845+ nlinfo = nl_writer .NLWriter ().write (
1846+ m , OUT , symbolic_solver_labels = True , linear_presolve = True
1847+ )
1848+ self .assertEqual (
1849+ LOG .getvalue (),
1850+ "presolve identified an underdetermined independent linear subsystem "
1851+ "that was removed from the model. Setting 'z' == 0\n " ,
1852+ )
1853+
1854+ self .assertEqual (* nl_diff (ref , OUT .getvalue ()))
1855+
1856+ m .x .lb = 5.0
1857+
1858+ OUT = io .StringIO ()
1859+ with LoggingIntercept () as LOG :
1860+ nlinfo = nl_writer .NLWriter ().write (
1861+ m , OUT , symbolic_solver_labels = True , linear_presolve = True
1862+ )
1863+ self .assertEqual (
1864+ LOG .getvalue (),
1865+ "presolve identified an underdetermined independent linear subsystem "
1866+ "that was removed from the model. Setting 'z' == 5.0\n " ,
1867+ )
1868+
1869+ self .assertEqual (* nl_diff (ref , OUT .getvalue ()))
1870+
1871+ m .x .lb = - 5.0
1872+ m .z .ub = - 2.0
1873+
1874+ OUT = io .StringIO ()
1875+ with LoggingIntercept () as LOG :
1876+ nlinfo = nl_writer .NLWriter ().write (
1877+ m , OUT , symbolic_solver_labels = True , linear_presolve = True
1878+ )
1879+ self .assertEqual (
1880+ LOG .getvalue (),
1881+ "presolve identified an underdetermined independent linear subsystem "
1882+ "that was removed from the model. Setting 'z' == -2.0\n " ,
1883+ )
1884+
1885+ self .assertEqual (* nl_diff (ref , OUT .getvalue ()))
1886+
18151887 def test_scaling (self ):
18161888 m = pyo .ConcreteModel ()
18171889 m .x = pyo .Var (initialize = 0 )
0 commit comments