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
06abf8e0
Commit
06abf8e0
authored
5 years ago
by
Florian Heinrichs
Browse files
Options
Downloads
Patches
Plain Diff
First try to include multiple lower bound algorithms
parent
e0bd0f6c
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bnb/bnb.cpp
+77
-7
77 additions, 7 deletions
bnb/bnb.cpp
include/gp-bnb/bnb.hpp
+4
-0
4 additions, 0 deletions
include/gp-bnb/bnb.hpp
with
81 additions
and
7 deletions
bnb/bnb.cpp
+
77
−
7
View file @
06abf8e0
#include
<cassert>
#include
<iostream>
#include
<time.h>
#include
<gp-bnb/bnb.hpp>
static
constexpr
bool
verbose
=
false
;
int
visited_nodes
=
0
;
bool
ibfs
;
bool
ek
;
bool
pr
;
bool
gp
;
namespace
gp_bnb
{
...
...
@@ -26,20 +32,65 @@ void trail_state::pop() {
solver
::
solver
(
graph
&
g
)
:
graph_
(
g
),
partition_
(
partition
{
g
})
{
}
unsigned
int
solver
::
get_lower
(){
unsigned
int
lower_bound
;
if
(
ek
){
std
::
vector
<
node_id
>
sources
,
sinks
;
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
);
}
auto
ek
=
edmonds_karp
(
graph_
,
sources
,
sinks
);
ek
.
run
();
lower_bound
=
ek
.
get_max_flow
();
}
else
if
(
ibfs
){
std
::
vector
<
node_id
>
sources
,
sinks
;
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
);
}
auto
i_bfs
=
incremental_bfs
(
graph_
,
sources
,
sinks
);
i_bfs
.
run
();
lower_bound
=
i_bfs
.
get_max_flow
();
}
else
if
(
pr
){
}
else
if
(
gp
){
}
else
{
lower_bound
=
partition_
.
current_objective
();
}
return
lower_bound
;
}
void
solver
::
solve
()
{
//anfangs lower bound?
best_objective_
=
graph_
.
num_nodes
();
clock_t
begin
=
clock
();
//ek = true;
//ibfs = true;
while
(
true
)
{
//falls current sol schlechter als bisher beste lösung:
//zähle schritte bis zur nächsten alternative und
if
(
partition_
.
current_objective
()
>=
best_objective_
)
{
if
(
get_lower
()
>=
best_objective_
)
{
int
i
=
trail_
.
length
()
-
1
;
while
(
true
)
{
if
(
i
<
0
)
if
(
i
<
0
){
std
::
cerr
<<
"visited nodes: "
<<
visited_nodes
<<
std
::
endl
;
return
;
}
// Only backtrack to assignments that have an alternative.
if
(
trail_
.
alternative_at
(
i
)
!=
subgraph
::
none
)
break
;
...
...
@@ -62,11 +113,29 @@ void solver::solve() {
best_solution_
[
node
]
=
partition_
.
assigned_subgraph_of
(
node
+
1
);
}
best_objective_
=
partition_
.
current_objective
();
std
::
cerr
<<
"Solution improved to k = "
<<
best_objective_
<<
std
::
endl
;
clock_t
end
=
clock
();
double
time
=
(
double
)(
end
-
begin
)
/
CLOCKS_PER_SEC
;
std
::
cerr
<<
"Solution improved to k = "
<<
best_objective_
<<
" after : "
<<
time
<<
" seconds and: "
<<
visited_nodes
<<
" besuchten knoten"
<<
std
::
endl
;
}
else
{
//sonst expandiere suchbaum weiter
int
node
=
trail_
.
length
()
+
1
;
expand
(
node
,
next_possible_subgraph
(
node
,
subgraph
::
sg_a
));
int
next_node
;
//sort after degree
/*int node_deg = 0;
for(node_id node = 1; node <= graph_.num_nodes(); node++){
if(partition_.assigned_subgraph_of(node) == subgraph::none){
if(graph_.get_adjacency(node).size() > node_deg){
node_deg = graph_.get_adjacency(node).size();
next_node = node;
}
}
}
*/
next_node
=
trail_
.
length
()
+
1
;
expand
(
next_node
,
next_possible_subgraph
(
next_node
,
subgraph
::
sg_a
));
}
}
}
...
...
@@ -76,6 +145,7 @@ void solver::expand(node_id node, subgraph sg) {
// Search for an alternative BEFORE assigning the node.
// Because the node is not assigned, this calculation is easy.
subgraph
alt
;
visited_nodes
++
;
if
(
partition_
.
num_nodes_of
(
subgraph
::
sg_a
)
==
0
&&
partition_
.
num_nodes_of
(
subgraph
::
sg_b
)){
alt
=
subgraph
::
none
;
}
else
{
...
...
@@ -95,7 +165,7 @@ void solver::backtrack() {
auto
node
=
trail_
.
node_at
(
trail_
.
length
()
-
1
);
if
(
verbose
)
std
::
cout
<<
"Unassign node "
<<
node
<<
std
::
endl
;
std
::
cout
<<
"Unassign node "
<<
node
<<
std
::
endl
;
trail_
.
pop
();
partition_
.
unassign_node
(
node
);
...
...
This diff is collapsed.
Click to expand it.
include/gp-bnb/bnb.hpp
+
4
−
0
View file @
06abf8e0
...
...
@@ -6,6 +6,8 @@
#include
<gp-bnb/graph.hpp>
#include
<gp-bnb/partition.hpp>
#include
<gp-bnb/edmonds_karp.hpp>
#include
<gp-bnb/incremental_bfs.hpp>
namespace
gp_bnb
{
...
...
@@ -62,6 +64,8 @@ struct solver {
return
best_solution_
;
}
unsigned
int
get_lower
();
// Expand a search tree node, i.e., assigns an node to a partition and update all data structures.
void
expand
(
node_id
node
,
subgraph
sg
);
...
...
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