6#include <gtest/gtest.h>
27TEST(ErdosRenyiGeneratorTest, BasicGeneration)
38 EXPECT_EQ(net.
vsize(), 10);
39 EXPECT_GT(net.
esize(), 0);
42TEST(ErdosRenyiGeneratorTest, ConnectivityGuarantee)
60TEST(ErdosRenyiGeneratorTest, DifferentDensities)
71 size_t arcs_low = net_low.
esize();
78 size_t arcs_high = net_high.
esize();
81 EXPECT_LT(arcs_low, arcs_high);
89TEST(LayeredGeneratorTest, BasicGeneration)
100 EXPECT_EQ(net.
vsize(), 12);
101 EXPECT_GT(net.
esize(), 0);
104TEST(LayeredGeneratorTest, FlowsCorrectly)
123 EXPECT_GT(flow, 0.0);
131TEST(GridGeneratorTest, BasicGeneration)
140 EXPECT_EQ(net.
vsize(), 25);
144 EXPECT_EQ(net.
esize(), 40);
147TEST(GridGeneratorTest, FlowFromCornerToCorner)
160 EXPECT_GT(flow, 0.0);
163TEST(GridGeneratorTest, DifferentSizes)
178 EXPECT_EQ(net_small.
vsize(), 9);
179 EXPECT_EQ(net_large.
vsize(), 100);
187TEST(BipartiteGeneratorTest, BasicGeneration)
197 EXPECT_EQ(net.
vsize(), 12);
200TEST(BipartiteGeneratorTest, MatchingProblem)
214 EXPECT_LE(flow, 6.0);
215 EXPECT_GT(flow, 0.0);
223TEST(CostNetworkGeneratorTest, ErdosRenyiWithCosts)
246 EXPECT_GT(flow, 0.0);
247 EXPECT_GT(cost, 0.0);
250TEST(CostNetworkGeneratorTest, LayeredWithCosts)
278 EXPECT_GT(flow, 0.0);
279 EXPECT_GT(cost, 0.0);
287TEST(StressTest, MultipleRandomNetworks)
295 for (
int i = 0; i < 10; ++i)
297 config.
seed = 1000 + i;
314 EXPECT_NEAR(flow_ek, flow_dinic, 1e-6);
317 EXPECT_GT(flow_ek, 0.0);
318 EXPECT_GT(flow_dinic, 0.0);
326TEST(StressTest, LargeGridNetworks)
347 EXPECT_GT(flow, 0.0);
351TEST(StressTest, VaryingDensities)
358 for (
double density = 0.1; density <= 0.9; density += 0.2)
375 EXPECT_GT(flow, 0.0);
384TEST(FactoryTest, CreateAllGeneratorTypes)
391 auto gen_er = create_generator<TestNet>(
"erdos-renyi", config);
392 EXPECT_NE(gen_er,
nullptr);
394 gen_er->generate(net_er);
395 EXPECT_GT(net_er.
vsize(), 0);
397 auto gen_layered = create_generator<TestNet>(
"layered", config);
398 EXPECT_NE(gen_layered,
nullptr);
400 gen_layered->generate(net_layered);
401 EXPECT_GT(net_layered.
vsize(), 0);
403 auto gen_grid = create_generator<TestNet>(
"grid", config);
404 EXPECT_NE(gen_grid,
nullptr);
406 gen_grid->generate(net_grid);
407 EXPECT_GT(net_grid.
vsize(), 0);
409 auto gen_bipartite = create_generator<TestNet>(
"bipartite", config);
410 EXPECT_NE(gen_bipartite,
nullptr);
412 gen_bipartite->generate(net_bipartite);
413 EXPECT_GT(net_bipartite.
vsize(), 0);
416TEST(FactoryTest, InvalidTypeThrows)
420 EXPECT_THROW(create_generator<TestNet>(
"invalid-type", config),
421 std::invalid_argument);
427 ::testing::InitGoogleTest(&argc, argv);
428 return RUN_ALL_TESTS();
Complete bipartite network generator.
void generate(Net &net) override
Erdős–Rényi random network generator.
void generate(Net &net) override
void generate(Net &net) override
Layered (staged) network generator.
void generate(Net &net) override
void reseed()
Reset the random number generator to the original seed.
constexpr size_t vsize() const noexcept
See get_num_nodes().
size_t esize() const noexcept
Return the total of arcs of graph.
Main namespace for Aleph-w library functions.
Net::Flow_Type edmonds_karp_maximum_flow(Net &net)
Maximize flow using the Edmonds-Karp algorithm.
size_t size(Node *root) noexcept
See compute_cardinality_rec(Node * root).
Net::Flow_Type dinic_maximum_flow(Net &net)
Compute maximum flow using Dinic's algorithm.
Net::Flow_Type capacity_scaling_maximum_flow(Net &net)
Compute maximum flow using capacity scaling.
Net::Flow_Type hlpp_maximum_flow(Net &net)
Compute maximum flow using Highest-Label Preflow-Push.
std::pair< typename Net::Flow_Type, typename Net::Flow_Type > successive_shortest_paths(Net &net)
Compute minimum cost maximum flow using Successive Shortest Paths.
Random network generators for testing flow algorithms.
Arc of a flow network implemented with adjacency lists.
Arc type for maximum flow minimum cost networks.
Capacitated flow network with costs associated to arcs.
Flow network implemented with adjacency lists.
bool check_network() const
Validate flow-conservation and capacity constraints.
void make_super_source()
Convert a multi-source network into a single super-source network.
void make_super_sink()
Convert a multi-sink network into a single super-sink network.
constexpr bool is_single_source() const noexcept
Return true if the network has a single source.
constexpr bool is_single_sink() const noexcept
Return true if the network has a single sink.
Random network generator configuration.
size_t num_nodes
Number of nodes.
bool ensure_connected
Ensure source can reach sink.
double min_cost
Minimum arc cost (for cost networks)
double max_cost
Maximum arc cost.
double min_capacity
Minimum arc capacity.
unsigned seed
Random seed (0 = time-based)
double density
Edge density [0, 1] (for Erdős–Rényi)
double max_capacity
Maximum arc capacity.
Advanced maximum flow algorithms.
Advanced minimum cost flow algorithms.
Network flow graph structures.
Maximum flow minimum cost network algorithms.