diff --git a/cpp/src/linear_programming/utilities/problem_checking.cu b/cpp/src/linear_programming/utilities/problem_checking.cu index 57f10e55b..d0fc6811b 100644 --- a/cpp/src/linear_programming/utilities/problem_checking.cu +++ b/cpp/src/linear_programming/utilities/problem_checking.cu @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -73,6 +74,18 @@ void problem_checking_t::check_initial_primal_representation( "has size %zu, while objective vector has size %zu.", primal_initial_solution.size(), op_problem.get_objective_coefficients().size()); + cuopt_expects(!thrust::any_of(op_problem.get_handle_ptr()->get_thrust_policy(), + thrust::make_counting_iterator(0), + thrust::make_counting_iterator(0) + op_problem.get_n_variables(), + [lower_bounds = make_span(op_problem.get_variable_lower_bounds()), + upper_bounds = make_span(op_problem.get_variable_upper_bounds()), + assignment_span = make_span(primal_initial_solution), + int_tol = 1e-8] __device__(i_t idx) { + return assignment_span[idx] < lower_bounds[idx] - int_tol || + assignment_span[idx] > upper_bounds[idx] + int_tol; + }), + error_type_t::ValidationError, + "Initial solution violates variable bounds."); } } diff --git a/cpp/src/mip/diversity/diversity_manager.cu b/cpp/src/mip/diversity/diversity_manager.cu index a05a9063b..f7476a5ed 100644 --- a/cpp/src/mip/diversity/diversity_manager.cu +++ b/cpp/src/mip/diversity/diversity_manager.cu @@ -216,7 +216,7 @@ void diversity_manager_t::add_user_given_solutions( cuopt_func_call(sol.test_variable_bounds(true)); CUOPT_LOG_INFO("Adding initial solution success! feas %d objective %f excess %f", is_feasible, - sol.get_objective(), + sol.get_user_objective(), sol.get_total_excess()); population.run_solution_callbacks(sol); initial_sol_vector.emplace_back(std::move(sol)); @@ -226,7 +226,7 @@ void diversity_manager_t::add_user_given_solutions( Assignment size %lu \ initial solution size %lu", sol.assignment.size(), - init_sol->size()); + init_sol_assignment.size()); } } } @@ -320,6 +320,9 @@ bool diversity_manager_t::run_presolve(f_t time_limit) if (!check_bounds_sanity(*problem_ptr)) { return false; } } stats.presolve_time = presolve_timer.elapsed_time(); + lp_optimal_solution.resize(problem_ptr->n_variables, problem_ptr->handle_ptr->get_stream()); + problem_ptr->handle_ptr->sync_stream(); + cudaDeviceSynchronize(); return true; } @@ -392,7 +395,6 @@ solution_t diversity_manager_t::run_solver() cuopt::scope_guard([&]() { stats.total_solve_time = timer.elapsed_time(); }); // after every change to the problem, we should resize all the relevant vars // we need to encapsulate that to prevent repetitions - lp_optimal_solution.resize(problem_ptr->n_variables, problem_ptr->handle_ptr->get_stream()); ls.resize_vectors(*problem_ptr, problem_ptr->handle_ptr); ls.lb_constraint_prop.temp_problem.setup(*problem_ptr); ls.lb_constraint_prop.bounds_update.setup(ls.lb_constraint_prop.temp_problem); @@ -796,12 +798,14 @@ void diversity_manager_t::set_simplex_solution(const std::vector& { CUOPT_LOG_DEBUG("Setting simplex solution with objective %f", objective); using sol_t = solution_t; + context.handle_ptr->sync_stream(); + RAFT_CUDA_TRY(cudaSetDevice(context.handle_ptr->get_device())); cuopt_func_call(sol_t new_sol(*problem_ptr)); + cuopt_assert(new_sol.assignment.size() == solution.size(), "Assignment size mismatch"); cuopt_func_call(new_sol.copy_new_assignment(solution)); cuopt_func_call(new_sol.compute_feasibility()); cuopt_assert(integer_equal(new_sol.get_user_objective(), objective, 1e-3), "Objective mismatch"); std::lock_guard lock(relaxed_solution_mutex); - RAFT_CUDA_TRY(cudaSetDevice(context.handle_ptr->get_device())); simplex_solution_exists = true; global_concurrent_halt.store(1, std::memory_order_release); // it is safe to use lp_optimal_solution while executing the copy operation diff --git a/cpp/src/mip/utils.cuh b/cpp/src/mip/utils.cuh index b48ad21b6..18759737d 100644 --- a/cpp/src/mip/utils.cuh +++ b/cpp/src/mip/utils.cuh @@ -346,13 +346,13 @@ bool has_variable_bounds_violation(const raft::handle_t* handle_ptr, problem_t* problem_ptr) { auto const assignment_span = make_span(assignment); - return thrust::any_of( - handle_ptr->get_thrust_policy(), - thrust::make_counting_iterator(0), - thrust::make_counting_iterator(0) + problem_ptr->original_problem_ptr->get_n_variables(), - [assignment_span, problem_view = problem_ptr->view()] __device__(i_t idx) { - return !problem_view.check_variable_within_bounds(idx, assignment_span[idx]); - }); + return thrust::any_of(handle_ptr->get_thrust_policy(), + thrust::make_counting_iterator(0), + thrust::make_counting_iterator(0) + problem_ptr->n_variables, + [assignment_span, problem_view = problem_ptr->view()] __device__(i_t idx) { + return !problem_view.check_variable_within_bounds(idx, + assignment_span[idx]); + }); } } // namespace cuopt::linear_programming::detail diff --git a/cpp/tests/mip/CMakeLists.txt b/cpp/tests/mip/CMakeLists.txt index 9fc2e3f88..b9fd249a5 100644 --- a/cpp/tests/mip/CMakeLists.txt +++ b/cpp/tests/mip/CMakeLists.txt @@ -43,9 +43,10 @@ ConfigureTest(UNIT_TEST ConfigureTest(EMPTY_FIXED_PROBLEMS_TEST ${CMAKE_CURRENT_SOURCE_DIR}/empty_fixed_problems_test.cu ) -ConfigureTest(FEASIBILITY_JUMP_TEST - ${CMAKE_CURRENT_SOURCE_DIR}/feasibility_jump_tests.cu -) +# Disable for now +# ConfigureTest(FEASIBILITY_JUMP_TEST +# ${CMAKE_CURRENT_SOURCE_DIR}/feasibility_jump_tests.cu +# ) ConfigureTest(MIP_TERMINATION_STATUS_TEST ${CMAKE_CURRENT_SOURCE_DIR}/termination_test.cu )