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
7d283333
Commit
7d283333
authored
5 years ago
by
p-hamann
Browse files
Options
Downloads
Patches
Plain Diff
Adjust sources and sinks dynamically in bnb
parent
8ca8c755
Branches
Branches containing commit
1 merge request
!9
Perf optimization
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bnb/bnb.cpp
+22
-14
22 additions, 14 deletions
bnb/bnb.cpp
include/gp-bnb/bnb.hpp
+2
-0
2 additions, 0 deletions
include/gp-bnb/bnb.hpp
with
24 additions
and
14 deletions
bnb/bnb.cpp
+
22
−
14
View file @
7d283333
#include
<algorithm>
#include
<cassert>
#include
<cassert>
#include
<iostream>
#include
<iostream>
#include
<time.h>
#include
<time.h>
...
@@ -29,36 +30,27 @@ solver::solver(graph& g, lb lb_algorithm) : graph_(g), partition_(partition{g}),
...
@@ -29,36 +30,27 @@ solver::solver(graph& g, lb lb_algorithm) : graph_(g), partition_(partition{g}),
}
}
unsigned
int
solver
::
get_lower
(){
unsigned
int
solver
::
get_lower
(){
std
::
vector
<
node_id
>
sources
,
sinks
;
if
(
current_sources_
.
empty
()
||
current_sinks_
.
empty
())
{
for
(
node_id
node
=
1
;
node
<=
graph_
.
num_nodes
();
node
++
){
if
(
partition_
.
assigned_subgraph_of
(
node
)
==
partition
::
sg_a
)
sources
.
push_back
(
node
);
else
if
(
partition_
.
assigned_subgraph_of
(
node
)
==
partition
::
sg_b
)
sinks
.
push_back
(
node
);
}
if
(
sources
.
empty
()
||
sinks
.
empty
())
{
return
partition_
.
current_objective
();
return
partition_
.
current_objective
();
}
}
if
(
lb_algorithm_
==
lb
::
ek
){
if
(
lb_algorithm_
==
lb
::
ek
){
ek_
.
reset
(
sources
,
sinks
);
ek_
.
reset
(
current_
sources
_
,
current_
sinks
_
);
ek_
.
run
();
ek_
.
run
();
return
ek_
.
get_max_flow
();
return
ek_
.
get_max_flow
();
}
}
else
if
(
lb_algorithm_
==
lb
::
ibfs
){
else
if
(
lb_algorithm_
==
lb
::
ibfs
){
i_bfs_
.
reset
(
sources
,
sinks
);
i_bfs_
.
reset
(
current_
sources
_
,
current_
sinks
_
);
i_bfs_
.
run
();
i_bfs_
.
run
();
return
i_bfs_
.
get_max_flow
();
return
i_bfs_
.
get_max_flow
();
}
}
else
if
(
lb_algorithm_
==
lb
::
pr
){
else
if
(
lb_algorithm_
==
lb
::
pr
){
pr_
.
reset
(
sources
,
sinks
);
pr_
.
reset
(
current_
sources
_
,
current_
sinks
_
);
pr_
.
run
();
pr_
.
run
();
return
pr_
.
get_max_flow
();
return
pr_
.
get_max_flow
();
}
}
else
if
(
lb_algorithm_
==
lb
::
gp
){
else
if
(
lb_algorithm_
==
lb
::
gp
){
gp_
.
reset
(
sources
,
sinks
);
gp_
.
reset
(
current_
sources
_
,
current_
sinks
_
);
gp_
.
run
();
gp_
.
run
();
return
gp_
.
get_max_flow
();
return
gp_
.
get_max_flow
();
}
}
...
@@ -70,6 +62,17 @@ void solver::solve() {
...
@@ -70,6 +62,17 @@ void solver::solve() {
best_objective_
=
graph_
.
num_nodes
();
best_objective_
=
graph_
.
num_nodes
();
clock_t
begin
=
clock
();
clock_t
begin
=
clock
();
/*
// builds a vector of node ids with descending degree
std::vector<node_id> sorted_nodes;
for (node_id i = 1; i <= graph_.num_nodes(); ++i) {
sorted_nodes.push_back(i);
}
std::sort(sorted_nodes.begin(), sorted_nodes.end(), [this](node_id a, node_id b) {
return graph_.get_adjacency(a).size() > graph_.get_adjacency(b).size();
});
*/
while
(
true
)
{
while
(
true
)
{
//falls current sol schlechter als bisher beste lösung:
//falls current sol schlechter als bisher beste lösung:
//zähle schritte bis zur nächsten alternative und
//zähle schritte bis zur nächsten alternative und
...
@@ -125,6 +128,7 @@ void solver::solve() {
...
@@ -125,6 +128,7 @@ void solver::solve() {
next_node
=
trail_
.
length
()
+
1
;
next_node
=
trail_
.
length
()
+
1
;
//next_node = sorted_nodes[trail_.length()];
expand
(
next_node
,
next_possible_subgraph
(
next_node
,
subgraph
::
sg_a
));
expand
(
next_node
,
next_possible_subgraph
(
next_node
,
subgraph
::
sg_a
));
}
}
...
@@ -149,6 +153,8 @@ void solver::expand(node_id node, subgraph sg) {
...
@@ -149,6 +153,8 @@ void solver::expand(node_id node, subgraph sg) {
partition_
.
assign_node
(
node
,
sg
);
partition_
.
assign_node
(
node
,
sg
);
trail_
.
push_node
(
node
,
alt
);
trail_
.
push_node
(
node
,
alt
);
if
(
sg
==
partition
::
sg_a
)
current_sources_
.
push_back
(
node
);
else
current_sinks_
.
push_back
(
node
);
}
}
void
solver
::
backtrack
()
{
void
solver
::
backtrack
()
{
...
@@ -160,6 +166,8 @@ void solver::backtrack() {
...
@@ -160,6 +166,8 @@ void solver::backtrack() {
trail_
.
pop
();
trail_
.
pop
();
partition_
.
unassign_node
(
node
);
partition_
.
unassign_node
(
node
);
if
(
current_sources_
.
back
()
==
node
)
current_sources_
.
erase
(
current_sources_
.
begin
()
+
current_sources_
.
size
()
-
1
);
else
if
(
current_sinks_
.
back
()
==
node
)
current_sinks_
.
erase
(
current_sinks_
.
begin
()
+
current_sinks_
.
size
()
-
1
);
}
}
// Finds the next partition in which the given node can be placed.
// Finds the next partition in which the given node can be placed.
...
...
This diff is collapsed.
Click to expand it.
include/gp-bnb/bnb.hpp
+
2
−
0
View file @
7d283333
...
@@ -93,6 +93,8 @@ private:
...
@@ -93,6 +93,8 @@ private:
edmonds_karp
ek_
;
edmonds_karp
ek_
;
push_relabel
pr_
;
push_relabel
pr_
;
greedy_packing
gp_
;
greedy_packing
gp_
;
std
::
vector
<
node_id
>
current_sources_
;
std
::
vector
<
node_id
>
current_sinks_
;
// Value of best solution seen so far.
// Value of best solution seen so far.
std
::
vector
<
subgraph
>
best_solution_
;
std
::
vector
<
subgraph
>
best_solution_
;
...
...
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