예제 #1
0
def compute_fj_edges(graph, rounds=None, perturb=True):
    """ Compute the bet-and-run relaxation reduced costs for each edge """

    problem = mip_model.tspProblem(
        solver="scip",
        var_type="continuous",
        graph=graph,
        verbose=False,
        shuffle_columns=False,
        perturb=perturb,
        get_quick=False,
    )

    if rounds is None:
        rounds = int(np.ceil(np.log2(len(graph.edges))))
    costs = []

    for i in range(rounds):
        problem.optimise(max_rounds=1)
        costs.append(problem.get_redcosts())
        problem.problem.freeTransform()
        problem.set_objective(graph)
        costs = [(np.array(item) / np.max(item)).tolist() for item in costs]
        print(len(costs))
        return np.mean(costs, axis=0)
예제 #2
0
def compute_f8_edges(graph):
    """ Compute the root relxation features for each edge """

    problem = mip_model.tspProblem(var_type="binary",
                                   graph=graph,
                                   verbose=False)

    problem.perform_relaxation()
    return problem.get_varvals()
예제 #3
0
def get_all_optimal_tsp_solutions(graph, solver="scip"):
    """ Get all optimal solutions for the given problem """

    problem = mip_model.tspProblem(graph, solver=solver, var_type="binary")
    solutions = [solve_problem(problem=problem)]
    optimal_value, global_optimum = (problem.get_objective_value(), ) * 2

    while optimal_value == global_optimum:
        problem = mip_model.tspProblem(graph, solver=solver, var_type="binary")
        # problem._funcs["add_solution"](problem.problem, solutions[0])
        # problem = add_bound(problem, global_optimum)
        solution = solve_problem_without_previous_solutions(
            problem=problem, solutions=solutions)
        optimal_value = problem.get_objective_value()

        if optimal_value == global_optimum:
            solutions.append(solution)

    return (np.sum(solutions, axis=0) > 0.1).astype(int)
def solve_problem_custom(graph, params=None):
    """ Solve the given problem using the specified params, if there are any """

    if params is None:
        params = {
            "solver": "xpress",
            "var_type": "binary",
            "verbose": False,
            }

    problem = mip_model.tspProblem(graph=graph, **params)
    problem.optimise()

    return problem
예제 #5
0
def compute_fk_edges(graph):
    """ Compute the cutting solution features for each edge """

    problem = mip_model.tspProblem(
        solver="xpress",
        var_type="continuous",
        graph=graph,
        verbose=False,
        get_quick=False,
    )

    problem.perform_relaxation()
    costs = np.array(problem.get_redcosts())
    return costs / costs.max()
예제 #6
0
def compute_fh_edges(graph):
    """ Compute the cutting solution features for each edge """

    problem = mip_model.tspProblem(
        solver="scip",
        var_type="continuous",
        graph=graph,
        verbose=False,
        get_quick=True,
    )

    rounds = int(np.ceil(np.log2(len(graph.edges))))
    problem.optimise(max_rounds=rounds)
    return problem.get_varvals()
예제 #7
0
def compute_fi_edges_scip(graph):
    """ Compute the cutting reduced cost features for each edge """

    problem = mip_model.tspProblem(
        solver="scip",
        var_type="continuous",
        graph=graph,
        verbose=False,
        get_quick=False,
    )

    rounds = int(np.ceil(np.log2(len(graph.edges))))
    problem.optimise(max_rounds=rounds)
    costs = np.array(problem.get_redcosts())
    return costs / costs.max()