All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
facility_location_solution.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
16 #ifndef PAAL_FACILITY_LOCATION_SOLUTION_HPP
17 #define PAAL_FACILITY_LOCATION_SOLUTION_HPP
18 
19 #define BOOST_RESULT_OF_USE_DECLTYPE
20 
22 
24 
25 #include <unordered_set>
26 #include <cassert>
27 #include <type_traits>
28 
29 namespace paal {
30 namespace data_structures {
31 
42 template <typename FacilityCost, typename VoronoiType>
44 public:
46  typedef typename VT::VertexType VertexType;
47  typedef typename VT::DistanceType Dist;
48  typedef typename VT::GeneratorsSet ChosenFacilitiesSet;
49  typedef std::unordered_set<VertexType, boost::hash<VertexType>>
50  UnchosenFacilitiesSet;
51 
52 private:
53 
54  VoronoiType m_voronoi;
55  UnchosenFacilitiesSet m_unchosen_facilities;
56  const FacilityCost &m_fac_costs;
57 public:
58 
66  facility_location_solution(VoronoiType voronoi, UnchosenFacilitiesSet uf,
67  const FacilityCost &c)
68  : m_voronoi(std::move(voronoi)), m_unchosen_facilities(std::move(uf)),
69  m_fac_costs(c) {}
70 
72  Dist add_facility(VertexType f) {
73  assert(m_unchosen_facilities.find(f) != m_unchosen_facilities.end());
74  m_unchosen_facilities.erase(f);
75 
76  return m_fac_costs(f) + m_voronoi.add_generator(f);
77  }
78 
80  Dist rem_facility(VertexType f) {
81  assert(m_unchosen_facilities.find(f) == m_unchosen_facilities.end());
82  m_unchosen_facilities.insert(f);
83 
84  return -m_fac_costs(f) + m_voronoi.rem_generator(f);
85  }
86 
88  const UnchosenFacilitiesSet &get_unchosen_facilities() const {
89  return m_unchosen_facilities;
90  }
91 
93  const ChosenFacilitiesSet &get_chosen_facilities() const {
94  return m_voronoi.get_generators();
95  }
96 
98  auto get_clients_for_facility(VertexType f) const ->
99  decltype(m_voronoi.get_vertices_for_generator(f))
100  {
101  return m_voronoi.get_vertices_for_generator(f);
102  }
103 
105  const VoronoiType &get_voronoi() const { return m_voronoi; }
106 
107 };
108 
115 template <typename FacilityCost, typename Voronoi>
117  facility_location_solution<FacilityCost, Voronoi>> {
118  typedef voronoi_traits<Voronoi> VT;
120 
121  public:
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;
128 };
129 
130 } // !data_structures
131 } // !paal
132 
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.
Definition: voronoi.hpp:42
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