38#include <gtest/gtest.h>
93 auto n1 = net.insert_node(10.0);
94 auto n2 = net.insert_node(5.0);
95 net.insert_arc(n1, n2, 15.0, 0.0);
108 auto node = net.insert_node();
111 EXPECT_EQ(node->max_cap, numeric_limits<double>::max());
118 auto node = net.insert_node(100.0);
125 auto node = net.insert_node(0.0);
141 auto node = net.insert_node(numeric_limits<double>::max());
142 EXPECT_EQ(node->max_cap, numeric_limits<double>::max());
147 auto node = net.insert_node(numeric_limits<double>::min());
148 EXPECT_EQ(node->max_cap, numeric_limits<double>::min());
153 auto node = net.insert_node(numeric_limits<double>::epsilon());
154 EXPECT_EQ(node->max_cap, numeric_limits<double>::epsilon());
163 auto n1 = net.insert_node(10.0);
164 auto n2 = net.insert_node(10.0);
165 auto arc = net.insert_arc(n1, n2, 0.0, 0.0);
173 auto n1 = net.insert_node(10.0);
174 auto n2 = net.insert_node(10.0);
175 auto arc = net.insert_arc(n1, n2, 5.0, 5.0);
183 auto n1 = net.insert_node(10.0);
184 auto n2 = net.insert_node(10.0);
186 EXPECT_THROW(net.insert_arc(n1, n2, 5.0, 10.0), std::overflow_error);
195 auto n1 = net.insert_node(10.0);
196 auto n2 = net.insert_node(5.0);
197 net.insert_arc(n1, n2, 15.0, 0.0);
199 net.compute_aux_net();
217 auto n1 = net.insert_node(10.0);
218 auto n2 = net.insert_node(5.0);
219 net.insert_arc(n1, n2, 15.0, 0.0);
222 for (
int i = 0; i < 3; ++i)
237 auto n1 = net.insert_node(10.0);
238 auto n2 = net.insert_node(5.0);
239 net.insert_arc(n1, n2, 15.0, 3.0);
250 auto n1 = net.insert_node(10.0);
251 auto n2 = net.insert_node(5.0);
252 net.insert_arc(n1, n2, 15.0, 3.0);
253 net.compute_aux_net();
261 moved.free_aux_net();
285 auto b = net.insert_node(5.0);
286 auto c = net.insert_node(15.0);
289 net.insert_arc(b, c, 8.0, 0.0);
294 auto aux = net.compute_aux_net();
308 for (
int i = 0; i < 10; ++i)
309 nodes.push_back(net.insert_node(10.0 + i));
311 for (
int i = 0; i < 9; ++i)
312 net.insert_arc(
nodes[i],
nodes[i+1], 5.0 + i, 0.0);
317 auto aux = net.compute_aux_net();
331 auto hub = net.insert_node(50.0);
333 for (
int i = 0; i < 5; ++i)
335 auto spoke = net.insert_node(10.0);
336 net.insert_arc(
spoke,
hub, 15.0, 0.0);
342 auto aux = net.compute_aux_net();
363 auto a = net.insert_node(100.0);
364 auto b = net.insert_node(30.0);
365 auto c = net.insert_node(40.0);
366 auto d = net.insert_node(100.0);
368 net.insert_arc(a, b, 50.0, 0.0);
369 net.insert_arc(a, c, 60.0, 0.0);
370 net.insert_arc(b, d, 50.0, 0.0);
371 net.insert_arc(c, d, 60.0, 0.0);
376 auto aux = net.compute_aux_net();
390 for (
int i = 0; i < 5; ++i)
391 nodes.push_back(net.insert_node(20.0));
393 for (
int i = 0; i < 5; ++i)
394 for (
int j = 0; j < 5; ++j)
396 net.insert_arc(
nodes[i],
nodes[j], 10.0, 0.0);
401 auto aux = net.compute_aux_net();
417 for (
int i = 0; i < 3; ++i)
418 left.push_back(net.insert_node(10.0));
420 for (
int i = 0; i < 3; ++i)
421 right.push_back(net.insert_node(15.0));
426 net.insert_arc(
l, r, 5.0, 0.0);
431 auto aux = net.compute_aux_net();
468 for (
int i = 0; i < 3; ++i)
473 for (
int i = 0; i < 10; ++i)
477 for (
int i = 0; i < 10; ++i)
480 int dc2 = (i + 1) % 3;
514 for (
int i = 0; i < 3; ++i)
518 for (
int i = 0; i < 10; ++i)
526 for (
int i = 0; i < 10; ++i)
555 for (
int i = 0; i < 4; ++i)
556 for (
int j = 0; j < 4; ++j)
560 for (
int i = 0; i < 4; ++i)
561 for (
int j = 0; j < 3; ++j)
568 for (
int i = 0; i < 3; ++i)
569 for (
int j = 0; j < 4; ++j)
607 const int NUM_NODES = 500;
615 for (
int i = 0; i < NUM_NODES; ++i)
620 for (
int i = 0; i < NUM_NODES; ++i)
682 const int WIDTH = 200;
688 for (
int i = 0; i <
WIDTH; ++i)
720 auto n2 = net.insert_node(10.0);
737 auto n1 = net.insert_node(10.0);
738 auto n2 = net.insert_node(5.0);
739 net.insert_arc(n1, n2, 8.0, 0.0);
752 auto n1 = net.insert_node(10.0);
753 auto n2 = net.insert_node(5.0);
754 net.insert_arc(n1, n2, 8.0, 0.0);
767 auto node = net.insert_node(10.0);
769 node->out_flow = 5.0;
778 auto node = net.insert_node(10.0);
780 node->out_flow = 5.0;
788 auto node = net.insert_node(10.0);
806 auto n2 = net.insert_node(0, 50L);
807 auto arc = net.insert_arc(n1, n2, 75L, 0
L);
816 auto n1 = net.insert_node(0, 100L);
817 auto n2 = net.insert_node(0, 50L);
818 net.insert_arc(n1, n2, 75L, 0
L);
820 auto aux = net.compute_aux_net();
839 auto n2 = net.insert_node(
"Sink", 50.0);
840 auto arc = net.insert_arc(n1, n2, 75.0, 0.0,
"Connection");
844 EXPECT_EQ(arc->get_info(),
"Connection");
849 auto n1 = net.insert_node(
"Node_A", 100.0);
850 auto n2 = net.insert_node(
"Node_B", 50.0);
851 net.insert_arc(n1, n2, 75.0, 0.0);
853 auto aux = net.compute_aux_net();
872 auto n2 = net.insert_node(20.0);
875 net.compute_aux_net();
894 auto n1 = net.insert_node(10.0);
895 auto n2 = net.insert_node(20.0);
896 auto arc = net.insert_arc(n1, n2, 15.0, 0.0);
898 net.compute_aux_net();
937 for (
int i = 0; i < 1000; ++i)
941 if (
nodes.size() < 2 || op == 0)
945 nodes.push_back(node);
947 else if (op == 1 &&
nodes.size() >= 2)
995 numeric_limits<double>::min(),
996 numeric_limits<double>::epsilon(),
1003 numeric_limits<double>::max() / 2,
1011 for (
size_t i = 0; i <
nodes.size() - 1; ++i)
1027 ::testing::InitGoogleTest(&
argc,
argv);
T & insert(const T &item)
Insert a new item by copy.
void * insert_arc(void *arc)
static void set_node_cap(Node *node, const Flow_Type &cap)
Set the capacity of a node.
bool has_aux_net() const noexcept
Check if auxiliary network has been computed.
void free_aux_net()
Free the auxiliary network.
void update()
Update flow values from auxiliary network to this network.
Node * insert_node(Node *p) override
Aux_Net * compute_aux_net()
Compute the equivalent arc-capacitated auxiliary network.
Node with capacity constraint for flow networks.
Node with supply/demand flow value.
constexpr size_t vsize() const noexcept
size_t esize() const noexcept
Return the total of arcs of graph.
iterator end() noexcept
Return an STL-compatible end iterator.
DynArray< Graph::Node * > nodes
#define ARC_COOKIE(p)
Return the arc cookie
#define NODE_COOKIE(p)
Return the node cookie
Main namespace for Aleph-w library functions.
Itor2 copy(Itor1 sourceBeg, const Itor1 &sourceEnd, Itor2 destBeg)
Copy elements from one range to another.
DynList< T > maps(const C &c, Op op)
Classic map operation.
TEST_F(NetCapGraphEdgeCases, EmptyNetwork_NoNodes)
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.
Network flow graph structures.
Network flow graph with capacities.