Beispiel #1
0
    def test(self):
        lastcountshouldbe = 4

        logging.basicConfig(level=logging.WARN)
        # ensuring reproducibility by setting the seed
        np.random.seed(34756)
        xdim = 10
        ydim = 10
        n_tsteps = 8000  # because we cycle through the 100 sites each time, this represents 80K events
        g = igraph.Graph.Lattice([xdim, ydim],
                                 nei=1,
                                 directed=False,
                                 circular=False)
        agents = [Site(v) for v in g.vs]
        env = AxelrodEnvironment(g)
        time = dworp.BasicTime(n_tsteps)
        # ensuring reproducibility by setting the seed
        scheduler = dworp.RandomOrderScheduler(np.random.RandomState(4587))
        observer = AxelrodObserver(1000)
        term = AxelrodTerminator(1000)
        sim = dworp.TwoStageSimulation(agents,
                                       env,
                                       time,
                                       scheduler,
                                       observer,
                                       terminator=term)

        sim.run()

        lastcount = observer.computenumregions(0, agents, env)
        print("Last Count = %d" % (lastcount))
        if lastcount == lastcountshouldbe:
            print("Regression test passed!")
            return True
        else:
            print("Regression test failed! last count should be %d" %
                  (lastcountshouldbe))
            return False
Beispiel #2
0
        # get this simulation's seed
        curseed = seedlist[place]
        place = place + 1
        np.random.seed(curseed)
        timeobj = dworp.BasicTime(n_tsteps)
        # reset all the agent states
        agents = [
            axelrod_aurora_test1.Site(v, num_features, num_traits)
            for v in g.vs
        ]
        # ensuring reproducibility by setting the seed
        scheduler = dworp.RandomOrderScheduler(
            np.random.RandomState(curseed + 1))
        sim = dworp.TwoStageSimulation(agents,
                                       env,
                                       timeobj,
                                       scheduler,
                                       observer,
                                       terminator=term)
        sim.run()
        lastcount = observer.computenumregions(0, agents, env)
        allresults[i, k] = lastcount
        this_e_time = time.clock()
        alltimings[i, k] = this_e_time - this_s_time
try:
    end_time = time.clock()
    sim_time_minutes = float(end_time - start_time) / 60.0
    print("simulation finished after %.2f minutes" % (sim_time_minutes))
except:
    print("error here")
    pdb.set_trace()
Beispiel #3
0
        self.state.fill(0)

    def step(self, new_time, agents):
        self.state[self.TEMP] = np.random.randint(self.MIN_TEMP, self.MAX_TEMP)
        self.logger.info("Temperature is now {}".format(self.state[self.TEMP]))

    @property
    def temp(self):
        return self.state[self.TEMP]


class ShortsObserver(dworp.Observer):
    def step(self, time, agents, env):
        count = sum([agent.wearing_shorts for agent in agents])
        print("{}: Temp {} - Shorts {}".format(time, env.temp, count))

    def done(self, agents, env):
        print("Simulation over")


logging.basicConfig(level=logging.WARN)
g = igraph.Graph.Erdos_Renyi(n=100, p=0.05, directed=False)
agents = [CollegeStudent(v) for v in g.vs]
env = WeatherEnvironment(g)
time = dworp.BasicTime(10)
scheduler = dworp.BasicScheduler()
observer = ShortsObserver()
sim = dworp.TwoStageSimulation(agents, env, time, scheduler, observer)

sim.run()