import sys, os sys.path.append(os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), '..')) from tulip import * import tulip.polytope as pc # Specify where the smv file, spc file and aut file will go testfile = 'intersection' path = os.path.abspath(os.path.dirname(sys.argv[0])) smvfile = os.path.join(path, 'specs', testfile+'.smv') spcfile = os.path.join(path, 'specs', testfile+'.spc') autfile = os.path.join(path, 'specs', testfile+'.aut') # Specify the environment variables env_vars = {'C2' : 'boolean', 'C3' : 'boolean', 'C4' : 'boolean', 'C5' : 'boolean', 'C7' : 'boolean'} # Specify the discrete system variable sys_disc_vars = {} # Specify the transition system representing the continuous dynamics disc_dynamics = prop2part.PropPreservingPartition(list_region=[], list_prop_symbol=[]) # These following propositions specify in which cell the robot is, i.e., # Xi means that the robot is in cell Ci disc_dynamics.list_prop_symbol = ['X0', 'X2', 'X5', 'X6'] disc_dynamics.num_prop = len(disc_dynamics.list_prop_symbol) # Regions. Note that the first argument of Region(poly, prop) should be a list of # polytopes. But since we are not dealing with the actual controller, we will # just fill it with a string (think of it as a name of the region). # The second argument of Region(poly, prop) is a list that specifies which # propositions in cont_props above is satisfied. As specified below, regioni # satisfies proposition Xi. region0 = pc.Region('C0', [1, 0, 0, 0]) region2 = pc.Region('C1', [0, 1, 0, 0]) region5 = pc.Region('C2', [0, 0, 1, 0]) region6 = pc.Region('C3', [0, 0, 0, 1]) disc_dynamics.list_region = [region0, region2, region5, region6] disc_dynamics.num_regions = len(disc_dynamics.list_region) # The transition relation between regions. disc_dynamics.trans[i][j] = 1 if starting from # region j, the robot can move to region i while only staying in the union of region i # and region j. disc_dynamics.trans = XXXX FILL IN THE TRANSITION MATRIX XXXX # Spec assumption = XXXX FILL IN THE ASSUMPTIONS XXXX guarantee = XXXX FILL IN THE GUARANTEES XXXX # Generate input to JTLV prob = jtlvint.generateJTLVInput(env_vars, sys_disc_vars, [assumption, guarantee], \ {}, disc_dynamics, smvfile, spcfile, verbose=2) # Check realizability realizability = jtlvint.checkRealizability(smv_file=smvfile, spc_file=spcfile, \ aut_file=autfile, verbose=3) # Compute an automaton jtlvint.computeStrategy(smv_file=smvfile, spc_file=spcfile, aut_file=autfile, \ priority_kind=3, verbose=3) aut = automaton.Automaton(autfile, [], 3) # Simulate #states = grsim(aut, init_state={}, num_it=30, deterministic_env=False) #writeStatesToFile(states, 'autonomous_car_int_sim.txt') # Simulate num_it = 30 # states = grsim.grsim(aut, init_state, num_it=num_it, deterministic_env=False) states = grsim.grsim([aut], aut_trans_dict={}, env_states = [{}], num_it=num_it, deterministic_env=False) destfile = 'intersection_sim.txt' label_vars = ['C2','C3','C4','C5','C7','cellID'] #grsim.writeStatesToFile([aut], destfile, aut_states_list = states,label_vars = label_vars) grsim.writeSimStatesToFile(states, destfile)