Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
Discrete Optimization Library
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
0
Merge Requests
0
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Test Cases
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Metrics
Incidents
Environments
Packages & Registries
Packages & Registries
Package Registry
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Bachelorarbeit
Discrete Optimization Library
Commits
f0387bae
Commit
f0387bae
authored
Oct 02, 2020
by
Jonas Seidel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
scanning graphs from file
parent
f460d26b
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
198 additions
and
32 deletions
+198
-32
.gitignore
.gitignore
+1
-0
Graphtheory/Basic_Graph.h
Graphtheory/Basic_Graph.h
+4
-0
Graphtheory/Basic_Graph.ipp
Graphtheory/Basic_Graph.ipp
+24
-12
Graphtheory/Basic_Graph_advanced.ipp
Graphtheory/Basic_Graph_advanced.ipp
+38
-0
Graphtheory/Edge.h
Graphtheory/Edge.h
+3
-0
Graphtheory/Edge.ipp
Graphtheory/Edge.ipp
+48
-6
Graphtheory/Node.h
Graphtheory/Node.h
+3
-0
Graphtheory/Node.ipp
Graphtheory/Node.ipp
+57
-11
graph_test.cpp
graph_test.cpp
+13
-0
maintenance_problem_test.cpp
maintenance_problem_test.cpp
+7
-3
No files found.
.gitignore
View file @
f0387bae
...
...
@@ -7,3 +7,4 @@ linear_program_test
maintenance_problem_test
.test
*.lp
*.netw
Graphtheory/Basic_Graph.h
View file @
f0387bae
...
...
@@ -65,6 +65,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
;});
// _special_members_and_operators:
...
...
@@ -75,6 +76,9 @@ public:
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
;}
#include "Basic_Graph.ipp"
#include "Basic_Graph_advanced.ipp"
#include "Basic_Graph_special_members_and_operators.ipp"
...
...
Graphtheory/Basic_Graph.ipp
View file @
f0387bae
...
...
@@ -75,18 +75,30 @@ void Graph<N, E>::reset_attribute_values(std::set<E> edge_attr, std::set<N> node
template <typename N, typename E>
std::ostream& operator<<(std::ostream& os, Graph<N,E>& g){
os << "\033[0;31m";
os << "Graph{ Nodes: { \n";
for(Node<N, E>* n : g.nodes()){
os << *n << "\n";
}
os << "\033[0;31m";
os << "} Edges: {" << "\n";
for(Edge<N, E>* e : g.edges()){
os << *e << "\n";
if(&os == &std::cout){
os << "\033[0;31m";
os << "Graph { Nodes { \n";
for(Node<N, E>* n : g.nodes()){
os << *n << "\n";
}
os << "\033[0;31m";
os << "} Edges {" << "\n";
for(Edge<N, E>* e : g.edges()){
os << *e << "\n";
}
os << "\033[0;31m";
os << "} }";
os << "\033[0m";
}else{
os << "Graph { Nodes { \n";
for(Node<N, E>* n : g.nodes()){
os << *n << "\n";
}
os << "} Edges {" << "\n";
for(Edge<N, E>* e : g.edges()){
os << *e << "\n";
}
os << "} }";
}
os << "\033[0;31m";
os << "} }";
os << "\033[0m";
return os;
}
Graphtheory/Basic_Graph_advanced.ipp
View file @
f0387bae
template <typename N, typename E>
Graph<N,E>::Graph(std::istream& is){
std::map<std::string, Node<N,E>* > name_lookup;
std::string curr;
is >> curr;
assert(curr == "Graph");
is >> curr;
assert(curr == "{");
is >> curr;
assert(curr == "Nodes");
is >> curr;
assert(curr == "{");
auto pos = is.tellg();
is >> curr;
while(curr == "Node"){
is.seekg(pos);
Node<N,E>* tmp = new Node<N,E>(is);
name_lookup.insert({tmp->description(), tmp});
this->_nodes.insert(tmp);
pos = is.tellg();
is >> curr;
}
assert(curr == "}");
is >> curr;
assert(curr == "Edges");
is >> curr;
assert(curr == "{");
pos = is.tellg();
is >> curr;
while(curr == "Edge"){
is.seekg(pos);
Edge<N,E>* tmp = new Edge(is, name_lookup);
this->_edges.insert(tmp);
pos = is.tellg();
is >> curr;
}
}
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){
/*
...
...
Graphtheory/Edge.h
View file @
f0387bae
...
...
@@ -8,6 +8,7 @@
#include <stdexcept>
#include <string>
#include <sstream>
#include <cassert>
#include "Attribute.h"
...
...
@@ -42,6 +43,8 @@ public:
to
->
add_incident
(
this
);
};
Edge
(
std
::
istream
&
is
,
std
::
map
<
std
::
string
,
Node
<
N
,
E
>*
>&
name_lookup
);
std
::
string
description
(){
if
(
this
->
_description
==
""
){
std
::
stringstream
name
;
...
...
Graphtheory/Edge.ipp
View file @
f0387bae
template <typename N, typename E>
Edge<N,E>::Edge(std::istream& is, std::map<std::string, Node<N,E>* >& name_lookup){
std::string curr;
is >> curr;
assert(curr == "Edge");
is >> this->_description;
is >> curr;
assert(curr == "(");
is >> curr;
while(curr != ")"){
assert(curr.length() == 1);
E attribute = static_cast<E>(curr.c_str()[0]);
is >> curr;
assert(curr == "=");
is >> curr;
this->_attributes.insert({attribute, {fix, std::stod(curr), Continuous}});
is >> curr;
}
is >> curr;
assert(curr == "{");
is >> curr;
this->_from = name_lookup.find(curr)->second;
this->_from->add_incident(this);
is >> curr;
this->_to = name_lookup.find(curr)->second;
this->_to->add_incident(this);
is >> curr;
assert(curr == "}");
}
template <typename N, typename E>
std::ostream& operator<<(std::ostream& os, Edge<N, E>& e){
os << "\033[0;32m";
os << "Edge " << e.description() << " (";
for(std::pair<E, Attribute> pair : e.attributes()){
os << pair.second.value() << ", ";
if(&os == &std::cout){
os << "\033[0;32m";
os << "Edge " << e.description() << " ( ";
for(std::pair<E, Attribute> pair : e.attributes()){
os << static_cast<char>(pair.first) << " = " << pair.second.value() << ", ";
}
os << ") {" << e.from()->description() << ", " << e.to()->description() << "}";
os << "\033[0m";
}else{
os << "Edge " << e.description() << " ( ";
for(std::pair<E, Attribute> pair : e.attributes()){
os << static_cast<char>(pair.first) << " = " << pair.second.value() << " ";
}
os << " ) { " << e.from()->description() << " " << e.to()->description() << " }";
}
os << ") {" << e.from()->description() << ", " << e.to()->description() << "}";
os << "\033[0m";
return os;
}
Graphtheory/Node.h
View file @
f0387bae
...
...
@@ -25,6 +25,7 @@ public:
}
Node
(
Node
&
node
)
:
_description
(
node
.
description
()),
_incident
({}),
_attributes
(
node
.
attributes
())
{}
Node
(
Node
&&
node
)
:
_description
(
std
::
move
(
node
.
_description
)),
_incident
(
std
::
move
(
node
.
_incident
)),
_attributes
(
std
::
move
(
node
.
_attributes
))
{}
Node
(
std
::
istream
&
is
);
std
::
string
description
(){
if
(
this
->
_description
==
""
){
...
...
@@ -62,6 +63,8 @@ public:
template
<
typename
N
,
typename
E
>
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
Node
<
N
,
E
>&
n
);
template
<
typename
N
,
typename
E
>
std
::
istream
&
operator
>>
(
std
::
istream
&
is
,
Node
<
N
,
E
>&
n
)
{
n
=
Node
<
N
,
E
>
(
is
);
return
is
;}
#include "Node.ipp"
...
...
Graphtheory/Node.ipp
View file @
f0387bae
template <typename N, typename E>
std::ostream& operator<<(std::ostream& os, Node<N, E>& n){
os << "\033[0;36m";
os << "Node " << n.description() << " { (";
for(std::pair<N, Attribute> pair : n.attributes()){
os << pair.second.value() << ", ";
Node<N,E>::Node(std::istream& is){
std::string curr;
is >> curr;
assert(curr == "Node");
is >> this->_description;
is >> curr;
assert(curr == "(");
is >> curr;
while(curr != ")"){
assert(curr.length() == 1);
N attribute = static_cast<N>(curr.c_str()[0]);
is >> curr;
assert(curr == "=");
is >> curr;
this->_attributes.insert({attribute, {fix, std::stod(curr), Continuous}});
is >> curr;
}
is >> curr;
assert(curr == "{");
size_t counter = 1;
while(counter != 0){
is >> curr;
if(curr == "{"){
++counter;
}else if(curr == "}"){
--counter;
}
}
os << ")\n \tEdges : {\n";
for(Edge<N, E>* e : n.incident()){
os << *e << "\n";
}
template <typename N, typename E>
std::ostream& operator<<(std::ostream& os, Node<N, E>& n){
if(&os == &std::cout){
os << "\033[0;36m";
os << "Node " << n.description() << " ( ";
for(std::pair<N, Attribute> pair : n.attributes()){
os << static_cast<char>(pair.first) << " = " << pair.second.value() << ", ";
}
os << ") {\n \tEdges {\n";
for(Edge<N, E>* e : n.incident()){
os << *e << "\n";
}
os << "\033[0;36m";
os << "} }";
os << "\033[0m";
}else{
os << "Node " << n.description() << " ( ";
for(std::pair<N, Attribute> pair : n.attributes()){
os << static_cast<char>(pair.first) << " = " << pair.second.value() << ", ";
}
os << " ) {\n \tEdges {\n";
for(Edge<N, E>* e : n.incident()){
os << *e << "\n";
}
os << "} }";
}
os << "\033[0;36m";
os << "} }";
os << "\033[0m";
return os;
}
graph_test.cpp
View file @
f0387bae
#include "Specialization/Graph_Specialization/Circulation_Network.h"
#include "Graphtheory/Generators/random_graph_generator.h"
#include <fstream>
#include <sstream>
int
main
(){
CirculationNetwork
g
({{
Flow
,
Attribute
(
max
,
0
)},
{
Demand
,
Attribute
(
fix
,
0
)},
{
Capacity
,
Attribute
(
fix
,
1
)},{
Cost
,
Attribute
(
fix
,
0
)}});
...
...
@@ -23,5 +25,16 @@ int main(){
std
::
cout
<<
"MaxFlow: "
<<
ford_fulkerson
(
g
,
m
.
first
,
m
.
second
,
Flow
,
Demand
,
Capacity
)
<<
std
::
endl
;
std
::
cout
<<
g
<<
std
::
endl
;
std
::
stringstream
path
;
path
<<
"./.data/.cache/"
<<
&
g
<<
".netw"
;
std
::
ofstream
ofs_graph
(
path
.
str
());
ofs_graph
<<
g
<<
std
::
endl
;
ofs_graph
.
close
();
std
::
ifstream
ifs_graph
(
path
.
str
());
CirculationNetwork
g2
(
ifs_graph
);
std
::
cout
<<
g2
<<
std
::
endl
;
return
0
;
}
maintenance_problem_test.cpp
View file @
f0387bae
...
...
@@ -23,10 +23,14 @@ int main(){
Maintenance_Problem
mp
;
mpg
>>
mp
;
std
::
ofstream
ofs
(
"./.data/Maintenance_Problem/mp.lp"
);
ofs
<<
mp
<<
std
::
endl
;
std
::
ofstream
ofs_graph
(
"./.data/Maintenance_Problem/mp.netw"
);
ofs_graph
<<
mp
.
network
()
<<
std
::
endl
;
ofs_graph
.
close
();
std
::
ofstream
ofs_program
(
"./.data/Maintenance_Problem/mp.lp"
);
ofs_program
<<
mp
<<
std
::
endl
;
std
::
cout
<<
mp
<<
std
::
endl
;
ofs
.
close
();
ofs
_program
.
close
();
system
(
"polymake --script .data/Maintenance_Problem/pm_script_lp2facets"
);
...
...
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