Novel Integrated Framework for Crowd Simulation Qingge Ji* and Yugang Han School of Information Science and Technology, Sun Yat-sen University, Guangzhou, China issjqg@mail.sysu.edu.cn Abstract. In this paper, two intuitive and highly efficient solutions are proposed for global planning and local avoidance. We introduce guide and repel vectors to study global planning, which generates a steady and smooth navigation field through a simple and efficient bilinear interpo- lation method. In addition, this paper proposes a novel velocity-based approach to simulate the local avoidance of agents based on least-effort principle. During the local avoidance phase, humans slightly adjust their motions, so that the energy required to perform a step becomes minimal. The two solutions are integrated into one system, which finally simulates the natural-looking navigation and interaction behavior of agents. Keywords: Crowd Simulation, Global Planning, Navigation Fields, Lo- cal Avoidance, Least effort 1 Introduction As virtual reality technology develops, crowd simulation technology is paid in- creasing attention. According to different modeling granularities, existing crowd models can be generally classified into two categories, namely, macroscopic and microscopic approaches. The former models a crowd as continuous flow of fluid [1]. This technology is mainly useful in large and dense crowds but basically neglects the features of individuals. The latter models a crowd as a collective of homogeneous/heterogeneous entities with interactions among them, and the representative approaches include entity-based and agent-based. Individuals are modeled as a set of homogenous entities in the entity-based approach. A typ- ical example of this approach is Helbing’s social force model (SFM) [2]. The agent-based approach models each individual in a crowd as an intelligent and autonomous agent [3], in which each agent perceives its own state and reacts to dynamic entities in its neighborhood. The microscopic approach models are flexible, such that adding physical, social, and psychological factors can simu- late various interactive behavior. As a result, these models are the most popular ones. However, their computing cost is high. Jiang et al.[4] presented a semantic model for representing the complex environment, where the semantic informa- tion is described with a geometric level, a semantic level and an application level. The model promotes the interactions between pedestrians and the environment. 68 Kraayenbrink et al.[5] proposed semantic crowds that allowed one to re-use the same population for virtual environment. Main Contribution: Based on previous research, two intuitive and highly efficient solutions are proposed in this paper for global planning and collision avoidance. We introduce guide and repel vectors to study global planning, which gener- ates a steady and smooth navigation field through a simple and efficient bilinear interpolation method. In addition, we propose a novel velocity-based approach to simulating the collision avoidance of agents through the observation of human behavior in avoiding dynamic obstacles in real life. 2 Related Work In this section, we briefly discuss prior literature on global planning and local avoidance, which are the two key issues in crowd modeling technology. Global Planning: To navigate a complex environment, a high-level path plan- ning technology is needed. The most popular crowd navigation technologies in- clude graph search and potential fields. Graph-based algorithms are widely used in global planning [6]. Pettre et al. [7] proposed a graph structure that decom- poses a space into multilayered terrains to support fast graph search for multiple characters. Bandi et al. [8] extended A* algorithm to a 3D space and reproduced many interesting navigation behaviors. Roadmaps [9] and Voronoi diagrams [10] are recently introduced to crowd navigation. Potential fields are extensively s- tudied in robot motion planning [11]. Dapper et al. [12] introduced harmonic function to generate potential fields; thus, they would not fall into the local minimum and could simulate various navigation behaviors by adjusting the pa- rameters in the function. Moreover, many researchers have directly attempted to govern navigation by computing velocity fields based on environment description [13], designing velocity fields manually [14], or capturing the velocity fields from videos and user inputs [15]. Our global planning algorithm is inspired by [13]. We introduce two types of vectors, namely, repel and guide vectors. An efficient bilinear interpolation method is used to obtain smooth navigation fields. Local Avoidance: Collision should be avoided locally by adjusting movements when other agents become sufficiently close. Many local avoidance approaches have been proposed, including particle force interaction [16], geometric [17], and synthetic-vision models [18]. Many researchers have introduced velocity-based methods for collision avoidance recently. Paris and Pettre et al. [19] proposed a predictive approach and resolved potential collisions successfully. Karamouzas and Overmars [20] proposed a velocity-based approach by analyzing experimen- tal data and extended this approach to small groups [21]. Koh and Zhou [22] introduced a collision avoidance framework called relative frame. According to 69 the duality property of the relative frame and other constraints, they selected a collision-free velocity for an agent. Our local avoidance algorithm is inspired by the work of Koh and Zhou. We use a modified relative frame to predict the po- tential collision and select an optimal velocity for an agent. However, unlike Koh and Zhou, we adopt the least-effort principle and eventually obtain a realistic and natural-looking result. 3 Global Path Planning 3.1 Environment Decomposition and Organization To compute a global path to the goal for each agent, we decompose the envi- ronment into grids, which have different size and are represented by rectangles. When static obstacles are dense, our method will subdivide the environment until each mixed grid is almost occupied by obstacles; when static obstacles are sparse, our decomposition method roughly divides the environment into several grids, then merges the empty grids, and forms a large empty area. We use a four-connected graph to organize the empty grids. The connective graph is defined to be the graph that has a vertex for each grid and an edge between two vertices only if the corresponding grids share a segment on their boundaries. A path over this graph is computed, such that following the path from any vertex leads to the vertex corresponding to the grid containing the goal state. The resulting directed graph defines a successor for every grid, except the goal grid. The successor of a grid is the next grid on the path to the goal grid. Each grid with a successor is termed as an intermediate grid, and the intermediate grid has only one successor. Specially, the goal grid has no successor. See Figure 1 for an illustration. Fig. 1. Environment decomposed into grids and the corresponding connectivity and directed graphs. 3.2 Repel and Guide Vectors We assume that each grid has four adjacent grids (because the graph is four- connected). A grid must be set as the successor of the grid. The shared boundary is called exit face, and the others are called repel faces. See Figure 2 for an 70 illustration. To obtain a proper transition from the current grid to successor, we introduce two types of vector fields, i.e., those corresponding to grids in the decomposition, which we call guide vector fields, and those corresponding to faces, which we call repel vector fields. A guide vector field guides an agent through the grid to the exit face, which leads to the successor grid. Repel vector fields prevent an improper grid transition, i.e., a transition from the current grid to a grid that is not the successor is prohibited. For the repel vector on repel faces, its direction is orthogonal to the face and points inward. For the repel vector on the exit face, its direction is orthogonal to the exit face and points outward. The guide vector fields always point toward the exit face. In the case of the goal grid, all repel and guide vector fields point inward to the goal state. Fig. 2. Illustration for repel face, exit face, repel vector, and guide vector. The different sizes between adjacent grids pose a difficulty in choosing the appropriate repel or guide vector fields. Zhang et al. [23] proposed a method to resolve this problem. 3.3 Vector Interpolation To obtain a smooth transition from the current grid to successor for an agent, an efficient and simple bilinear interpolation method is used to compute the final repel vector Vrepel (Figure 3).We assume that the position of agent(xi ,yi ) is in grid C={(x1 , y1 ) , (x2 , y2 )}, and its successor is S={(x3 , y3 ) , (x4 , y4 )}, where {(x1 , y1 ) , (x2 , y2 )} and {(x3 , y3 ) , (x4 , y4 )} represent the upper left and lower right vertex coordinates of C and S, respectively. The repel vector set of grid C is F ={f0 , f1 , f2 , f3 }. x2 − xi xi − x1 y2 − yi yi − y1 Vrepel = ∗ f0 + ∗ f2 + ∗ f1 + ∗ f3 (1) x2 − x1 x2 − x1 y2 − y1 y2 − y1 71 Fig. 3. Computation of the final repel vector Vrepel . Considering that the grid size might differ, two cases are considered for f2 . Figure 4 shows that when the current position of agent (xi ,yi ) locates below the green-dotted line, f2 =fvirtual , when (xi ,yi ) locates above the green-dotted line, f2 =f21 . fvirtual represents the repel vector on the virtual face, and f21 represents the repel vector on the exit face. ( f21 yi > y3 ∧ yi < y4 f2 = (2) fvirtual yi ≥ y4 ∧ yi ≤ y2 Fig. 4. Selection of f2 in two cases. Assuming that the guide vector is Vguide , we calculate the linear interpola- tion between Vrepel and Vguide , and obtain the navigation vector at (xi ,yi ), denoted as Vnav . Vnav = α ∗ Vrepel + β ∗ Vguide (3) We suppose that α = 0.5 and β = 0.5. We can calculate the navigation vector of each spot in the configuration space using Equation (3). Disregarding other agents, each agent can move step by step along the direction of Vnav to the goal state. Figure 5(a) shows an example for the navigation fields, and Figure 5(b) shows the path of an agent moving from the initial point to the goal state. No steep turn exists in the corners, and the whole path is smooth, which vividly simulates the human behavior when turning in our real life. 72 Fig. 5. (a) Example for the navigation fields. The black rectangle denotes obstacle, and the red point denotes the goal state. (b) Path for an agent from the initial position to the goal state. 4 Local Collision Avoidance Two main challenges occur in local collision avoidance, namely, collision predic- tion and collision avoidance. In this section, we describe our collision avoidance model. 4.1 Problem Formulation In our problem setting, we are given a virtual environment where n agents PN={P1 , . . . , Pn } have to navigate toward their specified goal without collid- ing with the environment and with one another. For simplicity, we assume that each agent moves on a plane and is modeled as a disc with radius ri , and its personal space is modeled as a disc with radius ρi . At a fixed time t, the agent Pi is at the position xi (t), defined by the disc center, and moves with velocity vi (t). This velocity is limited by a maximum speed umaxi , i.e., kvi (t)k ≤ umax i . For notational convenience, we will not explicitly indicate the time dependence. In every simulation step, the agent Pi has a desired velocity vides (t), whose orientation is Vnav , which have been computed in Section 3, and magnitude is udes i , which is closely related to the crowd density ρ according to Fang et al. [24]. Vnav vides = udes i ∗ (4) kVnav k   max ui ρ ≤ ρmin des ρ−ρmin ui = umini max + ρmax −ρmin ∗ (ui min − ui ) ρmin < ρ < ρmax (5)   ū ρ ≥ ρmax In the above equations, ρmin and ρmax are the minimum and maximum crowd density thresholds, respectively. u is the average speed of all agents, which are in the vision range of Pi ’s vision range. 73 4.2 Collision Prediction An agent configuration is defined by its position and velocity. Koh and Zhou proposed a relative frame model for collision prediction. Source agent is denoted as the agent that avoids a target agent. Figure 6 shows the relative frame between a source agent and a target agent, where vr is the relative velocity between the source and target agents; θs and θg are the orientation of the source and target agents, respectively; θr is the relative orientation between the source and target agents. Rg =rg +ρs , it means that the target agent should not invade the personal space of the source agent. Fig. 6. Relative frame. The collision zone is defined as a region of space where the source agent should prevent collision with the target agent, i.e., collision is predicted in future if θrmin ≤ θr ≤ θrmax (6) and if the two agents do not change their speed and orientation. When a collision has been predicted, we then compute the time to collision (ttc); if ttc is less than a certain anticipation time t, the target agent is insert- ed into a set of agents that are on the collision course with the source agent. In real-life, an individual tries to avoid a limited number of other pedestrians, usually those that are on the collision course with him in the coming short time. Similarly, the source agent tries to evade N agents with which will collide first. In our implementation, N is less than 4. 4.3 Collision Avoidance The least-effort principle originates from the field of psychology and states that given different possibilities of actions, people select the one that requires the 74 least effort [25]. Based on least-effort theory, many systems for crowd simulation have been proposed [26], [27]. However, all these approaches aim to control the macroscopic (global) behavior of virtual humans, whereas our focus is on the local interactions of individuals. Based on the least-effort principle, we therefore hypothesize that an individual, upon interacting with other individual, tries to resolve potential collisions immediately by slightly adapting his motion. The individual will adjust his trajectory in advance, trying to reduce the interactions with the other walker. We describe our local avoidance algorithm below. We first retrieve a set of candidate relative orientation Or , such that the orientation of relative velocity can be selected to resolve the collision with the agents who are on the collision course. According to condition (6), the collision can be avoided if the source agent selects a new relative velocity vrnew , that satisfies the condition ¬(θrmin ≤ θrnew ≤ θrmax ) (7) To avoid unrealistic orientation deviate, we bound the max angle deviation θimax to π2 . We can compute Or by combining condition (7) and θimax . We then retrieve the set of candidate relative speed Ur . When Or is deter- mined, the max relative speed umaxr = vides +kvj k and the min relative speed umin r = vides − kvj k . Having retrieving Or and Ur , we select an optimal pair P =(ur ,θr ), where ur ∈ Ur ∧ θr ∈ Or , so that the expenditure energy for the source agent is minimum. See Figure 7(a) for an illustration. Fig. 7. (a)Selection of an optimal relative velocity for the source agent.(b)(c)Two cases for imminent collision:case(b)One agent enters into the personal space of other but they are not overlapping yet.case(c)Two agents have overlapped vinew = vrnew + vj (8) ∆ui = kvinew k − vides (9) vinew · vides ∆θi = arccos new (10) kvi k ∗ vides 75 In the above equations, ∆ui is the value for speed changed, and ∆i is the angle deviation of the source agent. The cost function is ∆ui ∆θi f (ur , θr ) = α ∗ + β ∗ max (11) umax θ where umax =1.5m/s is the maximal value for speed changed, and θmax = π2 is the maximum angle deviation. The constants α and β define the weights of specific cost terms and can vary among the agents to simulate a wide variety of avoidance behavior. Computing the minimum value of Equation (11) is time-consuming. Thus, we restrict the domain Or to a discrete set of orientation samples (the default size of the discretization step is set to 0.01π). Similarly, we discretize the domain Ur into a set of adjacent speed samples (the default distance between adjacent samples is set to 0.05). Assuming that the discretized set of Or is Or and that of Ur is Ur , then the set of admissible relative velocity is F AVr = {ur θr | ur ∈ Ur ∧ θr ∈ Or } (12) The discretized cost function is vrnew = argmin V cand ∈F AVr ( ) v cand + vj − vides (v cand + vj ) · vides (13) α∗ + β ∗ arccos cand umax kv + vj k ∗ vides Having retrieving vrnew , the optimal new velocity for the source agent is easy to compute. We then update the source agent position into xnew i = xi + vinew ∗ ∆t (14) 4.4 Resolve Imminent Collision We divide imminent collision into two cases (Figure 7(b)(c)). In case (b), we introduce the concept of relative tangential velocity, which is equivalent to ap- plying a tangential force to separate the two agents. In case (c), we introduce the concept of repel velocity, which is equivalent to applying a repulsive force to separate the two agents immediately. 4.5 Avoiding Static Obstacles An agent Ai also needs to avoid colliding with the static obstacles of the envi- ronment. In our simulations, such obstacles are modeled as axis aligned boxes. Collisions are resolved by following an approach similar to the one described above. We first retrieve the nearest obstacles of the agent Ai that are inside the visual field of the agent. We then compute the maximum and minimum orientations among the vectors lined from the current position of Ai ’s to each vertex of the convex polygon obstacle. The maximum and minimum orientations are θrmax and θrmin , respectively, which have been discussed above. Finally, we use a least-effort criterion to select an optimal velocity for the agent Ai . 76 5 Experimental Results We test our approach against a wide range of scenarios. These scenarios range from the simple interactions between pairs of agents to more challenging and large test cases as follows:  Squeeze: Two agents have to avoid a head-on collision while walking in an opposite direction (Figure 8(a)).  Overtake: An agent moves down a hallway and encounters a slower agent in front (Figure 8(b)).  Square: Four agents are placed on the vertex of a square and have to walk toward their diagonal position (Figure 8(c)).  Complex environment: Three hundred agents walk through an environment filled with many obstacles and have to evacuate from the exit (Figure 8(d)). Fig. 8. Scenarios: (a)-(c) interactions in simple environments; (d) three hundred agents evacuate from an obstacle-filled environment. 6 Conclusion In this paper, we present a novel integrated framework for navigation and in- teraction behavior. A creative global path planning algorithm and a bilinear interpolation method were used to compute the navigation fields. A least-effort criterion was also employed in the local avoidance to achieve realistic local move- ments. 7 Acknowledgement This research was supported by National Natural Science Foundation of China (No. 60473109), NSFC-Guangdong Union Foundation of China (No.U0735001). We would like to thank the anonymous reviewers for their suggestions and com- ments. 77 References 1. Treuille A, Cooper S, Popovi? Z. Continuum crowds[C]. ACM Transactions on Graphics (TOG). ACM, 2006, 25(3): 1160-1168. 2. Helbing D, Molnar P. Social force model for pedestrian dynamics[J]. Physical re- view E, 1995, 51(5): 4282-4286.) 3. Shao W, Terzopoulos D. Autonomous pedestrians[C]. Proceedings of the 2005 ACM SIGGRAPH/Eurographics, 2005: 19-28. 4. Hao Jiang, et al., A Semantic Environment Model for Crowd Simulation in Mul- tilayered Complex Environment. VRST 2009, Kyoto, Japan, November 18 C 20, 2009. pp191-198 5. Kraayenbrink N, Kessing J, Tutenel T, et al. Semantic crowds. Entertainment Computing[J], 2014(5):297-312 6. Paris S, Donikian S, Bonvalet N. Environmental abstraction and path planning techniques for realistic crowd simulation[J]. Computer Animation and Virtual Worlds, 2006, 17(3-4): 325-335. 7. Pettre J, Laumond J P, Thalmann D. A navigation graph for real-time crowd animation on multilayered and uneven terrain[C]. First International Workshop on Crowd Simulation. 2005, 43(44): 194-202. 8. Bandi S, Thalmann D. Space discretization for efficient human navigation[C]. Com- puter Graphics Forum. Blackwell Publishers Ltd, 1998, 17(3): 195-206. 9. Bayazit O B, Lien J M, Amato N M. Better Group Behaviors in Complex Envi- ronments using Global Roadmaps[J]. Artificial Life 8, 2003: 362-371. 10. Sud A, Andersen E, Curtis S, et al. Real-time path planning in dynamic virtual environments using multiagent navigation graphs[J]. Visualization and Computer Graphics, IEEE Transactions on, 2008, 14(3): 526-538. 11. Philippsen R, Siegwart R. An interpolated dynamic navigation function[C]. Robotics and Automation, 2005. ICRA 2005. Proceedings of the 2005 IEEE Inter- national Conference on. IEEE, 2005: 3782-3789. 12. Dapper F, Prestes E, Idiart M A P, et al. Simulating pedestrian behavior with potential fields[M]. Advances in Computer Graphics. Springer Berlin Heidelberg, 2006: 324-335. 13. Lindemann S R, LaValle S M. Simple and efficient algorithms for computing s- mooth, collision-free feedback laws over given cell decompositions[J]. The Interna- tional Journal of Robotics Research, 2009, 28(5): 600-621. 14. Park M J. Guiding flows for controlling crowds[J]. The Visual Computer, 2010, 26(11): 1383-1391. 15. Patil S, Van Den Berg J, Curtis S, et al. Directing crowd simulations using naviga- tion fields[J]. Visualization and Computer Graphics, IEEE Transactions on, 2011, 17(2): 244-254. 16. Karamouzas I, Heil P, van Beek P, et al. A predictive collision avoidance model for pedestrian simulation[M]. Motion in Games. Springer Berlin Heidelberg, 2009: 41-52. 17. Van den Berg J, Lin M, Manocha D. Reciprocal velocity obstacles for real-time multi-agent navigation[C]. Robotics and Automation, 2008. ICRA 2008. IEEE In- ternational Conference on. IEEE, 2008: 1928-1935. 18. Ondr̆ej J, Pettr J, Olivier A H, et al. A synthetic-vision based steering approach for crowd simulation[J]. ACM Transactions on Graphics (TOG), 2010, 29(4): 123-131. 19. Paris S, Pettr J, Donikian S. Pedestrian reactive navigation for crowd simulation: a predictive approach[C]. Computer Graphics Forum. Blackwell Publishing Ltd, 2007, 26(3): 665-674. 78 20. Karamouzas I, Overmars M. Simulating human collision avoidance using a velocity- based approach[C]. Workshop in Virtual Reality Interactions and Physical Simu- lation. The Eurographics Association, 2010: 125-134. 21. Karamouzas I, Overmars M. Simulating and evaluating the local behavior of small pedestrian groups[J]. Visualization and Computer Graphics, IEEE Transactions on, 2012, 18(3): 394-406. 22. Wee Lit Koh and SuiPing Zhou. Modeling and Simulation of Pedestrian Behavior in Crowded Places. ACM Transactions on Modeling and Computer Simulation, 2011, 21(3): 20-42. 23. Zhang L, LaValle S M, Manocha D. Global vector field computation for feedback motion planning[C]. Robotics and Automation, 2009. ICRA’09. IEEE International Conference on. IEEE, 2009: 477-482. 24. Fang Z, Lo S M, Lu J A. On the relationship between crowd density and movement velocity[J]. Fire Safety Journal, 2003, 38(3): 271-283. 25. George K. Zipf. Human behavior and the principle of least effort[J]. Addison- Wesley, 1949. 3. 26. Safonova A, Hodgins J K. Construction and optimal search of interpolated motion graphs[C]. ACM Transactions on Graphics (TOG). ACM, 2007, 26(3): 106-116. 27. Guy S J, Curtis S, Lin M C, et al. Least-effort trajectories lead to emergent crowd behaviors[J]. Physical Review E, 2012, 85(1): 016110.