All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
facility_location_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 
19 #include "paal/utils/functors.hpp"
20 
21 #include <boost/range/algorithm/copy.hpp>
22 
23 #include <iostream>
24 
25 using namespace paal::local_search;
26 
27 int main() {
28 
29 
30  // sample data
31  typedef sample_graphs_metrics SGM;
32  auto gm = SGM::get_graph_metric_small();
33  std::vector<int> fcosts{ 7, 8 };
35 
36  // define voronoi and solution
39  Sol;
41  typedef VT::GeneratorsSet GSet;
42  typedef VT::VerticesSet VSet;
43  typedef Sol::UnchosenFacilitiesSet USet;
44 
45  // create voronoi and solution
46  VorType voronoi(GSet{}, VSet{ SGM::A, SGM::B, SGM::C, SGM::D, SGM::E }, gm);
47  Sol sol(std::move(voronoi), USet{ SGM::A, SGM::B },
49 
50  // create facility location local search components
54 
55  // search
56  facility_location_first_improving(sol, rem, add, swap);
57 
58  // print result
59  boost::copy(sol.get_chosen_facilities(), std::ostream_iterator<int>(std::cout, ","));
60  std::cout << std::endl;
61 
62  return true;
63 }
Multisearch_components< facility_locationget_moves_add, facility_location_gain_add, facility_location_commit_add > default_add_fl_components
add components for facility location
default VertexType is int.
Adapts array as function, providing operator()().
Definition: functors.hpp:326
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.
This file contains set of simple useful functors or functor adapters.
Model of Multisearch_components with default multi search components for facility location...
auto make_array_to_functor(const Array &a, int offset=0)
make function for array_to_functor
Definition: functors.hpp:364
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
bool local_search(Solution &solution, SearchStrategy searchStrategy, ContinueOnSuccess succ, ContinueOnFail fail, components...comps)
detail
Multisearch_components< facility_locationget_moves_swap, facility_location_gain_swap, facility_location_commit_swap > default_swap_fl_components
Swap components for facility location.