updated advancedSimulation
This commit is contained in:
parent
f1bce8dc4e
commit
3961ee0030
2
python/.vscode/launch.json
vendored
2
python/.vscode/launch.json
vendored
@ -10,7 +10,7 @@
|
|||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${file}",
|
"program": "${file}",
|
||||||
"console": "integratedTerminal",
|
"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"]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
BIN
python/__pycache__/graphUtils.cpython-39.pyc
Normal file
BIN
python/__pycache__/graphUtils.cpython-39.pyc
Normal file
Binary file not shown.
21
python/graphUtils.py
Normal file
21
python/graphUtils.py
Normal file
@ -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)
|
||||||
@ -1,11 +1,12 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import sys
|
import sys
|
||||||
|
import graphUtils
|
||||||
statesComp = ["S", "I", "R"]
|
statesComp = ["S", "I", "R"]
|
||||||
rulesComp = [("I", "R", 1.0), # spontaneous rule I -> R with rate 1.0
|
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
|
("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
|
(("I","S"),("I","I"), 0.8)] # contact rule I+S -> I+I with rate 0.4
|
||||||
|
|
||||||
allStates = []
|
simulation = []
|
||||||
|
|
||||||
class Rule:
|
class Rule:
|
||||||
def __init__(self, ruleParts, probability):
|
def __init__(self, ruleParts, probability):
|
||||||
@ -65,7 +66,6 @@ def stringToRule(Input):
|
|||||||
while(len(Input) > 0):
|
while(len(Input) > 0):
|
||||||
newString = parseState(Input)
|
newString = parseState(Input)
|
||||||
rulePartsBuffer.append(newString[0])
|
rulePartsBuffer.append(newString[0])
|
||||||
allStates.append(newString[0])
|
|
||||||
|
|
||||||
# check if we are at the end
|
# check if we are at the end
|
||||||
if(newString[1][0].isdigit()):
|
if(newString[1][0].isdigit()):
|
||||||
@ -80,25 +80,34 @@ def stringToRule(Input):
|
|||||||
output.append(r.getOutput())
|
output.append(r.getOutput())
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def generateStatesList():
|
def stringToStates(inp):
|
||||||
|
inp = inp.split(" ")
|
||||||
out = []
|
out = []
|
||||||
for s in allStates:
|
for s in inp:
|
||||||
if(not(s in out)):
|
|
||||||
out.append(s)
|
out.append(s)
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
def stringToDistr(inp):
|
||||||
|
inp = inp.split(" ")
|
||||||
|
out = []
|
||||||
|
for i in inp:
|
||||||
|
out.append(float(i))
|
||||||
|
return out
|
||||||
|
|
||||||
# parse the input wohooooo
|
# parse the input wohooooo
|
||||||
rules = stringToRule(sys.argv[1])
|
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)]
|
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
|
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
|
timepoint_num = 101
|
||||||
def get_next_state(current_labels):
|
def get_next_state(current_labels):
|
||||||
fastes_firing_time = 10000000.0 #dummy
|
fastes_firing_time = 10000000.0 #dummy
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user