Пример #1
0
    def generate(self, m: clingo.Model) -> None:
        self._raw_model = m.__str__()

        self.infra_agents = []
        self.product_agents = []

        predicates = m.symbols(atoms=True)
        node_func = {
            "infra_agent": self.add_infra_agent,
            "product_agent": self.add_product_agent,
        }
        edge_func = {"depends_on": self.add_edge}

        for predicate in predicates:
            if predicate.name in node_func:
                node_func[predicate.name](predicate.arguments[0].number)

        self.edges = [
            set() for x in range(len(self.infra_agents) + len(self.product_agents))
        ]

        for predicate in predicates:
            if predicate.name in edge_func:
                edge_func[predicate.name](
                    predicate.arguments[0].number, predicate.arguments[1].number
                )

        print(self._raw_model)
Пример #2
0
    def on_model(self, m: clingo.Model) -> bool:
        # Same set of parameters and search algorithm will produce the same
        # result set. To make sure two different agent using the same settings
        # can produce different output, we are counting models in the result
        # set. The first agent using the same configuration gets first one,
        # the second agent using the same configuration gets second one, and so
        # on so forth.
        self.model_count -= 1
        if self.model_count > 0:
            return True

        self._raw_model = m.__str__()
        return False
Пример #3
0
 def on_model(self, m: clingo.Model) -> None:
     self._raw_model = m.__str__()