Exemple #1
0
def compare_methods(g,
                    nbr_tests=default_tests,
                    p=default_p,
                    gamma=default_gamma):
    d_multi_obj, v, t, time = algos.pl_part3_1(g, p, gamma)
    d_pdm, v, t, time = algos.iteration_de_la_valeur(g, p, gamma)
    # on calcul le cout moyen pour chacune des ces politiques, en pratique
    mean_multi_obj = ot.mean_experienced_cost_p3(d_multi_obj, g, p, nbr_tests)
    mean_pdm = ot.mean_experienced_cost_p3(d_pdm, g, p, nbr_tests)
    return (mean_multi_obj, mean_pdm)
Exemple #2
0
 def affiche_res_iteration_valeur(self):
     p = 0.6
     gamma = 0.9
     epsilon = 0.00001
     d, val_etats, t, time = algos.iteration_de_la_valeur(
         self.g, p, gamma, epsilon)
     self.resultat.config(state=tk.NORMAL)
     self.resultat.delete(1.0, tk.END)
     self.resultat.insert(tk.INSERT, ot.from_action_to_dir(d, self.g))
     self.resultat.insert(tk.INSERT, '\nnumber of iteration :' + str(t))
     self.resultat.insert(tk.INSERT, '\ntime :' + str(time))
     self.resultat.config(state=tk.DISABLED)
Exemple #3
0
def impact_q(variation_q,
             nbLignes=default_nbLignes,
             nbCol=default_nbCol,
             p=default_p,
             gamma=default_gamma,
             epsilon=default_epsilon):
    couts = [0, 1, 2, 3, 4]
    for q in variation_q:
        random.seed(1)
        np.random.seed(1)
        print(q)
        new_couts = [x**q for x in couts]
        g = grille.Grille(nbLignes, nbCol, 2, 0.2, 0.2, 0.2, 0.2, 0.2,
                          new_couts, 1000).g
        d, v, t, time = algos.iteration_de_la_valeur(g, p, gamma, epsilon)
        print(ot.from_action_to_dir(d, g))
Exemple #4
0
def resolution_nbr_cases(nbLignes=default_nbLignes,
                         nbCol=default_nbCol,
                         p=default_p,
                         gamma=default_gamma,
                         epsilon=default_epsilon):
    size = nbLignes * nbCol
    couts = [0, 1, size**1, size**2, size**3]
    reward = 1000
    grid = grille.Grille(nbLignes, nbCol, 2, 0.2, 0.2, 0.2, 0.2, 0.2, couts,
                         reward)
    d, v, t, time = algos.iteration_de_la_valeur(grid.g, p, gamma, epsilon)
    print(ot.from_action_to_dir(d, grid.g))

    #affichage dans la GUI
    grid.resultat.config(state=tk.NORMAL)
    grid.resultat.delete(1.0, tk.END)
    grid.resultat.insert(tk.INSERT, ot.from_action_to_dir(d, grid.g))
    grid.resultat.insert(tk.INSERT, '\nnumber of iteration :' + str(t))
    grid.resultat.insert(tk.INSERT, '\ntime :' + str(time))
    grid.resultat.config(state=tk.DISABLED)
    grid.Mafenetre.mainloop()


# resolution_nbr_cases()
Exemple #5
0
def impact_size(sizes,
                nbr_tests=default_tests,
                p=default_p,
                gamma=default_gamma,
                epsilon=default_epsilon):
    df = pd.DataFrame(columns=[
        "dimensions",
        "taille",
        "iter_val",
        "iter_pol",
        "iter_pl",
        "time_val",
        "time_pol",
        "time_pl",
    ])
    for i, taille in enumerate(sizes):
        print(taille)
        somme1_it = 0
        somme1_t = 0
        somme2_it = 0
        somme2_t = 0
        somme3_it = 0
        somme3_t = 0
        for k in range(nbr_tests):
            fenetre = grille.Grille(taille[0], taille[1], 2, 0.2, 0.2, 0.2,
                                    0.2, 0.2, [0, 1, 2, 3, 4], 1000)
            g = fenetre.g

            # iteration de la valeur
            d, v, t, time = algos.iteration_de_la_valeur(g, p, gamma, epsilon)
            somme1_it += t
            somme1_t += time

            # iteration de la politique
            d, v, t, time = algos.iteration_de_la_politique(
                g, p, gamma, epsilon)
            somme2_it += t
            somme2_t += time

            #pl
            d, v, t, time = algos.pl(g, p, gamma)
            somme3_it += t
            somme3_t += time
            # ajouter le pl
            line = pd.Series({
                'dimensions': taille,
                'taille': taille[0] * taille[1],
                'iter_val': somme1_it / nbr_tests,
                'iter_pol': somme2_it / nbr_tests,
                'iter_pl': somme3_it / nbr_tests,
                'time_val': somme1_t / nbr_tests,
                'time_pol': somme2_t / nbr_tests,
                'time_pl': somme3_t / nbr_tests,
            })

        df = df.append(line, ignore_index=True)

    # Affichage des résultats
    print(df)
    #stocke dans un fichier csv
    df.to_csv("./impact_size.csv", ';')

    plt.figure(1)

    ax1 = plt.subplot(211)
    plt.scatter(df.taille, df.iter_val, label="Iteration de la valeur")
    plt.scatter(df.taille, df.iter_pol, label="Iteration de la politique")
    plt.scatter(df.taille, df.iter_pl, label="Programmation mathématique")
    plt.xlabel("Taille de l'instance")
    plt.ylabel("Nombre d'itérations")
    plt.setp(ax1.get_xticklabels(), visible=False)

    plt.legend(bbox_to_anchor=(1, 1), loc=0, borderaxespad=0.)

    plt.subplot(212, sharex=ax1)
    plt.scatter(df.taille, df.time_val, label="Iteration de la valeur")
    plt.scatter(df.taille, df.time_pol, label="Iteration de la politique")
    plt.scatter(df.taille, df.time_pl, label="Programmation mathématique")
    plt.xlabel("Taille de l'instance")
    plt.ylabel("Durée d'execution")

    plt.show()
Exemple #6
0
def impact_p(interval_p,
             nbr_tests=default_tests,
             nbLignes=default_nbLignes,
             nbCol=default_nbCol,
             gamma=default_gamma,
             epsilon=default_epsilon):
    df = pd.DataFrame(columns=[
        "p",
        "iter_val",
        "iter_pol",
        "iter_pl",
        "time_val",
        "time_pol",
        "time_pl",
    ])
    for p in interval_p:
        print("p = " + str(p))
        somme1_it = 0
        somme1_t = 0
        somme2_it = 0
        somme2_t = 0
        somme3_it = 0
        somme3_t = 0
        for k in range(nbr_tests):
            g = grille.Grille(nbLignes, nbCol, 2, 0.2, 0.2, 0.2, 0.2, 0.2,
                              [0, 1, 2, 3, 4], 1000).g

            #iteration de la valeur
            d, v, t, time = algos.iteration_de_la_valeur(g, p, gamma, epsilon)
            somme1_it += t
            somme1_t += time

            #iteration de la politque
            d, v, t, time = algos.iteration_de_la_politique(
                g, p, gamma, epsilon)
            somme2_it += t
            somme2_t += time

            #PL
            d, v, t, time = algos.pl(g, p, gamma)
            somme3_it += t
            somme3_t += time

            line = pd.Series({
                'p': p,
                'iter_val': somme1_it / nbr_tests,
                'iter_pol': somme2_it / nbr_tests,
                'iter_pl': somme3_it / nbr_tests,
                'time_val': somme1_t / nbr_tests,
                'time_pol': somme2_t / nbr_tests,
                'time_pl': somme3_t / nbr_tests,
            })
        df = df.append(line, ignore_index=True)

    print(df)
    df.to_csv("./impact_p.csv", ';')
    plt.figure(1)
    ax1 = plt.subplot(211)
    plt.title("Impact de p")
    plt.scatter(df.p, df.iter_val, label="Iteration de la valeur")
    plt.scatter(df.p, df.iter_pol, label="Iteration de la politique")
    plt.scatter(df.p, df.iter_pl, label="Programmation mathématique")

    plt.ylabel("Nombre d'itérations")
    plt.setp(ax1.get_xticklabels(), visible=False)

    plt.legend(bbox_to_anchor=(1, 1), loc=0, borderaxespad=0.)

    plt.subplot(212, sharex=ax1)
    plt.scatter(df.p, df.time_val, label="Iteration de la valeur")
    plt.scatter(df.p, df.time_pol, label="Iteration de la politique")
    plt.scatter(df.p, df.time_pl, label="Programmation mathématique")

    plt.xlabel("Valeur de p")
    plt.ylabel("Durée d'execution")

    plt.show()