# [0]: Fraction of N still alive (1 means no collision) # [1]: Fraction of still alive Mobot’s in the largest connected component (1 means all connected) # [2]: Cohesion radius (maximum distance to centroid) divided by sqrt(N) * ”good distance” # [3]: Average square (error to “good distance” divided by “good distance”) # [4]: Effect of steering vector components # [5]: ... # [6]: ... # [7]: ... #p=KPIdata(name,7,TS) N = 50 period = 0.1 total_time = 5 * 60 steps = int(total_time / period) s.spawn_bodies(N, room=[(-4, -4), (4, -4), (4, 4), (-4, 4)]) for b in s.bodies: if isinstance(b, Mobot): Boid(b, s, R, 0.1 * TS) # ADD YOUR ARGUMENTS data_gather = [] KPI = [0, 0, 0, 0, 0, 0, 0, 0] for i in tqdm(range(steps + 1)): # KPI[2] centroid_pos = Point2D(0.0, 0.0) for b in s.bodies: if isinstance(b, MoBody): b.update() s.update_dist()
p = KPIdata(name, 2, TS) # a big nest in the second quadrant: bignest = Nest('BigNest', pos=(uniform(-0.8 * W, -0.2 * W), uniform(0.4 * H, 0.6 * H)), area=0.02, fc=(0, 0, 1)) smallnest = Nest('SmallNest', pos=(uniform(0.8 * W, 0.2 * W), uniform(-0.4 * H, -0.6 * H)), area=0.04, fc=(1, 0, 0)) # s.bodies.append(bignest) s.bodies.append(smallnest) N = 100 s.spawn_bodies(nm=N) for b in s.bodies: if isinstance(b, Mobot): b.cmd_vel(v=b.v_max / 2) # a new Soul for b (who assigns new Knowledge too) Demo(b, s, TS / 10, r=2, rng=np.pi / 2) b.knows.set_state('Random_Walk') # [ fraction of live mobots who know ThereAreNests , fraction of initial robots still alive ] KPI = [0, 1] end = False numero = 0 while not end: numero = numero + 1 for b in s.bodies: if isinstance(b, Mobot):
## License: CC-BY-SA from time import time_ns, time, localtime, strftime import numpy as np from random import uniform from matplotlib.animation import FFMpegWriter # requires having ffmpeg installed, from https://ffmpeg.org/ from small_worl2d_config import visual, TS, RT, room from small_worl2d import Space, KPIdata, Mobot, Voronoid ## MAIN name = 'BasicVoronoids' + strftime("%Y%m%d%H%M", localtime()) s = Space(name, T=RT, R=0, limits='') # No comm p = KPIdata(name, 1, 2 * TS) s.spawn_bodies(100) # Mobots only for b in s.bodies: if isinstance(b, Mobot): Voronoid( b, s, 5, T=uniform(TS, 2 * TS), Q=room ) # rng=uniform(0.75*np.pi,0.95*np.pi) would be WithoutRearView KPI = [1] end = False while not end: for b in s.bodies: if isinstance(b, Mobot): b.update() s.update_dist() s.remobodies(s.collisions()) s.update_conn() if visual and time() > s.t0 + (s.updates + 1) * s.T: