Skip to content

Commit 609c578

Browse files
committed
move timer with inout parameters
1 parent 0c81173 commit 609c578

9 files changed

Lines changed: 42 additions & 68 deletions

File tree

cpp/src/branch_and_bound/branch_and_bound.cpp

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,15 +1886,11 @@ lp_status_t branch_and_bound_t<i_t, f_t>::solve_root_relaxation(
18861886
root_crossover_settings,
18871887
original_lp_.lower,
18881888
original_lp_.upper,
1889+
exploration_stats_.start_time,
18891890
basic_list,
18901891
nonbasic_list,
1891-
crossover_vstatus_,
1892-
exploration_stats_.start_time);
1893-
if (refactor_status == TIME_LIMIT_RETURN) {
1894-
root_status = lp_status_t::TIME_LIMIT;
1895-
} else if (refactor_status == CONCURRENT_HALT_RETURN) {
1896-
root_status = lp_status_t::CONCURRENT_LIMIT;
1897-
} else if (refactor_status != 0) {
1892+
crossover_vstatus_);
1893+
if (refactor_status != 0) {
18981894
settings_.log.printf("Failed to refactor basis. %d deficient columns.\n", refactor_status);
18991895
assert(refactor_status == 0);
19001896
root_status = lp_status_t::NUMERICAL_ISSUES;
@@ -1906,15 +1902,6 @@ lp_status_t branch_and_bound_t<i_t, f_t>::solve_root_relaxation(
19061902
user_objective = root_crossover_soln_.user_objective;
19071903
iter = root_crossover_soln_.iterations;
19081904
solver_name = "Barrier/PDLP and Crossover";
1909-
} else if (crossover_status == crossover_status_t::TIME_LIMIT ||
1910-
toc(exploration_stats_.start_time) > settings_.time_limit) {
1911-
set_root_concurrent_halt(1);
1912-
root_status = root_status_future.get();
1913-
set_root_concurrent_halt(0);
1914-
root_status = lp_status_t::TIME_LIMIT;
1915-
user_objective = root_relax_soln_.user_objective;
1916-
iter = root_relax_soln_.iterations;
1917-
solver_name = "Dual Simplex";
19181905
} else {
19191906
root_status = root_status_future.get();
19201907
user_objective = root_relax_soln_.user_objective;
@@ -1946,18 +1933,6 @@ lp_status_t branch_and_bound_t<i_t, f_t>::solve_root_relaxation(
19461933
return root_status;
19471934
}
19481935

1949-
template <typename i_t, typename f_t>
1950-
bool branch_and_bound_t<i_t, f_t>::stop_for_time_limit(mip_solution_t<i_t, f_t>& solution)
1951-
{
1952-
const f_t elapsed = toc(exploration_stats_.start_time);
1953-
if (elapsed > settings_.time_limit) {
1954-
solver_status_ = mip_status_t::TIME_LIMIT;
1955-
set_final_solution(solution, root_objective_);
1956-
return true;
1957-
}
1958-
return false;
1959-
}
1960-
19611936
template <typename i_t, typename f_t>
19621937
mip_status_t branch_and_bound_t<i_t, f_t>::solve(mip_solution_t<i_t, f_t>& solution)
19631938
{
@@ -2029,9 +2004,12 @@ mip_status_t branch_and_bound_t<i_t, f_t>::solve(mip_solution_t<i_t, f_t>& solut
20292004

20302005
if (root_status == lp_status_t::INFEASIBLE) {
20312006
settings_.log.printf("MIP Infeasible\n");
2032-
if (settings_.heuristic_preemption_callback != nullptr) {
2033-
settings_.heuristic_preemption_callback();
2034-
}
2007+
// FIXME: rarely dual simplex detects infeasible whereas it is feasible.
2008+
// to add a small safety net, check if there is a primal solution already.
2009+
// Uncomment this if the issue with cost266-UUE is resolved
2010+
// if (settings.heuristic_preemption_callback != nullptr) {
2011+
// settings.heuristic_preemption_callback();
2012+
// }
20352013
return mip_status_t::INFEASIBLE;
20362014
}
20372015
if (root_status == lp_status_t::UNBOUNDED) {
@@ -2148,7 +2126,6 @@ mip_status_t branch_and_bound_t<i_t, f_t>::solve(mip_solution_t<i_t, f_t>& solut
21482126
// Score the cuts
21492127
f_t score_start_time = tic();
21502128
cut_pool.score_cuts(root_relax_soln_.x);
2151-
if (stop_for_time_limit(solution)) { return solver_status_; }
21522129
f_t score_time = toc(score_start_time);
21532130
if (score_time > 1.0) { settings_.log.debug("Cut scoring time %.2f seconds\n", score_time); }
21542131
// Get the best cuts from the cut pool
@@ -2276,8 +2253,11 @@ mip_status_t branch_and_bound_t<i_t, f_t>::solve(mip_solution_t<i_t, f_t>& solut
22762253
if (dual_phase2_time > 1.0) {
22772254
settings_.log.debug("Dual phase2 time %.2f seconds\n", dual_phase2_time);
22782255
}
2279-
2280-
if (stop_for_time_limit(solution)) { return solver_status_; }
2256+
if (cut_status == dual::status_t::TIME_LIMIT) {
2257+
solver_status_ = mip_status_t::TIME_LIMIT;
2258+
set_final_solution(solution, root_objective_);
2259+
return solver_status_;
2260+
}
22812261

22822262
if (cut_status != dual::status_t::OPTIMAL) {
22832263
settings_.log.printf("Numerical issue at root node. Resolving from scratch\n");
@@ -2291,7 +2271,6 @@ mip_status_t branch_and_bound_t<i_t, f_t>::solve(mip_solution_t<i_t, f_t>& solut
22912271
nonbasic_list,
22922272
root_vstatus_,
22932273
edge_norms_);
2294-
if (stop_for_time_limit(solution)) { return solver_status_; }
22952274
if (scratch_status == lp_status_t::OPTIMAL) {
22962275
// We recovered
22972276
cut_status = convert_lp_status_to_dual_status(scratch_status);
@@ -2372,11 +2351,6 @@ mip_status_t branch_and_bound_t<i_t, f_t>::solve(mip_solution_t<i_t, f_t>& solut
23722351
set_uninitialized_steepest_edge_norms(original_lp_, basic_list, edge_norms_);
23732352

23742353
pc_.resize(original_lp_.num_cols);
2375-
if (toc(exploration_stats_.start_time) >= settings_.time_limit) {
2376-
solver_status_ = mip_status_t::TIME_LIMIT;
2377-
set_final_solution(solution, root_objective_);
2378-
return solver_status_;
2379-
}
23802354
{
23812355
raft::common::nvtx::range scope_sb("BB::strong_branching");
23822356
strong_branching<i_t, f_t>(original_problem_,

cpp/src/cuts/cuts.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2646,7 +2646,7 @@ i_t remove_cuts(lp_problem_t<i_t, f_t>& lp,
26462646

26472647
basis_update.resize(lp.num_rows);
26482648
i_t refactor_status = basis_update.refactor_basis(
2649-
lp.A, settings, lp.lower, lp.upper, basic_list, nonbasic_list, vstatus, start_time);
2649+
lp.A, settings, lp.lower, lp.upper, start_time, basic_list, nonbasic_list, vstatus);
26502650
if (refactor_status == CONCURRENT_HALT_RETURN) { return CONCURRENT_HALT_RETURN; }
26512651
if (refactor_status == TIME_LIMIT_RETURN) { return TIME_LIMIT_RETURN; }
26522652
}

cpp/src/dual_simplex/basis_solves.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,14 @@ template <typename i_t, typename f_t>
159159
i_t factorize_basis(const csc_matrix_t<i_t, f_t>& A,
160160
const simplex_solver_settings_t<i_t, f_t>& settings,
161161
const std::vector<i_t>& basic_list,
162+
f_t start_time,
162163
csc_matrix_t<i_t, f_t>& L,
163164
csc_matrix_t<i_t, f_t>& U,
164165
std::vector<i_t>& p,
165166
std::vector<i_t>& pinv,
166167
std::vector<i_t>& q,
167168
std::vector<i_t>& deficient,
168-
std::vector<i_t>& slacks_needed,
169-
f_t start_time)
169+
std::vector<i_t>& slacks_needed)
170170
{
171171
raft::common::nvtx::range scope("LU::factorize_basis");
172172
const i_t m = basic_list.size();
@@ -875,14 +875,14 @@ template void get_basis_from_vstatus<int>(int m,
875875
template int factorize_basis<int>(const csc_matrix_t<int, double>& A,
876876
const simplex_solver_settings_t<int, double>& settings,
877877
const std::vector<int>& basis_list,
878+
double start_time,
878879
csc_matrix_t<int, double>& L,
879880
csc_matrix_t<int, double>& U,
880881
std::vector<int>& p,
881882
std::vector<int>& pinv,
882883
std::vector<int>& q,
883884
std::vector<int>& deficient,
884-
std::vector<int>& slacks_needed,
885-
double start_time);
885+
std::vector<int>& slacks_needed);
886886

887887
template int basis_repair<int, double>(const csc_matrix_t<int, double>& A,
888888
const simplex_solver_settings_t<int, double>& settings,

cpp/src/dual_simplex/basis_solves.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ template <typename i_t, typename f_t>
3030
i_t factorize_basis(const csc_matrix_t<i_t, f_t>& A,
3131
const simplex_solver_settings_t<i_t, f_t>& settings,
3232
const std::vector<i_t>& basis_list,
33+
f_t start_time,
3334
csc_matrix_t<i_t, f_t>& L,
3435
csc_matrix_t<i_t, f_t>& U,
3536
std::vector<i_t>& p,
3637
std::vector<i_t>& pinv,
3738
std::vector<i_t>& q,
3839
std::vector<i_t>& deficient,
39-
std::vector<i_t>& slacks_need,
40-
f_t start_time);
40+
std::vector<i_t>& slacks_need);
4141

4242
// Repair the basis by bringing in slacks
4343
template <typename i_t, typename f_t>

cpp/src/dual_simplex/basis_updates.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,10 +2262,10 @@ int basis_update_mpf_t<i_t, f_t>::refactor_basis(
22622262
const simplex_solver_settings_t<i_t, f_t>& settings,
22632263
const std::vector<f_t>& lower,
22642264
const std::vector<f_t>& upper,
2265+
f_t start_time,
22652266
std::vector<i_t>& basic_list,
22662267
std::vector<i_t>& nonbasic_list,
2267-
std::vector<variable_status_t>& vstatus,
2268-
f_t start_time)
2268+
std::vector<variable_status_t>& vstatus)
22692269
{
22702270
raft::common::nvtx::range scope("LU::refactor_basis");
22712271
std::vector<i_t> deficient;
@@ -2277,14 +2277,14 @@ int basis_update_mpf_t<i_t, f_t>::refactor_basis(
22772277
i_t status = factorize_basis(A,
22782278
settings,
22792279
basic_list,
2280+
start_time,
22802281
L0_,
22812282
U0_,
22822283
row_permutation_,
22832284
inverse_row_permutation_,
22842285
q,
22852286
deficient,
2286-
slacks_needed,
2287-
start_time);
2287+
slacks_needed);
22882288
if (status == CONCURRENT_HALT_RETURN) { return CONCURRENT_HALT_RETURN; }
22892289
if (status == TIME_LIMIT_RETURN) { return TIME_LIMIT_RETURN; }
22902290
if (status == -1) {
@@ -2320,14 +2320,14 @@ int basis_update_mpf_t<i_t, f_t>::refactor_basis(
23202320
status = factorize_basis(A,
23212321
settings,
23222322
basic_list,
2323+
start_time,
23232324
L0_,
23242325
U0_,
23252326
row_permutation_,
23262327
inverse_row_permutation_,
23272328
q,
23282329
deficient,
2329-
slacks_needed,
2330-
start_time);
2330+
slacks_needed);
23312331
if (status == CONCURRENT_HALT_RETURN) { return CONCURRENT_HALT_RETURN; }
23322332
if (status == TIME_LIMIT_RETURN) { return TIME_LIMIT_RETURN; }
23332333
if (status == -1) {

cpp/src/dual_simplex/basis_updates.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,10 @@ class basis_update_mpf_t {
380380
const simplex_solver_settings_t<i_t, f_t>& settings,
381381
const std::vector<f_t>& lower,
382382
const std::vector<f_t>& upper,
383+
f_t start_time,
383384
std::vector<i_t>& basic_list,
384385
std::vector<i_t>& nonbasic_list,
385-
std::vector<variable_status_t>& vstatus,
386-
f_t start_time);
386+
std::vector<variable_status_t>& vstatus);
387387

388388
void set_refactor_frequency(i_t new_frequency) { refactor_frequency_ = new_frequency; }
389389

cpp/src/dual_simplex/crossover.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ i_t dual_push(const lp_problem_t<i_t, f_t>& lp,
506506
std::vector<i_t> deficient;
507507
std::vector<i_t> slacks_needed;
508508
i_t rank = factorize_basis(
509-
lp.A, settings, basic_list, L, U, p, pinv, q, deficient, slacks_needed, start_time);
509+
lp.A, settings, basic_list, start_time, L, U, p, pinv, q, deficient, slacks_needed);
510510
if (rank == CONCURRENT_HALT_RETURN) {
511511
return CONCURRENT_HALT_RETURN;
512512
} else if (rank < 0) {
@@ -524,7 +524,7 @@ i_t dual_push(const lp_problem_t<i_t, f_t>& lp,
524524
superbasic_list,
525525
vstatus);
526526
rank = factorize_basis(
527-
lp.A, settings, basic_list, L, U, p, pinv, q, deficient, slacks_needed, start_time);
527+
lp.A, settings, basic_list, start_time, L, U, p, pinv, q, deficient, slacks_needed);
528528
if (rank == CONCURRENT_HALT_RETURN) {
529529
return CONCURRENT_HALT_RETURN;
530530
} else if (rank < 0) {
@@ -862,7 +862,7 @@ i_t primal_push(const lp_problem_t<i_t, f_t>& lp,
862862
std::vector<i_t> deficient;
863863
std::vector<i_t> slacks_needed;
864864
i_t rank = factorize_basis(
865-
lp.A, settings, basic_list, L, U, p, pinv, q, deficient, slacks_needed, start_time);
865+
lp.A, settings, basic_list, start_time, L, U, p, pinv, q, deficient, slacks_needed);
866866
if (rank == CONCURRENT_HALT_RETURN) {
867867
return CONCURRENT_HALT_RETURN;
868868
} else if (rank < 0) {
@@ -883,7 +883,7 @@ i_t primal_push(const lp_problem_t<i_t, f_t>& lp,
883883
find_primal_superbasic_variables(
884884
lp, settings, solution, solution, vstatus, nonbasic_list, superbasic_list);
885885
rank = factorize_basis(
886-
lp.A, settings, basic_list, L, U, p, pinv, q, deficient, slacks_needed, start_time);
886+
lp.A, settings, basic_list, start_time, L, U, p, pinv, q, deficient, slacks_needed);
887887
if (rank == CONCURRENT_HALT_RETURN) {
888888
return CONCURRENT_HALT_RETURN;
889889
} else if (rank < 0) {
@@ -1226,7 +1226,7 @@ crossover_status_t crossover(const lp_problem_t<i_t, f_t>& lp,
12261226
std::vector<i_t> slacks_needed;
12271227

12281228
rank = factorize_basis(
1229-
lp.A, settings, basic_list, L, U, p, pinv, q, deficient, slacks_needed, start_time);
1229+
lp.A, settings, basic_list, start_time, L, U, p, pinv, q, deficient, slacks_needed);
12301230
if (rank < 0) { return return_to_status(rank); }
12311231
if (rank != m) {
12321232
settings.log.debug("Failed to factorize basis. rank %d m %d\n", rank, m);
@@ -1241,7 +1241,7 @@ crossover_status_t crossover(const lp_problem_t<i_t, f_t>& lp,
12411241
superbasic_list,
12421242
vstatus);
12431243
rank = factorize_basis(
1244-
lp.A, settings, basic_list, L, U, p, pinv, q, deficient, slacks_needed, start_time);
1244+
lp.A, settings, basic_list, start_time, L, U, p, pinv, q, deficient, slacks_needed);
12451245
if (rank == CONCURRENT_HALT_RETURN) {
12461246
return crossover_status_t::CONCURRENT_LIMIT;
12471247
} else if (rank < 0) {
@@ -1397,7 +1397,7 @@ crossover_status_t crossover(const lp_problem_t<i_t, f_t>& lp,
13971397
superbasic_list.clear();
13981398
get_basis_from_vstatus(m, vstatus, basic_list, nonbasic_list, superbasic_list);
13991399
rank = factorize_basis(
1400-
lp.A, settings, basic_list, L, U, p, pinv, q, deficient, slacks_needed, start_time);
1400+
lp.A, settings, basic_list, start_time, L, U, p, pinv, q, deficient, slacks_needed);
14011401
if (rank < 0) {
14021402
return return_to_status(rank);
14031403
} else if (rank != m) {
@@ -1413,7 +1413,7 @@ crossover_status_t crossover(const lp_problem_t<i_t, f_t>& lp,
14131413
superbasic_list,
14141414
vstatus);
14151415
rank = factorize_basis(
1416-
lp.A, settings, basic_list, L, U, p, pinv, q, deficient, slacks_needed, start_time);
1416+
lp.A, settings, basic_list, start_time, L, U, p, pinv, q, deficient, slacks_needed);
14171417
if (rank < 0) {
14181418
settings.log.printf("Failed to factorize basis after repair. rank %d m %d\n", rank, m);
14191419
return return_to_status(rank);

cpp/src/dual_simplex/phase2.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2505,7 +2505,7 @@ dual::status_t dual_phase2_with_advanced_basis(i_t phase,
25052505
assert(nonbasic_list.size() == n - m);
25062506

25072507
i_t refactor_status = ft.refactor_basis(
2508-
lp.A, settings, lp.lower, lp.upper, basic_list, nonbasic_list, vstatus, start_time);
2508+
lp.A, settings, lp.lower, lp.upper, start_time, basic_list, nonbasic_list, vstatus);
25092509
if (refactor_status == CONCURRENT_HALT_RETURN) { return dual::status_t::CONCURRENT_LIMIT; }
25102510
if (refactor_status == TIME_LIMIT_RETURN) { return dual::status_t::TIME_LIMIT; }
25112511
if (refactor_status > 0) { return dual::status_t::NUMERICAL; }
@@ -3373,7 +3373,7 @@ dual::status_t dual_phase2_with_advanced_basis(i_t phase,
33733373
num_refactors++;
33743374
bool should_recompute_x = false;
33753375
i_t refactor_status = ft.refactor_basis(
3376-
lp.A, settings, lp.lower, lp.upper, basic_list, nonbasic_list, vstatus, start_time);
3376+
lp.A, settings, lp.lower, lp.upper, start_time, basic_list, nonbasic_list, vstatus);
33773377
if (refactor_status == CONCURRENT_HALT_RETURN) { return dual::status_t::CONCURRENT_LIMIT; }
33783378
if (refactor_status == TIME_LIMIT_RETURN) { return dual::status_t::TIME_LIMIT; }
33793379
if (refactor_status > 0) {
@@ -3384,7 +3384,7 @@ dual::status_t dual_phase2_with_advanced_basis(i_t phase,
33843384
i_t deficient_size = 0;
33853385
while (true) {
33863386
deficient_size = ft.refactor_basis(
3387-
lp.A, settings, lp.lower, lp.upper, basic_list, nonbasic_list, vstatus, start_time);
3387+
lp.A, settings, lp.lower, lp.upper, start_time, basic_list, nonbasic_list, vstatus);
33883388
if (deficient_size == CONCURRENT_HALT_RETURN) {
33893389
return dual::status_t::CONCURRENT_LIMIT;
33903390
}

cpp/src/dual_simplex/primal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ primal::status_t primal_phase2(i_t phase,
295295
std::vector<i_t> deficient;
296296
std::vector<i_t> slacks_needed;
297297
i_t rank = factorize_basis(
298-
lp.A, settings, basic_list, L, U, p, pinv, q, deficient, slacks_needed, start_time);
298+
lp.A, settings, basic_list, start_time, L, U, p, pinv, q, deficient, slacks_needed);
299299
if (rank == CONCURRENT_HALT_RETURN) {
300300
return primal::status_t::CONCURRENT_LIMIT;
301301
} else if (rank == TIME_LIMIT_RETURN) {
@@ -316,7 +316,7 @@ primal::status_t primal_phase2(i_t phase,
316316
superbasic_list,
317317
vstatus);
318318
rank = factorize_basis(
319-
lp.A, settings, basic_list, L, U, p, pinv, q, deficient, slacks_needed, start_time);
319+
lp.A, settings, basic_list, start_time, L, U, p, pinv, q, deficient, slacks_needed);
320320
if (rank == CONCURRENT_HALT_RETURN) {
321321
return primal::status_t::CONCURRENT_LIMIT;
322322
} else if (rank == TIME_LIMIT_RETURN) {

0 commit comments

Comments
 (0)