@@ -88,7 +88,7 @@ def place_random_agents(agent_type, groups, max_agents, cluster=False):
8888 self .barn .place_agent (Bed (self ), (x , y ))
8989 self .barn .sleep_positions .append ((x ,y ))
9090
91- place_random_agents ('wall' , groups = 10 , max_agents = 10 )
91+ place_random_agents ('wall' , groups = 30 , max_agents = 10 )
9292 place_random_agents ('grass' , groups = 5 , max_agents = 5 )
9393 place_random_agents ('water' , groups = 5 , max_agents = 3 )
9494 place_random_agents ('feeder' , groups = 5 , max_agents = 2 )
@@ -107,27 +107,33 @@ def place_random_agents(agent_type, groups, max_agents, cluster=False):
107107 def random_pos (self ):
108108 x = random .randrange (config ["barn_height" ])
109109 y = random .randrange (config ["barn_width" ])
110+ while not self .barn .is_cell_empty ((x ,y )):
111+ x = random .randrange (config ["barn_height" ])
112+ y = random .randrange (config ["barn_width" ])
110113 return (x , y )
111114
112115 def state (self ):
113116 debug_cow = next (cow for cow in self .cows if cow .debug )
114117 dead = len ([cow for cow in self .cows if not cow .alive ])
115- water = [cow .water for cow in self .cows ]
116- # print("Mean:", numpy.mean(results), " Median:", numpy.median(results), " Stdev:", numpy.std(results))
118+ water = [cow .water for cow in self .cows if cow . alive ]
119+ stuck_recalc = [ cow . stuck_recalc for cow in self . cows if cow . alive ]
117120 return {
118121 "model" : {
119122 "dead" : dead ,
120123 "water_mean" : numpy .mean (water ),
121124 "water_median" : numpy .median (water ),
122125 "water_stdev" : numpy .std (water ),
126+ "stuck_recalc_mean" : numpy .mean (stuck_recalc ),
127+ "stuck_recalc_median" : numpy .median (stuck_recalc ),
128+ "stuck_recalc_stdev" : numpy .std (stuck_recalc ),
129+ "step" : self .step ,
123130 },
124- "barn" : self .barn .state (),
125- "step" : self .step ,
126131 "debug_cow" : debug_cow ,
132+ "barn" : self .barn .state (),
127133 }
128134
129135 def human_readable_state (self , state ):
130- output = "Step: {}\n " .format (state ["step" ])
136+ output = "Step: {}\n " .format (state ['model' ][ "step" ])
131137 grid = state ["barn" ]["grid" ]
132138 debug_cow_path = state ["debug_cow" ].current_path
133139 debug_cow_state = state ["debug_cow" ].state ()
@@ -152,19 +158,19 @@ def json_state(self, state):
152158 grid = state ["barn" ]["grid" ]
153159 debug_cow_path = state ["debug_cow" ].current_path
154160 debug_cow_state = state ["debug_cow" ].state ()
155- model = state ["model" ]
156161 w , h = len (grid ), len (grid [0 ])
157- to_json = [[[] for x in range (h )] for y in range (w )]
162+ grid_json = [[[] for x in range (h )] for y in range (w )]
158163 for x in range (len (grid )):
159164 for y in range (len (grid [x ])):
160165 if grid [x ][y ]:
161- to_json [x ][y ] = [a .state () for a in grid [x ][y ]]
166+ grid_json [x ][y ] = [a .state () for a in grid [x ][y ]]
162167 elif (x , y ) in debug_cow_path :
163- to_json [x ][y ] = []
168+ grid_json [x ][y ] = [{ 'type' : '*' } ]
164169 else :
165- to_json [x ][y ] = []
170+ grid_json [x ][y ] = []
166171
167- return to_json
172+ return {'barn' : grid_json ,
173+ 'simulation' : state ['model' ]}
168174
169175 def run (self ):
170176 for s in range (self .config ["steps" ]):
0 commit comments