Skip to content

Commit f89f683

Browse files
committed
Added TerminationStatus to PDLPSolver::solveReturn
1 parent 35a2fc2 commit f89f683

File tree

4 files changed

+19
-13
lines changed

4 files changed

+19
-13
lines changed

check/TestPdlp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ TEST_CASE("hi-pdlp", "[pdlp]") {
392392
}
393393

394394
TEST_CASE("hi-pdlp-timer", "[pdlp]") {
395-
std::string model = "shell";
395+
std::string model = "shell";//"avgas";//
396396
std::string model_file =
397397
std::string(HIGHS_DIR) + "/check/instances/" + model + ".mps";
398398
Highs h;

highs/pdlp/HiPdlpWrapper.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ HighsStatus solveLpHiPdlp(const HighsOptions& options, HighsTimer& timer,
7777
debugPdlpFinalSolutionLog(pdlp.debug_pdlp_log_file_,
7878
pdlp_solution.col_value.data(), lp.num_col_,
7979
pdlp_solution.row_dual.data(), lp.num_row_);
80+
pdlp.closeDebugLog();
81+
82+
// Report profiling
8083
pdlp.reportHipdlpTimer();
8184

8285
// --- Print Summary ---

highs/pdlp/hipdlp/pdhg.cc

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,7 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
538538
if (solver_timer.read() > params_.time_limit) {
539539
logger_.info("Time limit reached.");
540540
final_iter_count_ = iter;
541-
results_.term_code = TerminationStatus::TIMEOUT;
542-
return solveReturn();
541+
return solveReturn(TerminationStatus::TIMEOUT);
543542
}
544543

545544
// --- 3. Convergence and Restart Check (BEFORE iterate update) ---
@@ -562,6 +561,7 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
562561
SolverResults current_results;
563562
SolverResults average_results;
564563

564+
hipdlpTimerStart(kHipdlpClockConvergenceCheck);
565565
auto conv_start = std::chrono::high_resolution_clock::now();
566566
// Compute residuals for current iterate
567567
bool current_converged = checkConvergence(
@@ -574,6 +574,7 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
574574
params_.tolerance, average_results, "[A]");
575575
auto conv_end = std::chrono::high_resolution_clock::now();
576576
timings_.convergence_check_time += std::chrono::duration<double>(conv_end - conv_start).count();
577+
hipdlpTimerStop(kHipdlpClockConvergenceCheck);
577578

578579
debugPdlpIterHeaderLog(debug_pdlp_log_file_);
579580

@@ -588,8 +589,7 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
588589
x = x_current_;
589590
y = y_current_;
590591
results_ = current_results;
591-
results_.term_code = TerminationStatus::OPTIMAL;
592-
return solveReturn();
592+
return solveReturn(TerminationStatus::OPTIMAL);
593593
}
594594

595595
if (average_converged) {
@@ -599,8 +599,7 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
599599
x = x_avg_;
600600
y = y_avg_;
601601
results_ = average_results;
602-
results_.term_code = TerminationStatus::OPTIMAL;
603-
return solveReturn();
602+
return solveReturn(TerminationStatus::OPTIMAL);
604603
}
605604

606605
// --- 4. Restart Check (using computed results) ---
@@ -684,7 +683,7 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
684683
x = x_avg_;
685684
y = y_avg_;
686685
hipdlpTimerStop(kHipdlpClockIterateUpdate);
687-
return solveReturn();
686+
return solveReturn(TerminationStatus::ERROR);
688687
}
689688
}
690689
auto update_end = std::chrono::high_resolution_clock::now();
@@ -726,16 +725,15 @@ void PDLPSolver::solve(std::vector<double>& x, std::vector<double>& y) {
726725
x = x_avg_;
727726
y = y_avg_;
728727

729-
results_.term_code = TerminationStatus::TIMEOUT;
730728
auto solve_end = std::chrono::high_resolution_clock::now();
731729
timings_.total_time = std::chrono::duration<double>(solve_end - solve_start).count();
732730

733-
return solveReturn();
731+
return solveReturn(TerminationStatus::TIMEOUT);
734732
}
735733

736-
void PDLPSolver::solveReturn() {
734+
void PDLPSolver::solveReturn(const TerminationStatus term_code) {
735+
results_.term_code = term_code;
737736
hipdlpTimerStop(kHipdlpClockSolve);
738-
if (debug_pdlp_log_file_) fclose(debug_pdlp_log_file_);
739737
}
740738

741739
void PDLPSolver::initialize() {
@@ -1650,3 +1648,7 @@ void PDLPSolver::hipdlpTimerStop(const HighsInt hipdlp_clock) {
16501648
HighsInt highs_timer_clock = hipdlp_clocks_.clock_[hipdlp_clock];
16511649
hipdlp_clocks_.timer_pointer_->stop(highs_timer_clock);
16521650
}
1651+
1652+
void PDLPSolver::closeDebugLog() {
1653+
if (debug_pdlp_log_file_) fclose(debug_pdlp_log_file_);
1654+
}

highs/pdlp/hipdlp/pdhg.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ class PDLPSolver {
5555
const DetailedTimings& getTimings() const { return timings_; }
5656

5757
void reportHipdlpTimer();
58+
void closeDebugLog();
5859

5960
private:
6061
// --- Core Algorithm Logic ---
61-
void solveReturn();
62+
void solveReturn(const TerminationStatus term_code);
6263
void initialize();
6364
void printConstraintInfo();
6465
bool checkConvergence(const int iter, const std::vector<double>& x,

0 commit comments

Comments
 (0)