Ejemplo n.º 1
0
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
Ejemplo n.º 2
0
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
Ejemplo n.º 3
0
    def loadProjectAndRegions(self, proj):
        """
        This function is used to (re)initialize region objects and proj object.
        """
        self.proj = proj
        self.regions = self.proj.rfi.regions  # contains decomposed names
        if self.fastslow:
            self.regionCompleted_domain = strategy.Domain(
                "regionCompleted", proj.rfi.regions, strategy.Domain.B0_IS_MSB)
        self.region_domain = strategy.Domain("region", proj.rfi.regions,
                                             strategy.Domain.B0_IS_MSB)

        #find out mapping from new_names to old ones
        self.newRegionNameToOld = {}
        for rname, subregs in proj.regionMapping.iteritems():
            for newReg in subregs:
                self.newRegionNameToOld[newReg] = rname

        # form regionList with original names
        self.regionList = []
        for region in self.regions:
            self.regionList.append(self.newRegionNameToOld[region.name])

        # for mapping original region name to bit encoding
        self.bitEncode = parseEnglishToLTL.bitEncoding(
            len(self.regionList),
            int(numpy.ceil(numpy.log2(len(self.regionList)))))
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
def TestLoadAndDump(spec_filename):
    import project
    import pprint
    import strategy  # When running from the context of __name__ == "__main__", we need to
                     # explicitly import like this or else things get weird... e.g. __main__.Domain
                     # and strategy.Domain become different things

    ### Load the project
    proj = project.Project()
    proj.loadProject(spec_filename)
    spec_map = proj.loadRegionFile(decomposed=True)

    ### Load the strategy
    region_domain = strategy.Domain("region", spec_map.regions, Domain.B0_IS_MSB)

    strat = createStrategyFromFile(proj.getStrategyFilename(),
                                   proj.enabled_sensors,
                                   proj.enabled_actuators + proj.all_customs + proj.internal_props + [region_domain])

    ### Choose a starting state
    initial_region = spec_map.regions[0]  # Hopefully this is a valid region to start from...
    start_state = strat.searchForOneState({"region": initial_region, "radio": False})
    #pprint.pprint(strat.findTransitionableStates({}, from_state=start_state))

    ### Dump the strategy from this initial state
    strat.exportAsDotFile("strategy_test.dot", starting_states = [start_state])
Ejemplo n.º 6
0
    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
Ejemplo n.º 7
0
    def _loadFromFile(self, filename):
        """
        Load in a strategy BDD from a file produced by a synthesizer,
        such as JTLV or Slugs.
        """

        # Clear any existing states
        self.states.clearStates()

        a = pycudd.DdArray(1)

        # Load in the actual BDD itself
        # Note: We are using an ADD loader because the BDD loader
        # would expect us to have a reduced BDD with only one leaf node
        self.mgr.AddArrayLoad(pycudd.DDDMP_ROOT_MATCHLIST, None,
                              pycudd.DDDMP_VAR_MATCHIDS, None, None, None,
                              pycudd.DDDMP_MODE_TEXT, filename, None, a)

        # Convert from a binary (0/1) ADD to a BDD
        self.strategy = self.mgr.addBddPattern(a[0])

        # Load in meta-data
        with open(filename, 'r') as f:
            # Seek forward to the max goal ID notation
            line = ""
            while not line.startswith("# Num goals:"):
                line = f.readline()

            self.num_goals = int(line.split(":")[1])

            # Seek forward to the start of the variable definition section
            while not line.startswith("# Variable names:"):
                line = f.readline()

            # Parse the variable definitions
            for line in f:
                m = re.match(r"^#\s*(?P<num>\d+)\s*:\s*(?P<name>\w+'?)", line)

                # We will stop parsing as soon as we encounter an invalid line
                # Note: This includes empty lines!
                if m is None:
                    break

                varname = m.group("name")
                varnum = int(m.group("num"))

                #### TEMPORARY HACK: REMOVE ME AFTER OTHER COMPONENTS ARE UPDATED!!!
                # Rewrite proposition names to make the old bitvector system work
                # with the new one
                varname = re.sub(r"^bit(\d+)('?)$", r'region_b\1\2', varname)
                #################################################################

                if varname == "strat_type":
                    self.strat_type_var = self.mgr.IthVar(varnum)
                else:
                    self.BDD_to_var_name[self.mgr.IthVar(varnum)] = varname
                    self.var_name_to_BDD[varname] = self.mgr.IthVar(varnum)

                # TODO: check for consecutivity

        # Create a Domain for jx to help with conversion to/from bitvectors
        self.jx_domain = strategy.Domain("_jx",
                                         value_mapping=range(self.num_goals),
                                         endianness=strategy.Domain.B0_IS_LSB)