Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
net_float_flow_test.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 version 2.0.0b
6 https://github.com/lrleon/Aleph-w
7
8 This file is part of Aleph-w library
9
10 Copyright (c) 2002-2026 Leandro Rabindranath Leon
11
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files (the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29*/
30
31
32
43#include <gtest/gtest.h>
44
45#if defined(_MSC_VER) && !defined(__clang__)
46# pragma warning(push)
47# pragma warning(disable : 4996)
48#else
49# pragma GCC diagnostic push
50# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
51#endif
52#include <tpl_maxflow.H>
53#include <tpl_net.H>
54#if defined(_MSC_VER) && !defined(__clang__)
55# pragma warning(pop)
56#else
57# pragma GCC diagnostic pop
58#endif
59
60using namespace Aleph;
61
62namespace
63{
65} // anonymous namespace
66
67// A float flow is deprecated, not rejected: on a network of capacities
68// exact in binary, the maximum flows take it as before
69TEST(FloatFlowTest, AFloatFlowStillWorksWhileDeprecated)
70{
71 for (int algo = 0; algo < 3; ++algo)
72 {
73 Float_Net net;
74 auto s = net.insert_node(0);
75 auto a = net.insert_node(1);
76 auto t = net.insert_node(2);
77 net.insert_arc(s, a, 3.0f);
78 net.insert_arc(a, t, 2.0f);
79 net.insert_arc(s, t, 1.5f);
80 const float value = algo == 0 ? ford_fulkerson_maximum_flow(net)
81 : algo == 1 ? edmonds_karp_maximum_flow(net)
82 : dinic_maximum_flow(net);
83 EXPECT_EQ(value, 3.5f) << "algorithm " << algo;
84 EXPECT_TRUE(net.check_network()) << "algorithm " << algo;
85 }
86}
87
88int main(int argc, char **argv)
89{
90 ::testing::InitGoogleTest(&argc, argv);
91 return RUN_ALL_TESTS();
92}
int main()
size_t size_t int32_t value
Definition ca-c-api.h:116
#define TEST(name)
Main namespace for Aleph-w library functions.
Net::Flow_Type edmonds_karp_maximum_flow(Net &net)
Maximize flow using the Edmonds-Karp algorithm.
Definition tpl_net.H:2336
Net::Flow_Type dinic_maximum_flow(Net &net)
Compute maximum flow using Dinic's algorithm.
Net::Flow_Type ford_fulkerson_maximum_flow(Net &net)
Maximize flow using the Ford-Fulkerson algorithm.
Definition tpl_net.H:2306
Arc of a flow network implemented with adjacency lists.
Definition tpl_net.H:160
Flow network implemented with adjacency lists.
Definition tpl_net.H:311
Advanced maximum flow algorithms.
Network flow graph structures.