From 71136cb6ab44fe6242b863b8c97c10b10c1e7823 Mon Sep 17 00:00:00 2001 From: Dennis van den Berg Date: Thu, 1 Apr 2021 14:26:01 +0200 Subject: [PATCH] Add run.py --- parse/GraphUtils.py | 4 ++-- run.py | 3 +++ test/algorithms/test_AntBundleAlgorithm.py | 12 +++++++----- test/data/test_PheromoneField.py | 6 ++++-- ui/pyedgebundleUI/main.py | 13 ++++++++++--- 5 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 run.py diff --git a/parse/GraphUtils.py b/parse/GraphUtils.py index 4e429cd..df544a8 100644 --- a/parse/GraphUtils.py +++ b/parse/GraphUtils.py @@ -1,4 +1,4 @@ -from typing import Tuple +from typing import Tuple, List import networkx as nx from PySide2.QtWidgets import QDialog @@ -8,7 +8,7 @@ class GraphUtils: @staticmethod - def getCommonProperties(g: nx.Graph) -> list[str]: + def getCommonProperties(g: nx.Graph) -> List[str]: properties = None for n, data in g.nodes.items(): if properties is None: diff --git a/run.py b/run.py new file mode 100644 index 0000000..d435956 --- /dev/null +++ b/run.py @@ -0,0 +1,3 @@ +from ui.pyedgebundleUI.main import start + +start() \ No newline at end of file diff --git a/test/algorithms/test_AntBundleAlgorithm.py b/test/algorithms/test_AntBundleAlgorithm.py index 77cb993..46b0b54 100644 --- a/test/algorithms/test_AntBundleAlgorithm.py +++ b/test/algorithms/test_AntBundleAlgorithm.py @@ -9,7 +9,7 @@ from demo.demo import AirlineDemo, SmallDemo from parse.GraphUtils import GraphUtils -G = nx.DiGraph() +G = nx.Graph() G.add_nodes_from([ (1, {"x": 0, "y": 0}), (2, {"x": 0, "y": 50}), @@ -21,6 +21,8 @@ for i in range(1, 6): G.add_edge(i, 6) +nx.readwrite.write_graphml_xml(G, '../../examplegraphs/join.graphml', named_key_ids=True) + G_pres = nx.DiGraph() G_pres.add_nodes_from([ (1, {"x": 20, "y": 100}), @@ -40,7 +42,7 @@ class TestAntBundleAlgorithm(TestCase): def test_example(self): random.seed(1) np.random.seed(10) - a = AntBundleAlgorithm(G, BSplineInterpolate(max_degree=2), 50, 4, True, 0.0001, 0.4, 0.0005, 5, 6) + a = AntBundleAlgorithm(G, BSplineInterpolate(max_degree=2), 10, 4, True, 0.0001, 0.4, 0.0005, 5, 6) result = a.bundle() a.field.plot() result.plot() @@ -80,8 +82,8 @@ def test_demo(self): g = AirlineDemo().get_graph() d = {} for node, data in g.nodes(data=True): - d[node] = {'x': int(data["x"]*0.7), - 'y': int(data["y"]*0.7)} + d[node] = {'x': int(data["x"] * 0.7), + 'y': int(data["y"]* 0.7)} nx.set_node_attributes(g, d) a = AntBundleAlgorithm(g, BSplineInterpolate(max_degree=3), 100, 4, False, 0.98, 0.4, 0.0005, 5, 6) @@ -92,5 +94,5 @@ def test_small_demo(self): random.seed(1) np.random.seed(1) g = SmallDemo().get_graph() - a = AntBundleAlgorithm(g, BSplineInterpolate(max_degree=3), 50, 4, False, 0.98, 0.4, 0.0005, 5, 6) + a = AntBundleAlgorithm(g, BSplineInterpolate(max_degree=3), 1, 4, False, 0.98, 0.4, 0.0005, 5, 6) a.bundle().plot() diff --git a/test/data/test_PheromoneField.py b/test/data/test_PheromoneField.py index 5b2932c..0b8632f 100644 --- a/test/data/test_PheromoneField.py +++ b/test/data/test_PheromoneField.py @@ -59,7 +59,8 @@ def test_update_field(self): path = [ (3, x) for x in range(7) ] - test.field += test.updateField(path, 0, 3) + test.updateField(path, 0, 3) + test.field += test.diff_matrix self.assertEqual(np.count_nonzero(test.field), 35 * 2) self.assertEqual(list(test.field[3][0]), [1, 0, 0, 1, 0]) @@ -69,7 +70,8 @@ def test_update_field_diag(self): path = [ (x, x) for x in range(7) ] - test.field += test.updateField(path, 0, 0) + test.updateField(path, 0, 0) + test.field += test.diff_matrix test.plot() diff --git a/ui/pyedgebundleUI/main.py b/ui/pyedgebundleUI/main.py index b0cdcdd..c3e634a 100644 --- a/ui/pyedgebundleUI/main.py +++ b/ui/pyedgebundleUI/main.py @@ -1,3 +1,5 @@ +import os +import pathlib import sys from threading import Thread from typing import Optional @@ -23,6 +25,7 @@ from ui.pyedgebundleUI.utils.AntBundleOutputWindow import AntBundleOutputWindow from ui.pyedgebundleUI.utils.AntBundleParameterSettings import AntBundleParameterSettings, AntBundleParameters + matplotlib.use('Qt5Agg') @@ -62,7 +65,7 @@ def __init__(self, ui_file, parent=None): # Matplotlib widget content = self.ui.widget - self.canvas = FigureCanvas(Figure((6,7))) + self.canvas = FigureCanvas(Figure((6, 7))) self.figure = self.canvas.figure self.ax = self.canvas.figure.subplots() self.ax.axes.xaxis.set_visible(False) @@ -201,8 +204,12 @@ def setGraphInfo(self): self.info.setText(f"#nodes: {node_count}\tdimensions: ({max_x}, {max_y})") -if __name__ == '__main__': +def start(): QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts) app = QApplication() - form = Form('form.ui') + form = Form(os.path.join(pathlib.Path(__file__).parent.absolute(), "form.ui")) sys.exit(app.exec_()) + + +if __name__ == '__main__': + start()