@@ -186,6 +186,31 @@ void GurobiCallbackSingleTree::callback()
186186
187187 try
188188 {
189+
190+ // Add current primal bound as new incumbent candidate
191+ auto primalBound = env->results ->getPrimalBound ();
192+
193+ if (((isMinimization && lastUpdatedPrimal < primalBound)
194+ || (!isMinimization && lastUpdatedPrimal > primalBound)))
195+ {
196+ auto primalSol = env->results ->primalSolution ;
197+
198+ if ((int )primalSol.size () < env->reformulatedProblem ->properties .numberOfVariables )
199+ env->reformulatedProblem ->augmentAuxiliaryVariableValues (primalSol);
200+
201+ assert (env->reformulatedProblem ->properties .numberOfVariables == primalSol.size ());
202+
203+ if (env->dualSolver ->MIPSolver ->hasDualAuxiliaryObjectiveVariable ())
204+ primalSol.push_back (env->reformulatedProblem ->objectiveFunction ->calculateValue (primalSol));
205+
206+ for (size_t i = 0 ; i < primalSol.size (); i++)
207+ {
208+ setSolution (vars[i], primalSol.at (i));
209+ }
210+
211+ lastUpdatedPrimal = env->results ->getPrimalBound ();
212+ }
213+
189214 // Check if better dual bound
190215 double tmpDualObjBound;
191216
@@ -394,21 +419,25 @@ void GurobiCallbackSingleTree::callback()
394419
395420 if (checkFixedNLPStrategy (candidatePoints.at (0 )))
396421 {
397- env->primalSolver ->addFixedNLPCandidate (candidatePoints.at (0 ).point , E_PrimalNLPSource::FirstSolution,
398- getDoubleInfo (GRB_CB_MIPSOL_OBJ ), env->results ->getCurrentIteration ()->iterationNumber ,
399- candidatePoints.at (0 ).maxDeviation );
400-
401422 if (taskSelectPrimNLPOriginal)
402- taskSelectPrimNLPOriginal->run ();
423+ {
424+ env->primalSolver ->addFixedNLPCandidate (candidatePoints.at (0 ).point ,
425+ E_PrimalNLPSource::FirstSolution, getDoubleInfo (GRB_CB_MIPSOL_OBJ ),
426+ env->results ->getCurrentIteration ()->iterationNumber , candidatePoints.at (0 ).maxDeviation );
403427
404- env-> primalSolver -> addFixedNLPCandidate (candidatePoints. at ( 0 ). point , E_PrimalNLPSource::FirstSolution,
405- getDoubleInfo ( GRB_CB_MIPSOL_OBJ ), env->results -> getCurrentIteration ()-> iterationNumber ,
406- candidatePoints. at ( 0 ). maxDeviation );
428+ taskSelectPrimNLPOriginal-> run ();
429+ env->primalSolver -> fixedPrimalNLPCandidates . clear ();
430+ }
407431
408432 if (taskSelectPrimNLPReformulated)
409- taskSelectPrimNLPReformulated->run ();
433+ {
434+ env->primalSolver ->addFixedNLPCandidate (candidatePoints.at (0 ).point ,
435+ E_PrimalNLPSource::FirstSolution, getDoubleInfo (GRB_CB_MIPSOL_OBJ ),
436+ env->results ->getCurrentIteration ()->iterationNumber , candidatePoints.at (0 ).maxDeviation );
410437
411- env->primalSolver ->fixedPrimalNLPCandidates .clear ();
438+ taskSelectPrimNLPReformulated->run ();
439+ env->primalSolver ->fixedPrimalNLPCandidates .clear ();
440+ }
412441
413442 env->primalSolver ->checkPrimalSolutionCandidates ();
414443 }
@@ -443,30 +472,6 @@ void GurobiCallbackSingleTree::callback()
443472 lastExploredNodes = (int )getDoubleInfo (GRB_CB_MIP_NODCNT );
444473 lastOpenNodes = (int )getDoubleInfo (GRB_CB_MIP_NODLFT );
445474 }
446-
447- // Add current primal bound as new incumbent candidate
448- auto primalBound = env->results ->getPrimalBound ();
449-
450- if (((isMinimization && lastUpdatedPrimal < primalBound)
451- || (!isMinimization && lastUpdatedPrimal > primalBound)))
452- {
453- auto primalSol = env->results ->primalSolution ;
454-
455- if ((int )primalSol.size () < env->reformulatedProblem ->properties .numberOfVariables )
456- env->reformulatedProblem ->augmentAuxiliaryVariableValues (primalSol);
457-
458- assert (env->reformulatedProblem ->properties .numberOfVariables == primalSol.size ());
459-
460- if (env->dualSolver ->MIPSolver ->hasDualAuxiliaryObjectiveVariable ())
461- primalSol.push_back (env->reformulatedProblem ->objectiveFunction ->calculateValue (primalSol));
462-
463- for (size_t i = 0 ; i < primalSol.size (); i++)
464- {
465- setSolution (vars[i], primalSol.at (i));
466- }
467-
468- lastUpdatedPrimal = env->results ->getPrimalBound ();
469- }
470475 }
471476 catch (GRBException& e)
472477 {
@@ -669,8 +674,8 @@ void GurobiCallbackSingleTree::addLazyConstraint(std::vector<SolutionPoint> cand
669674
670675 for (auto & hp : env->dualSolver ->hyperplaneWaitingList )
671676 {
672- this ->createHyperplane (hp);
673- this ->lastNumAddedHyperplanes ++;
677+ if ( this ->createHyperplane (hp))
678+ this ->lastNumAddedHyperplanes ++;
674679 }
675680
676681 env->dualSolver ->hyperplaneWaitingList .clear ();
0 commit comments