@@ -319,7 +319,25 @@ void HighsPrimalHeuristics::rootReducedCost() {
319319 localdom.col_lower_ , localdom.col_upper_ ,
320320 500 , // std::max(50, int(0.05 *
321321 // (mipsolver.mipdata_->num_leaves))),
322- 200 + mipsolver.mipdata_ ->num_nodes / 20 , 12 );
322+ 200 + static_cast <HighsInt>(mipsolver.mipdata_ ->num_nodes / 20 ),
323+ 12 );
324+ }
325+
326+ static double calcFixVal (double rootchange, double fracval, double cost) {
327+ // reinforce direction of this solution away from root
328+ // solution if the change is at least 0.4
329+ // otherwise take the direction where the objective gets worse
330+ // if objective is zero round to nearest integer
331+ if (rootchange >= 0.4 )
332+ return std::ceil (fracval);
333+ else if (rootchange <= -0.4 )
334+ return std::floor (fracval);
335+ else if (cost > 0.0 )
336+ return std::ceil (fracval);
337+ else if (cost < 0.0 )
338+ return std::floor (fracval);
339+ else
340+ return std::floor (fracval + 0.5 );
323341}
324342
325343void HighsPrimalHeuristics::RENS (const std::vector<double >& tmp) {
@@ -434,25 +452,15 @@ void HighsPrimalHeuristics::RENS(const std::vector<double>& tmp) {
434452
435453 if (numBranched == 0 ) {
436454 auto getFixVal = [&](HighsInt col, double fracval) {
437- double fixval;
438-
439455 // reinforce direction of this solution away from root
440456 // solution if the change is at least 0.4
441457 // otherwise take the direction where the objective gets worse
442458 // if objective is zero round to nearest integer
443- double rootchange = mipsolver.mipdata_ ->rootlpsol .empty ()
444- ? 0.0
445- : fracval - mipsolver.mipdata_ ->rootlpsol [col];
446- if (rootchange >= 0.4 )
447- fixval = std::ceil (fracval);
448- else if (rootchange <= -0.4 )
449- fixval = std::floor (fracval);
450- else if (mipsolver.model_ ->col_cost_ [col] > 0.0 )
451- fixval = std::ceil (fracval);
452- else if (mipsolver.model_ ->col_cost_ [col] < 0.0 )
453- fixval = std::floor (fracval);
454- else
455- fixval = std::floor (fracval + 0.5 );
459+ double fixval =
460+ calcFixVal (mipsolver.mipdata_ ->rootlpsol .empty ()
461+ ? 0.0
462+ : fracval - mipsolver.mipdata_ ->rootlpsol [col],
463+ fracval, mipsolver.model_ ->col_cost_ [col]);
456464 // make sure we do not set an infeasible domain
457465 fixval = std::min (localdom.col_upper_ [col], fixval);
458466 fixval = std::max (localdom.col_lower_ [col], fixval);
@@ -671,17 +679,8 @@ void HighsPrimalHeuristics::RINS(const std::vector<double>& relaxationsol) {
671679 // solution if the change is at least 0.4
672680 // otherwise take the direction where the objective gets worse
673681 // if objective is zero round to nearest integer
674- double rootchange = fracval - mipsolver.mipdata_ ->rootlpsol [col];
675- if (rootchange >= 0.4 )
676- fixval = std::ceil (fracval);
677- else if (rootchange <= -0.4 )
678- fixval = std::floor (fracval);
679- else if (mipsolver.model_ ->col_cost_ [col] > 0.0 )
680- fixval = std::ceil (fracval);
681- else if (mipsolver.model_ ->col_cost_ [col] < 0.0 )
682- fixval = std::floor (fracval);
683- else
684- fixval = std::floor (fracval + 0.5 );
682+ fixval = calcFixVal (fracval - mipsolver.mipdata_ ->rootlpsol [col],
683+ fracval, mipsolver.model_ ->col_cost_ [col]);
685684 }
686685 // make sure we do not set an infeasible domain
687686 fixval = std::min (localdom.col_upper_ [col], fixval);
0 commit comments