Exemplo n.º 1
0
    def _writeSMVFile(self):
        if self.proj.compile_options["decompose"]:
            numRegions = len(self.parser.proj.rfi.regions)
        else:
            numRegions = len(self.proj.rfi.regions)
        sensorList = self.proj.enabled_sensors
        robotPropList = self.proj.enabled_actuators + self.proj.all_customs + self.proj.internal_props

        # Add in regions as robot outputs
        if self.proj.compile_options["use_region_bit_encoding"]:
            robotPropList.extend(["bit"+str(i) for i in range(0,int(numpy.ceil(numpy.log2(numRegions))))])
        else:
            robotPropList.extend([r.name for r in self.parser.proj.rfi.regions])

        self.propList = sensorList + robotPropList
        
        createSMVfile(self.proj.getFilenamePrefix(), sensorList, robotPropList)
Exemplo n.º 2
0
    def _writeSMVFile(self):
        if self.proj.compile_options["decompose"]:
            numRegions = len(self.parser.proj.rfi.regions)
        else:
            numRegions = len(self.proj.rfi.regions)
        sensorList = self.proj.enabled_sensors
        robotPropList = self.proj.enabled_actuators + self.proj.all_customs + self.proj.internal_props

        # Add in regions as robot outputs
        if self.proj.compile_options["use_region_bit_encoding"]:
            robotPropList.extend(["bit"+str(i) for i in range(0,int(numpy.ceil(numpy.log2(numRegions))))])
        else:
            if self.proj.compile_options["decompose"]:
                robotPropList.extend([r.name for r in self.parser.proj.rfi.regions])
            else:
                robotPropList.extend([r.name for r in self.proj.rfi.regions])

        self.propList = sensorList + robotPropList
        
        createSMVfile(self.proj.getFilenamePrefix(), sensorList, robotPropList)
Exemplo n.º 3
0
    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
Exemplo n.º 4
0
    def _writeSMVFile(self):
        numRegions = len(self.parser.proj.rfi.regions)
        sensorList = self.proj.enabled_sensors
        robotPropList = self.proj.enabled_actuators + self.proj.all_customs

        createSMVfile(self.proj.getFilenamePrefix(), numRegions, sensorList, robotPropList)