Ejemplo n.º 1
0
class ExternalXCSPSolver(ExternalSolver):

    def __init__(self):
        super(ExternalXCSPSolver, self).__init__()

    def set_model(self, model, solver_id, solver_name, solver):
        self.model = model
        self.output_model()

        for nj_var, i in sorted(self.out_object.njvar_mapping.iteritems(), key=lambda (k, v): v):
            my_var = ExternalXCSPIntVariable(nj_var)
            nj_var.setVar(solver_id, solver_name, my_var, new_solver=solver)
            nj_var.solver = solver
            self.variables.append(my_var)

    def output_model(self):
        from XCSPOut import XCSPOutput
        self.out_object = XCSPOutput(self.model)
        self.out_object.output(self.filename)

    def parse_output(self, output):
        """
            Parses the solver output, which should conform to the output of the
            CSP Solver competitions. http://cpai.ucc.ie/09/
        """
        values = []
        for line in output.split("\n"):
            line = line.strip()
            first_two = line[:2]
            if len(line) == 0:
                continue

            if first_two == "s ":
                print line
                if "UNSATISFIABLE" in line or "UNSAT" in line:
                    self.sat = Numberjack.UNSAT
                elif "SATISFIABLE" in line or "SAT" in line:
                    self.sat = Numberjack.SAT
            elif first_two == "v ":
                values.extend(map(int, line[2:].split()))
            elif first_two == "d " or first_two == "c ":
                self.parse_solver_info_line(line[2:])

        if self.sat == Numberjack.SAT:
            for i, variable in enumerate(self.variables):
                variable.value = values[i]
Ejemplo n.º 2
0
class ExternalXCSPSolver(ExternalSolver):
    def __init__(self):
        super(ExternalXCSPSolver, self).__init__()

    def set_model(self, model, solver_id, solver_name, solver):
        self.model = model
        self.output_model()

        for nj_var, i in sorted(self.out_object.njvar_mapping.iteritems(),
                                key=lambda (k, v): v):
            my_var = ExternalXCSPIntVariable(nj_var)
            nj_var.setVar(solver_id, solver_name, my_var, new_solver=solver)
            nj_var.solver = solver
            self.variables.append(my_var)

    def output_model(self):
        from XCSPOut import XCSPOutput
        self.out_object = XCSPOutput(self.model)
        self.out_object.output(self.filename)

    def parse_output(self, output):
        """
            Parses the solver output, which should conform to the output of the
            CSP Solver competitions. http://cpai.ucc.ie/09/
        """
        values = []
        for line in output.split("\n"):
            line = line.strip()
            first_two = line[:2]
            if len(line) == 0:
                continue

            if first_two == "s ":
                print line
                if "UNSATISFIABLE" in line or "UNSAT" in line:
                    self.sat = Numberjack.UNSAT
                elif "SATISFIABLE" in line or "SAT" in line:
                    self.sat = Numberjack.SAT
            elif first_two == "v ":
                values.extend(map(int, line[2:].split()))
            elif first_two == "d " or first_two == "c ":
                self.parse_solver_info_line(line[2:])

        if self.sat == Numberjack.SAT:
            for i, variable in enumerate(self.variables):
                variable.value = values[i]
Ejemplo n.º 3
0
 def output_model(self):
     from XCSPOut import XCSPOutput
     self.out_object = XCSPOutput(self.model)
     self.out_object.output(self.filename)
Ejemplo n.º 4
0
 def output_model(self):
     from XCSPOut import XCSPOutput
     self.out_object = XCSPOutput(self.model)
     self.out_object.output(self.filename)