15 #ifndef PAAL_LP_ROW_GENERATION_HPP
16 #define PAAL_LP_ROW_GENERATION_HPP
22 #include <boost/range/counting_range.hpp>
35 template <
class TryAddViolated,
class SolveLp>
39 do res = solve_lp();
while (res == OPTIMAL && try_add_violated());
58 GetCandidates m_get_candidates;
59 HowViolated m_how_violated;
60 AddViolated m_add_violated;
66 HowViolated how_violated, AddViolated add_violated, CompareHow cmp)
67 : m_get_candidates(get_candidates), m_how_violated(how_violated),
68 m_add_violated(add_violated), m_cmp(cmp) {}
72 auto&& cands = m_get_candidates();
73 using how_violated_t =
puretype(m_how_violated(*std::begin(cands)));
74 using cand_it_t =
puretype(std::begin(cands));
75 boost::optional<std::pair<how_violated_t, cand_it_t>> most;
76 for (
auto cand : boost::counting_range(cands)) {
77 auto const how = m_how_violated(*cand);
79 if (!most || m_cmp(most->first, how))
80 most = std::make_pair(std::move(how), cand);
82 if (!most)
return false;
83 m_add_violated(*most->second);
98 GetCandidates get_candidates,
99 HowViolated is_violated,
100 AddViolated add_violated,
101 CompareHow compare_how = CompareHow{}
104 CompareHow>(get_candidates, is_violated, add_violated, compare_how);
109 template <
class GetCandidates,
112 class ReorderCandidates>
114 GetCandidates m_get_candidates;
115 HowViolated m_how_violated;
116 AddViolated m_add_violated;
117 ReorderCandidates m_reorder_candidates;
122 GetCandidates get_candidates,
123 HowViolated how_violated,
124 AddViolated add_violated,
125 ReorderCandidates reorder_candidates
126 ) : m_get_candidates(get_candidates),
127 m_how_violated(how_violated),
128 m_add_violated(add_violated),
129 m_reorder_candidates(std::move(reorder_candidates)) {}
133 auto&& cands = m_get_candidates();
135 m_reorder_candidates(std::forward<decltype(cands)>(cands));
136 for (
auto c : boost::counting_range(reordered)) {
137 if (m_how_violated(*c)) {
156 GetCandidates get_candidates,
157 HowViolated how_violated,
158 AddViolated add_violated,
159 ReorderCandidates reorder_candidates = ReorderCandidates{}
162 ReorderCandidates>(get_candidates, how_violated, add_violated,
168 template <
class URNG>
173 : m_g(std::forward<URNG>(g)) {}
174 template <
class ForwardRange>
175 auto operator()(
const ForwardRange& rng)
177 auto const len = boost::distance(rng);
178 std::uniform_int_distribution<decltype(len)> d(0, len);
183 template <
class URNG = std::default_random_engine>
184 auto make_random_rotate(URNG&& g = URNG{})
186 return random_rotate<URNG>(std::forward<URNG>(g));
198 class URNG = std::default_random_engine
202 GetCandidates get_candidates,
203 HowViolated how_violated,
204 AddViolated add_violated,
208 how_violated, add_violated, detail::make_random_rotate(std::forward<URNG>(g)));
216 #endif // PAAL_LP_ROW_GENERATION_HPP
auto operator()(GetCandidates get_candidates, HowViolated how_violated, AddViolated add_violated, URNG &&g=URNG{}) const
operator()
auto operator()(GetCandidates get_candidates, HowViolated how_violated, AddViolated add_violated, ReorderCandidates reorder_candidates=ReorderCandidates{}) const
operator()
bool operator()()
operator()
functor computing add_first_violated
functor for adding maximum violated constraint
problem_type
LP problem type.
problem_type row_generation(TryAddViolated try_add_violated, SolveLp solve_lp)
add_first_violated(GetCandidates get_candidates, HowViolated how_violated, AddViolated add_violated, ReorderCandidates reorder_candidates)
constructor
#define puretype(t)
for given expression returns its type with removed const and reference
auto rotate(const ForwardRange &rng, range_to_diff_type_t< ForwardRange > n)
returns rotated view of the given range
bool operator()()
operator()
add_max_violated(GetCandidates get_candidates, HowViolated how_violated, AddViolated add_violated, CompareHow cmp)
contructor
functor returns its argument
auto operator()(GetCandidates get_candidates, HowViolated is_violated, AddViolated add_violated, CompareHow compare_how=CompareHow{}) const
operator()
functor computing add_max_violated