3

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.

Andy Huang
  • 141
  • 3
  • Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – Michael E2 Jan 05 '15 at 04:27
  • I am new to here, thank you! – Andy Huang Jan 05 '15 at 04:29
  • I would suggest getting the constant-probability-of-entry case working first. Also, you might have better results if you don't use subscripts. Have a look at some of the suggestions in this question. – Verbeia Jan 05 '15 at 04:35
  • I use subscripts is to generate a set of differential equations quickly and make them look similar, is there better methods? – Andy Huang Jan 05 '15 at 04:41
  • Subscript: see this, second bullet. – Sjoerd C. de Vries Jan 05 '15 at 06:38
  • This title is very misleading, and nearly useless to future visitors to this site. Craft a title that centers on the specific problem that will be of use to the most people in the future. (Almost nobody will be doing a simulation of pedestrians in crowds.) Moreover, "adding" doesn't seem like the heart of your problem. – David G. Stork Jan 06 '15 at 00:03
  • Thank you, I've modified the title into "controlling" – Andy Huang Jan 06 '15 at 02:41
  • I like this question, you do, however, make no mention of any people exiting the room, if any. What is the goal of this simulation? – Bob Brooks Dec 17 '15 at 21:52

0 Answers0