def main():
    import matplotlib.pyplot as plt
    import task_scheduling.utils as tsu

    nodes = tsu.generate_nodes()
    cost = tsu.calculate_distances(nodes)
    salesmen = np.random.randint(2, 4)

    salesmen = 2

    nodes = []
    nodes = np.array([[0, 4], [-1.5, 0], [1.5, 0], [-1.5, 0], [-1.5, 1],
                      [-0.5, 2], [-0.5, 3], [0.5, 3], [0.5, 2], [1.5, 0],
                      [1.5, 1]])
    #nodes = np.array([[0, 3], [1, 1], [-1, 1], [1, 2], [1, 3], [-1, 3], [-1, 2]])
    cost = tsu.calculate_distances(nodes)

    solution, objective, _ = tsu.solve_problem(
        tlpp_solver,
        cost,
        salesmen=salesmen,
        areas=[0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0])
    # solution, objective, _ = tsu.solve_problem(tlpp_solver, cost, salesmen=salesmen, areas=[0, 0, 0, 1, 0, 1, 0])
    fig, ax = tsu.plot_problem(nodes, solution, objective)
    plt.show()
Exemple #2
0
def main():
    import matplotlib.pyplot as plt
    import task_scheduling.utils as tsu

    nodes = tsu.generate_nodes()
    cost = tsu.calculate_distances(nodes)

    solution, objective, _ = tsu.solve_problem(tsp_solver, cost)

    fig, ax = tsu.plot_problem(nodes, solution, objective)
    plt.show()
def main():
    import matplotlib.pyplot as plt
    import task_scheduling.utils as tsu

    nodes = tsu.generate_nodes()
    cost = tsu.calculate_distances(nodes)

    solution, cost_total, _ = tsu.solve_problem(ovrp_solver, cost)

    fig, ax = tsu.plot_problem(nodes, solution, cost_total)
    plt.show()
def main():
    import matplotlib.pyplot as plt
    import task_scheduling.utils as tsu

    nodes = tsu.generate_nodes()
    cost = tsu.calculate_distances(nodes)
    salesmen = np.random.randint(2, 4)

    solution, objective, _ = tsu.solve_problem(mtsp_solver, cost, salesmen=salesmen)

    fig, ax = tsu.plot_problem(nodes, solution, objective)
    plt.show()
def main():
    import matplotlib.pyplot as plt
    import task_scheduling.utils as tsu

    nodes = tsu.generate_nodes()
    cost = tsu.calculate_distances(nodes)

    solution, cost_total, _ = tsu.solve_problem(movrp_solver,
                                                cost,
                                                num_agents=3)

    fig, ax = tsu.plot_problem(nodes, solution, cost_total)
    plt.show()
Exemple #6
0
def main():
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import task_scheduling.utils as tsu
    import random

    mpl.rcParams['figure.facecolor'] = 'white'

    nodes = tsu.generate_nodes(n=40)
    cost = tsu.calculate_distances(nodes)

    nodes = []
    random.seed(42)
    nodes.append([0, 0])

    for i in range(-1, 3):
        for j in range(2, 0, -1):
            ni = i
            nj = j
            # ni = random.uniform(-0.5,0.5) + i
            # nj = random.uniform(-0.5,0.5) + j
            nodes.append([ni, nj])

    nodes.append([1, 0])
    nodes = np.array(nodes)
    print(nodes)

    cost = tsu.calculate_distances(nodes)
    print(cost)
    from math import sqrt
    max_cost = [sqrt(5) * 2.5 + sqrt(2)]

    for mc in max_cost:
        solution, objective, _ = tsu.solve_problem(inspection_op_solver,
                                                   cost,
                                                   cost_max=mc,
                                                   output_flag=1,
                                                   time_limit=36000,
                                                   mip_gap=0.001)

        print("Objective: {0}".format(objective))

    # fig, ax = tsu.plot_problem(nodes, solution, objective)
    # solution = [0, 3, 4, 9, 10, 15, 20, 25, 19, 13, 12, 7, 1, 6, 11, 16, 21, 22, 23, 26]
    # fig, ax = tsu.plot_problem_correlation_gradient(nodes, solution, objective)
    # ax.axis('equal')
    # plt.show()
    # plt.savefig('miqp-grad.png', dpi=300)
    fig, ax = tsu.plot_problem(nodes, solution, objective)
    ax.axis('equal')
    plt.show()
Exemple #7
0
def main():
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import task_scheduling.utils as tsu
    import random

    mpl.rcParams['figure.facecolor'] = 'white'

    nodes = tsu.generate_nodes(n=40)
    cost = tsu.calculate_distances(nodes)

    nodes = []
    random.seed(42)
    nodes.append([0, 0])
    for i in range(1, 6):
        for j in range(-2, 3):
            ni = i
            nj = j
            # ni = random.uniform(-0.5,0.5) + i
            # nj = random.uniform(-0.5,0.5) + j
            nodes.append([ni, nj])
    nodes.append([6, 0])
    nodes = np.array(nodes)
    cost = tsu.calculate_distances(nodes)
    max_cost = [25.5]
    mc = [13.5, 13.5]
    num_robots = 2
    # for mc in max_cost:
    solution, objective, _ = tsu.solve_problem(ctop_solver,
                                               cost,
                                               num_robots=num_robots,
                                               cost_max=mc,
                                               output_flag=1,
                                               time_limit=36000,
                                               mip_gap=0.0)

    # util = 0
    # print(solution)
    # for i in solution:
    #     extras = 0
    #     if i != 0 and i != solution[len(solution)-1]:
    #         for j in range(cost.shape[0]):
    #             if j != i and j not in solution and j != 0 and j != solution[len(solution)-1] and cost[i,j] < 2:
    #                 extras += np.e**(-2*cost[i,j])
    #         util += 1 + extras
    #
    # print("Utility: {0}".format(util))

    fig, ax = tsu.plot_problem(nodes, solution, objective)
    plt.show()
def main():
    import matplotlib.pyplot as plt
    import task_scheduling.utils as tsu

    nodes = tsu.generate_nodes()
    cost = tsu.calculate_distances(nodes)
    salesmen = np.random.randint(2, 4)
    constraints = np.random.randint(10, 100, salesmen).tolist()

    solution, objective, _ = tsu.solve_problem(ccmmtsp_solver,
                                               cost,
                                               salesmen=salesmen,
                                               constraints=constraints)

    fig, ax = tsu.plot_problem(nodes, solution, objective)
    plt.show()
Exemple #9
0
def main():
    import matplotlib.pyplot as plt
    import task_scheduling.utils as tsu
    import random

    nodes = tsu.generate_nodes(n=100, lb=-100, up=100, dims=2)
    cost = tsu.calculate_distances(nodes)

    nodes = []
    random.seed(42)
    nodes.append([0,0])

    for i in range(1,6):
        for j in range(-2,3):
            ni = i
            nj = j
            # ni = random.uniform(-0.5,0.5) + i
            # nj = random.uniform(-0.5,0.5) + j
            nodes.append([ni,nj])

    nodes.append([6,0])
    nodes = np.array(nodes)

    cost = tsu.calculate_distances(nodes)
    max_cost = [25.5]

    for mc in max_cost:
        solution, objective, _ = tsu.solve_problem(op_solver, cost, cost_max=mc, output_flag=1, mip_gap=0.0, time_limit=3600)
        util = 0

        for i in solution:
            extras = 0

            if i != 0 and i != solution[len(solution)-1]:
                for j in range(cost.shape[0]):
                    if j != i and j not in solution and j != 0 and j != solution[len(solution)-1]:
                        extras += np.e**(-2*cost[i,j])

                util += 1 + extras

        print("Utility: {0}".format(util))

    fig, ax = tsu.plot_problem(nodes, solution, objective)
    plt.show()
def main():
    import matplotlib as mpl
    import matplotlib.pyplot as plt
    import task_scheduling.utils as tsu
    import random

    mpl.rcParams['figure.facecolor'] = 'white'

    nodes = tsu.generate_nodes(n=40)
    cost = tsu.calculate_distances(nodes)

    nodes = []
    random.seed(42)
    nodes.append([0,0])

    for i in range(1,6):
        for j in range(-2,3):
            ni = i
            nj = j
            # ni = random.uniform(-0.5,0.5) + i
            # nj = random.uniform(-0.5,0.5) + j
            nodes.append([ni,nj])

    nodes.append([6,0])
    nodes = np.array(nodes)

    cost = tsu.calculate_distances(nodes)
    max_cost = [25.5]

    for mc in max_cost:
        solution, objective, _ = tsu.solve_problem(cop_solver, cost, cost_max=mc ,output_flag=1, time_limit=36000, mip_gap=0.1)
        utility = calculate_utility(solution, cost)

        print("Utility: {0}".format(utility))

    fig, ax = tsu.plot_problem(nodes, solution, objective)
    ax.axis('equal')
    plt.show()