Skip to content

Commit

Permalink
Limit solver time in a more fine-grained manner.
Browse files Browse the repository at this point in the history
  • Loading branch information
sukritkalra committed May 20, 2024
1 parent 07d99ba commit 49e2682
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 32 deletions.
43 changes: 23 additions & 20 deletions schedulers/tetrisched/src/GurobiSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,31 @@ GurobiSolver::GurobiInterruptOptimizationCallback::
void GurobiSolver::GurobiInterruptOptimizationCallback::callback() {
try {
auto currentTime = std::chrono::steady_clock::now();
if (where == GRB_CB_POLLING) {
if (params.timeLimitMs.has_value()) {
auto elapsedTimeMs =
std::chrono::duration_cast<std::chrono::milliseconds>(currentTime -
startTime)
.count();

if (elapsedTimeMs > params.timeLimitMs.value()) {
abort();
}

// Check if we need to abort due to time limits.
if (params.timeLimitMs.has_value()) {
auto elapsedTimeMs =
std::chrono::duration_cast<std::chrono::milliseconds>(currentTime -
startTime)
.count();

if (elapsedTimeMs > params.timeLimitMs.value()) {
abort();
}
if (params.newSolutionTimeLimitMs.has_value()) {
auto elapsedTimeMs =
std::chrono::duration_cast<std::chrono::milliseconds>(
currentTime - lastIncumbentSolutionTime)
.count();

if (elapsedTimeMs > params.newSolutionTimeLimitMs.value()) {
abort();
}
}
if (params.newSolutionTimeLimitMs.has_value()) {
auto elapsedTimeMs =
std::chrono::duration_cast<std::chrono::milliseconds>(
currentTime - lastIncumbentSolutionTime)
.count();

if (elapsedTimeMs > params.newSolutionTimeLimitMs.value()) {
abort();
}
} else if (where == GRB_CB_MIPSOL && params.utilityUpperBound.has_value()) {
}

// Check if we need to abort due to the upper bound of the objective.
if (where == GRB_CB_MIPSOL && params.utilityUpperBound.has_value()) {
auto solutionObjectiveValue = getDoubleInfo(GRB_CB_MIPSOL_OBJ);
if (solutionObjectiveValue >= params.utilityUpperBound.value() -
TETRISCHED_SOLUTION_UPPER_BOUND_DELTA) {
Expand Down
22 changes: 10 additions & 12 deletions schedulers/tetrisched/src/OptimizationPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,7 @@ void DiscretizationSelectorOptimizationPass::runPass(
// - minOccupancyTime] << std::endl;
// }

// changing the STRL expressions
// for (auto &[discreteTimeRange, discreteGranularity] : timeRangeToGranularities)
// Changing the STRL expressions
// Find Max expressions over NCK and remove NCK expressions with redundant
// start times
{
Expand All @@ -714,8 +713,6 @@ void DiscretizationSelectorOptimizationPass::runPass(
{
auto startTime = discreteTimeRange.first;
auto endTime = discreteTimeRange.second;
// find ncks within startTime and endTime for this Max expr
// std::vector<ExpressionPtr> ncksWithinTimeRange;

ExpressionPtr minStartTimeNckExpr = nullptr;
ExpressionPtr prevSolutionNckExpr = nullptr;
Expand All @@ -726,20 +723,19 @@ void DiscretizationSelectorOptimizationPass::runPass(
if (prevSolutionNckExpr == nullptr &&
(*child)->isPreviouslySatisfied()) {
prevSolutionNckExpr = *child;
// break;
}
if (minStartTimeNckExpr != nullptr) {
if (minStartTimeNckExpr->getTimeBounds().startTimeRange.first >
startTimeNck) {
if (minStartTimeNckExpr->getTimeBounds().startTimeRange.first > startTimeNck) {
minStartTimeNckExpr = *child;
}
} else {
minStartTimeNckExpr = *child;
}
} else{
if (startTimeNck < startTime)
{
throw exceptions::RuntimeException("No ncks for MAX expression: NckExpr: NckExpr(" + child->get()->getId() + ", " + child->get()->getName() + ")");
} else {
if (startTimeNck < startTime) {
throw exceptions::RuntimeException(
"No nCks for MAX expression: NckExpr: NckExpr(" + child->get()->getId() +
", " + child->get()->getName() + ")");
}
break;
}
Expand All @@ -756,7 +752,9 @@ void DiscretizationSelectorOptimizationPass::runPass(
}
}
if (savedChildren.size() == 0){
throw exceptions::RuntimeException("No ncks for MAX expression: MaxExprName: MaxExpr(" + maxNckExpr->getId() + ", " + maxNckExpr->getName()+")");
throw exceptions::RuntimeException(
"No ncks for MAX expression: MaxExprName: MaxExpr(" +
maxNckExpr->getId() + ", " + maxNckExpr->getName()+")");
}
maxNckExpr->replaceChildren(std::move(savedChildren));
}
Expand Down

0 comments on commit 49e2682

Please sign in to comment.