16 #ifndef PAAL_FACILITY_LOCATION_SOLUTION_HPP
17 #define PAAL_FACILITY_LOCATION_SOLUTION_HPP
19 #define BOOST_RESULT_OF_USE_DECLTYPE
25 #include <unordered_set>
27 #include <type_traits>
30 namespace data_structures {
42 template <
typename FacilityCost,
typename VoronoiType>
46 typedef typename VT::VertexType VertexType;
48 typedef typename VT::GeneratorsSet ChosenFacilitiesSet;
49 typedef std::unordered_set<VertexType, boost::hash<VertexType>>
50 UnchosenFacilitiesSet;
54 VoronoiType m_voronoi;
55 UnchosenFacilitiesSet m_unchosen_facilities;
56 const FacilityCost &m_fac_costs;
67 const FacilityCost &c)
68 : m_voronoi(std::move(voronoi)), m_unchosen_facilities(std::move(uf)),
73 assert(m_unchosen_facilities.find(f) != m_unchosen_facilities.end());
74 m_unchosen_facilities.erase(f);
76 return m_fac_costs(f) + m_voronoi.add_generator(f);
81 assert(m_unchosen_facilities.find(f) == m_unchosen_facilities.end());
82 m_unchosen_facilities.insert(f);
84 return -m_fac_costs(f) + m_voronoi.rem_generator(f);
89 return m_unchosen_facilities;
94 return m_voronoi.get_generators();
99 decltype(m_voronoi.get_vertices_for_generator(f))
101 return m_voronoi.get_vertices_for_generator(f);
115 template <
typename FacilityCost,
typename Voronoi>
122 typedef typename VT::VertexType VertexType;
123 typedef typename VT::DistanceType Dist;
124 typedef typename VT::GeneratorsSet ChosenFacilitiesSet;
126 typedef puretype(std::declval<FLS>().get_unchosen_facilities())
127 UnchosenFacilitiesSet;
133 #endif // PAAL_FACILITY_LOCATION_SOLUTION_HPP
default VertexType is int.
Dist rem_facility(VertexType f)
returns diff between new cost and old cost
Dist add_facility(VertexType f)
returns diff between new cost and old cost
auto get_clients_for_facility(VertexType f) const -> decltype(m_voronoi.get_vertices_for_generator(f))
gets clients assigned to specific facility
const UnchosenFacilitiesSet & get_unchosen_facilities() const
getter for unchosen facilities
describes solution to facility location The initial solution is passed as voronoi, which has to be the model of the Voronoi concept. The generators of the voronoi are the facilities and the vertices are the clients.
decltype(std::declval< V >().add_generator(std::declval< VertexType >())) typedef DistanceType
distance type
#define puretype(t)
for given expression returns its type with removed const and reference
simple implementation of the Voronoi concept.
facility_location_solution(VoronoiType voronoi, UnchosenFacilitiesSet uf, const FacilityCost &c)
constructor
const VoronoiType & get_voronoi() const
gets voronoi
const ChosenFacilitiesSet & get_chosen_facilities() const
setter for unchosen facilities