13#include <gtest/gtest.h>
41 return static_cast<long long>(
_getpid());
43 return static_cast<long long>(
getpid());
49 const auto *
test_info = ::testing::UnitTest::GetInstance()->current_test_info();
50 std::string base = std::string(
"alephw_") +
test_info->test_suite_name() +
"_" +
54 if (
ch ==
'/' ||
ch ==
'\\' ||
ch ==
' ')
57 auto dir = std::filesystem::temp_directory_path();
105 auto arc = it.get_curr();
116 params.ensure_connected =
true;
196 std::vector<size_t>
layers = {1, 5, 10, 5, 1};
205 std::vector<size_t>
layers = {1, 3, 3, 1};
214 std::vector<size_t>
layers = {1, 0, 1};
217 std::invalid_argument);
232 std::ifstream
file(dot_file);
235 std::string content((std::istreambuf_iterator<char>(
file)),
236 std::istreambuf_iterator<char>());
238 EXPECT_TRUE(content.find(
"digraph") != std::string::npos);
239 EXPECT_TRUE(content.find(
"->") != std::string::npos);
250 options.highlight_saturated =
true;
254 std::ifstream
file(dot_file);
264 EXPECT_TRUE(dot.find(
"digraph") != std::string::npos);
265 EXPECT_TRUE(dot.find(
"rankdir=LR") != std::string::npos);
279 std::ifstream
file(json_file);
282 std::string content((std::istreambuf_iterator<char>(
file)),
283 std::istreambuf_iterator<char>());
285 EXPECT_TRUE(content.find(
"\"num_nodes\"") != std::string::npos);
286 EXPECT_TRUE(content.find(
"\"arcs\"") != std::string::npos);
287 EXPECT_TRUE(content.find(
"\"cap\"") != std::string::npos);
296 EXPECT_TRUE(json.find(
"\"num_nodes\": 4") != std::string::npos);
297 EXPECT_TRUE(json.find(
"\"source\"") != std::string::npos);
298 EXPECT_TRUE(json.find(
"\"sink\"") != std::string::npos);
312 std::ifstream
file(dimacs_file);
315 std::string content((std::istreambuf_iterator<char>(
file)),
316 std::istreambuf_iterator<char>());
318 EXPECT_TRUE(content.find(
"p max 9") != std::string::npos);
319 EXPECT_TRUE(content.find(
"n") != std::string::npos);
320 EXPECT_TRUE(content.find(
"a") != std::string::npos);
369 EXPECT_EQ(result.algorithm_name,
"Dinic");
374 std::vector<MaxFlowBenchmarkResult<double>>
results;
376 results.push_back({100.0, 1.5,
"Algorithm A"});
377 results.push_back({100.0, 2.3,
"Algorithm B"});
380 testing::internal::CaptureStdout();
382 std::string
output = testing::internal::GetCapturedStdout();
421 ::testing::InitGoogleTest(&
argc,
argv);
void next_ne() noexcept
Advances the iterator to the next filtered element (noexcept version).
std::filesystem::path json_file
static long long process_id() noexcept
std::filesystem::path dot_file
std::filesystem::path dimacs_file
Main namespace for Aleph-w library functions.
void export_network_to_dimacs(const Net &net, const std::string &filename)
Export network to DIMACS max-flow format.
void export_network_to_dot(const Net &net, const std::string &filename, const DotExportOptions &options=DotExportOptions())
Export network to DOT format for GraphViz visualization.
Net::Flow_Type dinic_maximum_flow(Net &net)
Compute maximum flow using Dinic's algorithm.
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
void export_network_to_json(const Net &net, const std::string &filename)
Export network to JSON format.
std::string network_to_json_string(const Net &net)
Export network to JSON string.
MaxFlowBenchmarkResult< typename Net::Flow_Type > benchmark_maxflow(Net &net, Algo algo, const std::string &name)
Run and time a max-flow algorithm.
void print_benchmark_results(const std::vector< MaxFlowBenchmarkResult< Flow_Type > > &results)
Print benchmark results.
std::string network_to_dot_string(const Net &net, const DotExportOptions &options=DotExportOptions())
Generate DOT string for network (instead of file).
Network flow utilities: generators, visualization, serialization.
TEST_F(NetUtilsTest, GenerateRandomNetworkBasic)
static struct argp_option options[]
Filtered iterator on all the arcs of a graph.
bool show_flow
Show flow values on arcs.
Arc of a flow network implemented with adjacency lists.
Flow network implemented with adjacency lists.
Parameters for random network generation.
size_t num_nodes
Number of nodes.
Advanced maximum flow algorithms.