Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Bachelorarbeit
Discrete Optimization Library
Commits
340c2803
Commit
340c2803
authored
Oct 03, 2020
by
Jonas Seidel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bfs increase versatility
parent
f0387bae
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
12 deletions
+30
-12
Graphtheory/Basic_Graph.h
Graphtheory/Basic_Graph.h
+2
-2
Graphtheory/Basic_Graph_advanced.ipp
Graphtheory/Basic_Graph_advanced.ipp
+24
-9
Linear_Programming/lp_generator.ipp
Linear_Programming/lp_generator.ipp
+2
-1
maintenance_problem_test.cpp
maintenance_problem_test.cpp
+2
-0
No files found.
Graphtheory/Basic_Graph.h
View file @
340c2803
...
...
@@ -66,7 +66,7 @@ public:
// _advanced.cpp:
Graph
(
std
::
istream
&
is
);
void
conditional_bfs_all_components
(
std
::
function
<
void
(
Node
<
N
,
E
>*
from
,
Edge
<
N
,
E
>*
via
,
bool
used_in_traversal
)
>
edge_exec
,
std
::
function
<
void
(
Node
<
N
,
E
>*
)
>
node_exec
,
std
::
function
<
bool
(
Node
<
N
,
E
>*
from
,
Edge
<
N
,
E
>*
via
)
>
guide
=
[](
Node
<
N
,
E
>*
n
,
Edge
<
N
,
E
>*
e
)
->
bool
{
return
e
->
from
()
==
n
;});
void
conditional_bfs_all_components
(
std
::
function
<
void
(
Node
<
N
,
E
>*
from
,
Edge
<
N
,
E
>*
via
,
bool
used_in_traversal
)
>
edge_exec
,
std
::
function
<
bool
(
Edge
<
N
,
E
>*
via
,
Node
<
N
,
E
>*
node
)
>
node_exec
,
std
::
deque
<
Node
<
N
,
E
>*>
starting_nodes
=
{},
bool
all_paths
=
false
,
std
::
function
<
bool
(
Node
<
N
,
E
>*
from
,
Edge
<
N
,
E
>*
via
)
>
guide
=
[](
Node
<
N
,
E
>*
n
,
Edge
<
N
,
E
>*
e
)
->
bool
{
return
e
->
from
()
==
n
;});
// _special_members_and_operators:
void
operator
=
(
Graph
<
N
,
E
>&
graph
);
...
...
@@ -77,7 +77,7 @@ template <typename N, typename E>
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
Graph
<
N
,
E
>&
g
);
template
<
typename
N
,
typename
E
>
std
::
istream
&
operator
>>
(
std
::
istream
&
is
,
Graph
<
N
,
E
>&
g
){
g
=
Graph
(
is
);
return
is
;}
std
::
istream
&
operator
>>
(
std
::
istream
&
is
,
Graph
<
N
,
E
>&
g
){
g
=
Graph
<
N
,
E
>
(
is
);
return
is
;}
#include "Basic_Graph.ipp"
#include "Basic_Graph_advanced.ipp"
...
...
Graphtheory/Basic_Graph_advanced.ipp
View file @
340c2803
...
...
@@ -30,7 +30,7 @@ Graph<N,E>::Graph(std::istream& is){
is >> curr;
while(curr == "Edge"){
is.seekg(pos);
Edge<N,E>* tmp = new Edge(is, name_lookup);
Edge<N,E>* tmp = new Edge
<N,E>
(is, name_lookup);
this->_edges.insert(tmp);
pos = is.tellg();
is >> curr;
...
...
@@ -38,29 +38,44 @@ Graph<N,E>::Graph(std::istream& is){
}
template <typename N, typename E>
void Graph<N,E>::conditional_bfs_all_components(std::function<void(Node<N,E>* from, Edge<N,E>* via, bool used_in_traversal)> edge_exec, std::function<void(Node<N,E>*)> node_exec,std::function<bool(Node<N,E>* from, Edge<N,E>* via)> guide){
void Graph<N,E>::conditional_bfs_all_components(
std::function<void(Node<N,E>* from, Edge<N,E>* via, bool used_in_traversal)> edge_exec,
std::function<bool(Edge<N,E>* via, Node<N,E>* node)> node_exec,
std::deque<Node<N,E>*> starting_nodes,
bool all_paths,
std::function<bool(Node<N,E>* from, Edge<N,E>* via)> guide){
/*
executes edge_exec and node_exec for every edge or node in visiting order. Also executes for unused edges that test positive w.r.t guide
!! possibly executes twice if guide allows !!
node_exec will be called with nullptr for via for start node
node_exec might be called with nullptr for via if the graph is not strongly connected
node_exec need to return true in order to continue traversal over its incident edges
*/
std::set<Node<N,E>*> uncharted = this->nodes();
std::
que
ue<Node<N,E>*> active;
std::
deq
ue<Node<N,E>*> active
= starting_nodes
;
while(!uncharted.empty()){
active.push(*uncharted.begin());
uncharted.erase(*uncharted.begin());
if(active.empty()){
active.push_back(*uncharted.begin());
uncharted.erase(*uncharted.begin());
}
for(Node<N,E>* manually_inserted_node : active){
node_exec(nullptr, manually_inserted_node);
}
while(!active.empty()){
Node<N,E>* n = active.front(); active.pop();
node_exec(n);
Node<N,E>* n = active.front(); active.pop_front();
for(Edge<N,E>* e : n->incident()){
bool used_in_traversal = false;
if(guide(n, e)){
if(uncharted.find(e->to(n)) != uncharted.end()){
if(uncharted.find(e->to(n)) != uncharted.end()
|| all_paths
){
used_in_traversal = true;
active.push(e->to(n));
if(node_exec(e, e->to(n))){
active.push_back(e->to(n));
}
uncharted.erase(e->to(n));
}
...
...
Linear_Programming/lp_generator.ipp
View file @
340c2803
...
...
@@ -37,12 +37,13 @@ std::pair<std::map<std::pair<Node<N,E>*,N>, std::pair<Variable*, size_t>>, std::
edge_lookup.insert({{via, edge_prop.first}, p.add_variable(Variable(name.str(), std::get<0>(edge_prop.second), std::get<1>(edge_prop.second), std::get<2>(edge_prop.second)))});
}
};
std::function<
void(
Node<N,E>*)> node_function = [&p, &node_lookup, &node_var_data, start_index, name_appendix](Node<N,E>* n) ->
void
{
std::function<
bool(Edge<N,E>*,
Node<N,E>*)> node_function = [&p, &node_lookup, &node_var_data, start_index, name_appendix](
Edge<N,E>* via,
Node<N,E>* n) ->
bool
{
for(std::pair<N, std::tuple<integrality, std::pair<bool, double>, std::pair<bool, double>>> node_prop : node_var_data){
std::stringstream name;
name << "node_" << n->description() << "_" << static_cast<char>(node_prop.first) << "_" << name_appendix;
node_lookup.insert({{n,node_prop.first}, p.add_variable(Variable(name.str(), std::get<0>(node_prop.second), std::get<1>(node_prop.second), std::get<2>(node_prop.second)))});
}
return true;
};
g.conditional_bfs_all_components(
...
...
maintenance_problem_test.cpp
View file @
340c2803
...
...
@@ -20,12 +20,14 @@ int main(){
);
while
(
true
){
system
(
"killall graph_display"
);
Maintenance_Problem
mp
;
mpg
>>
mp
;
std
::
ofstream
ofs_graph
(
"./.data/Maintenance_Problem/mp.netw"
);
ofs_graph
<<
mp
.
network
()
<<
std
::
endl
;
ofs_graph
.
close
();
system
(
"cd ../display/graph_display/ && (./graph_display --file ../../discrete_optimization_library/.data/Maintenance_Problem/mp.netw &) && cd ../../discrete_optimization_library"
);
std
::
ofstream
ofs_program
(
"./.data/Maintenance_Problem/mp.lp"
);
ofs_program
<<
mp
<<
std
::
endl
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment