def compute_func(out_file, net_file): buckets = 20 (out, vehicleList) = parse.parse_out(out_file) net = parse.parse_net(net_file) edges = {} length = {} for k in net: edges[k] = {} length[k] = list(net[k].values())[0] # structure: edge id -> time -> buckets of vehicles for _, (t, es) in enumerate(out.items()): for e in edges: edges[e][t] = [] for i in range(buckets): edges[e][t].append(0) # i -- edge id, l -- we only care about vehicles inside for i, l in es.items(): for v in l.values(): for (loc, _) in v.values(): idx = int(loc * buckets / length[i]) if idx == len(edges[i][t]): idx -= 1 edges[i][t][idx] += 1 unused = [] for e in edges: if max([max(x) for x in edges[e].values()]) == 0: unused.append(e) for e in unused: edges.pop(e) return (edges, length)
def test_eu_proposition_1(): net, state = parse_net(""" P:2 T:0->1 S:5|0 """) prop = EUProposition(LessProposition(NumericExpression(0), VariableExpression(0)), EqualsProposition(VariableExpression(1), NumericExpression(3))) assert state.evaluate(prop) == True
def test_eg_continuation2(): net, state = parse_net(""" P:5 T:0->1 T:0->2 T:1->3 T:2->4 S:1|0|0|0|0""") prop = parse_props('EG $4=0')[0] assert state.evaluate(prop) == False
def test_ex_continuation(): net, state = parse_net(""" P:7 T:0->1 T:0->2 T:0->3 T:0->4 T:0->5 T:0->6 S:1|0|0|0|0|0|0 """) prop = parse_props('EX $5 = 1')[0] assert state.evaluate(prop) == True
def test_eg_continuation1(): net, state = parse_net(""" P:7 T:0->1 T:0->2 T:0->3 T:0->4 T:0->5 T:0->6 S:1|0|0|0|0|0|0 """) prop = parse_props('EG true')[0] prop1 = parse_props('EG false')[0] assert state.evaluate(prop) == True assert state.evaluate(prop1) == False
def test_parse_petri_net(): net = """P: 2 T: 0|1 -> 0|1 T: 0 -> 1 S:123|5345 """ pnet, state = parse_net(net) assert isinstance(pnet, PetriNet) assert len(pnet.transitions) == 2 t0 = pnet.transitions[0] assert t0.input == [0, 1] assert t0.output == [0, 1] t1 = pnet.transitions[1] assert t1.input == [0] assert t1.output == [1] assert state.tokens == [123, 5345]
def entry_point(argv): file = argv[1] net, state = parse_net(read_file(file)) props = parse_props(argv[2]) for prop in props: print prop.label() g_start = time.time() for p in props: print p.label(),"= ", start = time.time() res = state.evaluate(p) end = time.time() if res: print "True", else: print "False", print "(%f)" % (end -start,) g_end = time.time() print "Total runtime %f" % (g_end - g_start, ) print "Calculated %d states" % len(net._states_cache) return 0
# run simulation retcode = subprocess.call( [sumoBinary, "-c", "./cross3l.sumocfg", "--no-step-log"], stdout=sys.stdout, stderr=sys.stderr) print(">> Simulation closed with status %s" % retcode) sys.stdout.flush() # start the simulation and connect to it with the script: import traci import parse out_file = './out.xml' net_file = './net.net.xml' buckets = 20 net = parse.parse_net(net_file) step_length = 1 traci.start([ checkBinary('sumo-gui'), '-c', "./cross3l.sumocfg", '--step-length', str(step_length) ]) vehicles = [] start_vel = 5 step = 0 sidVehicle = {} # vehicles that want to do side move # Run a simulation until all vehicles have arrived while traci.simulation.getMinExpectedNumber() > 0: traci.simulationStep()