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
Julian Scherzer
psco-2019-gp
Commits
256a20d3
Commit
256a20d3
authored
5 years ago
by
p-hamann
Browse files
Options
Downloads
Patches
Plain Diff
Optimize edmonds karp
parent
156a8359
Branches
Branches containing commit
1 merge request
!9
Perf optimization
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bnb/edmonds_karp.cpp
+6
-10
6 additions, 10 deletions
bnb/edmonds_karp.cpp
with
6 additions
and
10 deletions
bnb/edmonds_karp.cpp
+
6
−
10
View file @
256a20d3
...
...
@@ -36,7 +36,7 @@ void edmonds_karp::reset(std::vector<node_id>& sources, std::vector<node_id>& si
std
::
pair
<
int
,
node_id
>
edmonds_karp
::
bfs
(
std
::
vector
<
unsigned
int
>
&
pred
)
const
{
pred
.
clear
();
pred
.
resize
(
g_
.
num_nodes
()
+
1
,
-
1
);
// undiscovered nodes are marked with -1
pred
.
assign
(
g_
.
num_nodes
()
+
1
,
-
1
);
// undiscovered nodes are marked with -1
std
::
vector
<
int
>
gain
(
g_
.
num_nodes
()
+
1
,
0
);
bool
sink_reached
=
false
;
node_id
sink
;
...
...
@@ -57,16 +57,12 @@ std::pair<int, node_id> edmonds_karp::bfs(std::vector<unsigned int> &pred) const
node_id
u
=
q
.
front
();
q
.
pop
();
const
std
::
vector
<
node_id
>
&
neighbors
=
g_
.
get_adjacency
(
u
);
const
auto
&
adjacency
=
g_
.
get_adjacency
(
u
);
const
auto
&
edge_ids
=
g_
.
get_edge_ids
(
u
);
// iterate through neighbors of u
for
(
node_id
v
:
neighbors
)
{
unsigned
int
edge_id
;
if
(
u
<
v
)
edge_id
=
g_
.
get_edge_id
(
u
,
v
);
else
edge_id
=
g_
.
get_edge_id
(
v
,
u
);
for
(
node_id
i
=
0
;
i
<
adjacency
.
size
();
++
i
)
{
node_id
v
=
adjacency
[
i
];
edge_id
edge_id
=
edge_ids
[
i
];
int
edge_weight
=
1
;
// unweighted graph
...
...
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