Exemplo n.º 1
0
 def only_one_root(self):
     """
     Gets the formula where every group value can only belong to one root value
     :return List<Expr>: a list of subformulae that when Anded together creates the formula for this rule
     """
     form = []
     for group in range(0, len(self.groups)):
         f = And(*[
             OneHot(*[
                 self.X[group, idx, root]
                 for root in range(0, self.items_per)
             ]) for idx in range(0, self.items_per)
         ])
         form.append(f.to_dnf())
     return form
Exemplo n.º 2
0
 def one_in_each(self):
     """
     Gets the formula where every value in a group must belong to different root values
     :return List<Expr>: a list of subformulae that when Anded together creates the formula for this rule
     """
     form = []
     for group in range(0, len(self.groups)):
         f = And(*[
             OneHot(*[
                 self.X[group, idx, root]
                 for idx in range(0, self.items_per)
             ]) for root in range(0, self.items_per)
         ])
         form.append(f.to_dnf())
     return form
Exemplo n.º 3
0
    def rules_dnf(self):
        """
        Gets the two formulas that represent the basic rules of having exactly one value per category match with each other
        and appends those two formulae And'd together in dnf form to this puzzle's formula. This must be done in merged stages
        because it is too big of a formula to turn to dnf all at once.
        """
        base = self.only_one_root() + self.one_in_each()
        group_by = 4
        while len(base) > 1:
            base_help = []
            for i in range(0, len(base), group_by):
                form = And(*[f for f in base[i:i + group_by]])
                base_help.append(form.to_dnf())
            base = base_help

        return base[0]