Example #1
0
    def setUp(self):
        raw_data = dm.Importer()
        #raw_data.import_data("./tests/cvrp2.test")
        #raw_data.import_data("./tests/ulysses-n16-k3.vrp")
        #raw_data.import_data("./tests/E-n23-k3.vrp")
        #raw_data.import_data("./tests/cvrp3.test")
        #raw_data.import_data("./tests/P-n19-k2.vrp")
        raw_data.import_data("./tests/cvrp4.test")
        data = dm.DataMapper(raw_data)

        self.instance = i.ProblemInstance(data)

        # self.instance.distance_matrix = [
        #     [0, 6, 3, 1, 7, 1],
        #     [6, 0, 1, 9, 6, 3],
        #     [3, 5, 0, 8, 1, 4],
        #     [1, 9, 8, 0, 9, 9],
        #     [1, 9, 2, 9, 0, 9],
        #     [11,1, 4, 9, 3, 0]
        # ]

        self.solution = a.Solution(self.instance)

        greedy = gf.GreedyFirst(self.solution.solution)
        greedy.run(sort=False)
        self.solution.value = self.solution.calculate_value()
        self.value = self.solution.value
Example #2
0
    def setUp(self):
        raw_data = dm.Importer()
        raw_data.import_data("./tests/cvrp2.test")
        data = dm.DataMapper(raw_data)

        self.instance = i.ProblemInstance(data)

        self.instance.distance_matrix = [
            [0, 6, 3, 1, 7, 11],
            [6, 0, 5, 9, 6, 3],
            [3, 5, 0, 8, 2, 4],
            [1, 9, 8, 0, 9, 9],
            [7, 6, 2, 9, 0, 3],
            [11,3, 4, 9, 3, 0]
        ]

        self.bounded_master = [
            [float("inf"), 1., 1., 2., 3., 4., 5., 6.],
            [1., float("inf"), float("inf"), 5., 2., 0., 6., 10.],
            [1., float("inf"), float("inf"), 5., 2., 0., 6., 10.],
            [2., 3., 3., float("inf"), 2., 6., 3., 0.],
            [3., 1., 1., 3., float("inf"), 6., 3., 0., 2.],
            [4., 0., 0., 8., 7., float("inf"), 8., 8.],
            [5., 5., 5., 4., 0., 7., float("inf"), 1.],
            [6., 8., 8., 0., 1., 6., 0., float("inf")]
        ]
    def setUp(self):
        raw_data = dm.Importer()
        raw_data.import_data("./tests/E-n23-k3.vrp")
        data = dm.DataMapper(raw_data)

        problem = i.ProblemInstance(data)
        self.solution = a.Solution(problem)
Example #4
0
    def setUp(self):
        raw_data = dm.Importer()
        # raw_data.import_data("./tests/cvrp2.test")
        # raw_data.import_data("./tests/ulysses-n16-k3.vrp")
        # raw_data.import_data("./tests/E-n23-k3.vrp")
        # raw_data.import_data("./tests/cvrp3.test")
        # raw_data.import_data("./tests/P-n19-k2.vrp")
        raw_data.import_data("./tests/E-n101-k14.vrp")
        data = dm.DataMapper(raw_data)
        self.instance = i.ProblemInstance(data)
        self.solution = a.Solution(self.instance)

        greedy = gf.GreedyFirst(self.solution.solution)
        greedy.run(sort=False)
        self.solution.value = self.solution.eval()
        self.tabu_search = tabu.TabuSearch(self.solution, 100)
    def setUp(self):
        self.test_filelines = [
            "NAME : test-E-n6-k4",
            "COMMENT : (##This is bullshit##Christophides and Eilon, Min no of trucks: 4, Optimal value: 375)",
            "TYPE : CVRP",
            "DIMENSION : 6",
            "EDGE_WEIGHT_TYPE : EUC_2D",
            "CAPACITY : 2500",
            "NODE_COORD_SECTION",
            "1 145 215",
            "2 151 264",
            "3 159 261",
            "4 130 254",
            "5 128 252",
            "6 163 247",
            "DEMAND_SECTION",
            "1 0",
            "2 1100",
            "3 700",
            "4 800",
            "5 1400",
            "6 2100",
            "DEPOT_SECTION",
            " 1",
            " -1",
            "EOF"
        ]

        self.test_node_coordinates_list = [
            (float(145), float(215)),
            (float(151), float(264)),
            (float(159), float(261)),
            (float(130), float(254)),
            (float(128), float(252)),
            (float(163), float(247))
        ]

        self.test_demand_list = [0, 1100, 700, 800, 1400, 2100]

        self.testobject = dm.Importer()
        self.testobject._read_file("./tests/cvrp1.test")
Example #6
0
    def setUp(self):
        raw_data = dm.Importer()
        raw_data.import_data("./tests/cvrp1.test")
        data = dm.DataMapper(raw_data)

        self.instance = i.ProblemInstance(data)
Example #7
0
def main():
    import argparse
    import time

    from code import instance as inst
    from code import datamapping as dm
    from code import greedyfirst as gf
    from code import algorithm as a
    from code import baseobjects as bo

    from code import tabu
    from code import branchnbound as bnb

    argparser = argparse.ArgumentParser(description='CVRP_Solver')
    argparser.add_argument('-ProblemInstance',
                           action='store',
                           dest='ProblemInstance',
                           help='path to the instance you want to solve',
                           required=True)
    arggroup = argparser.add_mutually_exclusive_group(required=True)
    arggroup.add_argument('-Tabu',
                          action='store_true',
                          help='use tabu search algorithm')
    arggroup.add_argument('-BnB',
                          action='store_true',
                          help='use branch and bound algorithm')

    args = argparser.parse_args()

    problem_path = args.ProblemInstance
    max_iterations = 100

    raw_data = dm.Importer()
    raw_data.import_data(problem_path)
    data = dm.DataMapper(raw_data)

    instance = inst.ProblemInstance(data)
    solution = a.Solution(instance)

    greedy_heuristic = gf.GreedyFirst(solution.solution)
    greedy_heuristic.run(sort=True)

    solution.value = solution.eval()

    value_from_greedy = solution.value
    if args.Tabu:
        tabu_search = tabu.TabuSearch(solution, max_iterations)
        print("Starting tabu search")
        start = time.process_time()
        tabu_search.run()
        end = time.process_time()
        print("time: " + str(end - start))
        print("initial value from greedy heuristic was: " +
              str(value_from_greedy))
        value_from_tabu = tabu_search.instance.value
        print("        value after running tabu search: " +
              str(value_from_tabu))
        print("routes:", end="")
        for i, vehicle in enumerate(tabu_search.instance.solution.fleet):
            print("\nvehicle " + str(i + 1) + ": ", end="")
            for node in vehicle.route:
                print(node.id, end=", ")
        print("\n\n")

    elif args.BnB:
        bnb_algo = bnb.BranchNBound()
        bnb_algo.initialize(instance, value_from_greedy)
        print(
            "Starting branch&bound with initial upper_bound from greedy heuristic"
        )
        start = time.process_time()
        upper_bound, routes, edges, times_branched = bnb_algo.run()
        end = time.process_time()
        print("time: " + str(end - start))
        conv_routes = route_from_edges(routes)
        print("initial value: " + str(value_from_greedy))
        print("optimal value: " + str(upper_bound))
        print("routes:", end="")
        for i, route in enumerate(conv_routes):
            print("\nvehicle " + str(i + 1) + ": ", end="")
            for node in route:
                print(node, end=", ")
        print("\n\n")
Example #8
0
 def setUp(self):
     self.test_object = dm.Importer()
     self.test_object.import_data("./tests/cvrp1.test")