Simulation- Let Birds Migrate!

Junyu Cao
Data Mining the City
6 min readOct 17, 2018

A simulation helps to find out the most suitable path for birds’ migration

Authors - Jianqi Li(jl5212), Junyu Cao(jc5040), Zeyi Jiang(zj2243)

The sustainability of ecosystem and biodiversity is essential to both human’s life and our planet. Birds migration is one of important part of our ecosystem. Every year, millions of birds migrate from one place to another. However, migration is a perilous journey and involves a wide range of threats which include habitats fragmentation, human activities and decline of food resources. In-between habitats should be protected and proposed for migrating birds to rest on and find food. Basically, we want to utilize the simulation model to simulate the migratory pathways and living environment of birds and find the one that works best for them, so we can give valuable information and suggestion to urban design.

Model

The final Model

Individuals (agents): migration birds

Environment: a region near the migration route, which includes the habitats, cities natural geography they will potentially cross.

Behavior:

Within the distance the birds have enough energy to fly through, if there exist the habitat which fits to birds’ requirement, the birds will fly to that place directly. (no curve)

When arrive the habitat, the birds will research the next stop with the same strategy.

When birds come across the wind flow area, the wind flow can result in either increasing or decreasing the energy and the speed of birds’ migrating, depending on the direction of both wind flow and birds flight.

Parameters:

The furthest distance of birds for each time which changes when birds come across the airflow.

The flying direction of a bird.

Their preference for habitat types, including types of vegetation (forest, crop, wetland), types of food resource, water resource, etc.

Input:

The starting and ending point of the specific migration bird.

The location of habitats with its characteristic information, including vegetation types, food resource types and amount, water resources, etc.

The location of windflow area, the direction and the strength of the wind.

Output:

After simulation we consider to select one or two routes with the lowest energy cost for migration birds within the specific limited time (we think that long time may cause birds miss their best time to habitat in new space). We can test all the possible route and choose ones fit for the above requirement. With the consideration of current urban fabric and future urban development these proposals can contribute to where is the best choice of preservation habitats for both birds and urban development.

Current model

Step 1: we select two points representing the starting point and ending point of birds’ migration.

Step 2: we randomly generate a specific number of points in our environment to represent the potential in-between habitat for migration point.

We connected every two points and calculate their total distance ( The distance represents the energy in our final model).

Step 3: We set a value and filter out all paths whose total distance exceed the value to get all potential migration paths.

Step 4: We filter the path with the shortest distance from all the potential migration paths.

Learning & Future Implications

We want to analyze what kind of in-between habitat does birds need for migration through analyzing their flying duration, food resources and the effect of wind. Through our simulation, we can find out one or two routes which may be best for their migration which can be used as a reference information for urban design for the future. For examples, in small scale, the model can suggest designers what kinds of vegetation should they plant (as food resources for birds) in the park near the potential in-between habitats. In the big scale, it can give information to help to preserve natural landscape or even create a more livable environment for the migratory birds. In the future, as global warming and other natural issues become more serious, protecting our biodiversity and ecosystem will be essential for human’s survival. So for urban designers, they not only need to design suitable environment for human-being, but also design a more sustainable ecosystem for all living creatures in our planet. If we had a magic wand, maybe the simulation could be simulating what all different kinds of creature need for their habitat, and considering all aspects can guide designers to develop a more sustainable environment.

Code

import random
import itertools
import math
import heapq
def gen_points(unit=100., size=8, n=20): #random n points+start and end point and remove the same point
grid_points = [(unit * (i+0.2), unit * (j+0.2)) for i in range(size + 1) for j in range(size + 1)]
random.shuffle(grid_points)
return set(grid_points[: n] + [(unit * 1, unit * 1), (unit * (size - 1), unit * (size - 1))])
def euclid(pair): #calculate the distance between two different points
return math.sqrt((pair[0][0] - pair[1][0]) ** 2 + (pair[0][1] - pair[1][1]) ** 2)
def gen_dist_dict(points_set, a=400.): #generate the graphy, select the possible route
dist_dict = dict()
for pair in itertools.permutations(points_set, 2):
d = euclid(pair)
if d > a:
continue
if pair[0] not in dist_dict:
dist_dict[pair[0]] = dict()

dist_dict[pair[0]][pair[1]] = euclid(pair)

return dist_dict
genpoints= gen_points()
g = gen_dist_dict(genpoints)
def init_distance(g,s): #part of dijkstra
distance = {s:0}
for vertex in g:
if vertex != s:
distance[vertex]=99999
return distance
def dijkstra(g,s): #find the shortest route
pqueue = []
heapq.heappush(pqueue,(0,s))
seen = set()

parent = {s:None}
distance =init_distance(g,s)

while (len(pqueue)>0):
p = heapq.heappop(pqueue)
dist = p[0]
vertex = p[1]
seen.add(vertex)
nodes = g[vertex].keys()

for w in nodes:
if w not in seen:
if dist + g[vertex][w]< distance[w]:
heapq.heappush(pqueue,(dist + g[vertex][w],w))
parent[w] = vertex
distance[w]= dist + g[vertex][w]
assert (700,700) in parent, 'Not connected'
return parent, distance
parent, distance = dijkstra(g,(100,100))
text_distance= distance[(700,700)]
print text_distance
v = (700,700)#find the shorcutpoint list
shortcut_points = [(700,700)]
while v!= None:
v= parent[v]
shortcut_points.append(v)
def setup():
frameRate(5)
size(1000,1000)
img=loadImage("map.jpg")
img2=loadImage("habitat.png")


global xbird,ybird
xbird=700
ybird=700

image(img,0,0,1000,1000)

c= [d for d in genpoints]#draw the random points(includes start and end)
for x in range(len(c)):
fill(255,255,255)
ellipse(c[x][0],c[x][1],10,10)
image(img2,c[x][0]-25,c[x][1]-35,70,70)



fill(255,0,0)#color the start and end points
ellipse(100,100,15,15)
ellipse(700,700,15,15)


for pair in itertools.permutations(genpoints, 2):#link the possible routes
d = euclid(pair)
if d > 400.:
continue
stroke(255,255,255)
strokeWeight(0.5)
line(pair[0][0],pair[0][1],pair[1][0],pair[1][1])
c=pair[1][0]-pair[0][0]
d=pair[1][1]-pair[0][1]
for i in range(len(shortcut_points)-2):#draw the shortcut
stroke(255,0,0)
strokeWeight(3)
line(shortcut_points[i][0],shortcut_points[i][1],
shortcut_points[i+1][0],shortcut_points[i+1][1])
def draw():

global xbird,ybird,xdirection,ydirection,img3,img #birds fly
img=loadImage("map.jpg")
img3=loadImage("bird.png")
if xbird>shortcut_points[1][0]:
xdirection=shortcut_points[1][0]-shortcut_points[0][0]
ydirection=shortcut_points[1][1]-shortcut_points[0][1]
elif xbird<shortcut_points[1][0] and xbird>shortcut_points[2][0]:
xdirection=shortcut_points[2][0]-shortcut_points[1][0]
ydirection=shortcut_points[2][1]-shortcut_points[1][1]
elif xbird<shortcut_points[2][0] and xbird>shortcut_points[3][0]:
xdirection=shortcut_points[3][0]-shortcut_points[2][0]
ydirection=shortcut_points[3][1]-shortcut_points[2][1]
distotal=sqrt(ydirection*ydirection+xdirection*xdirection)
xbird+=30*xdirection/sqrt(ydirection*ydirection+xdirection*xdirection)
ybird+=30*ydirection/sqrt(ydirection*ydirection+xdirection*xdirection)
image(img3, xbird, ybird,50,50)
if xbird<100:
xbird=100
ybird=100





fill(255,255,255)
textSize(16)
text("Shortest Distance:",100,800)
text(text_distance,250,800)

--

--