[Cbc] defining a custom cut generator
Tobias Stengel
Tobias.Stengel at locom.de
Tue May 10 12:28:39 EDT 2016
Hello,
I was able to reduce it tot he following:
#include <CglCutGenerator.hpp>
#include <OsiSolverInterface.hpp>
#include <OsiClpSolverInterface.hpp>
#include <iostream>
#include <CbcModel.hpp>
class CustomCutGenerator : public CglCutGenerator
{
public:
CustomCutGenerator() {}
CustomCutGenerator(const CustomCutGenerator &)
{
}
virtual ~CustomCutGenerator()
{
}
CustomCutGenerator &
operator=(
const CustomCutGenerator& rhs) {
return *this;
}
std::string generateCpp(FILE* file) override
{
return "foo";
}
void generateCuts(const OsiSolverInterface &si, OsiCuts &cs, const CglTreeInfo info = CglTreeInfo()) override
{
}
CglCutGenerator* clone() const override
{
return new CustomCutGenerator(*this);
}
};
int main(int argc, char* argv[])
{
std::cout << "foo" << std::endl;
OsiClpSolverInterface solver1;
int numMpsReadErrors = solver1.readMps("noswot","mps");
if (numMpsReadErrors != 0)
{
std::cout << "read model failed" << std::endl;
return 1;
}
CbcModel* model = new CbcModel(solver1);
CustomCutGenerator cutGenerator;
// this is the critical line. comment out and it works
model->addCutGenerator(&cutGenerator);
OsiClpSolverInterface* solver = dynamic_cast<OsiClpSolverInterface*>(model->solver());
CbcMain0(*model);
const char * argv2[] = { "driver4", "-solve", "-quit" };
CbcMain1(3, argv2, *model);
return 0;
}
My next step: try to build it under linux and see what valgrind says - hopefully tomorrow.
Tobias
Von: Cbc [mailto:cbc-bounces at coin-or.org] Im Auftrag von John Forrest
Gesendet: Dienstag, 10. Mai 2016 14:57
An: cbc at list.coin-or.org
Betreff: Re: [Cbc] defining a custom cut generator
Tobias,
Odd. By default the variable switchOffIfLessThan_ in a CbcCutGenerator is zero. This means that you would not get to 9401 as it would fail test -
if (generator_[i]->switchOffIfLessThan() < 0) {
at line 9398.
What value is switchOffIfLessThan_ when assert happens? You do not reference CbcCutGenerator so how is the generator being added to CbcModel?
John Forrest
On 10/05/16 13:02, Tobias Stengel wrote:
Hi all,
I am trying to define my on cut generator. My test problem is noswot problem from miplib 3. When I add the following generator (reduced from my generator) to my model, the assert "assert (iSwitch >= 0 && iSwitch < 2);" in CbcModel.cpp, line 9401 fails. If compiled in release mode (turning asserts off), the correct solution is found.
CustomCutGenerator::CustomCutGenerator() : CglCutGenerator() { }
CustomCutGenerator::CustomCutGenerator(const CustomCutGenerator & other) {}
CustomCutGenerator::~CustomCutGenerator()
{}
std::string CustomCutGenerator::generateCpp(FILE* file)
{
return "customCutGenerator";
}
void CustomCutGenerator::generateCuts(const OsiSolverInterface &si, OsiCuts &cs, const CglTreeInfo info)
{}
CglCutGenerator* CustomCutGenerator::clone() const
{
return new CustomCutGenerator();
}
CustomCutGenerator & CustomCutGenerator::operator=(const CustomCutGenerator& rhs) {
return *this;
}
CustomCutGenerator implements CglCutGenerator. Any help why this happens and/or how to fix it would be welcomed. Especially since the user guide chapter on cuts is empty. Feel free to ask for more information.
I am using Cbc 2.9.8 and Microsoft visual C++ 2013.
Thanks
Tobias
_______________________________________________
Cbc mailing list
Cbc at list.coin-or.org<mailto:Cbc at list.coin-or.org>
http://list.coin-or.org/mailman/listinfo/cbc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cbc/attachments/20160510/b8737e2a/attachment-0001.html>
More information about the Cbc
mailing list