PandA-2024.02
network_flow.hpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2004-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
44 #ifndef NETWORK_FLOW_HPP
45 #define NETWORK_FLOW_HPP
46 
47 #include "custom_set.hpp"
48 #include "graph.hpp"
49 #include "refcount.hpp"
50 #include <iosfwd>
51 #include <vector>
52 
53 #define I2S(number) std::to_string(number)
54 
56 {
57  private:
60  struct nf_name_t
61  {
62  using kind = boost::vertex_property_tag;
63  };
64 
65  struct nf_index_t
66  {
67  using kind = boost::vertex_property_tag;
68  };
69 
71  {
72  using kind = boost::vertex_property_tag;
73  };
74 
76  {
77  using kind = boost::vertex_property_tag;
78  };
79 
81  {
82  using kind = boost::vertex_property_tag;
83  };
84 
85  struct nf_balance_t
86  {
87  using kind = boost::vertex_property_tag;
88  };
89 
91  {
92  using kind = boost::vertex_property_tag;
93  };
94 
97  struct nf_cost_t
98  {
99  using kind = boost::edge_property_tag;
100  };
101 
103  {
104  using kind = boost::edge_property_tag;
105  };
106 
107  struct nf_flow_t
108  {
109  using kind = boost::edge_property_tag;
110  };
111 
113  {
114  using kind = boost::edge_property_tag;
115  };
116 
118  {
119  using kind = boost::edge_property_tag;
120  };
121 
123  {
124  using kind = boost::edge_property_tag;
125  };
126 
128  {
129  using kind = boost::edge_property_tag;
130  };
131 
134  using vertex_nf_description_property = boost::property<nf_vertex_description_t, std::string>;
135 
136  using vertex_nf_balance_property = boost::property<nf_balance_t, double, vertex_nf_description_property>;
137 
138  using vertex_nf_imbalance_property = boost::property<nf_imbalance_t, double, vertex_nf_balance_property>;
139 
140  using vertex_nf_potential_property = boost::property<nf_potential_t, double, vertex_nf_imbalance_property>;
141 
142  using vertex_nf_distance_property = boost::property<nf_distance_t, double, vertex_nf_potential_property>;
143 
144  using vertex_nf_index_property = boost::property<nf_index_t, unsigned long, vertex_nf_distance_property>;
145 
146  using vertex_nf_property = boost::property<nf_name_t, std::string, vertex_nf_index_property>;
147 
150  using edge_nf_description_property = boost::property<nf_edge_description_t, std::string>;
151 
152  using edge_nf_pseudo_flow_property = boost::property<nf_pseudo_flow_t, double, edge_nf_description_property>;
153 
155  boost::property<nf_residual_capacity_t, double, edge_nf_pseudo_flow_property>;
156 
157  using edge_nf_reduced_cost_property = boost::property<nf_reduced_cost_t, double, edge_nf_residual_capacity_property>;
158 
159  using edge_nf_flow_property = boost::property<nf_flow_t, double, edge_nf_reduced_cost_property>;
160 
161  using edge_nf_capacity_property = boost::property<nf_capacity_t, double, edge_nf_flow_property>;
162 
163  using edge_nf_property = boost::property<nf_cost_t, double, edge_nf_capacity_property>;
164 
165  public:
168  boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, vertex_nf_property, edge_nf_property>;
169 
170  private:
174 
176 
178 
180 
182 
184 
186 
190 
192 
194 
196 
198 
200 
202 
203  public:
206 
210 
212 
214 
216 
218 
220 
222 
226 
228 
230 
232 
234 
236 
238 
243  explicit network_flow(int _debug_level);
244 
248  ~network_flow() = default;
249 
255 
259  void clear_results();
260 
266  bool print_graph(const char* file_name = "network_flow.dot");
267 
268  private:
269  using vertex_pair =
270  std::pair<network_flow_graph_type::vertex_descriptor, network_flow_graph_type::vertex_descriptor>;
271  CustomOrderedSet<vertex_pair> inserted_edges; // used to remember the edges added to represent the residual network
272 
273  int debug_level; // the debug level
274 
282  std::string get_vertex_description(network_flow_graph_type::vertex_descriptor vd);
283 
291  std::string get_edge_description(network_flow_graph_type::edge_descriptor ed);
292 
297  void update_vertex_imbalance(network_flow_graph_type::vertex_descriptor vd);
298 
305  void generic_label_correcting_algorithm(network_flow_graph_type::vertex_descriptor source,
306  network_flow_graph_type::vertex_descriptor target,
307  std::vector<network_flow_graph_type::edge_descriptor>* P);
308 };
309 
312 
313 #endif
pmap_nf_index_t p_nf_index
boost::property_map< network_flow_graph_type, nf_capacity_t >::type pmap_nf_capacity_t
boost::property< nf_potential_t, double, vertex_nf_imbalance_property > vertex_nf_potential_property
boost::vertex_property_tag kind
boost::property_map< network_flow_graph_type, nf_reduced_cost_t >::type pmap_nf_reduced_cost_t
boost::property< nf_name_t, std::string, vertex_nf_index_property > vertex_nf_property
string target
Definition: lenet_tvm.py:16
pmap_nf_flow_t p_nf_flow
pmap_nf_imbalance_t p_nf_imbalance
boost::property< nf_imbalance_t, double, vertex_nf_balance_property > vertex_nf_imbalance_property
boost::property< nf_edge_description_t, std::string > edge_nf_description_property
edge properties
Class specification of the graph structures.
boost::property< nf_capacity_t, double, edge_nf_flow_property > edge_nf_capacity_property
pmap_nf_edge_description_t p_nf_edge_description
Edge maps variables.
boost::property_map< network_flow_graph_type, nf_edge_description_t >::type pmap_nf_edge_description_t
edge maps
std::string get_vertex_description(network_flow_graph_type::vertex_descriptor vd)
Generates the description string of the vertex vd.
boost::edge_property_tag kind
std::string get_edge_description(network_flow_graph_type::edge_descriptor ed)
Generates the description string of the edge ed.
~network_flow()=default
Destructor of the class.
bool successive_shortest_path_algorithm()
Computes the solution for the min cost flow problem with successive shortest path algorithm...
network_flow_graph_type network_flow_graph
Network flow graph pointer.
boost::property_map< network_flow_graph_type, nf_distance_t >::type pmap_nf_distance_t
network_flow(int _debug_level)
Constructor of the class.
pmap_nf_potential_t p_nf_potential
pmap_nf_pseudo_flow_t p_nf_pseudo_flow
const size_t P
Definition: helm.c:5
boost::property< nf_vertex_description_t, std::string > vertex_nf_description_property
vertex properties
void update_vertex_imbalance(network_flow_graph_type::vertex_descriptor vd)
Updates the vertex imbalance.
boost::property_map< network_flow_graph_type, nf_pseudo_flow_t >::type pmap_nf_pseudo_flow_t
boost::property_map< network_flow_graph_type, nf_vertex_description_t >::type pmap_nf_vertex_description_t
vertex maps
boost::property_map< network_flow_graph_type, nf_index_t >::type pmap_nf_index_t
boost::edge_property_tag kind
boost::property< nf_index_t, unsigned long, vertex_nf_distance_property > vertex_nf_index_property
void generic_label_correcting_algorithm(network_flow_graph_type::vertex_descriptor source, network_flow_graph_type::vertex_descriptor target, std::vector< network_flow_graph_type::edge_descriptor > *P)
Implements the generic label correcting algorithm for vertex distances labelling. ...
redefinition of set to manage ordered/unordered structures
boost::edge_property_tag kind
boost::property< nf_balance_t, double, vertex_nf_description_property > vertex_nf_balance_property
boost::vertex_property_tag kind
boost::property_map< network_flow_graph_type, nf_name_t >::type pmap_nf_name_t
pmap_nf_residual_capacity_t p_nf_residual_capacity
boost::property_map< network_flow_graph_type, nf_flow_t >::type pmap_nf_flow_t
boost::vertex_property_tag kind
boost::property_map< network_flow_graph_type, nf_potential_t >::type pmap_nf_potential_t
Template definition of refcount.
boost::edge_property_tag kind
boost::property< nf_flow_t, double, edge_nf_reduced_cost_property > edge_nf_flow_property
boost::property< nf_pseudo_flow_t, double, edge_nf_description_property > edge_nf_pseudo_flow_property
pmap_nf_vertex_description_t p_nf_vertex_description
Vertex maps variables.
boost::edge_property_tag kind
boost::vertex_property_tag kind
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, vertex_nf_property, edge_nf_property > network_flow_graph_type
definition of the Network Flow Graph
boost::property_map< network_flow_graph_type, nf_residual_capacity_t >::type pmap_nf_residual_capacity_t
pmap_nf_cost_t p_nf_cost
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
boost::vertex_property_tag kind
boost::vertex_property_tag kind
boost::edge_property_tag kind
pmap_nf_reduced_cost_t p_nf_reduced_cost
bool print_graph(const char *file_name="network_flow.dot")
Prints a textual description of the graph in a .dot file format.
boost::property< nf_reduced_cost_t, double, edge_nf_residual_capacity_property > edge_nf_reduced_cost_property
pmap_nf_balance_t p_nf_balance
boost::property< nf_residual_capacity_t, double, edge_nf_pseudo_flow_property > edge_nf_residual_capacity_property
boost::property_map< network_flow_graph_type, nf_imbalance_t >::type pmap_nf_imbalance_t
void clear_results()
Clears results of a previous computation.
pmap_nf_name_t p_nf_name
pmap_nf_capacity_t p_nf_capacity
boost::property< nf_cost_t, double, edge_nf_capacity_property > edge_nf_property
boost::property_map< network_flow_graph_type, nf_cost_t >::type pmap_nf_cost_t
boost::vertex_property_tag kind
boost::property< nf_distance_t, double, vertex_nf_potential_property > vertex_nf_distance_property
pmap_nf_distance_t p_nf_distance
std::pair< network_flow_graph_type::vertex_descriptor, network_flow_graph_type::vertex_descriptor > vertex_pair
CustomOrderedSet< vertex_pair > inserted_edges
boost::property_map< network_flow_graph_type, nf_balance_t >::type pmap_nf_balance_t

Generated on Mon Feb 12 2024 13:02:53 for PandA-2024.02 by doxygen 1.8.13