Clone wiki

OscaR / DES

Find all the DES (Discrete Event Simulation) examples here.

Epidemy Simulation

Here is a step by step guide to simulate the Epidemy presented by the team of "Reactive Programming" course on coursera.

Step 0: identifying the processes

Upon reading of the problem description, you can identify two different processes by citizen of Scalia:

  1. its moves: where and when does it changes its position ?
  2. its health: how does the disease evolve ?

The link between the two is contamination when a citizen enters a new room.

Step 1: moves of a citizen

The citizen displacement can be modelized by a process with a state using the following abstraction:

case class Position(val row:Int, val col:Int)
ProcessWithStates[Position,Unit] with SaveState[Position,Unit]

As written above the state of the displacement is a position (here, we consider moves as immediate).

val moves: ProcessWithStates[Position,Unit] with SaveState[Position,Unit] = new ProcessWithStates[Position,Unit] ("Position of %s" format id,initialPosition) with SaveState[Position,Unit]  {
  override def exec(implicit state:Position) = {
    if (!village.isSafe(state)) health.getInfected else unit // coming into a room with a sick might make you sick 
    if (!health.currentState().isInstanceOf[Dead]) {
      // select a nearby room with no visibly infectious person inside
      if (village.usePlane(m)) Iam(village.getPosition(m))
      else {
        val options = village.visiblySafeSurroundingHouses(state)
	if (options.isEmpty) Iam(state)
	else Iam(UniformChoice(options)(m))