Esempio n. 1
0
        # generate initial positions
        self.x = np.random.normal(0, 1, self.n)
        self.y = np.random.normal(0, 1, self.n)


class PointsVisual(simcx.MplVisual):
    def __init__(self, sim: RandomParticles):
        super(PointsVisual, self).__init__(sim)

        # create initial plot
        self.ax = self.figure.add_subplot(111)
        self.ax.set_xlim(-4, 4)
        self.ax.set_ylim(-4, 4)
        self.l, = self.ax.plot(self.sim.x, self.sim.y, '.')

    def draw(self):
        self.l.set_data(self.sim.x, self.sim.y)


if __name__ == '__main__':
    sim = RandomParticles()
    vis = PointsVisual(sim)
    display = simcx.Display()
    display.add_simulator(sim)
    display.add_visual(vis)

    # record the simulation on video
    display.start_recording('random.mp4')

    simcx.run()
    plt.close()
    '''

    # probabilistic
    for kind in list_of_kinds:
        for regenerate in list_of_regenerate:
            np.random.seed(911 + 112)
            gol = WildFires(250, 150, 5, 0.8, regenerate, 0.8, 3, 10, kind, True)
            gol.random(0.7)

            display = simcx.Display(interval=0.01)
            display.add_simulator(gol)
            display.paused = False
            gol.display = display

            simcx.run()

            print("NUMBER OF INTERACTIONS: ", gol.count_iteration)
            print("NUMBER OF OBSTACLES: ", gol.number_obstacles)
            print("SURVIVED FOREST: ", gol.survived_area)
            print("BURNED FOREST: ", gol.burned_area)

            plt.figure()
            plt.xlabel('Number of iterations')
            plt.ylabel('Number of fields')
            plt.plot(gol.burning_area_list, label="Burning", color="r")
            plt.plot(gol.burned_area_list, label="Burned", color="b")
            plt.plot(gol.survived_area_list, label="Forest", color="g")
            plt.plot(gol.number_obstacles_list, label="Obstacles", color="#A52A2A")
            plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
            plt.savefig("graphic_" + str(kind) + "_" + str(regenerate) + "_0.7.png", bbox_inches='tight')