Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
psco-2019-gp
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Heinrichs
psco-2019-gp
Commits
a54d40f2
Commit
a54d40f2
authored
5 years ago
by
Lukas Garbas
Browse files
Options
Downloads
Patches
Plain Diff
Tests for Edmonds-Karp
parent
f7280fd8
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/edmonds_karp_test.cpp
+90
-2
90 additions, 2 deletions
test/edmonds_karp_test.cpp
with
90 additions
and
2 deletions
test/edmonds_karp_test.cpp
+
90
−
2
View file @
a54d40f2
...
...
@@ -4,8 +4,96 @@
#include
<gp-bnb/graph.hpp>
#include
<gp-bnb/metis_reader.hpp>
// T
o do: t
ests for Edmonds-Karp Max Flow algorithm
// Tests for Edmonds-Karp Max Flow algorithm
TEST_CASE
(
"EdmondsKarpMaxFlow"
)
{
// Same graph instance as in IBFS test
std
::
vector
<
std
::
vector
<
node_id
>>
adjacency_list
{
{
2
,
7
},
// 1
{
1
,
3
,
4
},
// 2
{
2
,
5
},
// 3
{
2
,
5
},
// 4
{
3
,
4
,
6
},
// 5
{
5
,
8
},
// 6
{
1
,
8
},
// 7
{
6
,
7
}
// 8
};
graph
g
(
adjacency_list
);
std
::
vector
<
node_id
>
sources
{
1
};
std
::
vector
<
node_id
>
sinks
{
8
};
edmonds_karp
ek
=
edmonds_karp
(
g
,
sources
,
sinks
);
ek
.
run
();
int
max_flow
=
ek
.
get_max_flow
();
REQUIRE
(
max_flow
==
2
);
//Testing multiple sources and sinks
std
::
vector
<
std
::
vector
<
node_id
>>
adjacency_list2
{
{
5
,
2
,
3
},
{
1
,
3
,
4
},
{
5
,
4
,
2
,
1
},
{
2
,
3
,
6
,
7
},
{
1
,
3
,
6
},
{
5
,
4
,
7
},
{
6
,
4
}
};
graph
g2
(
adjacency_list2
);
// 1 Case for g2
std
::
vector
<
node_id
>
sources2
{
1
};
std
::
vector
<
node_id
>
sinks2
{
6
,
7
};
edmonds_karp
ek2
=
edmonds_karp
(
g2
,
sources2
,
sinks2
);
ek2
.
run
();
int
max_flow2
=
ek2
.
get_max_flow
();
REQUIRE
(
max_flow2
==
3
);
// 2 Case for g2
std
::
vector
<
node_id
>
sources3
{
2
,
3
};
std
::
vector
<
node_id
>
sinks3
{
5
,
6
};
edmonds_karp
ek3
=
edmonds_karp
(
g2
,
sources3
,
sinks3
);
ek3
.
run
();
int
max_flow3
=
ek3
.
get_max_flow
();
REQUIRE
(
max_flow3
==
4
);
// 3 Case for g2 (balanced 2-partition)
std
::
vector
<
node_id
>
sources4
{
1
,
4
,
6
};
std
::
vector
<
node_id
>
sinks4
{
2
,
3
,
5
,
7
};
edmonds_karp
ek4
=
edmonds_karp
(
g2
,
sources4
,
sinks4
);
ek4
.
run
();
int
max_flow4
=
ek4
.
get_max_flow
();
REQUIRE
(
max_flow4
==
8
);
// 4 Case for g2 (balanced 2-partition)
std
::
vector
<
node_id
>
sources5
{
1
,
2
,
3
,
5
};
std
::
vector
<
node_id
>
sinks5
{
4
,
6
,
7
};
edmonds_karp
ek5
=
edmonds_karp
(
g2
,
sources5
,
sinks5
);
ek5
.
run
();
int
max_flow5
=
ek5
.
get_max_flow
();
REQUIRE
(
max_flow5
==
3
);
// Testing on a graph with ~1000 nodes
std
::
string
graph_file
=
"../test/inputs/delaunay_n10.graph"
;
graph
g3
=
metis_reader
().
read
(
graph_file
);
std
::
vector
<
node_id
>
sources6
=
{
1
,
3
,
8
,
9
,
100
};
std
::
vector
<
node_id
>
sinks6
=
{
50
,
60
,
88
};
edmonds_karp
ek6
=
edmonds_karp
(
g3
,
sources6
,
sinks6
);
ek6
.
run
();
int
max_flow6
=
ek6
.
get_max_flow
();
REQUIRE
(
max_flow6
==
18
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment