def scalarizing_moop(instance, C=[1,10,100]):
    sols = []
    exec_time = []
    for i in range(len(C)):
        start_time = time.time()
        instance.set_renting_ratio(C[i])
        TTP_solver = TTPSolver(instance)
        sol = TTP_solver.hyprid_EA(initial_strategy='greedy',
                                        n_population=10,n_offspring= 10,
                                        local_search=True,verbose=False)
        print(i)
        sols.append((i,sol,sol.profit,np.ceil(sol.duration).astype(int)))
        exec_time.append(time.time()-start_time)
    return np.array(sols), exec_time
Пример #2
0
                        label='Mean')
    axes[1, 1].legend()

    #plt.figure(figsize=(8,6))
    for i, n_p in enumerate(n_pop):
        axes[2, 1].errorbar(range(o),
                            mean_time[i, :],
                            std_time[i, :],
                            label='Pop size = ' + str(n_p))
        axes[2, 1].set_xticks(range(o))
        axes[2, 1].set_xticklabels(n_offspring)
    axes[2, 1].errorbar(range(o),
                        np.mean(mean_time, axis=0),
                        np.mean(std_time, axis=0),
                        linestyle='--',
                        linewidth=2,
                        label='Mean')
    axes[2, 1].legend()


KP_instance = KPSolver("instances/kp/kp-n279.txt")
TSP_instance = TSPSolver("instances/tsp/tsp-a280.txt")
TTP_inst = TTPInstance("instances/ttp/ttp-a280-n279.txt")
TTP_instance = TTPSolver(TTP_inst)

n_pop = [5, 10, 20, 50, 100]
n_offspring = [10, 20, 50, 100, 200]

#data = EA_paramters_tuning(TTP_instance,n_pop=n_pop,n_offspring=n_offspring,problem = 'TTP',initial_strategy = 'random',local_search=True,verbose = True, repeat= 10)
plot(data, n_pop, n_offspring)
Пример #3
0
from core.ttp import TTPSolver, TTPInstance
import numpy as np
import matplotlib.pyplot as plt
from glob import glob
import time
import pandas as pd
import seaborn as sns
"""
Test file fot TTP
"""

TTP_inst = TTPInstance("instances/ttp/ttp-a280-n279.txt")
TTP_solver = TTPSolver(TTP_inst)


def sequential_non_dominated(sol, sorted_archive):
    if len(sorted_archive) == 0:
        sorted_archive.append([sol])
    else:
        for i, sol_list in enumerate(sorted_archive):
            larger_prof = False
            inferior_idx = None
            for idx, pl_sol in enumerate(sol_list):
                if pl_sol[0] > sol[0]:
                    larger_prof = True
                    break
                else:
                    if pl_sol[1] > sol[1] and inferior_idx is None:
                        inferior_idx = idx

            if larger_prof:
Пример #4
0
        sub_data.append((solution.score, time() - start))
        """


        data.append(sub_data)

    # If you add a strategy, please add its label here:
    strategies_labels = ("independent", "local_search", "annealing") #, "hybrid_EA/20/20")

    data = np.array(data).transpose(1, 0, 2)
    return strategies_labels, data


for instance_uri in instances_uris:
    try:
        instance = TTPSolver(TTPInstance(instance_uri))
    except:
        continue
    name = instance_uri.split("/")[-1]
    # Get a array of size (n_strategies x n_repeat x 2)
    # The dimension of size 3 is for (length, time duration)
    # The dimension of size n_repeat is for average and standard deviation purpose

    strategies_labels, data = try_strategies(instance)

    plt.boxplot(data[:, :, 0].T)
    plt.xticks(range(1, len(strategies_labels) + 1), strategies_labels, rotation=45)
    plt.title("score for: " + name)
    plt.savefig("./experiment_data/overall_analysis/ttp/" + name + ".score.png",  bbox_inches='tight')
    plt.clf()