Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cpp/cuopt_cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ std::string param_name_to_arg_name(const std::string& input)
int main(int argc, char* argv[])
{
// Get the version string from the version_config.hpp file
const auto version_string = std::string("cuOpt ") + std::to_string(CUOPT_VERSION_MAJOR) + "." +
std::to_string(CUOPT_VERSION_MINOR) + "." +
std::to_string(CUOPT_VERSION_PATCH);
const std::string version_string = std::string("cuOpt ") + std::to_string(CUOPT_VERSION_MAJOR) +
"." + std::to_string(CUOPT_VERSION_MINOR) + "." +
std::to_string(CUOPT_VERSION_PATCH);

// Create the argument parser
argparse::ArgumentParser program("cuopt_cli", version_string);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#pragma once

#include <vector>

#include <cuopt/linear_programming/constants.h>
#include <cuopt/linear_programming/utilities/internals.hpp>

Expand Down
2 changes: 2 additions & 0 deletions cpp/libmps_parser/src/utilities/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
#pragma once

#include <string>

#include <stdarg.h>
#include <stdexcept>

Expand Down
14 changes: 7 additions & 7 deletions cpp/src/linear_programming/pdlp_constants.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@
#include <raft/util/cuda_utils.cuh>

namespace cuopt::linear_programming::detail {
constexpr int block_size = 128;
inline constexpr int block_size = 128;

// When using APIs that handle variable stride sizes these are used to express that we assume that
// the data accessed has a contigous layout in memory for both solutions
// {
constexpr int primal_stride = 1;
constexpr int dual_stride = 1;
inline constexpr int primal_stride = 1;
inline constexpr int dual_stride = 1;
// }

// #define PDLP_DEBUG_MODE

// Value used to determine what we see as too small (the value) or too large (1/value) values when
// computing the new primal weight during the restart.
template <typename f_t>
constexpr f_t safe_guard_for_extreme_values_in_primal_weight_computation = 1.0e-10;
inline constexpr f_t safe_guard_for_extreme_values_in_primal_weight_computation = 1.0e-10;
// }

// used to detect divergence in the movement as should trigger a numerical_error
template <typename f_t>
constexpr f_t divergent_movement = f_t{};
inline constexpr f_t divergent_movement = f_t{};

template <>
constexpr float divergent_movement<float> = 1.0e20f;
inline constexpr float divergent_movement<float> = 1.0e20f;

template <>
constexpr double divergent_movement<double> = 1.0e100;
inline constexpr double divergent_movement<double> = 1.0e100;

// }

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/linear_programming/utils.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ struct relative_residual_t {

// Used for best primal so far, count how many constraints are violated
if (abs_.has_value() && nb_violated_constraints_.has_value()) {
if (residual >= abs_.value() + rel_ * rhs) atomicAdd(nb_violated_constraints_.value(), 1);
if (residual >= *abs_ + rel_ * rhs) atomicAdd(*nb_violated_constraints_, 1);
}
return residual - rel_ * rhs;
}
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/math_optimization/solution_reader.cu
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,15 @@

#include "solution_reader.hpp"

#include <algorithm>
#include <fstream>
#include <optional>
#include <regex>
#include <sstream>
#include <stdexcept>
#include <string>
#include <unordered_map>

namespace cuopt::linear_programming {

/**
Expand Down
23 changes: 12 additions & 11 deletions cpp/src/mip/diversity/diversity_manager.cu
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool diversity_manager_t<i_t, f_t>::regenerate_solutions()
const i_t min_size = 2;
while (population.current_size() <= min_size && (current_step == 0 || counter < 5)) {
CUOPT_LOG_DEBUG("Trying to regenerate solution, pop size %d\n", population.current_size());
time_limit = min(time_limit, timer.remaining_time());
time_limit = std::min(time_limit, timer.remaining_time());
ls.fj.randomize_weights(problem_ptr->handle_ptr);
population.add_solution(generate_solution(time_limit));
if (timer.check_time_limit()) { return false; }
Expand All @@ -90,18 +90,18 @@ std::vector<solution_t<i_t, f_t>> diversity_manager_t<i_t, f_t>::generate_more_s
{
std::vector<solution_t<i_t, f_t>> solutions;
timer_t total_time_to_generate = timer_t(timer.remaining_time() / 5.);
f_t time_limit = min(60., total_time_to_generate.remaining_time());
f_t ls_limit = min(5., timer.remaining_time() / 20.);
f_t time_limit = std::min(60., total_time_to_generate.remaining_time());
f_t ls_limit = std::min(5., timer.remaining_time() / 20.);
const i_t n_sols_to_generate = 2;
for (i_t i = 0; i < n_sols_to_generate; ++i) {
CUOPT_LOG_DEBUG("Trying to generate more solutions");
time_limit = min(time_limit, timer.remaining_time());
time_limit = std::min(time_limit, timer.remaining_time());
ls.fj.randomize_weights(problem_ptr->handle_ptr);
auto sol = generate_solution(time_limit);
population.run_solution_callbacks(sol);
solutions.emplace_back(solution_t<i_t, f_t>(sol));
if (total_time_to_generate.check_time_limit()) { return solutions; }
timer_t timer(min(ls_limit, timer.remaining_time()));
timer_t timer(std::min(ls_limit, timer.remaining_time()));
ls.run_local_search(sol, population.weights, timer);
population.run_solution_callbacks(sol);
solutions.emplace_back(std::move(sol));
Expand Down Expand Up @@ -183,7 +183,7 @@ void diversity_manager_t<i_t, f_t>::generate_initial_solutions()
// solution if we can generate faster generate up to 10 sols
const f_t generation_time_limit = 0.6 * timer.get_time_limit();
const f_t max_island_gen_time = 600;
f_t total_island_gen_time = min(generation_time_limit, max_island_gen_time);
f_t total_island_gen_time = std::min(generation_time_limit, max_island_gen_time);
timer_t gen_timer(total_island_gen_time);
f_t sol_time_limit = gen_timer.remaining_time();
for (i_t i = 0; i < maximum_island_size; ++i) {
Expand Down Expand Up @@ -265,7 +265,7 @@ void diversity_manager_t<i_t, f_t>::generate_quick_feasible_solution()
{
solution_t<i_t, f_t> solution(*problem_ptr);
// min 1 second, max 10 seconds
const f_t generate_fast_solution_time = min(10., max(1., timer.remaining_time() / 20.));
const f_t generate_fast_solution_time = std::min(10., std::max(1., timer.remaining_time() / 20.));
timer_t sol_timer(generate_fast_solution_time);
// do very short LP run to get somewhere close to the optimal point
ls.generate_fast_solution(solution, sol_timer);
Expand Down Expand Up @@ -306,7 +306,7 @@ solution_t<i_t, f_t> diversity_manager_t<i_t, f_t>::run_solver()
const f_t time_limit = timer.remaining_time();
constexpr f_t time_ratio_on_init_lp = 0.1;
constexpr f_t max_time_on_lp = 30;
const f_t lp_time_limit = min(max_time_on_lp, time_limit * time_ratio_on_init_lp);
const f_t lp_time_limit = std::min(max_time_on_lp, time_limit * time_ratio_on_init_lp);

// after every change to the problem, we should resize all the relevant vars
// we need to encapsulate that to prevent repetitions
Expand All @@ -328,7 +328,8 @@ solution_t<i_t, f_t> diversity_manager_t<i_t, f_t>::run_solver()
generate_quick_feasible_solution();
constexpr f_t time_ratio_of_probing_cache = 0.10;
constexpr f_t max_time_on_probing = 60;
f_t time_for_probing_cache = min(max_time_on_probing, time_limit * time_ratio_of_probing_cache);
f_t time_for_probing_cache =
std::min(max_time_on_probing, time_limit * time_ratio_of_probing_cache);
timer_t probing_timer{time_for_probing_cache};
if (check_b_b_preemption()) { return population.best_feasible(); }
compute_probing_cache(ls.constraint_prop.bounds_update, *problem_ptr, probing_timer);
Expand Down Expand Up @@ -542,7 +543,7 @@ diversity_manager_t<i_t, f_t>::recombine_and_local_search(solution_t<i_t, f_t>&
cuopt_assert(population.test_invariant(), "");
cuopt_assert(lp_offspring.test_number_all_integer(), "All must be integers before LP");
f_t lp_run_time = offspring.get_feasible() ? 3. : 1.;
lp_run_time = min(lp_run_time, timer.remaining_time());
lp_run_time = std::min(lp_run_time, timer.remaining_time());
run_lp_with_vars_fixed(*lp_offspring.problem_ptr,
lp_offspring,
lp_offspring.problem_ptr->integer_indices,
Expand All @@ -553,7 +554,7 @@ diversity_manager_t<i_t, f_t>::recombine_and_local_search(solution_t<i_t, f_t>&
cuopt_assert(lp_offspring.test_number_all_integer(), "All must be integers after LP");
f_t lp_qual = lp_offspring.get_quality(population.weights);
CUOPT_LOG_DEBUG("After LP offspring sol cost:feas %f : %d", lp_qual, lp_offspring.get_feasible());
f_t offspring_qual = min(offspring.get_quality(population.weights), lp_qual);
f_t offspring_qual = std::min(offspring.get_quality(population.weights), lp_qual);
recombine_stats.update_improve_stats(
offspring_qual, sol1.get_quality(population.weights), sol2.get_quality(population.weights));
return std::make_pair(std::move(offspring), std::move(lp_offspring));
Expand Down
16 changes: 8 additions & 8 deletions cpp/src/mip/diversity/population.cu
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ template <typename i_t, typename f_t>
void population_t<i_t, f_t>::initialize_population()
{
var_threshold =
max(problem_ptr->n_variables - var_threshold, (problem_ptr->n_variables / 10) * 8);
std::max(problem_ptr->n_variables - var_threshold, (problem_ptr->n_variables / 10) * 8);
initial_threshold_ratio = (f_t)var_threshold / problem_ptr->n_variables;
solutions.reserve(max_solutions);
indices.reserve(max_solutions);
Expand Down Expand Up @@ -378,7 +378,7 @@ void population_t<i_t, f_t>::compute_new_weights()
infeasibility_importance *= weight_increase_ratio;
}

infeasibility_importance = min(max_infeasibility_weight, infeasibility_importance);
infeasibility_importance = std::min(max_infeasibility_weight, infeasibility_importance);
thrust::for_each(best_sol.handle_ptr->get_thrust_policy(),
thrust::counting_iterator(0),
thrust::counting_iterator(0) + weights.cstr_weights.size(),
Expand All @@ -394,7 +394,7 @@ void population_t<i_t, f_t>::compute_new_weights()
} else {
CUOPT_LOG_DEBUG("Decreasing weights!");
infeasibility_importance *= weight_decrease_ratio;
infeasibility_importance = max(min_infeasibility_weight, infeasibility_importance);
infeasibility_importance = std::max(min_infeasibility_weight, infeasibility_importance);

thrust::for_each(
best_sol.handle_ptr->get_thrust_policy(),
Expand Down Expand Up @@ -535,7 +535,7 @@ template <typename i_t>
i_t get_max_var_threshold(i_t n_vars)
{
if (n_vars < 50) {
return max(1, n_vars - 1);
return std::max(1, n_vars - 1);
} else if (n_vars < 80) {
return n_vars - 2;
} else if (n_vars < 200) {
Expand All @@ -559,7 +559,7 @@ void population_t<i_t, f_t>::halve_the_population()
size_t max_var_threshold = get_max_var_threshold(problem_ptr->n_integer_vars);
while (current_size() > max_solutions / 2) {
clear_except_best_feasible();
var_threshold = max(var_threshold * 0.97, 0.5 * problem_ptr->n_integer_vars);
var_threshold = std::max(var_threshold * 0.97, 0.5 * problem_ptr->n_integer_vars);
for (auto& sol : sol_vec) {
add_solution(solution_t<i_t, f_t>(sol));
}
Expand All @@ -569,9 +569,9 @@ void population_t<i_t, f_t>::halve_the_population()
// if we removed too many decrease the diversity a little
while (current_size() < max_solutions / 4) {
clear_except_best_feasible();
var_threshold =
min(max_var_threshold,
min((size_t)(var_threshold * 0.97), (size_t)(0.995 * problem_ptr->n_integer_vars)));
var_threshold = std::min(
max_var_threshold,
std::min((size_t)(var_threshold * 0.97), (size_t)(0.995 * problem_ptr->n_integer_vars)));
for (auto& sol : sol_vec) {
add_solution(solution_t<i_t, f_t>(sol));
}
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/mip/diversity/recombiners/recombiner_stats.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ struct recombine_stats {

void update_improve_stats(double cost_new, double cost_first, double cost_second)
{
if (cost_new < (min(cost_first, cost_second) - OBJECTIVE_EPSILON)) ++better_than_both;
if (cost_new < (max(cost_first, cost_second) - OBJECTIVE_EPSILON)) ++better_than_one;
if (cost_new < (std::min(cost_first, cost_second) - OBJECTIVE_EPSILON)) ++better_than_both;
if (cost_new < (std::max(cost_first, cost_second) - OBJECTIVE_EPSILON)) ++better_than_one;
}

void add_attempt() { ++attempts; }
Expand Down
8 changes: 4 additions & 4 deletions cpp/src/mip/feasibility_jump/load_balancing.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
* limitations under the License.
*/

#include <cuda_runtime_api.h>

#include "feasibility_jump_kernels.cuh"

#include <cub/block/block_merge_sort.cuh>
Expand Down Expand Up @@ -380,8 +382,7 @@ __global__ void load_balancing_mtm_compute_candidates(
i_t lane_id = threadIdx.x % raft::WarpSize;

const i_t stride = get_warp_id_stride();
for (auto [var_idx, subworkid, offset_begin, offset_end, csr_offset, skip] :
csr_load_balancer<i_t, f_t>{
for (auto [var_idx, subworkid, offset_begin, offset_end, _, skip] : csr_load_balancer<i_t, f_t>{
fj, fj.row_size_nonbin_prefix_sum, fj.work_id_to_nonbin_var_idx}) {
cuopt_assert(!fj.pb.is_binary_variable[var_idx], "variable is binary");

Expand Down Expand Up @@ -483,8 +484,7 @@ __launch_bounds__(TPB_loadbalance, 16) __global__
i_t lane_id = threadIdx.x % raft::WarpSize;

const i_t stride = get_warp_id_stride();
for (auto [var_idx, subworkid, offset_begin, offset_end, csr_offset, skip] :
csr_load_balancer<i_t, f_t>{
for (auto [var_idx, subworkid, offset_begin, offset_end, _, skip] : csr_load_balancer<i_t, f_t>{
fj, fj.row_size_nonbin_prefix_sum, fj.work_id_to_nonbin_var_idx}) {
cuopt_assert(!fj.pb.is_binary_variable[var_idx], "variable is binary");

Expand Down
14 changes: 7 additions & 7 deletions cpp/src/mip/local_search/feasibility_pump/feasibility_pump.cu
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ bool feasibility_pump_t<i_t, f_t>::linear_project_onto_polytope(solution_t<i_t,
get_tolerance_from_ratio(ratio_of_set_integers, context.settings.tolerances.absolute_tolerance);
temp_p.check_problem_representation(true);
f_t time_limit = longer_lp_run ? 5. : 1.;
time_limit = min(time_limit, timer.remaining_time());
time_limit = std::min(time_limit, timer.remaining_time());
static f_t lp_time = 0;
static i_t n_calls = 0;
f_t old_remaining = timer.remaining_time();
Expand Down Expand Up @@ -336,13 +336,13 @@ bool feasibility_pump_t<i_t, f_t>::round_multiple_points(solution_t<i_t, f_t>& s
{
n_fj_single_descents = 0;
const f_t max_time_limit = last_lp_time * 0.1;
timer_t round_timer{min(max_time_limit, timer.remaining_time())};
timer_t round_timer{std::min(max_time_limit, timer.remaining_time())};
bool is_feasible = random_round_with_fj(solution, round_timer);
if (is_feasible) {
CUOPT_LOG_DEBUG("Feasible found after random round with fj");
return true;
}
timer_t line_segment_timer{min(1., timer.remaining_time())};
timer_t line_segment_timer{std::min(1., timer.remaining_time())};
i_t n_points_to_search = n_fj_single_descents;
bool is_feasibility_run = true;
// create a copy, because assignment is changing within kernel and we want a separate point_1
Expand Down Expand Up @@ -379,8 +379,8 @@ bool feasibility_pump_t<i_t, f_t>::round(solution_t<i_t, f_t>& solution)
{
bool result;
CUOPT_LOG_DEBUG("Rounding the point");
timer_t bounds_prop_timer(min(2., timer.remaining_time()));
const f_t lp_run_time_after_feasible = min(3., timer.remaining_time() / 20.);
timer_t bounds_prop_timer(std::min(2., timer.remaining_time()));
const f_t lp_run_time_after_feasible = std::min(3., timer.remaining_time() / 20.);
result = lb_constraint_prop.apply_round(solution, lp_run_time_after_feasible, bounds_prop_timer);
cuopt_func_call(solution.test_variable_bounds(true));
// copy the last rounding
Expand Down Expand Up @@ -409,7 +409,7 @@ bool feasibility_pump_t<i_t, f_t>::run_fj_cycle_escape(solution_t<i_t, f_t>& sol
fj.settings.update_weights = true;
fj.settings.feasibility_run = true;
fj.settings.n_of_minimums_for_exit = 5000;
fj.settings.time_limit = min(3., timer.remaining_time());
fj.settings.time_limit = std::min(3., timer.remaining_time());
fj.settings.termination = fj_termination_flags_t::FJ_TERMINATION_TIME_LIMIT;
is_feasible = fj.solve(solution);
// if FJ didn't change the solution, take last incumbent solution
Expand All @@ -432,7 +432,7 @@ bool feasibility_pump_t<i_t, f_t>::test_fj_feasible(solution_t<i_t, f_t>& soluti
fj.settings.update_weights = true;
fj.settings.feasibility_run = true;
fj.settings.n_of_minimums_for_exit = 5000;
fj.settings.time_limit = min(time_limit, timer.remaining_time());
fj.settings.time_limit = std::min(time_limit, timer.remaining_time());
fj.settings.termination = fj_termination_flags_t::FJ_TERMINATION_TIME_LIMIT;
cuopt_func_call(solution.test_variable_bounds(true));
is_feasible = fj.solve(solution);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ bool line_segment_search_t<i_t, f_t>::search_line_segment(solution_t<i_t, f_t>&
fj.settings.mode = fj_mode_t::GREEDY_DESCENT;
fj.settings.update_weights = false;
fj.settings.feasibility_run = is_feasibility_run;
fj.settings.time_limit = min(0.5, timer.remaining_time());
fj.settings.time_limit = std::min(0.5, timer.remaining_time());
is_feasible = fj.solve(solution);
if (is_feasibility_run) {
if (is_feasible) {
Expand Down
14 changes: 7 additions & 7 deletions cpp/src/mip/local_search/local_search.cu
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ void local_search_t<i_t, f_t>::generate_fast_solution(solution_t<i_t, f_t>& solu
fj.settings.update_weights = true;
fj.settings.feasibility_run = true;
fj.settings.termination = fj_termination_flags_t::FJ_TERMINATION_TIME_LIMIT;
fj.settings.time_limit = min(30., timer.remaining_time());
fj.settings.time_limit = std::min(30., timer.remaining_time());
while (!timer.check_time_limit()) {
timer_t constr_prop_timer = timer_t(min(timer.remaining_time(), 2.));
timer_t constr_prop_timer = timer_t(std::min(timer.remaining_time(), 2.));
// do constraint prop on lp optimal solution
constraint_prop.apply_round(solution, 1., constr_prop_timer);
if (solution.compute_feasibility()) { return; }
if (timer.check_time_limit()) { return; };
fj.settings.time_limit = min(3., timer.remaining_time());
fj.settings.time_limit = std::min(3., timer.remaining_time());
// run fj on the solution
fj.solve(solution);
// TODO check if FJ returns the same solution
Expand Down Expand Up @@ -150,7 +150,7 @@ bool local_search_t<i_t, f_t>::run_fj_annealing(solution_t<i_t, f_t>& solution,
fj.settings.mode = fj_mode_t::EXIT_NON_IMPROVING;
fj.settings.candidate_selection = fj_candidate_selection_t::FEASIBLE_FIRST;
fj.settings.termination = fj_termination_flags_t::FJ_TERMINATION_TIME_LIMIT;
fj.settings.time_limit = min(10., timer.remaining_time());
fj.settings.time_limit = std::min(10., timer.remaining_time());
fj.settings.parameters.allow_infeasibility_iterations = 100;
fj.settings.update_weights = 1;
fj.solve(solution);
Expand Down Expand Up @@ -189,7 +189,7 @@ bool local_search_t<i_t, f_t>::check_fj_on_lp_optimal(solution_t<i_t, f_t>& solu
}
cuopt_func_call(solution.test_variable_bounds(false));
f_t lp_run_time_after_feasible = 1.;
timer_t bounds_prop_timer = timer_t(min(timer.remaining_time(), 10.));
timer_t bounds_prop_timer = timer_t(std::min(timer.remaining_time(), 10.));
bool is_feasible =
constraint_prop.apply_round(solution, lp_run_time_after_feasible, bounds_prop_timer);
if (!is_feasible) {
Expand All @@ -209,7 +209,7 @@ bool local_search_t<i_t, f_t>::check_fj_on_lp_optimal(solution_t<i_t, f_t>& solu
fj.settings.update_weights = true;
fj.settings.feasibility_run = true;
fj.settings.termination = fj_termination_flags_t::FJ_TERMINATION_TIME_LIMIT;
fj.settings.time_limit = min(30., timer.remaining_time());
fj.settings.time_limit = std::min(30., timer.remaining_time());
fj.solve(solution);
return solution.get_feasible();
}
Expand All @@ -227,7 +227,7 @@ bool local_search_t<i_t, f_t>::run_fj_on_zero(solution_t<i_t, f_t>& solution, ti
fj.settings.update_weights = true;
fj.settings.feasibility_run = true;
fj.settings.termination = fj_termination_flags_t::FJ_TERMINATION_TIME_LIMIT;
fj.settings.time_limit = min(30., timer.remaining_time());
fj.settings.time_limit = std::min(30., timer.remaining_time());
bool is_feasible = fj.solve(solution);
return is_feasible;
}
Expand Down
Loading