Example #1
0
def testme1():
    p = CSP()
    with p.par():
        p.process(printme, 1, 2, 3, 4, 5)
        p.process(printme, 6, 7, 7, 8, 9)
        p.process(printme, 2, 3, 6, 3, 2)
    p.start()
Example #2
0
def testme1():
    p = CSP()
    with p.par():
        p.process(printme, 1, 2, 3, 4, 5)
        p.process(printme, 6, 7, 7, 8, 9)
        p.process(printme, 2, 3, 6, 3, 2)
    p.start()
Example #3
0
    def solve(self) -> Tuple[Optional[Dict[int, int]], int]:
        """
        Prova a risolvere il problema.
        Returns:
            Una tupla formata da:
            - Un dizionario, che associa ad ogni regina (colonna) una riga.
            - Un intero, che rappresenta il numero di passi svolti dall'algoritmo.

            In caso non sia stato possibile arrivare ad una soluzione (anche a causa del timeout),
             il metodo ritorna una tupla avente "None" come primo parametro e -1 come secondo parametro.
        """
        blocked_queens_constraint: BlockedQueensConstraint = BlockedQueensConstraint(
            self.blocked_queens)

        queens: List[int] = list(range(self.n))
        domains: Dict[int, List[int]] = {}

        for column in queens:
            domains[column] = list(range(self.n))

        csp: CSP[int, int] = CSP(queens,
                                 domains,
                                 self.value_sorter,
                                 ac3=self.use_ac3,
                                 mrv=self.use_mrv,
                                 fc=self.use_fc)

        csp.add_constraint(QueensConstraint(queens))
        csp.add_constraint(blocked_queens_constraint)

        solution, iterations = csp.backtracking()
        self.solution = solution
        return solution, iterations
Example #4
0
def testme2():
    p = CSP()
    with p.seq():
        p.process(printme, 1, 2, 3)
        with p.par():
            p.process(printme, 1)
            p.process(printme, 2)
            p.process(printme, 3)
        p.process(printme, 5, 6, 7)
    p.start()
Example #5
0
def testme2():
    p = CSP()
    with p.seq():
        p.process(printme, 1, 2, 3)
        with p.par():
            p.process(printme, 1)
            p.process(printme, 2)
            p.process(printme, 3)
        p.process(printme, 5, 6, 7)
    p.start()