Beispiel #1
0
        environment.append(rowlist)


#for j range (len(environment)):
#print("Environment ",len (environment))

#print("output ",pathname)
#write_outputfile(environment, pathname)

'''
STEP 3:      Generate Agents
'''
print("Generate agents. ")
for i in range(number_of_agents):
    random_seed += 1
    agentslist.append(af.Agent(environment,agentslist, random_seed))
    #print("agentslist after initialising: ",agentslist)
 
'''
STEP 4:      Agents Acting
  
Agents acting: moving and consumption of environment (eating and sharing).
In order to avoid model artifacts the order in which the agents are processed
is changed at each iteration, i.e. the list of agents is shuffled before action
is performed.
'''
print("Moving agents and consumption of environment")
for j in range (number_of_moves): 
    random.shuffle (agentslist)
    for i in range (number_of_agents):
        agentslist[i].move()
Beispiel #2
0
    for word in parsed_line:  #this cycles through each word in the identified line
        data_line.append(float(word))  #this appends each word as a float
    environment.append(
        data_line
    )  #The fata line (that is now a float) is appended to the environment list.
#print(data)
f.close()

num_of_agents = 10
num_of_iterations = 10
agents = []  # declare agent as a list
neighbourhood = 20

# Make the agents.
for i in range(num_of_agents):
    agents.append(agentframework7.Agent(environment, agents))
"""CODE TO PROVE IMPACT OF SHUFFLE
print('before')
for agent in agents:
    print(agent.x)
random.shuffle(agents)
print('after')
for agent in agents:
    print(agent.x)
"""

# Move the agents.
for j in range(num_of_iterations):
    random.shuffle(agents)
    for i in range(num_of_agents):
        agents[i].move()
Beispiel #3
0
    parsed_line = str.split(line, ",")
    rowlist = []
    for word in parsed_line:
        rowlist.append(float(word))
    environment.append(rowlist)
f.close()

#Set the number of agents, iterations and the neighbourhood.
num_of_agents = 10
num_of_iterations = 100
neighbourhood = 20
agents = []

#Make the agents.
for i in range(num_of_agents):
    agents.append(agentframework.Agent(agents, environment))

#Move the agents, have them eat and share their stores.
for j in range(num_of_iterations):
    for i in range(num_of_agents):
        random.shuffle(agents)
        agents[i].move()
        agents[i].eat()
        agents[i].share_with_neighbours(neighbourhood)

#Make a plot.
width = len(environment)
height = len(environment[0])
matplotlib.pyplot.xlim(0, width)
matplotlib.pyplot.ylim(0, height)
for i in range(num_of_agents):