def parse_ilasp_solutions(ilasp_learnt_filename):
    with open(ilasp_learnt_filename) as f:
        automaton = SubgoalAutomaton()
        edges = {}
        for line in f:
            line = line.strip()
            if line.startswith(N_TRANSITION_STR):
                parsed_transition = parse_negative_transition_rule(line)
                current_edge = ((parsed_transition.src, parsed_transition.dst),
                                parsed_transition.edge)
                if current_edge not in edges:
                    edges[current_edge] = []
                for pos_fluent in parsed_transition.pos:
                    edges[current_edge].append("~" + pos_fluent)
                for neg_fluent in parsed_transition.neg:
                    edges[current_edge].append(neg_fluent)
            elif line.startswith(CONNECTED_STR):
                parsed_edge = parse_edge_rule(line)
                current_edge = ((parsed_edge.src, parsed_edge.dst),
                                parsed_edge.edge)
                if current_edge not in edges:
                    edges[current_edge] = []

        for edge in edges:
            from_state, to_state = edge[0]
            automaton.add_state(from_state)
            automaton.add_state(to_state)
            automaton.add_edge(from_state, to_state, edges[edge])

        return automaton
Example #2
0
    def _set_basic_automata(self):
        self.automata = []

        for _ in range(self.num_domains):
            # the initial automaton is an automaton that doesn't accept nor reject anything
            automaton = SubgoalAutomaton()
            automaton.add_state(ISAAlgorithmBase.INITIAL_STATE_NAME)
            automaton.set_initial_state(ISAAlgorithmBase.INITIAL_STATE_NAME)
            # automaton.add_state(ISAAlgorithm.ACCEPTING_STATE_NAME)  # DO NOT UNCOMMENT!
            # automaton.add_state(ISAAlgorithm.REJECTING_STATE_NAME)
            # automaton.set_accept_state(ISAAlgorithm.ACCEPTING_STATE_NAME)
            # automaton.set_reject_state(ISAAlgorithm.REJECTING_STATE_NAME)
            self.automata.append(automaton)
 def get_automaton(self):
     automaton = SubgoalAutomaton()
     automaton.add_state("u0")
     automaton.add_state("u1")
     automaton.add_state("u_acc")
     automaton.add_state("u_rej")
     automaton.add_edge(
         "u0", "u1",
         [OfficeWorldObject.ROOM_A, "~" + OfficeWorldObject.PLANT])
     automaton.add_edge("u0", "u_rej", [OfficeWorldObject.PLANT])
     automaton.add_edge(
         "u1", "u_acc",
         [OfficeWorldObject.ROOM_B, "~" + OfficeWorldObject.PLANT])
     automaton.add_edge("u1", "u_rej", [OfficeWorldObject.PLANT])
     automaton.set_initial_state("u0")
     automaton.set_accept_state("u_acc")
     automaton.set_reject_state("u_rej")
     return automaton
    def get_automaton(self):
        automaton = SubgoalAutomaton()
        automaton.add_state("u0")
        automaton.add_state("u1")
        automaton.add_state("u_acc")

        if self.enforce_single_observable_per_location:
            automaton.add_edge("u0", "u1", [CraftWorldObject.GRASS])
        else:
            automaton.add_edge(
                "u0", "u1",
                [CraftWorldObject.GRASS, "~" + CraftWorldObject.TOOLSHED])
            automaton.add_edge(
                "u0", "u_acc",
                [CraftWorldObject.GRASS, CraftWorldObject.TOOLSHED])
        automaton.add_edge("u1", "u_acc", [CraftWorldObject.TOOLSHED])

        automaton.set_initial_state("u0")
        automaton.set_accept_state("u_acc")
        return automaton
    def get_automaton(self):
        automaton = SubgoalAutomaton()
        automaton.add_state("u0")
        automaton.add_state("u1")
        automaton.add_state("u_acc")

        automaton.add_edge(
            "u0", "u1",
            [OfficeWorldObject.COFFEE, "~" + OfficeWorldObject.OFFICE])
        automaton.add_edge(
            "u0", "u_acc",
            [OfficeWorldObject.COFFEE, OfficeWorldObject.OFFICE])
        automaton.add_edge(
            "u1", "u_acc",
            [OfficeWorldObject.OFFICE, "~" + OfficeWorldObject.PLANT])

        if self.drop_coffee_on_plant_enable:
            automaton.add_edge("u1", "u0", [OfficeWorldObject.PLANT])
        else:
            automaton.add_state("u_rej")
            automaton.set_reject_state("u_rej")
            automaton.add_edge("u0", "u_rej", [
                OfficeWorldObject.PLANT, "~" + OfficeWorldObject.COFFEE,
                "~" + OfficeWorldObject.OFFICE
            ])
            automaton.add_edge("u1", "u_rej", [OfficeWorldObject.PLANT])

        automaton.set_initial_state("u0")
        automaton.set_accept_state("u_acc")
        return automaton
    def get_automaton(self):
        automaton = SubgoalAutomaton()
        automaton.add_state("u0")
        automaton.add_state("u1")
        automaton.add_state("u2")
        automaton.add_state("u3")
        automaton.add_state("u_acc")

        if self.enforce_single_observable_per_location:
            automaton.add_edge(
                "u0", "u2",
                [CraftWorldObject.WOOD, "~" + CraftWorldObject.IRON])
            automaton.add_edge("u0", "u3", [CraftWorldObject.IRON])
            automaton.add_edge("u2", "u1", [CraftWorldObject.IRON])
            automaton.add_edge("u3", "u1", [CraftWorldObject.WOOD])
        else:
            automaton.add_edge("u0", "u1", [
                CraftWorldObject.WOOD, "~" + CraftWorldObject.WORKBENCH,
                CraftWorldObject.IRON
            ])
            automaton.add_edge(
                "u0", "u2",
                [CraftWorldObject.WOOD, "~" + CraftWorldObject.IRON])
            automaton.add_edge(
                "u0", "u3",
                ["~" + CraftWorldObject.WOOD, CraftWorldObject.IRON])
            automaton.add_edge("u0", "u_acc", [
                CraftWorldObject.WOOD, CraftWorldObject.WORKBENCH,
                CraftWorldObject.IRON
            ])
            automaton.add_edge(
                "u2", "u1",
                ["~" + CraftWorldObject.WORKBENCH, CraftWorldObject.IRON])
            automaton.add_edge(
                "u2", "u_acc",
                [CraftWorldObject.WORKBENCH, CraftWorldObject.IRON])
            automaton.add_edge(
                "u3", "u1",
                [CraftWorldObject.WOOD, "~" + CraftWorldObject.WORKBENCH])
            automaton.add_edge(
                "u3", "u_acc",
                [CraftWorldObject.WOOD, CraftWorldObject.WORKBENCH])
        automaton.add_edge("u1", "u_acc", [CraftWorldObject.WORKBENCH])

        automaton.set_initial_state("u0")
        automaton.set_accept_state("u_acc")
        return automaton