Example #1
0
    void set_candidates_and_demands
    (const Graph& g, Vertices& candidates, Vertices& demands,
     ExistedCenterMap existed_center_map, CandidateMap candidate_map)
    {
      using boost::vertices;
      const typename boost::graph_traits<Graph>::vertices_size_type
        num_v = num_vertices(g);

      candidates.reserve(num_v);
      demands.reserve(num_v);

      typename boost::graph_traits<Graph>::vertex_iterator vi, vi_end;
      for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) {
        if (get(candidate_map, *vi) != false &&
            get(existed_center_map, *vi) == false) {
          candidates.push_back(*vi);
        }
        demands.push_back(*vi);
      }

      // TODO copy_if or filter_iterator
      //
      if (candidates.empty()) {
        throw std::runtime_error("The number of candidate vertex is too small");
      }
    }
  inline void
  parallel_dijkstra_shortest_paths_no_init
    (const Graph& g, RootVertexMap root_vertex_map,
     PredecessorMap predecessor_map, DistanceMap distance_map,
     WeightMap weight_map, IndexMap index_map,
     Compare compare, Combine combine, DistZero zero,
     DijkstraVisitor vis, ColorMap color_map)
  {
    using boost::vertices;
    using boost::num_vertices;
    // TODO VertexList and IncidentGraph CenceptCheck
    typedef
      typename boost::property_traits<RootVertexMap>::value_type
      RootVertex;
    typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
    boost::function_requires< boost::Convertible<RootVertex, Vertex> >();

    typedef boost::indirect_cmp<DistanceMap, Compare> IndirectCmp;
    IndirectCmp icmp(distance_map, compare);

#ifdef BOOST_GRAPH_DIJKSTRA_USE_RELAXED_HEAP
    typedef boost::relaxed_heap<Vertex, IndirectCmp, IndexMap> MutableQueue;
    MutableQueue Q(num_vertices(g), icmp, index_map);
#else // Now the default: use a d-ary heap
    boost::scoped_array<std::size_t> index_in_heap_map_holder;
    typedef
      boost::detail::vertex_property_map_generator<Graph, IndexMap, std::size_t>
      IndexInHeapMapHelper;
    typedef typename IndexInHeapMapHelper::type IndexInHeapMap;
    IndexInHeapMap index_in_heap =
      IndexInHeapMapHelper::build(g, index_map, index_in_heap_map_holder);
    typedef
      boost::d_ary_heap_indirect<Vertex, 4, IndexInHeapMap, DistanceMap, Compare>
      MutableQueue;
    MutableQueue Q(distance_map, index_in_heap, compare);
#endif // Relaxed heap

    typename boost::graph_traits<Graph>::vertex_iterator vi, vi_end;
    for (boost::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi) {
      if (get(root_vertex_map, *vi) != false) {
        Q.push(*vi);
      }
    }
    if (Q.empty()) {
      // TODO
      throw std::runtime_error("not specified root vertices.");
    }

    boost::detail::dijkstra_bfs_visitor<DijkstraVisitor, MutableQueue,
      WeightMap, PredecessorMap, DistanceMap, Combine, Compare>
        bfs_vis(vis, Q, weight_map, predecessor_map, distance_map,
            combine, compare, zero);

    const Vertex s = Q.top();
    Q.pop();
    boost::breadth_first_visit(g, s, Q, bfs_vis, color_map);
  }
 graph_info
 (const Graph& g, Compare cmp, Combine& cmb, DistZero zero,
  OptimalSolutions& opt_sols, OptimalResouceContainers& opt_res_conts)
   : graph(g), num_center(0), prev_value(zero), next_value(zero),
   compare(cmp), combine(&cmb),
   optimal_solutions(&opt_sols),
   optimal_resource_containers(&opt_res_conts)
 {
   using boost::num_vertices;
   using boost::vertex;
   typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
   if (num_vertices(graph) > 1) {
     const Vertex s = vertex(0, graph);
     const Vertex t = vertex(num_vertices(graph) - 1, graph);
     typename boost::graph_traits<Graph>::edge_descriptor e;
     boost::tie(e, boost::tuples::ignore) = edge(s, t, graph);
     prev_value = g[e];
     prev_solution.push_back(e);
     calc_next_sols();
   }
 }
 inline void
 parallel_dijkstra_shortest_paths
   (const VertexListGraph& g,
    RootVertexMap root_vertex_map,
    PredecessorMap predecessor_map, DistanceMap distance_map,
    WeightMap weight_map, IndexMap index_map,
    Compare compare, Combine combine, DistInf inf, DistZero zero,
    DijkstraVisitor vis,
    const boost::bgl_named_params<T, Tag, Base>&
    BOOST_GRAPH_ENABLE_IF_MODELS_PARM(VertexListGraph,boost::vertex_list_graph_tag))
 {
   using boost::num_vertices;
   boost::two_bit_color_map<IndexMap> color_map(num_vertices(g), index_map);
   parallel_dijkstra_shortest_paths
     (g, root_vertex_map, predecessor_map, distance_map, weight_map, index_map,
      compare, combine, inf, zero, vis,
      color_map);
 }
        void calc_next_sols()
        {
          if (is_allocable()) {
            dag_hop_constrained_shortest_paths(
                graph,
                num_center + 2,
                get(boost::vertex_index, graph),
                get(boost::edge_index, graph),
                vertex(0, graph),
                vertex(num_vertices(graph) - 1, graph),
                get(boost::edge_bundle, graph),
                *optimal_solutions,
                *optimal_resource_containers);

            next_value = (*optimal_resource_containers)[0].weight;
            next_solution.swap((*optimal_solutions)[0]);
          }
        }
	void distances_to_w(const VertexListGraph& graph, Vertex* uwv, Distances& d) {
		typedef graph_traits<GraphW>::vertex_descriptor VertexW;
		typedef graph_traits<GraphW>::edge_descriptor EdgeW;
		typedef typename graph_traits<VertexListGraph>::edge_descriptor Edge;

		const int num_nodes = num_vertices(graph);
		GraphW graph_temp(num_nodes);

		property_map <GraphW, edge_weight_t>::type weightmap = 
  		get(edge_weight, graph_temp);

  	BOOST_FOREACH(Edge e, edges(graph)) {
			VertexW s = source(e, graph), t = target(e, graph);
			if(s == uwv[FIRST] || s == uwv[THIRD] || 
				t == uwv[FIRST] || t == uwv[THIRD])
				continue;
			EdgeW e_temp; bool inserted;
			tie(e_temp, inserted) = add_edge(s, t, graph_temp);
			weightmap[e_temp] = 1;
		}
    inline void
    parallel_dijkstra_dispatch1
      (const VertexListGraph& g,
       RootVertexMap root_vertex_map,
       DistanceMap distance_map, WeightMap weight_map, IndexMap index_map,
       const Params& params)
    {
      using boost::num_vertices;
      // Default for distance map
      typedef typename boost::property_traits<WeightMap>::value_type D;
      const typename std::vector<D>::size_type
        n = boost::is_default_param(distance_map) ? num_vertices(g) : 1;
      std::vector<D> d_map(n);

      detail::parallel_dijkstra_dispatch2
        (g, root_vertex_map, choose_param
         (distance_map,
          boost::make_iterator_property_map
          (d_map.begin(), index_map, d_map[0])),
         weight_map, index_map, params);
    }
Example #8
0
    typename DistMatrix<
        typename boost::property_traits<WeightMap>::value_type
      >::type
    create_distance_matrix
    (const Graph& g, WeightMap w_map, IndexMap i_map,
     Compare compare, Combine combine, DistInf inf, DistZero zero)
    {
      using boost::num_vertices;
      const typename boost::graph_traits<Graph>::vertices_size_type
        num_v = num_vertices(g);

      typedef typename boost::property_traits<WeightMap>::value_type DistValue;
      typedef boost::multi_array<DistValue, 2> DistanceMatrix;
      DistanceMatrix d_matrix(boost::extents[num_v][num_v]);

      boost::johnson_all_pairs_shortest_paths(
          g, d_matrix,
          boost::weight_map(w_map). vertex_index_map(i_map).
          distance_compare(compare). distance_combine(combine).
          distance_inf(inf). distance_zero(zero));

      return d_matrix;
    }
 bool is_allocable() const
 {
   using boost::num_vertices;
   return num_vertices(graph) > num_center + 2;
 }