Ejemplo n.º 1
0
def main():
    if len(sys.argv) < 2:
        raise ValueError(f"{sys.argv[0]}: expected file location.")

    problem = Problem.from_file(sys.argv[1], delimiter=',')

    alns = ALNS(default_rng(problem.instance))

    for op in D_OPERATORS:
        alns.add_destroy_operator(op)

    for op in R_OPERATORS:
        alns.add_repair_operator(op)

    local_search = LocalSearch()

    for op in SOLUTION_OPERATORS:
        local_search.add_solution_operator(op)

    for op in ROUTE_OPERATORS:
        local_search.add_route_operator(op)

    alns.on_best(local_search)

    init = initial_solution()
    result = alns.iterate(init, WEIGHTS, DECAY, CRITERION, ITERATIONS)

    # noinspection PyTypeChecker
    solution: Solution = result.best_state
    solution.to_file(f"solutions/oracs_{problem.instance}.csv")
Ejemplo n.º 2
0
def main():
    args = parse_args()

    Problem.from_instance(args.experiment, args.instance)

    if args.experiment == "tuning":
        generator = rnd.default_rng(args.instance)
    else:
        # E.g. for exp 72 and inst. 1, this becomes 7201. This way, even for
        # inst. 100, there will never be overlap between random number streams
        # across experiments.
        generator = rnd.default_rng(100 * args.experiment + args.instance)

    alns = ALNS(generator)  # noqa

    for operator in DESTROY_OPERATORS:
        if args.exclude == operator.__name__:
            continue

        alns.add_destroy_operator(operator)

    for operator in REPAIR_OPERATORS:
        if args.exclude == operator.__name__:
            continue

        alns.add_repair_operator(operator)

    if args.exclude == "reinsert_learner":
        alns.on_best(reinsert_learner)

    init = initial_solution()
    criterion = get_criterion(init.objective())
    result = alns.iterate(init, WEIGHTS, DECAY, criterion, ITERATIONS)

    location = f"experiments/{args.experiment}/{args.instance}-heuristic.json"
    result.best_state.to_file(location)  # noqa