def initDPatching(specpath): """ specpath: path to specification """ executor = None proj = project.Project() proj.loadProject(specpath) hsub = handlerSubsystem.HandlerSubsystem(executor, proj.project_root) hsub.setExecutingConfig(proj.current_config) proj.rfi = proj.loadRegionFile(decomposed=True) patchExecutor = centralCoordinator.decentralizedPatchingExecutor.PatchingExecutor( hsub, proj, testDPatchingMode=True) # loadStrategy region_domain = [ strategy.Domain("region", proj.rfi.regions, strategy.Domain.B0_IS_MSB) ] regionCompleted_domain = [ strategy.Domain("regionCompleted", proj.rfi.regions, strategy.Domain.B0_IS_MSB) ] enabled_sensors = [ x for x in proj.enabled_sensors if not x.endswith('_rc') ] strat = strategy.createStrategyFromFile( specpath.replace('.spec', '.aut'), enabled_sensors + regionCompleted_domain, proj.enabled_actuators + proj.all_customs + proj.internal_props + region_domain) return patchExecutor, strat
def loadRobotClient(specpath, otherRobotName): """ specpath: path to specification """ executor = None proj = project.Project() proj.loadProject(specpath) hsub = handlerSubsystem.HandlerSubsystem(executor, proj.project_root) hsub.setExecutingConfig(proj.current_config) proj.rfi = proj.loadRegionFile(decomposed=True) robClient = negotiationMonitor.robotClient.RobotClient(hsub, proj) # loadStrategy region_domain = [ strategy.Domain("region", proj.rfi.regions, strategy.Domain.B0_IS_MSB) ] regionCompleted_domain = [ strategy.Domain("regionCompleted", proj.rfi.regions, strategy.Domain.B0_IS_MSB) ] enabled_sensors = [ x for x in proj.enabled_sensors if not x.endswith('_rc') or x.startswith(otherRobotName) ] strat = strategy.createStrategyFromFile( specpath.replace('.spec', '.aut'), enabled_sensors + regionCompleted_domain, proj.enabled_actuators + proj.all_customs + proj.internal_props + region_domain) return robClient, strat
def _autIsNonTrivial(self): """ Check for a) empty automaton, or b) trivial initial-state automaton with no transitions (This can indicate unsatisfiable system initial conditions (case a), or an unsat environment (case b).) TODO: Do this in the Java code; it's super inefficient to load the whole aut just to check this. """ if self.proj.compile_options["decompose"]: regions = self.parser.proj.rfi.regions else: regions = self.proj.rfi.regions region_domain = strategy.Domain("region", regions, strategy.Domain.B0_IS_MSB) strat = strategy.createStrategyFromFile( self.proj.getStrategyFilename(), self.proj.enabled_sensors, self.proj.enabled_actuators + self.proj.all_customs + [region_domain]) nonTrivial = any([ len(strat.findTransitionableStates({}, s)) > 0 for s in strat.iterateOverStates() ]) return nonTrivial
def checkViolationWithGivenPropsDict(fileName, propDict): """ This function instead takes in a dict and check if any EnvTrans is violated """ logging.info("Given file name:" + str(fileName)) logging.info("Given prop dict:" + str(propDict)) # Then extract assumptions from the LTL file spec = getSpecDict(fileName + '.ltl') #extract inputs and outputs inputs, outputs = getInputsOutputs(fileName + '.smv') # create strategy strat = strategy.createStrategyFromFile(fileName + '.aut', inputs, outputs) # set current state currentStateObject = strat.states.addNewState() for prop_name, value in propDict.iteritems(): currentStateObject.setPropValue(prop_name, value) # check violation LTLViolationCheck = LTLParser.LTLcheck.LTL_Check("", {}, spec) logging.info('-------------------------') logging.info('Printing violations') logging.info("EnvTransHolds:" + str( LTLViolationCheck.checkViolation( currentStateObject, currentStateObject, LTLMoP=False))) logging.info("Specific line in .spec file:" + str(LTLViolationCheck.violated_specStr)) logging.info('=========================')
def loadAutFile(self, filename): """ This function loads the the .aut/.bdd file named filename and returns the strategy object. filename (string): name of the file with path included """ region_domain = strategy.Domain("region", self.proj.rfi.regions, strategy.Domain.B0_IS_MSB) strat = strategy.createStrategyFromFile(filename, self.proj.enabled_sensors, self.proj.enabled_actuators + self.proj.all_customs + [region_domain]) return strat
def loadAutFile(self, filename): """ This function loads the the .aut/.bdd file named filename and returns the strategy object. filename (string): name of the file with path included """ region_domain = strategy.Domain("region", self.proj.rfi.regions, strategy.Domain.B0_IS_MSB) strat = strategy.createStrategyFromFile( filename, self.proj.enabled_sensors, self.proj.enabled_actuators + self.proj.all_customs + [region_domain]) return strat
def _autIsNonTrivial(self): """ Check for a) empty automaton, or b) trivial initial-state automaton with no transitions (This can indicate unsatisfiable system initial conditions (case a), or an unsat environment (case b).) TODO: Do this in the Java code; it's super inefficient to load the whole aut just to check this. """ if self.proj.compile_options["decompose"]: regions = self.parser.proj.rfi.regions else: regions = self.proj.rfi.regions region_domain = strategy.Domain("region", regions, strategy.Domain.B0_IS_MSB) strat = strategy.createStrategyFromFile(self.proj.getStrategyFilename(), self.proj.enabled_sensors, self.proj.enabled_actuators + self.proj.all_customs + [region_domain]) nonTrivial = any([len(strat.findTransitionableStates({}, s)) > 0 for s in strat.iterateOverStates()]) return nonTrivial
def compileCentralizedSpec(self): """ Compile centralized spec. """ # synthesize our new centralized controller again self.compiler = specCompiler.SpecCompiler() self.compiler.proj.compile_options[ 'synthesizer'] = 'slugs' # use slugs self.compiler.proj.project_root = os.path.dirname( os.path.realpath(__file__)) #set directory to save slugsin self.compiler.proj.project_basename = self.filePath createSMVfile(self.filePath, self.smvEnvPropList, self.smvSysPropList) # create a new SMV file # create a new LTL file LTLspec_envList = [] LTLspec_sysList = [] # append new sys and env init currentEnvInitState = '(' + self.currentState.getLTLRepresentation( mark_players=True, use_next=False, include_inputs=True, include_outputs=False) + ')' currentSysInitState = '(' + self.currentState.getLTLRepresentation( mark_players=True, use_next=False, include_inputs=False, include_outputs=True) + ')' ## construct specification for specType in self.spec.keys(): if specType in ['EnvInit', 'SysInit']: if specType == 'EnvInit': # append init state LTLspec_envList.append(currentEnvInitState) else: LTLspec_sysList.append(currentSysInitState) for robot in self.coordinatingRobots: # here we will skip the goals and join them together below if specType in ['SysGoals']: continue elif specType in ['SysInit', 'SysTrans']: LTLspec_sysList.append(self.spec[specType][robot]) else: LTLspec_envList.append(self.spec[specType][robot]) # join the goals of the robots so that the goals are pursued at the same time specSysGoals = " &\n ".join( filter(None, [ x.strip().lstrip('[]<>') for x in self.spec['SysGoals'].values() ])) LTLspec_sysList.append("[]<>(" + specSysGoals + ")" if specSysGoals else specSysGoals) # set up violation check object specSysGoalsOld = " &\n ".join( filter( None, [x.strip().lstrip('[]<>') for x in self.sysGoalsOld.values()])) logging.debug("specSysGoalsOld:" + str(specSysGoalsOld)) if specSysGoalsOld: self.sysGoalsCheck = LTLParser.LTLcheck.LTL_Check( None, {}, {'sysGoals': specSysGoalsOld}, 'sysGoals') createLTLfile(self.filePath, " &\n".join(filter(None, LTLspec_envList)), " &\n".join(filter(None, LTLspec_sysList))) startTime = time.time() #HACK: Make it to recovery mode to try it out #self.compiler.proj.compile_options['recovery']=True # interactive strategy auto synthesizes with recovery option self.compiler.cooperativeGR1Strategy = True self.compiler.onlyRealizability = True realizable, realizableFS, output = self.compiler._synthesize() endTime = time.time() logging.info(output) """ If realizable, load AUT and return status to each robot. The execution of each robot resumes. """ if realizable: logging.info('Strategy synthesized in ' + str(endTime - startTime) + ' s.') # load strategy and initial state #self.strategy = strategy.createStrategyFromFile(self.filePath + '.aut', self.smvEnvPropList, self.smvSysPropList) self.strategy = strategy.createStrategyFromFile( self.filePath + '.slugsin', self.smvEnvPropList, self.smvSysPropList) # TODO: need to be finished self.strategy.current_state = self.strategy.searchForOneState( self.currentAssignment) logging.info('Starting at State ' + str(self.strategy.current_state.state_id)) else: logging.error('cannot synthesize a centralized patch') pass
if noSuccessorsStateList: # extract props from states with no successor noSuccessorsStateDict = getTruePropsInStates(fileName + '.aut', noSuccessorsStateList) for key in noSuccessorsStateDict.keys(): logging.info(str(key) + ':' + str(noSuccessorsStateDict[key])) # Then extract assumptions from the LTL file spec = getSpecDict(fileName + '.ltl') #extract inputs and outputs inputs, outputs = getInputsOutputs(fileName + '.smv') # create strategy strat = strategy.createStrategyFromFile(fileName + '.aut', inputs, outputs) # set up violation check object LTLViolationCheck = LTLParser.LTLcheck.LTL_Check("", {}, spec) LTLViolationCheckSysTrans = LTLParser.LTLcheck.LTL_Check( "", {}, spec, specType='SysTrans') if not spec['SysGoals'].count('[]<>') == 1: sysGoalsList = LTLParser.LTLcheck.ltlStrToList(spec['SysGoals']) else: sysGoalsList = [spec['SysGoals']] LTLViolationCheckSysGoalslist = [] for ltlStr in sysGoalsList: LTLViolationCheckSysGoalslist.append( LTLParser.LTLcheck.LTL_Check("", {}, {'SysGoals': ltlStr}, specType='SysGoals'))