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
20e79178
Commit
20e79178
authored
5 years ago
by
Florian Heinrichs
Browse files
Options
Downloads
Patches
Plain Diff
fixed correctness - to-do: packing-flow bound
parent
2da68e72
Branches
Branches containing commit
1 merge request
!8
Resolve "Greedy Packing"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bnb/greedy_packing.cpp
+37
-35
37 additions, 35 deletions
bnb/greedy_packing.cpp
include/gp-bnb/greedy_packing.hpp
+2
-5
2 additions, 5 deletions
include/gp-bnb/greedy_packing.hpp
with
39 additions
and
40 deletions
bnb/greedy_packing.cpp
+
37
−
35
View file @
20e79178
...
...
@@ -2,27 +2,30 @@
#include
<gp-bnb/greedy_packing.hpp>
#include
<iostream>
bool
do_swap
=
true
;
greedy_packing
::
greedy_packing
(
const
graph
&
g
,
std
::
vector
<
node_id
>
a
,
std
::
vector
<
node_id
>
b
)
:
graph_
(
g
),
a
(
a
),
b
(
b
)
{
max_a
=
graph_
.
num_nodes
()
/
2
;
greedy_packing
::
greedy_packing
(
const
graph
&
g
,
std
::
vector
<
node_id
>
A
,
std
::
vector
<
node_id
>
B
)
:
graph_
(
g
),
a
(
A
),
b
(
B
){
if
(
do_swap
&&
A
.
size
()
>
B
.
size
()){
std
::
swap
(
a
,
b
);
}
max_a
=
(
graph_
.
num_nodes
()
+
1
)
/
2
;
};
//breadth-first-search to determine neighbors of B
void
greedy_packing
::
bfs
(){
x
.
resize
(
graph_
.
num_nodes
()
-
(
a
.
size
()
+
b
.
size
()));
visited
.
resize
(
graph_
.
num_nodes
()
+
1
,
false
);
for
(
node_id
node
:
b
){
q
.
push
(
node
);
visited
[
node
]
=
true
;
}
for
(
node_id
node
:
a
){
visited
[
node
]
=
true
;
}
unsigned
int
last_node
=
b
.
size
();
unsigned
int
count
=
0
;
while
(
!
q
.
empty
()){
node_id
node
=
q
.
front
();
...
...
@@ -31,47 +34,37 @@ void greedy_packing::bfs(){
std
::
vector
<
node_id
>
neighbors
=
graph_
.
get_adjacency
(
node
);
for
(
node_id
v
:
neighbors
){
if
(
v
==
last_node
)
end_of_neighbors
=
count
;
if
(
visited
[
v
]
==
false
){
q
.
push
(
v
);
x
[
count
++
]
=
v
;
x
.
push_back
(
v
);
}
visited
[
v
]
=
true
;
}
}
return
;
};
void
greedy_packing
::
run
(){
flow_
=
0
;
//x konstruieren: enthält alle unpartitionierten knoten
//zuerst die nachbarn von b bis zum index end_of_neighbors
//ab end_of_neighbors +1 kommen alle anderen unpartitionierten knoten
//x per bfs konstruieren
bfs
();
/*
std::cerr << x.size() << std::endl;
for(int i = 0; i < x.size(); i++){
std::cerr << x[i] << " ";
}
std::cerr << " end_of_neighbors: " << end_of_neighbors << std::endl;
*/
a_count
=
a
.
size
();
if
(
a_count
>=
max_a
)
return
;
//P konstruieren
partitioning
.
resize
(
x
.
size
());
//dafür für jeden nachbarn von B einen eigenen Block
//dann jeweils kleinsten block um einen nachbarn erweitern
//danach lokale suche um balance zu verbessern
//knoten aus x die in keinem block von P sind sind unerreichbar von B
partitioning
.
resize
(
end_of_neighbors
+
1
);
for
(
unsigned
int
i
=
0
;
i
<=
end_of_neighbors
;
i
++
){
for
(
unsigned
int
i
=
0
;
i
<
x
.
size
();
i
++
){
partitioning
[
i
].
push_back
(
x
[
i
]);
}
// baue mit B zusammenhängende Partitionen (noch ohne lokale Suche) und sortiere nach Größe absteigend
//dann jeweils kleinsten block um einen nachbarn erweitern
//baue mit B zusammenhängende Partitionen (noch ohne lokale Suche) und sortiere nach Größe absteigend
bool
found_new_element
=
true
;
while
(
found_new_element
)
{
found_new_element
=
false
;
...
...
@@ -86,6 +79,10 @@ void greedy_packing::run(){
}
}
}
//danach lokale suche um balance zu verbessern ?
std
::
sort
(
partitioning
.
begin
(),
partitioning
.
end
(),
[](
std
::
vector
<
node_id
>
a
,
std
::
vector
<
node_id
>
b
)
{
return
a
.
size
()
>
b
.
size
();
});
...
...
@@ -94,26 +91,31 @@ void greedy_packing::run(){
//füge von B unerreichbar knoten zu a hinzu (sind die knoten die
//bei konstruktion von P "übrig bleiben")
//danach füge Knoten aus größtem Block hinzu bis A* < n/2
// behandle von B aus unnerreichbare Knoten
for
(
node_id
i
=
1
;
i
<=
graph_
.
num_nodes
();
++
i
)
{
for
(
node_id
i
=
1
;
i
<=
graph_
.
num_nodes
();
i
++
)
{
if
(
!
visited
[
i
])
{
a
.
push_back
(
i
);
a_count
++
;
if
(
a_count
==
max_a
)
return
;
if
(
a_count
>=
max_a
){
return
;
}
}
}
// packe greedy (erst hier wird flow erhöht)
for
(
std
::
vector
<
node_id
>
partition
:
partitioning
)
{
flow_
++
;
for
(
node_id
node
:
partition
)
{
a
.
push_back
(
node
);
a_count
++
;
if
(
a_count
==
max_a
)
return
;
if
(
a_count
>=
max_a
){
return
;
}
}
}
return
;
};
...
...
This diff is collapsed.
Click to expand it.
include/gp-bnb/greedy_packing.hpp
+
2
−
5
View file @
20e79178
...
...
@@ -23,13 +23,10 @@ private:
const
graph
&
graph_
;
//end of neighbors determines index of x where the nodes
//aren't neighbors of B anymore
unsigned
int
a_count
,
end_of_neighbors
;
unsigned
int
a_count
;
//partial partition into blocks a and b
//x is block which starts with the neighbors of B
//following the other unpartitioned nodes
//x is block with the neighbors of B
std
::
vector
<
node_id
>
a
,
b
,
x
;
std
::
vector
<
std
::
vector
<
node_id
>>
partitioning
;
...
...
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