Beispiel #1
0
    def __init__(self):
        super().__init__()

        self.end_condition = end_condition
        self.trackers["agent_count"] = analysis.AgentTypeCountTracker()

        io_file_name = "bacteria_intelligent.qlearning.pkl"
        self.bacteria_decision = decision.QLearningDecision(
            perception=bacteria_perception,
            loss=bacteria_loss,
            simulation=self,
            input_file_name=io_file_name,
            output_file_name=io_file_name,
            nonconformity_probability=0)
        self.trackers["qlearning"] = analysis.QLearningHistoryTracker(
            self.bacteria_decision)

        # create bacteria agents
        for i in range(5):
            for j in range(5):
                self.agents.add(
                    Bacteria(np.array([10 * i, 10 * j], dtype=np.float),
                             self.bacteria_decision))

        # create yogurt agents
        for i in range(20):
            for j in range(20):
                self.agents.add(
                    Yogurt(np.array([5 * i, 5 * j + 50], dtype=np.float)))
Beispiel #2
0
def test_exponential_agent_type_count():
    from adjsim import core, analysis, decision
    from matplotlib import pyplot

    def increment_agents(env, source):
        env.agents.add(TestAgent())

    class TestAgent(core.Agent):
        def __init__(self):
            super().__init__()
            self.actions["increment"] = increment_agents
            self.decision = decision.RandomSingleCastDecision()

    test_sim = core.Simulation()
    test_sim.agents.add(TestAgent())
    test_sim.trackers["count"] = analysis.AgentTypeCountTracker()

    common.step_simulate_interpolation(test_sim)

    assert test_sim.trackers["count"].data[TestAgent] == [
        2**i for i in range(common.INTERPOLATION_NUM_TIMESTEP + 1)
    ]

    test_sim.trackers["count"].plot(block=False)
    pyplot.close()
Beispiel #3
0
    def __init__(self):
        super().__init__()

        self.end_condition = end_condition
        self.trackers["agent_count"] = analysis.AgentTypeCountTracker()

        self.bacteria_decision = decision.RandomRepeatedCastDecision()

        # create bacteria agents
        for i in range(5):
            for j in range(5):
                self.agents.add(
                    Bacteria(np.array([10 * i, 10 * j], dtype=np.float),
                             self.bacteria_decision))

        # create yogurt agents
        for i in range(20):
            for j in range(20):
                self.agents.add(
                    Yogurt(np.array([5 * i, 5 * j + 50], dtype=np.float)))
Beispiel #4
0
def test_agent_add():
    from adjsim import core, analysis, decision

    def addition_callback(agent):
        addition_callback.count += 1
    addition_callback.count = 0

    def increment_agents(env, source):
        env.agents.add(TestAgent()) 

    class TestAgent(core.Agent):
        def __init__(self):
            super().__init__()
            self.actions["increment"] = increment_agents
            self.decision = decision.RandomSingleCastDecision()

    test_sim = core.Simulation()
    test_sim.callbacks.agent_added.register(addition_callback)
    test_sim.agents.add(TestAgent())
    test_sim.trackers["count"] = analysis.AgentTypeCountTracker()
    
    common.step_simulate_interpolation(test_sim)

    assert addition_callback.count == 2**common.INTERPOLATION_NUM_TIMESTEP