Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Conditional jump or move depends on uninitialised value" for model with SOS 2 and MIP start (master) #625

Closed
tobiass-sdl opened this issue Nov 15, 2023 · 2 comments

Comments

@tobiass-sdl
Copy link

If the code below is compiled and run with valgrind the following is reported:

==314955== Conditional jump or move depends on uninitialised value(s)
==314955==    at 0x49FA7C1: CbcModel::setBestSolution(CBC_Message, double&, double const*, int) (CbcModel.cpp:14302)
==314955==    by 0x4A64F66: CbcMain1(std::deque<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >, CbcModel&, CbcParameters&, int (*)(CbcModel*, int), ampl_info*) (CbcSolver.cpp:6700)
==314955==    by 0x4A8B516: CbcMain1(int, char const**, CbcModel&, CbcParameters&, int (*)(CbcModel*, int), ampl_info*) (CbcSolver.cpp:13236)
==314955==    by 0x10EAC6: main (reproduction2.cpp:65)
==314955== 

As far as I can see this is caused by " double obj;" in CbcSolver line 6619 still being uninitialized in line 6700 and then passed to CbcModel::setBestSolution where an if depends on it.

#include "coin-or/CbcModel.hpp"
#include "coin-or/CbcSOS.hpp"
#include "coin-or/CbcSolver.hpp"
#include "coin-or/OsiClpSolverInterface.hpp"

#include <vector>
#include <limits>

int main() {
  int rowCount = 6;
  int columnCount = 8;
  int sosCount = 1;

  double objective[] = {0, 1, 0, 0, 1, 1.8, 2.2, 0};
  int rowIndices[] = {0, 1, 4, 0, 2, 1, 3, 2, 3, 4, 5, 4, 5, 4, 5, 5};
  double values[] = {-1, 1, -1, -1, 1, -1, 1, -1, 1, 1, 1, 3, 1, 5, 1, 1};
  int starts[] = {0, 3, 5, 7, 9, 11, 13, 15, 16};

  double rowLowerBounds[] = {-10, 0, 0, 5, 0, 1};
  double rowUpperBounds[] = {0, 0, 0, 5, 0, 1};
  double colLowerBounds[] = {0, 0, 0, 0, 0, 0, 0, 0};
  double colUpperBounds[] = {std::numeric_limits<double>::max(),
                             std::numeric_limits<double>::max(),
                             std::numeric_limits<double>::max(),
                             std::numeric_limits<double>::max(),
                             1,
                             1,
                             1,
                             1};

  double initialSolution[] = {5, 0, 5, 0, 0, 0, 1, 0};

  int sosIndices[] = {7, 4, 5, 6};
  double sosWeights[] = {0.0, 1, 3, 5};

  OsiClpSolverInterface solver;

  solver.loadProblem(columnCount, rowCount, starts, rowIndices, values,
                     colLowerBounds, colUpperBounds, objective, rowLowerBounds,
                     rowUpperBounds);

  CbcModel model(solver);
  std::vector<std::pair<std::string, double>> sol;
  auto modelSolver = model.solver();

  for (int i = 0; i < columnCount; ++i) {
    const auto val = initialSolution[i];
    sol.emplace_back(modelSolver->getColName(i), val);
  }

  model.setMIPStart(sol);

  OsiObject *sos = new CbcSOS(&model, 4, sosIndices, sosWeights, 0, 2);

  model.addObjects(1, &sos);

  delete sos;

  CbcSolverUsefulData usefulData;
  CbcMain0(model, usefulData);
  std::vector<const char *> argv = {
      "does_not_matter", "-threads", "1",      "-feas", "on", "-seconds", "100",
      "-ratio",          "0.0",      "-solve", "-quit"};

  CbcMain1(argv.size(), argv.data(), model, usefulData);
}
@jjhforrest
Copy link
Contributor

Unable to reproduce as CbcMipStart
gives
Cbc0045I Warning: MIPstart solution is not valid, column names do not match, ignoring it. So code does not follow path which led to undefined obj.

This is a bug arising because there were no integer variables.

I have fixed that. Valgrind does not complain when I run. Changes have been made recently in master which could have fixed problem.

@tobiass-sdl
Copy link
Author

Thanks, that commit fixed the unitialized read for me, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants