coin-or / Cbc

COIN-OR Branch-and-Cut solver
Other
814 stars 115 forks source link

build error on src/CbcHeuristicDive.cpp / code questions: #612

Closed leginee closed 3 months ago

leginee commented 1 year ago

Hello all,

I build on Ubuntu 22.04.2 LTS. I build release CoinMP-1.7.6, but the code in question seems to be the same compared to the latest release.

I get for some reason following error:

CbcHeuristicDive.cpp: In member function 'int CbcHeuristicDive::solution(double&, int&, int&, OsiRowCut, CbcSubProblem&, double)': CbcHeuristicDive.cpp:706:34: error: 'clpSolver' was not declared in this scope; did you mean 'solver'? 706 | ClpSimplex simplex = clpSolver->getModelPtr(); | ^~~~~

Checking for the definition of the code I stumble on:

https://github.com/coin-or/Cbc/blob/d4272be8c5e3b231f35e7555587e427a5f69d1ed/src/CbcHeuristicDive.cpp#L299C8-L299C8

this #if clause does not make much sense to me. If CBC_HAS_CLP is not defined the code breaks wich above error I assume. So this is clause must have an else statement, at least an error statement. I wonder: 1) What is the purpose of line 299?

If I coment the macro if clause out, I get the following error message:

CbcHeuristicDive.cpp: In member function 'int CbcHeuristicDive::solution(double&, int&, int&, OsiRowCut, CbcSubProblem&, double)': CbcHeuristicDive.cpp:215:7: error: cannot 'dynamic_cast' 'solver' (of type 'class OsiSolverInterface') to type 'class OsiClpSolverInterface' (target is not pointer or reference to complete type) 215 | = dynamic_cast<OsiClpSolverInterface > (solver); | ^~~~~~~~~~ CbcHeuristicDive.cpp:217:42: error: invalid use of incomplete type 'class OsiClpSolverInterface' 217 | ClpSimplex * clpSimplex = clpSolver->getModelPtr(); | ^~

note: line 215 == 301 today

I am not sure what to do with this error. 2) why do we need to cast from OsiSolverInterface to OsiClpSolverInterface? Why is OsiClpSolverInterface not a child of OsiSolverInterface? (did not compare both classes, I am unsure if i can read your desicion from the code)

Thanks for your time, and efforts.

leginee commented 1 year ago

ok, OsiClpSolverInterface is a child of OsiSolverInterface. So the code tries to convert the interface. and the mess starts maybe because the compiler does not find clp build, which converts the cast to a static cast and that fails?

not sure, but then asking if clp is available does make kind of sense. Is this theory about line 299 correct? #ifdef CBC_HAS_CLP

svigerske commented 1 year ago

Looks to me as if some #ifdef CBC_HAS_CLP are missing around the use of clpSolver. E.g., CbcHeuristicDive.cpp:706 shouldn't be compiled if Cbc is build without Clp (which is very rare).

tkralphs commented 1 year ago

Could you say more about how you are building CoinMP exactly? Are you installing the dependencies as Ubuntu packages or downloading sources for everything? Are you using coinbrew?

CoinMP is not really maintained and there aren't many use cases for it. If you can describe what you're trying to do, there may be a better alternative (In particular Cbc and Clp have C interfaces of their own). Version 1.7.6 CoinMP depends on Cbc 2.8, which is a very old version. Even 1.8.4 depends on Version 2.9, which is also an old version. It should be possible to build the latest CoinMP with version 2.10, since the API is the same as 2.9 and that would be the way to go in order to make sure you are not getting bugs in Cbc that have been fixed since. I can help if you need to figure out how to do this. Building with coinbrew is going to be the best way to go and it should work, even with older pre-coinbrew versions of CoinMP.

With all that said, your theory seems correct. The #ifdef COIN_HAS_CLP is a vestige of an earlier effort to allow Cbc to work with other LP solvers that has largely been abandoned since. In general, Cbc will not work without Clp and it's not a good idea to build it without COIN_HAS_CLP defined (which happens automatically if Clp is detected, as it should be). I don't really know why/how you are building Cbc in a way that it doesn't detect Clp during configuration. I think that if we get you building in the correct way, the error will go away. But I also would dissuade you from using CoinMP unless there is some compelling reason why you need it.