diff --git a/python/.vscode/launch.json b/python/.vscode/launch.json index 73c2f4a..59a7bb5 100644 --- a/python/.vscode/launch.json +++ b/python/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "program": "${file}", "console": "integratedTerminal", - "args": ["I R 1.0 R S 0.7 I S I I 0.8"] + "args": ["I R 1.0 R S 0.7 I S I I 0.8", "S I R", "0.5 0.5 0"] } ] } \ No newline at end of file diff --git a/python/__pycache__/graphUtils.cpython-39.pyc b/python/__pycache__/graphUtils.cpython-39.pyc new file mode 100644 index 0000000..d2ab611 Binary files /dev/null and b/python/__pycache__/graphUtils.cpython-39.pyc differ diff --git a/python/graphUtils.py b/python/graphUtils.py new file mode 100644 index 0000000..cbc299b --- /dev/null +++ b/python/graphUtils.py @@ -0,0 +1,21 @@ +def edgelistToDot(name, inp): + output = "strict graph \"" + name + "\" {\n" + for (x,y) in inp: + output += f" {x} -- {y};\n" + + output += "}" + return output + +def dotToEdgelist(graph): + outStr = [] + graph = graph.split("\n") + name = graph[0].split(" ")[2] + name = name[1:len(name) - 1] + for i in range(len(graph) - 1): + if(i == 0): + continue + nodes = graph[i].split("--") + node1 = int(nodes[0]) + node2 = int(nodes[1][0:len(nodes[1]) - 1]) + outStr.append((node1, node2,)) + return (name, outStr) diff --git a/python/simulationAdvanced.py b/python/simulationAdvanced.py index 1acff8a..3fafe8c 100644 --- a/python/simulationAdvanced.py +++ b/python/simulationAdvanced.py @@ -1,11 +1,12 @@ import numpy as np import sys +import graphUtils statesComp = ["S", "I", "R"] rulesComp = [("I", "R", 1.0), # spontaneous rule I -> R with rate 1.0 ("R", "S", 0.7), # spontaneous rule R -> S with rate 0.7 (("I","S"),("I","I"), 0.8)] # contact rule I+S -> I+I with rate 0.4 -allStates = [] +simulation = [] class Rule: def __init__(self, ruleParts, probability): @@ -65,7 +66,6 @@ def stringToRule(Input): while(len(Input) > 0): newString = parseState(Input) rulePartsBuffer.append(newString[0]) - allStates.append(newString[0]) # check if we are at the end if(newString[1][0].isdigit()): @@ -80,25 +80,34 @@ def stringToRule(Input): output.append(r.getOutput()) return output -def generateStatesList(): +def stringToStates(inp): + inp = inp.split(" ") out = [] - for s in allStates: - if(not(s in out)): - out.append(s) + for s in inp: + out.append(s) return out +def stringToDistr(inp): + inp = inp.split(" ") + out = [] + for i in inp: + out.append(float(i)) + return out # parse the input wohooooo rules = stringToRule(sys.argv[1]) -states = generateStatesList() +states = stringToStates(sys.argv[2]) +initial_distribution = stringToDistr(sys.argv[3]) -simulation = [] graph_as_edgelist = [(0, 4), (0, 1), (1, 5), (1, 2), (2, 6), (2, 3), (3, 7), (4, 8), (4, 5), (5, 9), (5, 6), (6, 10), (6, 7), (7, 11), (8, 12), (8, 9), (9, 13), (9, 10), (10, 14), (10, 11), (11, 15), (12, 13), (13, 14), (14, 15)] +print(graphUtils.edgelistToDot("testGraph", graph_as_edgelist)) +print(graphUtils.dotToEdgelist("strict graph 'testGraph' {\n0 -- 4;\n0 -- 1;\n1 -- 5;\n}")[0]) + horizon = 20.0 # wie lange wird simuliert -initial_distribution = [0.5, 0.5, 0.0] # gleiche Reihenfolge wie states, musss zu rules passen und normalisiert werden +# initial_distribution = [0.5, 0.5, 0.0] # gleiche Reihenfolge wie states, musss zu rules passen und normalisiert werden timepoint_num = 101 def get_next_state(current_labels): fastes_firing_time = 10000000.0 #dummy