All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
k_median_example.cpp
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 //=======================================================================
15 #include "test/test_utils/sample_graph.hpp"
17 
20 
21 #include <iostream>
22 
23 int main() {
24  // sample data
25  typedef sample_graphs_metrics SGM;
26  auto gm = SGM::get_graph_metric_small();
27 
28  // define voronoi and solution
29  const int k = 2;
33  typedef VT::GeneratorsSet GSet;
34  typedef VT::VerticesSet VSet;
35  typedef Sol::UnchosenFacilitiesSet USet;
36 
37  // create voronoi and solution
38  VorType voronoi(GSet{ SGM::B, SGM::D },
39  VSet{ SGM::A, SGM::B, SGM::C, SGM::D, SGM::E }, gm);
40  Sol sol(std::move(voronoi), USet{ SGM::A, SGM::C }, k);
41 
42  // create facility location local search step
43  paal::local_search::default_k_median_components swap;
44 
45  // search
47  sol, swap);
48 
49  // print result
50  auto const &ch = sol.get_chosen_facilities();
51  std::cout << "Solution:" << std::endl;
52  std::copy(ch.begin(), ch.end(), std::ostream_iterator<int>(std::cout, ","));
53  std::cout << std::endl << "Cost " << paal::simple_algo::get_km_cost(gm, sol)
54  << std::endl;
55 
56  std::cout << std::endl;
57 
58  return 0;
59 }
default VertexType is int.
simple implementation of the Voronoi concept.
Definition: voronoi.hpp:42
bool facility_location_first_improving(facility_location_solution &fls, components...comps)
simple version of local search for facility location
int main()
[K Median Search Example]