Swarms and Crowds

download Swarms and Crowds

of 37

  • date post

  • Category


  • view

  • download


Embed Size (px)


Swarms and Crowds. Kristen Gardner. Outline. Swarm Intelligence Flocking Basic Steering Swarms Applications Animals Vehicles People. Swarm Intelligence. What is it? Artificial intelligence that is based on collective behavior of decentralized, self organized systems Examples? - PowerPoint PPT Presentation

Transcript of Swarms and Crowds

Slide 1

Swarms and CrowdsKristen Gardner1OutlineSwarm IntelligenceFlockingBasicSteeringSwarmsApplicationsAnimalsVehiclesPeople2Swarm IntelligenceWhat is it?Artificial intelligence that is based on collective behavior of decentralized, self organized systemsExamples?Flocks of birds, schools of fish (Boids)Ant colonyBees

3What is Flocking?An example of emergent behavior which resembles the motion of a flock of birds, school of fish, or swarm of insects

First simulated on a computer in 1986 by Craig Reynolds program Boids

Considered emergent because unexpected behavior may occur when flocks split up and reunite to avoid obstacles4How Does Flocking Work?The behavior of each Boid is individual, but conforms to a few, relatively simple, rulesSeparationAlignmentCohesionOther, more complex rules may also be addedObstacle avoidanceGoal seeking

5Basic Rulesseparation: steer to avoid crowding local flock mates

alignment: steer towards the average heading of local flock mates

cohesion: steer to move toward the average position of local flock mates

6Field of ViewTo keep things realistic, respond only to the actions of neighboring Boids ExampleFancy Example

7Algorithmic ComplexityBasic un-optimized implementation is O(n2)Each Boid must calculate its distance from each other Boid

Basic optimized implementation is O(kn)Area the flock inhabits is divided into a grid with each Boid in a binEach Boid only needs to check its position relative to Boids in its (or neighboring) bins8Using SteeringModelmass (scalar) position (vector) velocity (vector) max_force (scalar) max_speed (scalar) orientation (N basis vectors)

Euler Integration for animationsteering_force = truncate (steering_direction, max_force) acceleration = steering_force / mass velocity = truncate (velocity + acceleration, max_speed) position = position + velocity 9Steering BehaviorsSeek and FleePursue and EvadeWanderArrivalWall FollowingPath FollowingFlow Field Following10Seek and FleeGo toward or away from a static target

Seek:desired_velocity = normalize (position - target) * max_speed steering = desired_velocity velocity

Flee:Inverse of seek

11Pursuit and EvasionSimilar to Seek and Flee, but estimates the quarrys position in the future

Based on the distance to the quarry, estimate the number of time steps (the predictor interval T) until the Boid could reach the quarryBase T on the distance between objects: T=Dc

Based on the quarrys current velocity, position, and the calculated predictor interval, estimate the target

Use seek or flee algorithm to determine steering

12WanderMultiple waysRandom steering force at each frameEasy to implementMay cause twitching behavior

Retain steering direction, but make small displacementConstrain steering to a sphere (or circle in 2D) in front of the BoidSize of sphere determines how quickly heading can change

13ArrivalSimilar to seek, but slows when approaching targettarget_offset = target - position distance = length (target_offset) ramped_speed = max_speed * (distance / slowing_distance) clipped_speed = minimum (ramped_speed, max_speed) desired_velocity = (clipped_speed / distance) * target_offset steering = desired_velocity - velocity

14Path FollowingBoid steers to follow a predetermined pathVelocity-based prediction of future positionFuture position projected to nearest point on pathIf distance from path is more than path radius, steer toward path

15Variation of Path FindingWall FollowingApproach a wall and maintain a certain distance from itGenerate a new goal position and steer toward it

ContainmentUse future position to determine if Boid will remain inside areaIf not steer back toward the center of area

16Flow Field FollowingSteer to align with flow vectorssteering = flow_direction-velocity

17Obstacle AvoidanceMultiple approaches can be used

Force Field model

Steer-to-avoid18Types of CollisionsObstaclesStationaryIncomingOutgoingSideswiping


19Force FieldsThe equation:

ki is a scaling constantdi is the distance from the agent to the obstacleei controls the magnitude of acceleration based on distanceki and ei should be negative for avoidance, positive values can be used for attraction

Advantages:Easy to modelDisadvantages:Field is exactly opposite, so no turning away from straight onToo weak far away, so long term planning may be required

20Steer-to-AvoidAlgorithm:Calculates silhouette for each obstacleTests collision with current headingIf there will be a collision, the Boid will aim for a point one body length beyond the silhouette

Advantages:Only affected by obstacles directly in front of it

21Combined BehaviorsCrowd Path Following path following and separation Leader FollowingLeader: wandering, seek random positionFollowers: arrival, separation, follow path set by leaderUnaligned Collision AvoidanceContainment, predictive obstacle avoidanceQueuingSeek, avoid, separation,

22And the result isSo, little circles running around are great, but really, what can flocking do?The Lion King

23Simple SwarmsAn alternative to flockingDue to complexity, flocking calculations may be prohibitive in real-time applicationsDoes not attempt to avoid collisions between swarm membersUse with large number of small creaturesSpiders, rats, etc.

24SwarmsIntroducing the swarmDrop from the ceiling, explode from a containerEach agent has a separate timer, set to a random value, so the agents enter the scene gradually

AlgorithmSmall changes in movement and direction should keep the agents separateOuter zoneIncrement agents speed if it is less than the maximum (should vary from agent to agent)If the agents heading is not roughly in the right direction (within some tolerance), rotate back to the correct headingInner zoneBehavior varies, depending on the overall desired movement of the group

25Modified swarmCan add simple collision tests, simple path following, and some other behaviors while still maintaining O(n) complexity

Also can be modified for agents who fly or walk on walls26ApplicationsWhy do we care about any of this?Animals: flocks, schools, herdsPeople: crowdsVehicles: traffic

When to flock, when to swarm?FlockingSmall to medium number of creaturesUse when behavior of creatures is major focus of game playPikminSwarmsLarge groups (tens or hundreds of agents)

27AnimalsAmbient Enhance the environmentGive more life-like feelNot relevant to game playSecondaryLimited amount of interaction with the playerPart of game play, but not the focusShould behave intelligently, but also limited so as not to distract from goalsPrimaryAre focus of the game and have direct relation to primary objectives

28Understand Behavior - GroupsFlocksStay togetherDont crowd each otherFollow the leaderSwitch leaders occasionallyIndividuals break away sometimes, but dont go too farSchoolsVery similar, but tend to change directions more often

High cohesion and alignment, low separation29Understand Behavior SolitaryDoes not mean antisocial, just not governed by the behavior of othersExamples chipmunks, eagles, etc.Stay in a limited areaEfforts mainly directed toward feedingMay or may not be comfortable with human presenceMaintain safe distance, but only depart if pursued

Low alignment and low to moderate cohesion30Ambient animalsBugs - Example behavior for butterfliesDont fly in straight lineDont always flap their wingsDont flap wings in full beatAttracted to flowers and bright colorsAvoid moving objectsStay in limited area

Easily governed by simple rules31Primary and SecondaryTend to follow a schedule throughout the dayFrequent a fixed number of placesHave more than one active sensing mechanism, some more keen than othersSenses are affected by factors in the environmentAvoid human contact, but may be dangerous when corneredTypically predictable, but should also demonstrate unexpected behavior occasionally

Require more complex individual behavior than ambient animals32TrafficMust obey traffic rulesStop signs and signals, speed limits, drive on correct side of streetCan be implemented with messages when the vehicle approaches specific objectsSet precedenceA stop sign or pedestrian is more important than maintaining a certain speedIntersections ticket systemIn order to go through, must be in possession of ticketAfter passing through, vehicle relinquishes control of the ticket33PeopleMillingLow max speed, planning for collision avoidance, small changes in heading, follow social/safety conventions (stay on sidewalk)Pedestrians on sidewalk, small groups standing around

Organized behaviorPay more attention to other agentsQueuing, military formations, doing the wave, waiting at cross-walks, etc.

Traumatic behaviorHigh maximum speed, large changes in heading, ignore conventions (running into traffic)Run away from the crazy person with a big gun

34Rome: Total WarStrategy game both turn-based and real timeGame engine Has the ability to render 30,000 units on a single battle fieldUsed by Decisive Battles (History Channel) to recreate historical battlesBattle of CannaeRome: Total War

2004, PC Gamer (UK): All time 5th best PC game "95%, IGN: Editor's Choice Award, 4th Best PC Game of all Time, PC Gamer (US): Editor's Choice, Best Strategy Game of 2004

35SummaryFlockingEmergent behavior that imitates a flock, school, or herdComputationally expensive for large groups

SwarmsUse when flocking too expensive (hundreds of agents)Organic motion, but flock mates may collide

ApplicationsVideo games, movies/TV, simulationsAnimals, vehicles, peopleUnderstand what you want to model before you model it36Thank you!Questions or Comments?37