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
7fccbe61
Commit
7fccbe61
authored
5 years ago
by
p-hamann
Browse files
Options
Downloads
Patches
Plain Diff
Avoid multiple generations of greedy packing
parent
5fb51690
Branches
Branches containing commit
1 merge request
!9
Perf optimization
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
bnb/bnb.cpp
+4
-7
4 additions, 7 deletions
bnb/bnb.cpp
bnb/greedy_packing.cpp
+26
-16
26 additions, 16 deletions
bnb/greedy_packing.cpp
include/gp-bnb/bnb.hpp
+1
-0
1 addition, 0 deletions
include/gp-bnb/bnb.hpp
include/gp-bnb/greedy_packing.hpp
+6
-2
6 additions, 2 deletions
include/gp-bnb/greedy_packing.hpp
with
37 additions
and
25 deletions
bnb/bnb.cpp
+
4
−
7
View file @
7fccbe61
...
@@ -25,7 +25,7 @@ void trail_state::pop() {
...
@@ -25,7 +25,7 @@ void trail_state::pop() {
// solver implementation.
// solver implementation.
// --------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------
solver
::
solver
(
graph
&
g
,
lb
lb_algorithm
)
:
graph_
(
g
),
partition_
(
partition
{
g
}),
lb_algorithm_
(
lb_algorithm
),
i_bfs_
(
incremental_bfs
(
g
)),
ek_
(
edmonds_karp
(
g
)),
pr_
(
push_relabel
(
g
))
{
solver
::
solver
(
graph
&
g
,
lb
lb_algorithm
)
:
graph_
(
g
),
partition_
(
partition
{
g
}),
lb_algorithm_
(
lb_algorithm
),
i_bfs_
(
incremental_bfs
(
g
)),
ek_
(
edmonds_karp
(
g
)),
pr_
(
push_relabel
(
g
))
,
gp_
(
greedy_packing
(
g
,
i_bfs_
,
true
))
{
}
}
unsigned
int
solver
::
get_lower
(){
unsigned
int
solver
::
get_lower
(){
...
@@ -58,12 +58,9 @@ unsigned int solver::get_lower(){
...
@@ -58,12 +58,9 @@ unsigned int solver::get_lower(){
return
pr_
.
get_max_flow
();
return
pr_
.
get_max_flow
();
}
}
else
if
(
lb_algorithm_
==
lb
::
gp
){
else
if
(
lb_algorithm_
==
lb
::
gp
){
bool
with_flow
=
true
;
gp_
.
reset
(
sources
,
sinks
);
auto
g_p
=
greedy_packing
(
graph_
,
sources
,
sinks
,
i_bfs_
,
with_flow
);
gp_
.
run
();
g_p
.
run
();
return
gp_
.
get_max_flow
();
if
(
with_flow
)
return
g_p
.
get_max_flow
();
return
g_p
.
get_max_flow
()
+
partition_
.
current_objective
();
}
}
return
partition_
.
current_objective
();
return
partition_
.
current_objective
();
}
}
...
...
This diff is collapsed.
Click to expand it.
bnb/greedy_packing.cpp
+
26
−
16
View file @
7fccbe61
...
@@ -4,27 +4,37 @@
...
@@ -4,27 +4,37 @@
bool
do_swap
=
true
;
bool
do_swap
=
true
;
greedy_packing
::
greedy_packing
(
graph
&
g
,
std
::
vector
<
node_id
>&
a
,
std
::
vector
<
node_id
>&
b
,
incremental_bfs
&
ibfs
,
bool
with_flow
)
greedy_packing
::
greedy_packing
(
graph
&
g
,
incremental_bfs
&
ibfs
,
bool
with_flow
)
:
graph_
(
g
),
a_
(
a
),
b_
(
b
),
i_bfs
(
ibfs
),
with_flow_
(
with_flow
){
:
graph_
(
g
),
i_bfs
(
ibfs
),
with_flow_
(
with_flow
){
if
(
do_swap
&&
a
.
size
()
>
b
.
size
()){
std
::
swap
(
a_
,
b_
);
}
visited
.
resize
(
graph_
.
num_nodes
()
+
1
,
false
);
max_a
=
(
graph_
.
num_nodes
()
+
1
)
/
2
;
max_a
=
(
graph_
.
num_nodes
()
+
1
)
/
2
;
};
};
void
greedy_packing
::
reset
(
std
::
vector
<
node_id
>&
a
,
std
::
vector
<
node_id
>&
b
)
{
a_
=
&
a
;
b_
=
&
b
;
x_
.
clear
();
flow_edges
.
clear
();
partitioning
.
clear
();
a_count
=
0
;
visited
.
assign
(
graph_
.
num_nodes
()
+
1
,
false
);
if
(
do_swap
&&
a
.
size
()
>
b
.
size
()){
std
::
swap
(
a_
,
b_
);
}
}
//breadth-first-search to determine neighbors of B
//breadth-first-search to determine neighbors of B
void
greedy_packing
::
bfs
(){
void
greedy_packing
::
bfs
(){
for
(
node_id
node
:
b_
){
for
(
unsigned
int
i
=
0
;
i
<
b_
->
size
();
++
i
)
{
node_id
node
=
b_
->
operator
[](
i
);
q
.
push
(
node
);
q
.
push
(
node
);
visited
[
node
]
=
true
;
visited
[
node
]
=
true
;
}
}
for
(
node_id
node
:
a_
)
{
for
(
unsigned
int
i
=
0
;
i
<
a_
->
size
();
++
i
)
{
visited
[
node
]
=
true
;
visited
[
a_
->
operator
[](
i
)
]
=
true
;
}
}
while
(
!
q
.
empty
()){
while
(
!
q
.
empty
()){
...
@@ -51,13 +61,13 @@ void greedy_packing::run(){
...
@@ -51,13 +61,13 @@ void greedy_packing::run(){
if
(
with_flow_
){
if
(
with_flow_
){
//get all flow edges and the flow
//get all flow edges and the flow
i_bfs
.
reset
(
a_
,
b_
);
i_bfs
.
reset
(
*
a_
,
*
b_
);
i_bfs
.
run
();
i_bfs
.
run
();
flow_
=
i_bfs
.
get_max_flow
();
flow_
=
i_bfs
.
get_max_flow
();
flow_edges
=
i_bfs
.
get_flow_edges
();
flow_edges
=
i_bfs
.
get_flow_edges
();
}
}
a_count
=
a_
.
size
();
a_count
=
a_
->
size
();
if
(
a_count
>=
max_a
)
if
(
a_count
>=
max_a
)
return
;
return
;
...
@@ -91,8 +101,8 @@ void greedy_packing::run(){
...
@@ -91,8 +101,8 @@ void greedy_packing::run(){
//danach lokale suche um balance zu verbessern ?
//danach lokale suche um balance zu verbessern ?
std
::
sort
(
partitioning
.
begin
(),
partitioning
.
end
(),
[](
std
::
vector
<
node_id
>
a_
,
std
::
vector
<
node_id
>
b_
)
{
std
::
sort
(
partitioning
.
begin
(),
partitioning
.
end
(),
[](
std
::
vector
<
node_id
>
x
,
std
::
vector
<
node_id
>
y
)
{
return
a_
.
size
()
>
b_
.
size
();
return
x
.
size
()
>
y
.
size
();
});
});
// behandle von B aus unnerreichbare Knoten
// behandle von B aus unnerreichbare Knoten
...
...
This diff is collapsed.
Click to expand it.
include/gp-bnb/bnb.hpp
+
1
−
0
View file @
7fccbe61
...
@@ -92,6 +92,7 @@ private:
...
@@ -92,6 +92,7 @@ private:
incremental_bfs
i_bfs_
;
incremental_bfs
i_bfs_
;
edmonds_karp
ek_
;
edmonds_karp
ek_
;
push_relabel
pr_
;
push_relabel
pr_
;
greedy_packing
gp_
;
// 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.
include/gp-bnb/greedy_packing.hpp
+
6
−
2
View file @
7fccbe61
...
@@ -10,7 +10,9 @@
...
@@ -10,7 +10,9 @@
class
greedy_packing
{
class
greedy_packing
{
public:
public:
greedy_packing
(
graph
&
g
,
std
::
vector
<
node_id
>&
a
,
std
::
vector
<
node_id
>&
b
,
incremental_bfs
&
ibfs
,
bool
with_flow
);
greedy_packing
(
graph
&
g
,
incremental_bfs
&
ibfs
,
bool
with_flow
);
void
reset
(
std
::
vector
<
node_id
>&
a
,
std
::
vector
<
node_id
>&
b
);
void
run
();
void
run
();
...
@@ -26,7 +28,9 @@ private:
...
@@ -26,7 +28,9 @@ private:
//partial partition into blocks a and b
//partial partition into blocks a and b
//x is block with the neighbors of B
//x is block with the neighbors of B
std
::
vector
<
node_id
>&
a_
,
b_
,
x_
;
std
::
vector
<
node_id
>*
a_
;
std
::
vector
<
node_id
>*
b_
;
std
::
vector
<
node_id
>
x_
;
incremental_bfs
&
i_bfs
;
incremental_bfs
&
i_bfs
;
...
...
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