38#include <gtest/gtest.h>
61 return std::fabs(a - b) < eps;
68 auto s = net.insert_node();
69 auto t = net.insert_node();
78 auto s = net.insert_node();
79 auto a = net.insert_node();
80 auto b = net.insert_node();
81 auto t = net.insert_node();
95 auto s = net.insert_node();
96 auto a = net.insert_node();
97 auto b = net.insert_node();
98 auto t = net.insert_node();
136 auto net = build_single_arc_network(10.0, 1.0);
138 auto nodes = net.nodes();
139 auto it =
nodes.get_it();
140 auto s = it.get_curr(); it.next();
141 auto t = it.get_curr();
143 size_t k = net.add_commodity(s, t, 5.0,
"Commodity 1");
148 const auto&
comm = net.get_commodity(0);
162 net.add_commodity(s, t, 5.0);
163 net.add_commodity(s, t, 8.0);
166 arc->set_flow(1, 8.0);
176 auto net = build_diamond_network();
178 auto nodes = net.nodes();
179 auto it =
nodes.get_it();
180 auto s = it.get_curr(); it.next();
181 it.next(); it.next();
182 auto t = it.get_curr();
184 net.add_commodity(s, t, 5.0,
"K1");
185 net.add_commodity(s, t, 3.0,
"K2");
188 EXPECT_EQ(net.get_commodity(0).demand, 5.0);
189 EXPECT_EQ(net.get_commodity(1).demand, 3.0);
198 auto net = build_single_arc_network(10.0, 2.0);
200 auto nodes = net.nodes();
201 auto it =
nodes.get_it();
202 auto s = it.get_curr(); it.next();
203 auto t = it.get_curr();
205 net.add_commodity(s, t, 5.0);
215 auto net = build_diamond_network();
217 auto nodes = net.nodes();
218 auto it =
nodes.get_it();
219 auto s = it.get_curr(); it.next();
220 it.next(); it.next();
221 auto t = it.get_curr();
223 net.add_commodity(s, t, 5.0);
233 auto net = build_parallel_paths();
235 auto nodes = net.nodes();
236 auto it =
nodes.get_it();
237 auto s = it.get_curr(); it.next();
238 it.next(); it.next();
239 auto t = it.get_curr();
241 net.add_commodity(s, t, 8.0);
267 net.add_commodity(
s1,
t1, 3.0,
"K1");
268 net.add_commodity(
s2,
t2, 3.0,
"K2");
284 net.add_commodity(s, t, 4.0,
"K1");
285 net.add_commodity(s, t, 4.0,
"K2");
299 auto net = build_diamond_network();
301 auto nodes = net.nodes();
302 auto it =
nodes.get_it();
303 auto s = it.get_curr(); it.next();
304 it.next(); it.next();
305 auto t = it.get_curr();
307 net.add_commodity(s, t, 2.0,
"K1");
308 net.add_commodity(s, t, 3.0,
"K2");
309 net.add_commodity(s, t, 4.0,
"K3");
323 auto net = build_single_arc_network(10.0, 1.0);
325 auto nodes = net.nodes();
326 auto it =
nodes.get_it();
327 auto s = it.get_curr(); it.next();
328 auto t = it.get_curr();
330 net.add_commodity(s, t, 0.0);
340 auto net = build_diamond_network();
359 net.add_commodity(s, t, 4.0);
360 net.add_commodity(s, t, 5.0);
376 net.add_commodity(s, t, 3.0,
"Cheap");
377 net.add_commodity(s, t, 2.0,
"Expensive");
380 arc->set_cost(0, 1.0);
381 arc->set_cost(1, 5.0);
419 2.0,
"TopLeft-BottomRight");
421 2.0,
"TopRight-BottomLeft");
426 <<
"cost=" << result.total_cost
427 <<
", time=" << result.solve_time_ms <<
" ms"
428 <<
", iterations=" << result.iterations <<
"\n";
451 net.add_commodity(s, t, 5.0,
"K1");
452 net.add_commodity(s, t, 3.0,
"K2");
457 EXPECT_EQ(result.commodity_costs.size(), 2u);
462 for (
auto c : result.commodity_costs)
469 ::testing::InitGoogleTest(&
argc,
argv);
Multi-commodity flow network (directed graph).
Arc * insert_arc(Node *src, Node *tgt, Flow_Type capacity, Flow_Type cost=0)
Insert arc with capacity and cost.
constexpr size_t vsize() const noexcept
size_t esize() const noexcept
Return the total of arcs of graph.
TestNet build_single_arc_network(double capacity, double cost)
TestNet build_diamond_network()
static constexpr double EPSILON
TestNet build_parallel_paths()
bool nearly_equal(double a, double b, double eps=EPSILON)
DynArray< Graph::Node * > nodes
Main namespace for Aleph-w library functions.
MCF_Result< typename Net::Flow_Type > solve_multicommodity_flow(Net &net)
Solve multi-commodity flow problem.
DynList< T > maps(const C &c, Op op)
Classic map operation.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.
Arc information for multi-commodity flow.
Flow network implemented with adjacency lists.
Node * insert_node(const Node_Type &node_info)
Insert a new node by copying node_info.
void set_flow(Arc *arc, const Flow_Type &flow)
Set the flow of an arc. Throws if flow exceeds capacity.
Arc * insert_arc(Node *src_node, Node *tgt_node, const Flow_Type &cap, const Flow_Type &flow, const typename Arc::Arc_Type &arc_info=Arc_Type())
Insert a capacitated arc with an initial flow.
Multi-commodity flow algorithms.
Graph_Anode< Empty_Class > TestNode
TEST_F(MultiCommodityTest, EmptyNetwork)