From bfe0857fb866483273aa89f01a7abf795c5a6485 Mon Sep 17 00:00:00 2001 From: Andrea Sgattoni Date: Thu, 19 Oct 2023 17:12:12 +0200 Subject: [PATCH] minor improvement to unittests --- .../linear_solver/unittests/xpress_interface.cc | 16 ++++++++-------- ortools/linear_solver/xpress_interface.cc | 8 +++++++- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ortools/linear_solver/unittests/xpress_interface.cc b/ortools/linear_solver/unittests/xpress_interface.cc index 492a183e27..870ea99b0d 100644 --- a/ortools/linear_solver/unittests/xpress_interface.cc +++ b/ortools/linear_solver/unittests/xpress_interface.cc @@ -224,14 +224,13 @@ namespace operations_research { class MyMPCallback : public MPCallback { private: MPSolver* mpSolver_; - int nSolutions_; + int nSolutions_=0; std::vector last_variable_values_; bool should_throw_; public: - MyMPCallback(MPSolver* mpSolver, bool should_throw = false) + MyMPCallback(MPSolver* mpSolver, bool should_throw) : MPCallback(false, false), mpSolver_(mpSolver), - nSolutions_(0), should_throw_(should_throw){}; ~MyMPCallback() override{}; @@ -256,7 +255,7 @@ namespace operations_research { MyMPCallback* buildLargeMipWithCallback(MPSolver &solver, int numVars, int maxTime) { buildLargeMip(solver, numVars, maxTime); - MPCallback* mpCallback = new MyMPCallback(&solver); + MPCallback* mpCallback = new MyMPCallback(&solver, false); solver.SetCallback(nullptr); // just to test that this does not cause failure solver.SetCallback(mpCallback); return static_cast(mpCallback); @@ -1245,9 +1244,10 @@ ENDATA EXPECT_GT(nSolutions, 5); // Test variable values for the last solution found for (int i = 0; i < solver.NumVariables(); ++i) { - EXPECT_DOUBLE_EQ(myMpCallback->getLastVariableValue(i), - solver.LookupVariableOrNull("x_" + std::to_string(i)) - ->solution_value()); + EXPECT_NEAR(myMpCallback->getLastVariableValue(i), + solver.LookupVariableOrNull("x_" + std::to_string(i)) + ->solution_value(), + 1e-10); } } @@ -1264,7 +1264,7 @@ ENDATA // Test that when we set a new callback then it is called, and old one is not called UNITTEST_INIT_MIP(); auto oldMpCallback = buildLargeMipWithCallback(solver, 100, 5); - auto newMpCallback = new MyMPCallback(&solver); + auto newMpCallback = new MyMPCallback(&solver, false); solver.SetCallback((MPCallback*) newMpCallback); solver.Solve(); EXPECT_EQ(oldMpCallback->getNSolutions(), 0); diff --git a/ortools/linear_solver/xpress_interface.cc b/ortools/linear_solver/xpress_interface.cc index c457482720..85850ff579 100644 --- a/ortools/linear_solver/xpress_interface.cc +++ b/ortools/linear_solver/xpress_interface.cc @@ -1217,7 +1217,13 @@ void XpressInterface::ClearObjective() { ++j; } } - if (j > 0) CHECK_STATUS(XPRSchgobj(mLp, j, ind.get(), zero.get())); + if (j > 0) { + LOG(ERROR) << "calling XPRSchgobj ... with ncols=" << j << " >>>>>>"; + LOG(ERROR) << "calling XPRSchgobj ... ind[0]=" << ind[0] << " >>>>>>"; + LOG(ERROR) << "calling XPRSchgobj ... zero[0]=" << zero[0] << " >>>>>>"; + LOG(ERROR) << "calling XPRSchgobj ... with coeffs.size()=" << coeffs.size() << " >>>>>>"; + CHECK_STATUS(XPRSchgobj(mLp, j, ind.get(), zero.get())); + } CHECK_STATUS(setobjoffset(mLp, 0.0)); } else { InvalidateModelSynchronization();