Repository navigation
Update APIs - SOCP support #1979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1038138
e2572f7
2c31258
fa633cd
62d595b
13a5215
4270b5c
050783d
6e20206
7d61502
698afbe
5cf8c5f
0ae8190
d1b4b73
43b9b29
0499d81
260d6a1
faf0aa2
bf7d115
854b857
8711e6b
bf7f479
84b0bbb
d9a579b
a1a936f
b00c416
8c66a93
2782e35
69191a6
9ea7635
f6da09d
64e84e8
6a2accb
efc0f55
720ad1b
fa03c34
1e4d92b
a40e97c
7bba0b3
6d41719
8895540
5ce0235
9b8e14a
a2ac329
d12fd7f
117cd99
648f805
78884b0
0e822d1
d1880ab
e8fe40e
80c103c
31f6f97
3aeb182
9f6136b
9a2a6dd
cdbd082
d40feac
883b644
4b77fac
347276b
e5b11c6
b92ede5
adf9cd6
bef9925
757e9eb
236ea7c
8ba7357
51b7b9d
5cb041a
34f9782
438fe0e
94dafd4
3234877
9a2372f
cc9209b
2e1a10e
5fec35c
2f022ba
17173b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,8 +23,9 @@ using barrier_iteration_data_t = barrier::iteration_data_t<int, double>; | |
| using barrier_iteration_data_ptr = | ||
| std::unique_ptr<barrier_iteration_data_t, void (*)(barrier_iteration_data_t*)>; | ||
|
|
||
| static void require_cache(barrier_transform_t const* transform, | ||
| barrier_iteration_data_t const* data, | ||
| template <typename i_t, typename f_t> | ||
| static void require_cache(barrier_transform_t<i_t, f_t> const* transform, | ||
| barrier::iteration_data_t<i_t, f_t> const* data, | ||
| char const* api) | ||
| { | ||
| cuopt_expects(transform != nullptr, | ||
|
|
@@ -38,7 +39,8 @@ static void require_cache(barrier_transform_t const* transform, | |
| } | ||
|
|
||
| // Re-adds the first solve's barrier-minus-crush shift so the update lands in the presolved model. | ||
| static void add_shift(std::vector<double>& crushed, std::vector<double> const& shift) | ||
| template <typename f_t> | ||
| static void add_shift(std::vector<f_t>& crushed, std::vector<f_t> const& shift) | ||
| { | ||
| cuopt_expects(shift.size() == crushed.size(), | ||
| error_type_t::ValidationError, | ||
|
|
@@ -59,7 +61,7 @@ struct barrier_cache_t::impl { | |
| std::unique_ptr<rmm::cuda_stream> stream; | ||
| std::unique_ptr<raft::handle_t> handle; | ||
| // Destroy iteration_data before transform: it may const-ref A/Q stored on the transform. | ||
| std::unique_ptr<barrier_transform_t> transform; | ||
| std::unique_ptr<barrier_transform_t<int, double>> transform; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. int -> i_t, double -> f_t |
||
| barrier_iteration_data_ptr iteration_data; | ||
| bool linear_objective_dirty{false}; | ||
| bool rhs_dirty{false}; | ||
|
|
@@ -107,14 +109,18 @@ barrier_iteration_data_t* barrier_cache_t::release_iteration_data() | |
| return impl_->iteration_data.release(); | ||
| } | ||
|
|
||
| void barrier_cache_t::store_transform(std::unique_ptr<barrier_transform_t> transform) | ||
| template <typename i_t, typename f_t> | ||
| void barrier_cache_t::store_transform(std::unique_ptr<barrier_transform_t<i_t, f_t>> transform) | ||
| { | ||
| impl_->transform = std::move(transform); | ||
| } | ||
|
|
||
| barrier_transform_t* barrier_cache_t::transform() { return impl_->transform.get(); } | ||
| barrier_transform_t<int, double>* barrier_cache_t::transform() { return impl_->transform.get(); } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. int -> i_t, double -> f_t |
||
|
|
||
| barrier_transform_t const* barrier_cache_t::transform() const { return impl_->transform.get(); } | ||
| barrier_transform_t<int, double> const* barrier_cache_t::transform() const | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. int -> i_t, double -> f_t |
||
| { | ||
| return impl_->transform.get(); | ||
| } | ||
|
|
||
| bool barrier_cache_t::dirty() const | ||
| { | ||
|
|
@@ -131,19 +137,20 @@ void barrier_cache_t::mark_clean() | |
|
|
||
| bool barrier_cache_t::rhs_infeasible() const { return impl_->rhs_infeasible; } | ||
|
|
||
| void barrier_cache_t::update_linear_objective(double const* c, int n) | ||
| template <typename i_t, typename f_t> | ||
| void barrier_cache_t::update_linear_objective(f_t const* c, i_t n) | ||
| { | ||
| require_cache(impl_->transform.get(), impl_->iteration_data.get(), "update_linear_objective"); | ||
| // Cached Q and c are in minimization space. | ||
| std::vector<double> user_objective; | ||
| std::vector<f_t> user_objective; | ||
| if (impl_->transform->maximize && c != nullptr && n > 0) { | ||
| user_objective.assign(c, c + n); | ||
| for (double& value : user_objective) { | ||
| for (f_t& value : user_objective) { | ||
| value = -value; | ||
| } | ||
| c = user_objective.data(); | ||
| } | ||
| std::vector<double> crushed; | ||
| std::vector<f_t> crushed; | ||
| try { | ||
| crushed = crush_user_linear_objective(*impl_->transform, c, n); | ||
| } catch (std::invalid_argument const& e) { | ||
|
|
@@ -154,35 +161,36 @@ void barrier_cache_t::update_linear_objective(double const* c, int n) | |
| auto const& linear_obj_shift = impl_->transform->linear_obj_shift; | ||
| auto const& column_scales = impl_->transform->column_scales; | ||
| auto const& translated_lower = impl_->transform->presolve_info.removed_lower_bounds; | ||
| simplex::lp_problem_t<int, double>& barrier_lp = *impl_->transform->barrier_lp; | ||
| simplex::lp_problem_t<i_t, f_t>& barrier_lp = *impl_->transform->barrier_lp; | ||
| if (!translated_lower.empty() && linear_obj_shift.size() == crushed.size() && | ||
| column_scales.size() == crushed.size() && barrier_lp.objective.size() == crushed.size()) { | ||
| double obj_constant_delta = 0.0; | ||
| f_t obj_constant_delta = 0.0; | ||
| std::size_t const n_lower = std::min(translated_lower.size(), crushed.size()); | ||
| for (std::size_t j = 0; j < n_lower; ++j) { | ||
| double const crushed_before = barrier_lp.objective[j] - linear_obj_shift[j]; | ||
| f_t const crushed_before = barrier_lp.objective[j] - linear_obj_shift[j]; | ||
| obj_constant_delta += (crushed[j] - crushed_before) * column_scales[j] * translated_lower[j]; | ||
| } | ||
| barrier_lp.obj_constant += obj_constant_delta; | ||
| } | ||
| add_shift(crushed, linear_obj_shift); | ||
| // The next solve builds its solver from barrier_lp, so keep its objective and the cached | ||
| // iteration workspace on the same c. | ||
| std::vector<double>& barrier_objective = barrier_lp.objective; | ||
| std::vector<f_t>& barrier_objective = barrier_lp.objective; | ||
| cuopt_expects(barrier_objective.size() == crushed.size(), | ||
| error_type_t::ValidationError, | ||
| "update_linear_objective: crushed objective size does not match the cached " | ||
| "barrier LP."); | ||
| barrier_objective = crushed; | ||
| barrier::apply_barrier_linear_objective( | ||
| *impl_->iteration_data, crushed.data(), static_cast<int>(crushed.size())); | ||
| *impl_->iteration_data, crushed.data(), static_cast<i_t>(crushed.size())); | ||
| impl_->linear_objective_dirty = true; | ||
| } | ||
|
|
||
| void barrier_cache_t::update_rhs(double const* b, int m) | ||
| template <typename i_t, typename f_t> | ||
| void barrier_cache_t::update_rhs(f_t const* b, i_t m) | ||
| { | ||
| require_cache(impl_->transform.get(), impl_->iteration_data.get(), "update_rhs"); | ||
| std::vector<double> crushed; | ||
| std::vector<f_t> crushed; | ||
| std::string error; | ||
| crush_rhs_status_t const status = crush_user_rhs(*impl_->transform, b, m, crushed, error); | ||
| if (status == crush_rhs_status_t::infeasible) { | ||
|
|
@@ -198,14 +206,21 @@ void barrier_cache_t::update_rhs(double const* b, int m) | |
| add_shift(crushed, impl_->transform->rhs_shift); | ||
| // barrier_lp->rhs also seeds the next solve's Mehrotra start, so keep it and the cached | ||
| // workspace on the same b. | ||
| std::vector<double>& barrier_rhs = impl_->transform->barrier_lp->rhs; | ||
| std::vector<f_t>& barrier_rhs = impl_->transform->barrier_lp->rhs; | ||
| cuopt_expects(barrier_rhs.size() == crushed.size(), | ||
| error_type_t::ValidationError, | ||
| "update_rhs: crushed RHS size does not match the cached barrier LP."); | ||
| barrier_rhs = crushed; | ||
| barrier::apply_barrier_rhs( | ||
| *impl_->iteration_data, crushed.data(), static_cast<int>(crushed.size())); | ||
| *impl_->iteration_data, crushed.data(), static_cast<i_t>(crushed.size())); | ||
| impl_->rhs_dirty = true; | ||
| } | ||
|
|
||
| #ifdef DUAL_SIMPLEX_INSTANTIATE_DOUBLE | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was included to addtress #1979 (comment) |
||
| template void barrier_cache_t::store_transform<int, double>( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We usually wrap template initialization in an ifdef. Please take a look at some of the other files in the barrier directory for an example
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated |
||
| std::unique_ptr<barrier_transform_t<int, double>>); | ||
| template void barrier_cache_t::update_linear_objective<int, double>(double const*, int); | ||
| template void barrier_cache_t::update_rhs<int, double>(double const*, int); | ||
| #endif | ||
|
|
||
| } // namespace cuopt::mathematical_optimization | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We still have int, double here