Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ba
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
markn92
ba
Commits
973f0e23
Commit
973f0e23
authored
5 years ago
by
markn92
Browse files
Options
Downloads
Patches
Plain Diff
Default layout with edges and marked stations
parent
082d8eb0
No related branches found
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
graph.tex
+6
-16
6 additions, 16 deletions
graph.tex
tests/config.py
+34
-0
34 additions, 0 deletions
tests/config.py
tests/conftest.py
+3
-53
3 additions, 53 deletions
tests/conftest.py
tests/draw.py
+52
-0
52 additions, 0 deletions
tests/draw.py
tests/test_graph.py
+6
-12
6 additions, 12 deletions
tests/test_graph.py
with
101 additions
and
81 deletions
graph.tex
+
6
−
16
View file @
973f0e23
\documentclass
{
standalone
}
\usepackage
{
tikz-network
}
\begin{document}
\begin{tikzpicture}
\clip
(0,0) rectangle (6,6);
\Vertex
[x=0.350,y=0.691]
{
0
}
\Vertex
[x=1.486,y=1.221]
{
1
}
\Vertex
[x=1.561,y=4.476]
{
3
}
\Vertex
[x=5.650,y=4.325]
{
2
}
\Vertex
[x=5.499,y=5.309]
{
4
}
\Edge
[label=0.33]
(0)(1)
\Edge
[label=1.05]
(0)(3)
\Edge
[label=0.53]
(1)(2)
\Edge
[label=0.33]
(1)(3)
\Edge
[label=1.08]
(3)(2)
\Edge
[label=1.06]
(3)(4)
\Edge
[label=0.26]
(2)(4)
\Vertex
[x=0.550,y=1.775,color={white},size={1.0},label={s,1},style={circle,style={draw,double}}]
{
0
}
\Vertex
[x=5.450,y=1.775,color={white},size={1.0},label={a,2},style={circle,style={draw,double}}]
{
1
}
\Vertex
[x=3.000,y=4.225,color={white},size={1.0},label={t},style={circle}]
{
2
}
\Edge
[label={(1, 1)}]
(0)(1)
\Edge
[label={(1, 4)}]
(0)(2)
\Edge
[label={(1, 1)}]
(1)(2)
\end{tikzpicture}
\end{document}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
tests/config.py
0 → 100644
+
34
−
0
View file @
973f0e23
from
collections
import
namedtuple
import
networkx
as
nx
Street
=
namedtuple
(
'
Street
'
,
[
'
u
'
,
'
v
'
,
'
distance
'
,
'
consumption
'
])
Node
=
namedtuple
(
'
Node
'
,
[
'
label
'
,
'
charging_coeff
'
],
defaults
=
(
None
,
None
))
edge_case
=
{
'
b_0
'
:
0
,
'
b_t
'
:
0
,
'
U
'
:
4
,
'
nodes
'
:
[
Node
(
'
s
'
,
charging_coeff
=
1
),
Node
(
'
a
'
,
charging_coeff
=
2
),
Node
(
'
t
'
),
],
'
edges
'
:
[
Street
(
0
,
1
,
distance
=
1
,
consumption
=
1
),
Street
(
0
,
2
,
distance
=
1
,
consumption
=
4
),
Street
(
1
,
2
,
distance
=
1
,
consumption
=
1
),
]
}
def
get_graph
(
config
):
G
=
nx
.
Graph
()
for
node_id
,
node
in
enumerate
(
config
[
'
nodes
'
]):
G
.
add_node
(
node_id
,
label
=
node
.
label
,
c
=
node
.
charging_coeff
)
for
edge
in
config
[
'
edges
'
]:
G
.
add_edge
(
edge
.
u
,
edge
.
v
,
weight
=
edge
.
distance
,
c
=
edge
.
consumption
)
return
G
This diff is collapsed.
Click to expand it.
tests/conftest.py
+
3
−
53
View file @
973f0e23
from
collections
import
namedtuple
import
pytest
import
networkx
as
nx
Street
=
namedtuple
(
'
Street
'
,
[
'
u
'
,
'
v
'
,
'
street_type
'
])
Edge
=
namedtuple
(
'
Edge
'
,
[
'
x
'
,
'
y
'
,
'
charging_coeff
'
],
defaults
=
(
None
,))
config
=
{
'
speed
'
:
{
'
default
'
:
50
,
# km/h
'
highway
'
:
130
# km/h
},
'
consumption
'
:
{
'
default
'
:
125
# Wh/km
},
'
nodes
'
:
[
Edge
(
14
,
16
,
10
),
Edge
(
29
,
23
),
Edge
(
84
,
64
),
Edge
(
30
,
66
),
Edge
(
82
,
77
)
],
'
edges
'
:
[
Street
(
0
,
1
,
'
default
'
),
Street
(
0
,
3
,
'
default
'
),
Street
(
1
,
2
,
'
highway
'
),
Street
(
1
,
3
,
'
highway
'
),
Street
(
2
,
3
,
'
default
'
),
Street
(
2
,
4
,
'
default
'
),
Street
(
3
,
4
,
'
default
'
)
]
}
from
.config
import
edge_case
,
get_graph
@pytest.fixture
def
G
():
G
=
ini
t_graph
()
def
G
_Edge_Case
():
G
=
ge
t_graph
(
edge_case
)
yield
G
del
G
def
init_graph
():
G
=
nx
.
Graph
()
for
edge
in
config
[
'
edges
'
]:
u_x
,
u_y
,
u_ch
=
config
[
'
nodes
'
][
edge
.
u
]
v_x
,
v_y
,
v_ch
=
config
[
'
nodes
'
][
edge
.
v
]
# Calculate euclidean distance
s
=
((
v_y
-
u_y
)
**
2
+
(
v_x
-
u_x
)
**
2
)
**
(
1
/
2
)
# in km
# Calc travel time via t = s/v
t
=
s
/
config
[
'
speed
'
][
edge
.
street_type
]
# in h
# Calc consumption via c = s * consumption_per_km
c
=
s
*
config
[
'
consumption
'
][
'
default
'
]
G
.
add_edge
(
edge
.
u
,
edge
.
v
,
weight
=
t
,
c
=
c
,
d
=
s
)
return
G
This diff is collapsed.
Click to expand it.
tests/draw.py
0 → 100644
+
52
−
0
View file @
973f0e23
import
networkx
as
nx
import
network2tikz
as
tikz
def
draw_graph
(
G
:
nx
.
Graph
,
filename
=
None
):
"""
Draw graph marking stations as double circles.
"""
layout
=
nx
.
planar_layout
(
G
)
tikz
.
plot
(
G
,
filename
=
filename
,
layout
=
layout
,
standalone
=
False
,
**
_get_edge_styles
(
G
),
**
_get_node_styles
(
G
)
)
def
_get_edge_styles
(
G
):
styles
=
{
'
edges_label
'
:
{(
u
,
v
):
'
({}, {})
'
.
format
(
G
[
u
][
v
][
'
weight
'
],
G
[
u
][
v
][
'
c
'
])
for
u
,
v
in
G
.
edges
}
}
return
styles
def
_get_node_styles
(
G
):
styles
=
{
'
vertex_color
'
:
[
'
white
'
for
n
in
G
.
nodes
],
'
vertex_size
'
:
1.
}
nodes_label
=
{}
nodes_style
=
{}
for
n
in
G
:
style
=
'
circle
'
label
=
G
.
nodes
[
n
].
get
(
'
label
'
,
str
(
n
))
c
=
G
.
nodes
[
n
].
get
(
'
c
'
,
None
)
if
c
is
not
None
:
style
+=
'
,style={draw,double}
'
label
+=
'
,{}
'
.
format
(
c
)
nodes_label
[
n
]
=
label
nodes_style
[
n
]
=
style
styles
[
'
nodes_label
'
]
=
nodes_label
styles
[
'
nodes_style
'
]
=
nodes_style
return
styles
This diff is collapsed.
Click to expand it.
tests/test_graph.py
+
6
−
12
View file @
973f0e23
import
networkx
as
nx
import
network2tikz
as
tikz
from
.
conftest
import
config
from
.
draw
import
draw_graph
def
test_graph_creation
(
G
:
nx
.
Graph
):
assert
G
.
number_of_nodes
()
==
5
assert
G
.
number_of_edges
()
==
7
def
test_graph_creation
(
G
_Edge_Case
:
nx
.
Graph
):
assert
G
_Edge_Case
.
number_of_nodes
()
==
3
assert
G
_Edge_Case
.
number_of_edges
()
==
3
def
test_print_graph
(
G
:
nx
.
Graph
):
layout
=
{
i
:
(
d
[
0
],
d
[
1
])
for
i
,
d
in
enumerate
(
config
[
'
nodes
'
])}
edges_label
=
{(
u
,
v
):
'
{:.2f}
'
.
format
(
G
[
u
][
v
][
'
weight
'
]).
format
()
for
u
,
v
in
G
.
edges
}
#layout = nx.planar_layout(G)
tikz
.
plot
(
G
,
'
graph.tex
'
,
layout
=
layout
,
edges_label
=
edges_label
)
def
test_print_graph
(
G_Edge_Case
:
nx
.
Graph
):
draw_graph
(
G_Edge_Case
,
'
graph.tex
'
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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