I am working on simulating crowds of a cross-typed region, given that pedestrians entering from 4 gates of north, east, west and south,
spacesize = 100;width = Floor[0.1 spacesize];
npeople = 10;nexit = 4;
entergates = {
{{u, 0}, {d, 0}},
{{u, spacesize}, {d, spacesize}},
{{0, u}, {0, d}},
{{spacesize, u}, {spacesize, d}}
} /. {u -> 0.5 (spacesize + width),
d -> 0.5 (spacesize - width)};(*position of gates*)
I would like to model that a person entering the region or not is decided by some probability. Such behavior is determined by some probability distribution with respect to time, I built a functions to control whether a person should enter the region or not, at some specific time.
Different interval of time would have different probability of giving 1 or 0. In here,
p={0.5,0.55,0.55,0.6,0.6,0.65,0.6,0.4,0.2,0.}
is the probability of showing 1 for each tine interval. If 1 is shown, the person enters from one of 4 gates. If the function gives 0, there would be no person enter until the function gives 1
timespan = ((60*(21 - 17)*60)/(10 60)) 2
prob[t_] := Module[{interval = ({#1 <= t <= #2}) & @@@
Table[{(i timespan)/(2 cc), ((i + 1) timespan)/(2 cc)}, {i, 0,
2 cc - 1}]}, Piecewise[Table[{p[[i]], interval[[i]]} // Flatten, {i, 1,Length[p]}]] ]
Below is the function showing enter or not, from t=0~t=timespan
enterprob[t_] := UnitStep[Random[] - (1 - prob[t])]
UnitStep[Random[] - (1 - prob[#])] & /@ Range[0, timespan];
So if this function works properly, I can get pedestrians enter as time evolves but I have difficulty implementing here.
How to add a person coming in for there are already some people inside?
Next I planned to solve equations from particle motion like below, fx, fy are forces to be determined but these settings are just preliminary, rough settings.
pos = Table[{Subscript[x, i][t], Subscript[y, i][t]}, {i, 1, npeople}];
xeqs = Table[Subscript[x, i]''[t] == Subscript[fx, i][pos], {i, 1, npeople}] ;(*x equations*)
yeqs = Table[Subscript[y, i]''[t] == Subscript[fy, i][pos], {i, 1, npeople}] ;(*y equations*)
xics = Table[Subscript[x, i][0] == Random[], {i, 1, npeople}];
yics = Table[Subscript[y, i][0] == Random[], {i, 1, npeople}];
vxics = Table[Subscript[vx, i][0] == 10 Exp[-(Random[])^2], {i, 1, npeople}];
vyics = Table[Subscript[vy, i][0] == 10 Exp[-(Random[])^2], {i, 1, npeople}];
(*Above are roughly settings*)
Sorry this long problem, and thank you for reading this.