You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems like nonlinear expressions is handled automagically. I don't know if this is by design since the java version throws a "nonlinear expression exception".
// This is a nonlinear expression and should not be supported
BOOST_AUTO_TEST_CASE(variable_is_denominator)
{
variable x(0), y(0);
simplex_solver solver;
BOOST_CHECK_EQUAL(x.value(), 0);
BOOST_CHECK_EQUAL(y.value(), 0);
solver.add_constraint(y == 10);
BOOST_CHECK_EQUAL(x.value(), 0);
BOOST_CHECK_EQUAL(y.value(), 10);
solver.add_constraint(x == 5 / y);
BOOST_CHECK_EQUAL(x.value(), 0.5);
BOOST_CHECK_EQUAL(y.value(), 10);
}
// This is a linear expression and should be supported
BOOST_AUTO_TEST_CASE(variable_is_numerator)
{
variable x(0), y(0);
simplex_solver solver;
BOOST_CHECK_EQUAL(x.value(), 0);
BOOST_CHECK_EQUAL(y.value(), 0);
solver.add_constraint(y == 10);
BOOST_CHECK_EQUAL(x.value(), 0);
BOOST_CHECK_EQUAL(y.value(), 10);
solver.add_constraint(x == y / 5);
BOOST_CHECK_EQUAL(x.value(), 2);
BOOST_CHECK_EQUAL(y.value(), 10);
}
Result
Running 41 test cases...
/unit_tests.cpp:777: error in "variable_is_denominator": check x.value() == 0.5 failed [2 != 0.5]
*** 1 failure detected in test suite "rhea"
This is the Rhea implementation
linear_expression& linear_expression::operator/=(const linear_expression& x)
{
if (is_constant())
return *this = x / constant();
if (!x.is_constant())
throw nonlinear_expression();
return operator/=(x.constant());
}
This is the java implementation
public final Expression divide(double x)
throws NonlinearExpression
{
if (Util.approx(x, 0.0))
{
throw new NonlinearExpression();
}
return times(1.0 / x);
}
The text was updated successfully, but these errors were encountered:
It seems like nonlinear expressions is handled automagically. I don't know if this is by design since the java version throws a "nonlinear expression exception".
Result
This is the Rhea implementation
This is the java implementation
The text was updated successfully, but these errors were encountered: