-
Notifications
You must be signed in to change notification settings - Fork 351
Upgrade HighsInt to int64_t #3239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -225,34 +225,45 @@ void HighsRedcostFixing::addRootRedcost(const HighsMipSolver& mipsolver, | |
| } | ||
| HighsInt maxNumSteps = static_cast<HighsInt>(1ULL << maxNumStepsExp); | ||
|
|
||
| auto fitsInt64 = [](double val) { | ||
| return val > std::numeric_limits<int64_t>::min() && | ||
| val < std::numeric_limits<int64_t>::max(); | ||
| }; | ||
|
|
||
| // lambda for finding lurking bounds | ||
| auto findLurkingBounds = | ||
| [&](HighsInt col, HighsInt direction, HighsInt bound, HighsInt otherBound, | ||
| [&](HighsInt col, HighsInt direction, int64_t bound, int64_t otherBound, | ||
| bool isOtherBoundFinite, double lpObjective, double redCost, | ||
| HighsInt maxNumSteps, HighsInt maxNumStepsExp, | ||
| std::multimap<double, HighsInt>& lurkingBounds, | ||
| std::multimap<double, HighsInt>& otherLurkingBounds) { | ||
| std::multimap<double, int64_t>& lurkingBounds, | ||
| std::multimap<double, int64_t>& otherLurkingBounds) { | ||
| if (direction * redCost == kHighsInf) { | ||
| lurkingBounds.clear(); | ||
| otherLurkingBounds.clear(); | ||
| lurkingBounds.emplace(-kHighsInf, bound); | ||
| return; | ||
| } | ||
|
|
||
| HighsInt lastBound; | ||
| int64_t lastBound; | ||
| if (!isOtherBoundFinite) | ||
| lastBound = bound + direction * maxNumSteps; | ||
| else | ||
| lastBound = otherBound - direction; | ||
|
|
||
| HighsInt step = 1; | ||
| HighsInt range = direction * (lastBound - bound); | ||
| if (range > maxNumSteps) | ||
| step = (range + maxNumSteps - 1) >> maxNumStepsExp; | ||
| int64_t step = 1; | ||
| uint64_t range = direction > 0 ? static_cast<uint64_t>(lastBound) - | ||
| static_cast<uint64_t>(bound) | ||
| : static_cast<uint64_t>(bound) - | ||
| static_cast<uint64_t>(lastBound); | ||
|
|
||
| if (range > static_cast<uint64_t>(maxNumSteps)) | ||
| step = static_cast<int64_t>( | ||
| (range >> maxNumStepsExp) + | ||
| ((range & (static_cast<uint64_t>(maxNumSteps) - 1)) != 0)); | ||
| double shift = direction * (1 - 10 * mipsolver.mipdata_->feastol); | ||
| step *= direction; | ||
|
|
||
| for (HighsInt lurkingBound = bound; | ||
| for (int64_t lurkingBound = bound; | ||
| direction * lurkingBound <= direction * lastBound; | ||
| lurkingBound += step) { | ||
| double fracBound = lurkingBound - bound + shift; | ||
|
|
@@ -289,35 +300,39 @@ void HighsRedcostFixing::addRootRedcost(const HighsMipSolver& mipsolver, | |
| }; | ||
|
|
||
| for (HighsInt col : mipsolver.mipdata_->integral_cols) { | ||
| bool lowerFinite = | ||
| fitsInt64(mipsolver.mipdata_->getDomain().col_lower_[col]); | ||
| bool upperFinite = | ||
| fitsInt64(mipsolver.mipdata_->getDomain().col_upper_[col]); | ||
| if (lpredcost[col] > mipsolver.mipdata_->feastol) { | ||
| // col <= (cutoffbound - lpobj)/redcost + lb | ||
| // so for lurkub = lb to ub - 1 we can compute the necessary cutoff | ||
| // bound to reach this bound which is: | ||
| // lurkub = (cutoffbound - lpobj)/redcost + lb | ||
| // cutoffbound = (lurkub - lb) * redcost + lpobj | ||
| if (!lowerFinite) continue; | ||
| findLurkingBounds( | ||
| col, HighsInt{1}, | ||
| static_cast<HighsInt>( | ||
| mipsolver.mipdata_->getDomain().col_lower_[col]), | ||
| static_cast<HighsInt>( | ||
| mipsolver.mipdata_->getDomain().col_upper_[col]), | ||
| mipsolver.mipdata_->getDomain().col_upper_[col] != kHighsInf, | ||
| lpobjective, lpredcost[col], maxNumSteps, maxNumStepsExp, | ||
| static_cast<int64_t>(mipsolver.mipdata_->getDomain().col_lower_[col]), | ||
| upperFinite ? static_cast<int64_t>( | ||
| mipsolver.mipdata_->getDomain().col_upper_[col]) | ||
| : int64_t{0}, | ||
| upperFinite, lpobjective, lpredcost[col], maxNumSteps, maxNumStepsExp, | ||
| lurkingColUpper[col], lurkingColLower[col]); | ||
| } else if (lpredcost[col] < -mipsolver.mipdata_->feastol) { | ||
| if (!upperFinite) continue; | ||
| // col >= (cutoffbound - lpobj)/redcost + ub | ||
| // so for lurklb = lb + 1 to ub we can compute the necessary cutoff | ||
| // bound to reach this bound which is: | ||
| // lurklb = (cutoffbound - lpobj)/redcost + ub | ||
| // cutoffbound = (lurklb - ub) * redcost + lpobj | ||
| findLurkingBounds( | ||
| col, HighsInt{-1}, | ||
| static_cast<HighsInt>( | ||
| mipsolver.mipdata_->getDomain().col_upper_[col]), | ||
| static_cast<HighsInt>( | ||
| mipsolver.mipdata_->getDomain().col_lower_[col]), | ||
| mipsolver.mipdata_->getDomain().col_lower_[col] != -kHighsInf, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| lpobjective, lpredcost[col], maxNumSteps, maxNumStepsExp, | ||
| static_cast<int64_t>(mipsolver.mipdata_->getDomain().col_upper_[col]), | ||
| lowerFinite ? static_cast<int64_t>( | ||
| mipsolver.mipdata_->getDomain().col_lower_[col]) | ||
| : int64_t{0}, | ||
| lowerFinite, lpobjective, lpredcost[col], maxNumSteps, maxNumStepsExp, | ||
| lurkingColLower[col], lurkingColUpper[col]); | ||
| } | ||
| } | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we just replace this line by:
mipsolver.mipdata_->getDomain().col_upper_[col] < kHighsIInf