Skip to content

Commit

Permalink
Add run.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennis van den Berg committed Apr 1, 2021
1 parent c0689e6 commit 71136cb
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
4 changes: 2 additions & 2 deletions parse/GraphUtils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Tuple
from typing import Tuple, List

import networkx as nx
from PySide2.QtWidgets import QDialog
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from ui.pyedgebundleUI.main import start

start()
12 changes: 7 additions & 5 deletions test/algorithms/test_AntBundleAlgorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}),
Expand All @@ -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}),
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand All @@ -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()
6 changes: 4 additions & 2 deletions test/data/test_PheromoneField.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand All @@ -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()

Expand Down
13 changes: 10 additions & 3 deletions ui/pyedgebundleUI/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os
import pathlib
import sys
from threading import Thread
from typing import Optional
Expand All @@ -23,6 +25,7 @@

from ui.pyedgebundleUI.utils.AntBundleOutputWindow import AntBundleOutputWindow
from ui.pyedgebundleUI.utils.AntBundleParameterSettings import AntBundleParameterSettings, AntBundleParameters

matplotlib.use('Qt5Agg')


Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()

0 comments on commit 71136cb

Please sign in to comment.