def _buildGuard(self, guardStr): """ Build solver for current guard based on guard string Args: guardStr (str): the guard string. For example:"And(v>=40-0.1*u, v-40+0.1*u<=0)" Returns: A Z3 Solver obj that check for guard. A symbol index dic obj that indicates the index of variables that involved in the guard. """ curSolver = Solver() # This magic line here is because sympy will evaluate == to be False # Therefore we are not be able to get free symbols from it # Thus we need to replace "==" to something else sympyGuardStr = guardStr.replace("==", ">=") symbols = list( sympy.sympify(sympyGuardStr, evaluate=False).free_symbols) symbols = [str(s) for s in symbols] symbolsIdx = { s: self.variables.index(s) + 1 for s in symbols if s in self.variables } if 't' in symbols: symbolsIdx['t'] = 0 guardStr = handleReplace(guardStr, self.varDic.keys()) curSolver.add(eval(guardStr)) return curSolver, symbolsIdx
def _buildGuard(self, guardStr): """ Build solver for current guard based on guard string Args: guardStr (str): the guard string. For example:"And(v>=40-0.1*u, v-40+0.1*u<=0)" Returns: A Z3 Solver obj that check for guard. A symbol index dic obj that indicates the index of variables that involved in the guard. """ curSolver = Solver() # This magic line here is because sympy will evaluate == to be False # Therefore we are not be able to get free symbols from it # Thus we need to replace "==" to something else sympyGuardStr = guardStr.replace("==",">=") symbols = list(sympy.sympify(sympyGuardStr, evaluate=False).free_symbols) symbols = [str(s) for s in symbols] symbolsIdx = {s:self.variables.index(s)+1 for s in symbols if s in self.variables} if 't' in symbols: symbolsIdx['t'] = 0 guardStr = handleReplace(guardStr,self.varDic.keys()) curSolver.add(eval(guardStr)) return curSolver, symbolsIdx
def __init__(self, unsafe, variables): self.varDic = {'t':Real('t')} self.variables = variables self.solverDic = {} for var in variables: self.varDic[var] = Real(var) unsafe = handleReplace(unsafe, self.varDic.keys()) unsafeList = unsafe[1:].split('@') for unsafe in unsafeList: mode, cond = unsafe.split(':') self.solverDic[mode] = [Solver(), Solver()] self.solverDic[mode][0].add(eval(cond)) self.solverDic[mode][1].add(eval(self._neg(cond)))
def __init__(self, unsafe, variables): """ Reset class initialization function. Args: unsafe (str): unsafe constraint variables (list): list of varibale name """ self.varDic = {'t': Real('t')} self.variables = variables self.solverDic = {} for var in variables: self.varDic[var] = Real(var) if not unsafe: return original = unsafe unsafe = handleReplace(unsafe, self.varDic.keys()) unsafeList = unsafe[1:].split('@') for unsafe in unsafeList: mode, cond = unsafe.split(':') self.solverDic[mode] = [Solver(), Solver()] self.solverDic[mode][0].add(eval(cond)) self.solverDic[mode][1].add(eval(neg(cond))) unsafeList = original[1:].split('@') for unsafe in unsafeList: mode, cond = unsafe.split(':') # This magic line here is because sympy will evaluate == to be False # Therefore we are not be able to get free symbols from it # Thus we need to replace "==" to something else, which is >= cond = cond.replace("==", ">=") symbols = list(sympy.sympify(cond).free_symbols) symbols = [str(s) for s in symbols] symbolsIdx = { s: self.variables.index(s) + 1 for s in symbols if s in self.variables } if 't' in symbols: symbolsIdx['t'] = 0 self.solverDic[mode].append(symbolsIdx)
def __init__(self, goal, variables): """ Goal checker class initialization function. Args: goal (str): a str describle the goal set. For example: "And(x_1>=19.5, x_1<=20.5, x_2>=-1.0, x_2<=1.0)" variables (list): list of varibale name """ self.varDic = {'t':Real('t')} self.variables = variables for var in variables: self.varDic[var] = Real(var) goal = handleReplace(goal, self.varDic.keys()) self.intersectChecker = Solver() self.containChecker = Solver() self.intersectChecker.add(eval(goal)) self.containChecker.add(eval(neg(goal)))
def __init__(self, goal, variables): """ Goal checker class initialization function. Args: goal (str): a str describle the goal set. For example: "And(x_1>=19.5, x_1<=20.5, x_2>=-1.0, x_2<=1.0)" variables (list): list of varibale name """ self.varDic = {'t': Real('t')} self.variables = variables for var in variables: self.varDic[var] = Real(var) goal = handleReplace(goal, self.varDic.keys()) self.intersectChecker = Solver() self.containChecker = Solver() self.intersectChecker.add(eval(goal)) self.containChecker.add(eval(neg(goal)))
def __init__(self, unsafe, variables): """ Reset class initialization function. Args: unsafe (str): unsafe constraint variables (list): list of varibale name """ self.varDic = {'t':Real('t')} self.variables = variables self.solverDic = {} for var in variables: self.varDic[var] = Real(var) if not unsafe: return original = unsafe unsafe = handleReplace(unsafe, self.varDic.keys()) unsafeList = unsafe[1:].split('@') for unsafe in unsafeList: mode, cond = unsafe.split(':') self.solverDic[mode] = [Solver(), Solver()] self.solverDic[mode][0].add(eval(cond)) self.solverDic[mode][1].add(eval(neg(cond))) unsafeList = original[1:].split('@') for unsafe in unsafeList: mode, cond = unsafe.split(':') # This magic line here is because sympy will evaluate == to be False # Therefore we are not be able to get free symbols from it # Thus we need to replace "==" to something else, which is >= cond = cond.replace("==",">=") symbols = list(sympy.sympify(cond).free_symbols) symbols = [str(s) for s in symbols] symbolsIdx = {s:self.variables.index(s)+1 for s in symbols if s in self.variables} if 't' in symbols: symbolsIdx['t'] = 0 self.solverDic[mode].append(symbolsIdx)
def _buildGuard(self, guardStr): # Build solver for current guard based on guard string curSolver = Solver() guardStr = handleReplace(guardStr, self.varDic.keys()) curSolver.add(eval(guardStr)) return curSolver