示例#1
0
        patch2 = patches2[patch_position]
        if not compare_patches(patch1, patch2):
            print("Patch at " + str(patch_position) + " differs.")
            equal = False
    for patch_position, patch2 in patches2.items():
        if patch_position not in patches1:
            print("Patch at " + str(patch_position) +
                  " is in the second simulator but not the first.")
            equal = False
    return equal


# create two simulators
save_frequency = 50
config = make_config()
sim1 = nel.Simulator(sim_config=config)
sim2 = nel.Simulator(sim_config=config,
                     save_filepath="./temp/simulator_state",
                     save_frequency=save_frequency)

# add one agent to each simulator
agent_type = SimpleAgent
agent1 = agent_type(sim1)
agent2 = agent_type(sim2)

# start main loop
start_time = default_timer()
elapsed = 0.0
sim_start_time = sim2.time()
(min_agent_position_x, min_agent_position_y) = (0, 0)
(max_agent_position_x, max_agent_position_y) = (0, 0)
示例#2
0
cv = Condition(Lock())
waiting = False


def on_step():
    global waiting
    cv.acquire()
    waiting = False
    cv.notify()
    cv.release()


# create new simulator server
config = make_config()
sim = nel.Simulator(sim_config=config,
                    is_server=True,
                    on_step_callback=on_step)

# add agents to simulator
agents = []
while len(agents) < 1:
    print("adding agent " + str(len(agents)))
    try:
        agent = EasterlyAgent(sim)
        agents.append(agent)
    except nel.AddAgentError:
        pass

    # move agents to avoid collision at (0,0)
    waiting = True
    for agent in agents:
示例#3
0
            nel.RelativeDirection.LEFT, nel.RelativeDirection.RIGHT
        ],
        patch_size=32,
        gibbs_num_iter=10,
        items=items,
        agent_color=[0.0, 0.0, 1.0],
        collision_policy=nel.MovementConflictPolicy.FIRST_COME_FIRST_SERVED,
        decay_param=0.4,
        diffusion_param=0.14,
        deleted_item_lifetime=2000)


if __name__ == "__main__":
    # create a local simulator
    config = make_config()
    sim = nel.Simulator(sim_config=config)

    # add agents to the simulation
    agents = []
    while len(agents) < 1:
        print("adding agent " + str(len(agents)))
        try:
            agent = SimpleAgent(sim)
            agents.append(agent)
        except nel.AddAgentError:
            pass

        # move agents to avoid collision at (0,0)
        for agent in agents:
            agent.do_next_action()
示例#4
0
    global waiting
    cv.acquire()
    waiting = False
    cv.notify()
    cv.release()


def on_lost_connection():
    global running
    running = False
    cv.notify()


# connect to server
sim = nel.Simulator(server_address="localhost",
                    on_step_callback=on_step,
                    on_lost_connection_callback=on_lost_connection)

# add agents to simulator
agents = []
while len(agents) < 1:
    print("adding agent " + str(len(agents)))
    try:
        agent = SimpleAgent(sim)
        agents.append(agent)
    except nel.AddAgentError:
        pass

    # move agents to avoid collision at (0,0)
    waiting = True
    for agent in agents:
示例#5
0
 def __init__(self, config):
     self.simulator = nel.Simulator(sim_config=config)
     self.prev_viz = np.zeros((3, 3, 3))
     self.prev_jelly_count = 0.0