Esempio n. 1
0
def scenario_A(file_in, file_out=None):
    print("Input file: {}".format(file_in))

    reader = FileReader(file_in)
    problem = reader.read()

    solver = Pizza(problem)
    print("Description:")
    print(solver.description())

    slices = solver.solve()

    is_valid, result = problem.validate_solution(slices)

    if is_valid:
        print("Solution for problem {} is correct. Score is {}".format(
            file_in, result))
        solution = Solution(problem)
        solution.load_slices(slices)
        if DEBUG:
            solution.print_solution()
        if file_out:
            writer = FileWriter(file_in + ".out")
            writer.write(solution)
    else:
        print("Incorrect solution. Please check the error messages below")
        for msg in result:
            print(msg)
Esempio n. 2
0
    def run_instance(self, id, parameters):
        init_solver = self.slave_solver(parameters)
        solution = init_solver.run(self.problem)
        score = solution.score()
        print("Initial solution score: {}, parameters: {}".
              format(score, ", ".join(["{}: {}".format(k, v) for k, v in parameters.items()])))

        if self.file_output:
            writer = FileWriter("{}.{}.{}.out".format(self.file_output, id, score))
            writer.write(solution)

        return solution, score
Esempio n. 3
0
def scenario_A(file_in, file_out):
    global DEBUG
    reader = FileReader(file_in)
    problem = reader.read()

    init_solver = InitSolverSilly()
    solution = init_solver.run(problem)
    print("Initial solution score: {}".format(solution.score()))
    if DEBUG:
        solution.print_solution()

    writer = FileWriter(file_out)
    writer.write(solution)
Esempio n. 4
0
def scenario_C(file_in, file_out, file_par=None):
    global DEBUG
    reader = FileReader(file_in)
    problem = reader.read()

    init_solver = ParallelInitSolver(InitSolverSillyParameterized,
                                     file_output=file_out)
    solution = init_solver.run(problem, file_par)
    print("Initial solution score: {}".format(solution.score()))
    if DEBUG:
        solution.print_solution()

    writer = FileWriter(file_out)
    writer.write(solution)
Esempio n. 5
0
def scenario_B(file_in, file_out):
    global DEBUG
    reader = FileReader(file_in)
    problem = reader.read()

    init_solver = InitSolverSilly()
    solution = init_solver.run(problem)
    print("Initial solution score: {}".format(solution.score()))
    if DEBUG:
        solution.print_solution()

    optimizer = Tabu(problem,
                     solution,
                     Neighbourhood_ChangeFormats,
                     debug=True)
    optimized_solution = optimizer.run(time_limit=100)

    print("optimized solution score: {}".format(optimized_solution.score()))
    if DEBUG:
        optimized_solution.print_solution()

    writer = FileWriter(file_out)
    writer.write(optimized_solution)
Esempio n. 6
0
def scenario_D(file_in, file_out, file_par=None):
    global DEBUG
    reader = FileReader(file_in)
    problem = reader.read()

    init_solver = ParallelInitSolver(InitSolverSillyParameterized,
                                     file_output=file_out)
    solution = init_solver.run(problem, file_par)
    print("Initial solution score: {}".format(solution.score()))
    if DEBUG:
        solution.print_solution()

    optimizer = ParallelTabu(problem,
                             solution,
                             Neighbourhood_ChangeFormats,
                             debug=True)
    optimized_solution = optimizer.run(time_limit=1000)

    print("optimized solution score: {}".format(optimized_solution.score()))
    if DEBUG:
        optimized_solution.print_solution()

    writer = FileWriter(file_out)
    writer.write(solution)