Skip to content
Extraits de code Groupes Projets
plot.py 1,74 ko
Newer Older
  • Learn to ignore specific revisions
  • Adrien Payen's avatar
    Adrien Payen a validé
    import matplotlib.pyplot as plt
    from simulate import Validation as Val
    from tmc import TransitionMatrixCalculator as tmc
    from markovDecision import MarkovDecisionSolver as mD
    import random as rd
    import numpy as np
    
    
    def plot_results(layouts, circle, n_iterations=100):
        results_markov = []
        results_safe = []
        results_normal = []
        results_risky = []
        results_random = []
    
        for layout in layouts:
            # Compute optimal policy
            expec, policy = mD(layout, circle)
    
            # Simulate game
            result_markov = Val.simulate_game(policy, layout, circle, n_iterations)
            results_markov.append(result_markov)
    
            result_safe = Val.simulate_game([1]*15, layout, circle, n_iterations)
            results_safe.append(result_safe)
    
            result_normal = Val.simulate_game([2]*15, layout, circle, n_iterations)
            results_normal.append(result_normal)
    
            result_risky = Val.simulate_game([3]*15, layout, circle, n_iterations)
            results_risky.append(result_risky)
    
            result_random = Val.simulate_game(np.random.randint(1, 4, size=15), layout, circle, n_iterations)
            results_random.append(result_random)
    
        # Plot the results
        plt.figure(figsize=(12, 8))
        plt.plot(range(len(layouts)), results_markov, label='Markov')
        plt.plot(range(len(layouts)), results_safe, label='Safe')
        plt.plot(range(len(layouts)), results_normal, label='Normal')
        plt.plot(range(len(layouts)), results_risky, label='Risky')
        plt.plot(range(len(layouts)), results_random, label='Random')
    
        plt.xticks(range(len(layouts)), range(len(layouts)))
        plt.xlabel('Layout number', fontsize=13)
        plt.ylabel('Average number of turns', fontsize=13)
        plt.legend(loc='upper left', bbox_to_anchor=(1, 1), ncol=1)
        plt.show()