コード例 #1
0
ファイル: main.py プロジェクト: chris4540/DD2380
#!/usr/bin/env python3
import math
import time
# from tabu import tabu_search
import tabu
# import matplotlib.pyplot as plt
import sys
from os.path import join, dirname
# import CVRPFileParser
sys.path.append(join(dirname(__file__), "../benchmark"))
from cvrp_parser import CVRPFileParser

if __name__ == '__main__':

    p = CVRPFileParser('../benchmark/instances/Vrp-Set-A/A-n32-k5.vrp')
    # p = CVRPFileParser('../benchmark/instances/Vrp-Set-A/A-n38-k5.vrp')
    p.parse()
    capacity = p.capacity
    distances = p.distances
    demands = p.demands
    coordinates = p.coordinates
    print(capacity)
    print(distances)
    print(demands)

    tabu.MAX_ITER = 2000

    time_begin = time.process_time()
    costs = []
    solution, distance = tabu.tabu_search(capacity=capacity,
                                          distances=distances,
コード例 #2
0
ファイル: benchmark.py プロジェクト: chris4540/DD2380
    result = dict()
    result['iteration'] = args.iter
    result['algorithm'] = args.algo

    # each instance, we make 5 runs
    num_runs = args.num_sample

    # case selection of which algo
    if args.algo == "tabu_search":
        # Tabu search
        import tabu_search.tabu as tabu
        tabu.MAX_ITER = args.iter

        for inst_ in benchmark_instances:
            p = CVRPFileParser(inst_)
            p.parse()

            inst_result = dict()
            inst_result['cost'] = []
            inst_result['proc_time'] = []
            inst_result['sol'] = []
            inst_result['loads'] = []
            for _ in range(num_runs):

                stime = time.process_time()
                solution, cost = tabu.tabu_search(
                    capacity=p.capacity, distances=p.distances, demands=p.demands)
                etime = time.process_time()

                # save down the cost and cpu time
コード例 #3
0
ファイル: test_cvrp_parser.py プロジェクト: chris4540/DD2380
from cvrp_parser import CVRPFileParser

if __name__ == '__main__':

    parser = CVRPFileParser('instances/Vrp-Set-A/A-n32-k5.vrp')
    parser.parse()

    print(parser.data)
    print(parser.capacity)
    print(parser.distances)
    print(parser.demands)
コード例 #4
0
import GA_VRP
import time
import matplotlib.pyplot as plt
import math
import sys
from os.path import join, dirname
# import CVRPFileParser
sys.path.append(join(dirname(__file__), "../benchmark"))
from cvrp_parser import CVRPFileParser

if __name__ == '__main__':

    # p = CVRPFileParser('../benchmark/instances/Vrp-Set-A/A-n32-k5.vrp')
    p = CVRPFileParser('../benchmark/instances/Vrp-Set-B/B-n34-k5.vrp')
    p.parse()
    # ============================
    # PUT PARAMETER INTO MODULE
    # ============================
    GA_VRP.mod_param_config(city_num=p.dimension,
                            coordinates=p.coordinates,
                            capacity=p.capacity,
                            distances=p.distances,
                            demands=p.demands)

    #GA
    time_begin = time.process_time()

    population = GA_VRP.initialization()
    population = GA_VRP.main_GA(population)
    best_chromo = population[0]
    best_trips = best_chromo.trips