Pedestrian movement

Here we present the models from the CARMA pedestrian movement example which is featured in the paper Mesoscopic modelling of pedestrian movement using
CARMA and its tools by Galpin, Zoń, Wilsdorf and Gilmore.

The example illustrates several features of the CARMA language, such as complex, time-dependent rates which can be used to shape the traffic according to the hour of the day, as shown below.

fun real SpawnRate(real currentNow){
    int nowTime := int(real(currentNow));
    real currentTimeOfDay = real(nowTime % minInDay);

    real mean9am = 540.0;
    real mean1230am = 750.0;
    real mean5pm = 1020.0;

    return (GaussianWith1hrStd(currentTimeOfDay, mean5pm) +
            GaussianWith1hrStd(currentTimeOfDay, mean9am) +
            GaussianWith1hrStd(currentTimeOfDay, mean1230am) + 0.1) *
                SPAWN_RATE_BOOSTER;
}

 

Functions can be used to control the probabilistic behaviour of pedestrians who respond to the presence or absence of traffic.

fun real ChooseProbabilityTraffic(location newLocation, location currentLocation,
            location goalLocation, int trafficSameDirection, int trafficOtherDirection){
    real distanceCurrent = getElementAt(DISTANCES, currentLocation.id, goalLocation.id);
    real distanceNew = getElementAt(DISTANCES, newLocation.id, goalLocation.id);
    real d = getElementAt(DISTANCES, currentLocation.id, newLocation.id);

    real difference = distanceCurrent - distanceNew;

    real overallTraffic = TRAFFIC_BOOSTER*(real(trafficOtherDirection)/d);

    real probResult = 0.0;

    if(overallTraffic != 0.0){
        if(difference >= 0.0) {
            probResult = abs(difference)/(overallTraffic);
        }
        else{
            probResult =  1.0/((abs(difference)*(overallTraffic)));
        }
    }
    else{
        if(difference >= 0.0) {
            probResult =  abs(difference);
        }
        else{
            probResult =  1.0/(abs(difference));
        }
    }

    return probResult;

}

 

Components define the path nodes which the pedestrians cross. Pedestrians do not initially have knowledge of all of the paths in the network, and the presence of a new path node is advertised to them as they travel.

component PathNode(location myLocation, int myCurrentOccupancy){

    store{
        attrib bool isPedestrian := false;
        attrib location nodeLocation := myLocation;
        attrib int arrived := 0;
        attrib real timeSum := 0.0;
    }

    behaviour{
        Advertisement =
            choose*[true]<my.nodeLocation>{}.Advertisement;
        Arrival =
            arrive[my.nodeLocation == arrivalLocation](arrivalLocation, startTime){
                my.arrived = my.arrived + 1;
                timeSum = timeSum + (now - startTime);
            }.Arrival;
        GoalAssignment = assignGoal*<my.nodeLocation>{}.GoalAssignment;
        StartAssignment = assignStart*<my.nodeLocation>{}.StartAssignment;
    }

    init{ Advertisement | Arrival | GoalAssignment | StartAssignment }
}

 

Components define the behaviour of pedestrians who repeatedly choose a path and move along the path until they reach their destination.

component Pedestrian(location start, location goal,
                        real stime_init, process Z){

    store{
        attrib bool isPedestrian := true;
        attrib location startLocation := start;
        attrib location currentLocation := start;
        attrib location goalLocation := goal;
        attrib location nextLocation := start;
        attrib location previousLocation := start;
        attrib stime := stime_init;
    }

    behaviour{
      ReadyToChoose =
            choose*[nodeLocation in my.currentLocation.post](nodeLocation){
                my.nextLocation := nodeLocation;
            }.ReadyToMove;
      ReadyToMove =
            move*[false]<my.currentLocation, my.nextLocation>{
                my.previousLocation := my.currentLocation;
                my.currentLocation := my.nextLocation;
            }.ReadyToArrive;
      ReadyToArrive =
            [my.currentLocation == my.goalLocation]
                arrive<my.goalLocation, my.stime>.kill
            +
            continue*[false]<>.ReadyToChoose;
    }

    init{Z}
}

The source code of the model is available for download from
https://github.com/SGilmore/pedestrianModel/blob/master/Model.carma