16 #ifndef PAAL_FACILITY_LOCATION_SOLUTION_ADAPTER_HPP
17 #define PAAL_FACILITY_LOCATION_SOLUTION_ADAPTER_HPP
19 #define BOOST_RESULT_OF_USE_DECLTYPE
26 #include <boost/range/algorithm/copy.hpp>
27 #include <boost/range/distance.hpp>
28 #include <boost/range/algorithm/find.hpp>
30 #include <unordered_map>
31 #include <unordered_set>
43 template <
typename facility_location_solution>
45 typedef facility_location_solution FLS;
48 template <
typename Collection,
typename Range
49 =
const typename boost::iterator_range<typename Collection::const_iterator>::type>
50 auto get_cycledCopy(
const Collection &col, std::size_t index)
const
51 -> boost::joined_range<Range, Range> {
53 boost::make_iterator_range(col.begin() + index, col.end()),
54 boost::make_iterator_range(col.begin(), col.begin() + index));
58 typedef typename facility_location_solution::VertexType VertexType;
60 typedef decltype(std::declval<FLS>().get_chosen_facilities())
Chosen;
62 typedef decltype(std::declval<FLS>().get_unchosen_facilities())
Unchosen;
63 typedef typename data_structures::facility_location_solution_traits<
65 typedef std::vector<VertexType> UnchosenCopy;
66 typedef std::vector<VertexType> ChosenCopy;
69 facility_location_solution &m_sol;
71 UnchosenCopy m_unchosen_copy;
73 ChosenCopy m_chosen_copy;
75 std::
size_t m_last_used_unchosen;
77 std::
size_t m_last_used_chosen;
86 : m_sol(sol), m_unchosen_copy(m_sol.get_unchosen_facilities().begin(),
87 m_sol.get_unchosen_facilities().end()),
88 m_chosen_copy(m_sol.get_chosen_facilities().begin(),
89 m_sol.get_chosen_facilities().end()),
90 m_last_used_unchosen{}, m_last_used_chosen{} {}
110 auto elemIter = boost::range::find(m_unchosen_copy, v);
111 assert(elemIter != m_unchosen_copy.end());
112 elemIter = m_unchosen_copy.erase(elemIter);
113 m_last_used_unchosen = elemIter - m_unchosen_copy.begin();
114 m_chosen_copy.push_back(v);
126 return m_sol.rem_facility(v);
138 m_unchosen_copy.push_back(v);
139 auto elemIter = boost::range::find(m_chosen_copy, v);
140 assert(elemIter != m_chosen_copy.end());
141 elemIter = m_chosen_copy.erase(elemIter);
142 m_last_used_chosen = elemIter - m_chosen_copy.begin();
170 m_unchosen_copy, m_last_used_unchosen)) {
171 return get_cycledCopy(m_unchosen_copy, m_last_used_unchosen);
182 m_chosen_copy, m_last_used_chosen)){
183 return get_cycledCopy(m_chosen_copy, m_last_used_chosen);
190 #endif // PAAL_FACILITY_LOCATION_SOLUTION_ADAPTER_HPP
decltype(std::declval< FLS >().get_unchosen_facilities()) typedef Unchosen
type of Unchosen collection
facility_location_solution & getfacility_location_solution()
get solution
Dist add_facility(VertexType v)
adds facility
decltype(std::declval< FLS >().get_chosen_facilities()) typedef Chosen
type of Chosen collection
This file contains set of simple useful functors or functor adapters.
Dist add_facility_tentative(VertexType v)
adds facility tentatively (used in gain computation).
Dist remove_facility(VertexType v)
removes facility
bool local_search(Solution &solution, SearchStrategy searchStrategy, ContinueOnSuccess succ, ContinueOnFail fail, components...comps)
detail
auto getChosenCopy() const -> decltype(this->get_cycledCopy(m_chosen_copy, m_last_used_chosen))
returns copy of chosen facilities
const facility_location_solution & getfacility_location_solution() const
gets solution
Dist remove_facility_tentative(VertexType v)
ads facility tentatively (used in gain computation)
auto getUnchosenCopy() const -> decltype(this->get_cycledCopy(m_unchosen_copy, m_last_used_unchosen))
returns copy of unchosen facilities
facility_location_solution adapter chosen range and unchosen range must be joined into one homogenus ...