Skip to content

Commit

Permalink
Merge pull request #141 from coin-or/evd-fix
Browse files Browse the repository at this point in the history
Fixes for, e.g. EVD
  • Loading branch information
andreaslundell authored Oct 20, 2021
2 parents a146a13 + 48ed866 commit 11fda1e
Show file tree
Hide file tree
Showing 15 changed files with 286 additions and 132 deletions.
11 changes: 9 additions & 2 deletions src/DualSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ void DualSolver::checkDualSolutionCandidates()
// New dual solution
env->results->setDualBound(C.objValue);
currDualBound = C.objValue;
env->solutionStatistics.iterationLastDualBoundUpdate = env->results->getCurrentIteration()->iterationNumber;

if(env->results->getNumberOfIterations() > 0)
env->solutionStatistics.iterationLastDualBoundUpdate
= env->results->getCurrentIteration()->iterationNumber;
else
env->solutionStatistics.iterationLastDualBoundUpdate = 0;

env->solutionStatistics.iterationLastDualBoundUpdate = env->timing->getElapsedTime("Total");

if(C.sourceType == E_DualSolutionSource::MIPSolutionOptimal
Expand Down Expand Up @@ -257,7 +263,8 @@ bool DualSolver::hasHyperplaneBeenAdded(double hash, int constraintIndex)

void DualSolver::addIntegerCut(IntegerCut integerCut)
{
if(env->reformulatedProblem->properties.numberOfIntegerVariables > 0 || env->reformulatedProblem->properties.numberOfSemiintegerVariables > 0)
if(env->reformulatedProblem->properties.numberOfIntegerVariables > 0
|| env->reformulatedProblem->properties.numberOfSemiintegerVariables > 0)
integerCut.areAllVariablesBinary = false;
else
{
Expand Down
6 changes: 6 additions & 0 deletions src/Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@ enum class ES_AddPrimalPointAsInteriorPoint
OnlyAverage
};

enum class ES_EigenValueDecompositionFormulation
{
CoefficientReformulated,
CoefficientRemains
};

enum class ES_HyperplaneCutStrategy
{
ESH,
Expand Down
27 changes: 16 additions & 11 deletions src/MIPSolver/MIPSolverCplexSingleTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,21 +315,26 @@ void CplexCallback::invoke(const IloCplex::Callback::Context& context)

if(checkFixedNLPStrategy(candidatePoints.at(0)))
{
env->primalSolver->addFixedNLPCandidate(candidatePoints.at(0).point, E_PrimalNLPSource::FirstSolution,
context.getCandidateObjective(), env->results->getCurrentIteration()->iterationNumber,
candidatePoints.at(0).maxDeviation);

if(taskSelectPrimNLPOriginal)
taskSelectPrimNLPOriginal->run();
{
env->primalSolver->addFixedNLPCandidate(candidatePoints.at(0).point,
E_PrimalNLPSource::FirstSolution, context.getCandidateObjective(),
env->results->getCurrentIteration()->iterationNumber, candidatePoints.at(0).maxDeviation);

env->primalSolver->addFixedNLPCandidate(candidatePoints.at(0).point, E_PrimalNLPSource::FirstSolution,
context.getCandidateObjective(), env->results->getCurrentIteration()->iterationNumber,
candidatePoints.at(0).maxDeviation);
taskSelectPrimNLPOriginal->run();
env->primalSolver->fixedPrimalNLPCandidates.clear();
}

if(taskSelectPrimNLPReformulated)
taskSelectPrimNLPReformulated->run();
{
env->primalSolver->addFixedNLPCandidate(candidatePoints.at(0).point,
E_PrimalNLPSource::FirstSolution, context.getCandidateObjective(),
env->results->getCurrentIteration()->iterationNumber, candidatePoints.at(0).maxDeviation);

env->primalSolver->fixedPrimalNLPCandidates.clear();
taskSelectPrimNLPReformulated->run();
env->primalSolver->fixedPrimalNLPCandidates.clear();
}

env->primalSolver->checkPrimalSolutionCandidates();
}
Expand Down Expand Up @@ -554,8 +559,8 @@ void CplexCallback::addLazyConstraint(

for(auto& hp : env->dualSolver->hyperplaneWaitingList)
{
this->createHyperplane(hp, context);
this->lastNumAddedHyperplanes++;
if(this->createHyperplane(hp, context))
this->lastNumAddedHyperplanes++;
}

env->dualSolver->hyperplaneWaitingList.clear();
Expand Down
24 changes: 14 additions & 10 deletions src/MIPSolver/MIPSolverCplexSingleTreeLegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,19 +428,23 @@ void CtCallbackI::main()

if(checkFixedNLPStrategy(solutionCandidate))
{
env->primalSolver->addFixedNLPCandidate(solution, E_PrimalNLPSource::FirstSolution, this->getObjValue(),
env->results->getCurrentIteration()->iterationNumber, solutionCandidate.maxDeviation);

if(taskSelectPrimNLPOriginal)
taskSelectPrimNLPOriginal->run();
{
env->primalSolver->addFixedNLPCandidate(solution, E_PrimalNLPSource::FirstSolution, this->getObjValue(),
env->results->getCurrentIteration()->iterationNumber, solutionCandidate.maxDeviation);

env->primalSolver->addFixedNLPCandidate(solution, E_PrimalNLPSource::FirstSolution, this->getObjValue(),
env->results->getCurrentIteration()->iterationNumber, solutionCandidate.maxDeviation);
taskSelectPrimNLPOriginal->run();
env->primalSolver->fixedPrimalNLPCandidates.clear();
}

if(taskSelectPrimNLPReformulated)
taskSelectPrimNLPReformulated->run();
{
env->primalSolver->addFixedNLPCandidate(solution, E_PrimalNLPSource::FirstSolution, this->getObjValue(),
env->results->getCurrentIteration()->iterationNumber, solutionCandidate.maxDeviation);

env->primalSolver->fixedPrimalNLPCandidates.clear();
taskSelectPrimNLPReformulated->run();
env->primalSolver->fixedPrimalNLPCandidates.clear();
}

env->primalSolver->checkPrimalSolutionCandidates();

Expand Down Expand Up @@ -485,8 +489,8 @@ void CtCallbackI::main()

for(auto& hp : env->dualSolver->hyperplaneWaitingList)
{
this->createHyperplane(hp);
this->lastNumAddedHyperplanes++;
if(this->createHyperplane(hp))
this->lastNumAddedHyperplanes++;
}

env->dualSolver->hyperplaneWaitingList.clear();
Expand Down
3 changes: 3 additions & 0 deletions src/MIPSolver/MIPSolverGurobi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,9 @@ void MIPSolverGurobi::setTimeLimit(double seconds)

void MIPSolverGurobi::setCutOff(double cutOff)
{
if(std::abs(cutOff) > 1e20)
return;

try
{
// Gurobi has problems if not an epsilon value is added to the cutoff...
Expand Down
77 changes: 41 additions & 36 deletions src/MIPSolver/MIPSolverGurobiSingleTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,31 @@ void GurobiCallbackSingleTree::callback()

try
{

// Add current primal bound as new incumbent candidate
auto primalBound = env->results->getPrimalBound();

if(((isMinimization && lastUpdatedPrimal < primalBound)
|| (!isMinimization && lastUpdatedPrimal > primalBound)))
{
auto primalSol = env->results->primalSolution;

if((int)primalSol.size() < env->reformulatedProblem->properties.numberOfVariables)
env->reformulatedProblem->augmentAuxiliaryVariableValues(primalSol);

assert(env->reformulatedProblem->properties.numberOfVariables == primalSol.size());

if(env->dualSolver->MIPSolver->hasDualAuxiliaryObjectiveVariable())
primalSol.push_back(env->reformulatedProblem->objectiveFunction->calculateValue(primalSol));

for(size_t i = 0; i < primalSol.size(); i++)
{
setSolution(vars[i], primalSol.at(i));
}

lastUpdatedPrimal = env->results->getPrimalBound();
}

// Check if better dual bound
double tmpDualObjBound;

Expand Down Expand Up @@ -394,21 +419,25 @@ void GurobiCallbackSingleTree::callback()

if(checkFixedNLPStrategy(candidatePoints.at(0)))
{
env->primalSolver->addFixedNLPCandidate(candidatePoints.at(0).point, E_PrimalNLPSource::FirstSolution,
getDoubleInfo(GRB_CB_MIPSOL_OBJ), env->results->getCurrentIteration()->iterationNumber,
candidatePoints.at(0).maxDeviation);

if(taskSelectPrimNLPOriginal)
taskSelectPrimNLPOriginal->run();
{
env->primalSolver->addFixedNLPCandidate(candidatePoints.at(0).point,
E_PrimalNLPSource::FirstSolution, getDoubleInfo(GRB_CB_MIPSOL_OBJ),
env->results->getCurrentIteration()->iterationNumber, candidatePoints.at(0).maxDeviation);

env->primalSolver->addFixedNLPCandidate(candidatePoints.at(0).point, E_PrimalNLPSource::FirstSolution,
getDoubleInfo(GRB_CB_MIPSOL_OBJ), env->results->getCurrentIteration()->iterationNumber,
candidatePoints.at(0).maxDeviation);
taskSelectPrimNLPOriginal->run();
env->primalSolver->fixedPrimalNLPCandidates.clear();
}

if(taskSelectPrimNLPReformulated)
taskSelectPrimNLPReformulated->run();
{
env->primalSolver->addFixedNLPCandidate(candidatePoints.at(0).point,
E_PrimalNLPSource::FirstSolution, getDoubleInfo(GRB_CB_MIPSOL_OBJ),
env->results->getCurrentIteration()->iterationNumber, candidatePoints.at(0).maxDeviation);

env->primalSolver->fixedPrimalNLPCandidates.clear();
taskSelectPrimNLPReformulated->run();
env->primalSolver->fixedPrimalNLPCandidates.clear();
}

env->primalSolver->checkPrimalSolutionCandidates();
}
Expand Down Expand Up @@ -443,30 +472,6 @@ void GurobiCallbackSingleTree::callback()
lastExploredNodes = (int)getDoubleInfo(GRB_CB_MIP_NODCNT);
lastOpenNodes = (int)getDoubleInfo(GRB_CB_MIP_NODLFT);
}

// Add current primal bound as new incumbent candidate
auto primalBound = env->results->getPrimalBound();

if(((isMinimization && lastUpdatedPrimal < primalBound)
|| (!isMinimization && lastUpdatedPrimal > primalBound)))
{
auto primalSol = env->results->primalSolution;

if((int)primalSol.size() < env->reformulatedProblem->properties.numberOfVariables)
env->reformulatedProblem->augmentAuxiliaryVariableValues(primalSol);

assert(env->reformulatedProblem->properties.numberOfVariables == primalSol.size());

if(env->dualSolver->MIPSolver->hasDualAuxiliaryObjectiveVariable())
primalSol.push_back(env->reformulatedProblem->objectiveFunction->calculateValue(primalSol));

for(size_t i = 0; i < primalSol.size(); i++)
{
setSolution(vars[i], primalSol.at(i));
}

lastUpdatedPrimal = env->results->getPrimalBound();
}
}
catch(GRBException& e)
{
Expand Down Expand Up @@ -669,8 +674,8 @@ void GurobiCallbackSingleTree::addLazyConstraint(std::vector<SolutionPoint> cand

for(auto& hp : env->dualSolver->hyperplaneWaitingList)
{
this->createHyperplane(hp);
this->lastNumAddedHyperplanes++;
if(this->createHyperplane(hp))
this->lastNumAddedHyperplanes++;
}

env->dualSolver->hyperplaneWaitingList.clear();
Expand Down
Loading

0 comments on commit 11fda1e

Please sign in to comment.