def minirecognizer(goalspec): # Change list of trace to set traceset = trace.copy() akey = list(traceset.keys())[0] # Loop through the trace to find the shortest best trace trace_len = len(traceset[akey])-1 t = self.create_trace_flloat(traceset, trace_len) # parse the formula parser = LTLfGParser() # Define goal formula/specification parsed_formula = parser(goalspec) # Evaluate the trace result = parsed_formula.truth(t) # print(result, goalspec, trace['KE'][-1], trace['LV'][-1]) if goalspec[0] == 'G': if not result: self.env_done = True return result, self.create_trace_dict( trace, trace_len) else: if result: return result, self.create_trace_dict( trace, trace_len) return result, self.create_trace_dict( trace, trace_len)
def recognizer(self, trace): """Recognizer. Which will reconize traces from the generator system.""" # parse the formula parser = LTLfGParser() # Define goal formula/specification parsed_formula = parser(self.goalspec) # Change list of trace to set traceset = trace.copy() akey = list(traceset.keys())[0] # Loop through the trace to find the shortest best trace for i in range(0, len(traceset[akey])): t = self.create_trace_flloat(traceset, i) result = parsed_formula.truth(t) if self.goalspec[0] == 'G': if not result: return result, self.create_trace_dict(trace, i) else: if result: return result, self.create_trace_dict(trace, i) return result, self.create_trace_dict(trace, i)
def recognizer(self, trace): """Recognizer. Which will reconize traces from the generator system.""" # parse the formula parser = LTLfGParser() # Define goal formula/specification parsed_formula = parser(self.goalspec) # Change list of trace to set traceset = trace.copy() # print('recognizer',traceset) akey = list(traceset.keys())[0] # Loop through the trace to find the shortest best trace for i in range(0, len(traceset[akey])): t = self.create_trace_flloat(traceset, i) # print(i, t['C'], parsed_formula) result = parsed_formula.truth(t) # print(i, t['C'], parsed_formula, result) if result is True: self.set_state(self.env, trace, i) return True, self.create_trace_dict(trace, i) return result, self.create_trace_dict(trace, i)
def evaluate_trace(self, goalspec, trace): # Test the prop algorithm parser = LTLfGParser() parsed_formula = parser(goalspec) # Quick fix. create_trace_float requires action to be list of list temp = trace['A'] trace['A'] = [temp] # Create a trace compatiable with Flloat library t = self.create_trace_flloat(self.list_to_trace(trace), 0) result = parsed_formula.truth(t) return result
def goalspec2BT(goalspec, planner=Planner.DEFAULT, node=GoalNode): parser = LTLfGParser() ltlformula = parser(goalspec) # nodeid for unique naming to the nodes nid = 0 # If the specification is already atomic no need to call his if type(ltlformula) in [LTLfgAtomic, LTLfEventually, LTLfAlways]: root = node(get_name(ltlformula), planner, id=nid) nid += 1 else: rootnode = find_control_node(ltlformula.operator_symbol) root = rparser(ltlformula.formulas, rootnode, planner, node, nid) recursive_until(root) return root
def recognition(trace, keys, goalspec): # goalspec = 'F P_[C][1,none,>=]' # parse the formula parser = LTLfGParser() # Define goal formula/specification parsed_formula = parser(goalspec) # Change list of trace to set traceset = trace.copy() akey = list(traceset.keys())[0] # print('recognizer', traceset) # Loop through the trace to find the shortest best trace for i in range(1, len(traceset[akey]) + 1): t = create_trace_flloat(traceset, i, keys) result = parsed_formula.truth(t) if result is True: # self.set_state(self.env, trace, i) return True, i return result, i