All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
capacitated_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 
20 #include "paal/utils/functors.hpp"
21 
22 using namespace paal::local_search;
23 
24 int main() {
25  // sample data
26  typedef sample_graphs_metrics SGM;
27  auto gm = SGM::get_graph_metric_small();
28 
29  std::vector<int> fcostsv{ 7, 8 };
30  auto facilityCost = paal::utils::make_array_to_functor(fcostsv);
31 
32  std::vector<int> fcapv{ 2, 2 };
33  auto facilityCapacity = paal::utils::make_array_to_functor(fcapv);
34 
35  std::vector<int> cdemv{ 2, 2, 1, 3, 3 };
36  auto clientDemand = paal::utils::make_array_to_functor(cdemv);
37 
38  // define voronoi and solution
40  decltype(gm), decltype(facilityCapacity), decltype(clientDemand)>
41  VorType;
43  decltype(facilityCost), VorType> Sol;
45  typedef VT::GeneratorsSet GSet;
46  typedef VT::VerticesSet VSet;
47  typedef Sol::UnchosenFacilitiesSet USet;
48 
49  // create voronoi and solution
50  VorType voronoi(GSet{ SGM::A },
51  VSet{ SGM::A, SGM::B, SGM::C, SGM::D, SGM::E }, gm,
52  facilityCapacity, clientDemand);
53  Sol sol(std::move(voronoi), USet{ SGM::B }, facilityCost);
54 
55  // search
59 
60  // print result
61  auto const &ch = sol.get_chosen_facilities();
62  std::copy(ch.begin(), ch.end(), std::ostream_iterator<int>(std::cout, ","));
63  std::cout << std::endl;
64 
65  return 0;
66 }
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.
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
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
This class is assigning vertices demands to capacitated generators in such a way that the total cost ...
Multisearch_components< facility_locationget_moves_swap, facility_location_gain_swap, facility_location_commit_swap > default_swap_fl_components
Swap components for facility location.