From cc9d6f0ad0cb2fbc7a0aa71741188df4e48f0366 Mon Sep 17 00:00:00 2001
From: "niehues.mark@gmail.com" <niehues.mark@gmail.com>
Date: Thu, 12 Mar 2020 17:45:19 +0100
Subject: [PATCH] Add possibility to create all graphs as tex files.

---
 .gitignore                      |  2 ++
 README.md                       | 12 ++++++++++++
 tests/draw.py => draw_graphs.py | 23 +++++++++++++++++++++++
 tests/config.py                 |  3 +++
 tests/test_graph.py             |  6 ------
 5 files changed, 40 insertions(+), 6 deletions(-)
 rename tests/draw.py => draw_graphs.py (67%)

diff --git a/.gitignore b/.gitignore
index 485dee6..bcaae93 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,3 @@
 .idea
+plots
+__pycache__
diff --git a/README.md b/README.md
index e69de29..bb9408a 100644
--- a/README.md
+++ b/README.md
@@ -0,0 +1,12 @@
+# Routing for Electric Vehicles
+
+## Extras
+
+### Draw Graphs used for Testing
+
+To draw all graphs, respectively create ```.tex``` snippets (that make use of the 
+[tikz-network](https://www.ctan.org/pkg/tikz-network)).
+
+```bash
+python draw_graphs.py [export_dir_path]
+```
diff --git a/tests/draw.py b/draw_graphs.py
similarity index 67%
rename from tests/draw.py
rename to draw_graphs.py
index ee38d09..22cd239 100644
--- a/tests/draw.py
+++ b/draw_graphs.py
@@ -50,3 +50,26 @@ def _get_node_styles(G):
     styles['nodes_style'] = nodes_style
 
     return styles
+
+
+if __name__ == '__main__':
+    # Write Latex files of all test case graph configs
+    import os
+    import sys
+    from tests import config
+
+    try:
+        plot_dir = sys.argv[1]
+    except IndexError:
+        plot_dir = 'plots'
+
+    if config.config_list:
+        try:
+            os.mkdir(plot_dir)
+        except FileExistsError:
+            pass
+
+    for conf_name in config.config_list:
+        conf = getattr(config, conf_name)
+        G = config.get_graph(conf)
+        draw_graph(G, os.path.join(plot_dir, conf_name + '.tex'))
diff --git a/tests/config.py b/tests/config.py
index d8f3408..92a27bb 100644
--- a/tests/config.py
+++ b/tests/config.py
@@ -5,6 +5,9 @@ import networkx as nx
 Street = namedtuple('Street', ['u', 'v', 'distance', 'consumption'])
 Node = namedtuple('Node', ['label', 'charging_coeff'], defaults=(None, None))
 
+# List of configs
+config_list = ['edge_case']
+
 edge_case = {
     'b_0': 0,
     'b_t': 0,
diff --git a/tests/test_graph.py b/tests/test_graph.py
index 278f7fb..42fa225 100644
--- a/tests/test_graph.py
+++ b/tests/test_graph.py
@@ -1,12 +1,6 @@
 import networkx as nx
 
-from .draw import draw_graph
-
 
 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_Edge_Case: nx.Graph):
-    draw_graph(G_Edge_Case, 'graph.tex')
-- 
GitLab