def arbitrary_init_machine(root, env, mch, solution_file_read=False): bstates = set_up_constants(root, env, mch, solution_file_read) if len(bstates)>0: env.state_space.add_state(bstates[0]) bstates = exec_initialisation(root, env, mch, solution_file_read) if len(bstates)>0: env.state_space.add_state(bstates[0])
def run_model_checking_mode(argv): print "\033[1m\033[91mWARNING\033[00m: model checking still experimental" root, env, parse_object, solution_file_present = startup(argv, offset=1) if not isinstance(parse_object, BMachine): print "Error: only model checking of b machines" return -1 assert isinstance(parse_object, BMachine) # 6. typecheck type_check_root_bmch(root, env, parse_object) # also checks all included, seen, used and extend mch = parse_object bstates = set_up_constants(root, env, mch, solution_file_read=False) # also evals properties # TODO: implement setup non determinism if len(bstates)==1: env.state_space.set_current_state(bstates[0]) elif len(bstates)>1: print "WARNING: non det. set up constants not supported yet" return -1 bstates = exec_initialisation(root, env, mch, solution_file_read=False) # TODO: volvo example 0 instead of 2 states for bstate in bstates: if not env.state_space.is_seen_state(bstate): env.state_space.set_current_state(bstate) if not mch.has_invariant_mc: print "WARNING: no invariant present" return -1 return _run_model_checking_mode(env, mch)
def run_checking_mode(): env = Environment() # 1. create env. file_name_str, solution_file_name_str = read_input_string(argv, 1) # 2. read filenames ast_string, error = file_to_AST_str_no_print(file_name_str) # 3. parse input-file to string if error: print error #env.set_search_dir(file_name_str) root = str_ast_to_python_ast(ast_string) # 4. parse string to python ast TODO: JSON #if solution_file_name_str: # 5. parse solution-file and write to env. # read_solution_file(env, solution_file_name_str) # The concreate solution values are added at # the bmachine object-init time to the respective mch # 6. replace defs and extern-functions inside mch and solution-file (if present) parse_object = remove_defs_and_parse_ast(root, env) # 7. which kind of ast? if not isinstance(parse_object, BMachine): # #PREDICATE or #EXPRESSION result = interpret(parse_object.root, env) # eval predicate or expression print result else: assert isinstance(parse_object, BMachine) # 8. typecheck type_check_root_bmch(root, env, parse_object) # also checks all included, seen, used and extend mch = parse_object #solution_file_read = not solution_file_name_str=="" bstates = set_up_constants(root, env, mch, solution_file_read=False) # also evals properties if not bstates==[]: bool = True for bstate in bstates: env.state_space.add_state(bstate) #if mch.has_properties_mc: # assert interpret(mch.aPropertiesMachineClause, env) init_bstates = exec_initialisation(root, env, mch, not solution_file_name_str=="") for init_bstate in init_bstates: env.state_space.add_state(init_bstate) if mch.has_invariant_mc: w_bool = interpret(mch.aInvariantMachineClause, env) bool = bool and w_bool.bvalue env.state_space.undo() if mch.has_assertions_mc: interpret(mch.aAssertionsMachineClause, env) env.state_space.undo() return bool else: # TODO: dont repeat yourself init_bstates = exec_initialisation(root, env, mch, not solution_file_name_str=="") for bstate in init_bstates: env.state_space.add_state(bstate) if mch.has_invariant_mc: w_bool = interpret(mch.aInvariantMachineClause, env) assert w_bool.bvalue if mch.has_assertions_mc: interpret(mch.aAssertionsMachineClause, env) env.state_space.undo() if not init_bstates==[]: env.state_space.add_state(init_bstates[0]) return eval_Invariant(root, env, mch)
def __calc_states_and_print_ui(root, env, mch, solution_file_read): # Schneider Book page 62-64: # The parameters p make the constraints C True # #p.C # Sets St and constants k which meet the constraints c make the properties B True # C => #St,k.B if not env.set_up_done: next_states = set_up_constants(root, env, mch, solution_file_read) if len(next_states)>0: print_set_up_bstates(next_states, mch) return next_states else: # no bstates and no exception: set up to do (e.g no constants) env.set_up_done = True # If C and B is True there should be Variables v which make the Invaraiant I True # B & C => #v.I if not env.init_done: next_states = exec_initialisation(root, env, mch, solution_file_read) if len(next_states)>0: undo_possible = not env.state_space.empty() print_init_bstates(next_states, mch, undo_possible) return next_states else: # no bstates and no exception: no init to do (e.g no variables) env.init_done = True print mch.mch_name," - Invariant:", eval_Invariant(root, env, mch) # TODO: move print to animation_clui if EVAL_CHILD_INVARIANT: bstate = env.state_space.get_state() for bmachine in bstate.bmch_list: if not bmachine is None and not bmachine.mch_name==mch.mch_name : print bmachine.mch_name, " - Invariant:", interpret(bmachine.aInvariantMachineClause, env) bstate_lst = calc_next_states(env, mch) show_ui(env, mch, bstate_lst) next_states = [] for n in bstate_lst: # all other data inside bstate_lst has already been processed by show_ui next_states.append(n.bstate) return next_states