Simulate indoor
Indoor environments
(bidimensional spaces with obstacles)
can be generated from images by leveraging
ImageEnvironment
,
which loads the map as raster image from file,
interpreting the black pixels as obstacles
(wall-like areas not accessible to nodes).
Color of pixels that represents obstacles can be set to
every color with a constructor’s parameter, black is default.
By default, each pixel is considered as a 1x1 block.
As a consequence, a 1200x600 image with a vertical line of black pixels at coordinate 500 will be interpreted as a single
obstacle of size 1x600 starting at coordinate (500, 0).
It is possible to scale up or down the size of the environment by acting on the zoom parameter of
ImageEnvironment
,
as well as changing the initial coordinates.
Examples
incarnation: protelis
variables:
danger: &danger
formula: "\"danger\""
exit1: &exit1
formula: "\"exit1\""
exit2: &exit2
formula: "\"exit2\""
exit3: &exit3
formula: "\"exit3\""
exit4: &exit4
formula: "\"exit4\""
environment:
type: ImageEnvironment
parameters: [images/multiple-exits.png, 0.0416]
seeds:
scenario: 1
simulation: 0
layers:
- type: BidimensionalGaussianLayer
molecule: *danger
parameters: [10, 10, 20, 8]
- type: BidimensionalGaussianLayer
molecule: *exit1
parameters: [0.0, 10.0, 5, 2]
- type: BidimensionalGaussianLayer
molecule: *exit2
parameters: [10.0, 20.0, 5, 2]
- type: BidimensionalGaussianLayer
molecule: *exit3
parameters: [20.0, 10.0, 5, 2]
- type: BidimensionalGaussianLayer
molecule: *exit4
parameters: [10.0, 0.0, 5, 2]
_reactions: &behavior
- time-distribution:
type: DiracComb
parameters: [1.0]
type: PrioritySteering
conditions:
- type: WantToEvacuate
actions:
- type: CognitiveAgentAvoidLayer
parameters: [*danger]
- type: CognitiveAgentFollowLayer
parameters: [*exit1]
- type: CognitiveAgentFollowLayer
parameters: [*exit2]
- type: CognitiveAgentFollowLayer
parameters: [*exit3]
- type: CognitiveAgentFollowLayer
parameters: [*exit4]
- time-distribution:
type: DiracComb
parameters: [0.25]
type: CognitiveBehavior
actions:
- type: HeadTowardRandomDirection
deployments:
- type: Circle
parameters: [75, 10, 10, 10]
nodes:
type: CognitivePedestrian2D
parameters: ["adult", "male", *danger]
programs:
- *behavior
- type: Circle
parameters: [75, 10, 10, 10]
nodes:
type: CognitivePedestrian2D
parameters: ["adult", "female", *danger]
programs:
- *behavior
incarnation: protelis
variables:
danger: &danger
formula: "\"danger\""
environment:
type: ImageEnvironment
parameters: [images/obstacles.png]
seeds:
scenario: 0
simulation: 1
layers:
- type: BidimensionalGaussianLayer
molecule: *danger
parameters: [600.0, 240.0, 10.0, 100.0]
_reactions: &behavior
- time-distribution:
type: DiracComb
parameters: [0.25]
type: BlendedSteering
actions:
- type: CognitiveAgentFollowLayer
parameters: [*danger]
- type: CognitiveAgentObstacleAvoidance
parameters: [50]
_homogeous_pedestrian: &homogeneous_pedestrian
properties:
- type: Pedestrian
- type: Social
- type: Perceptive2D
- type: CircularArea
deployments:
- type: Circle
parameters: [20, -100, 240, 30]
<<: *homogeneous_pedestrian
programs:
- *behavior
- type: Circle
parameters: [30, 0, 600, 50]
<<: *homogeneous_pedestrian
programs:
- *behavior
- type: Circle
parameters: [40, 100, -60, 40]
<<: *homogeneous_pedestrian
programs:
- *behavior
incarnation: protelis
environment:
type: ImageEnvironment
parameters: [planimetry.png]
_reactions: &behavior
- time-distribution:
type: DiracComb
parameters: [3.0]
type: PrioritySteering
actions:
- type: HeadTowardRandomDirection
- type: CognitiveAgentWander
parameters: [6, 4]
- type: CognitiveAgentObstacleAvoidance
parameters: [4]
deployments:
- type: Circle
parameters: [50, 0, 0, 25]
properties:
- type: Pedestrian
- type: Perceptive2D
- type: CircularArea
- type: Social
programs:
- *behavior
- Direct reference to the image
Click to show / hide code
incarnation: protelis environment: { type: ImageEnvironment, parameters: [chiaravalle.png, 0.1] } network-model: { type: ObstaclesBreakConnection, parameters: [50] } deployments: type: Rectangle parameters: [300, 62, 15, 95, 200] programs: - time-distribution: 1 program: > import protelis:coord:spreading let source = [110, 325] let vector = self.getCoordinates() - source let distance = hypot(vector.get(0), vector.get(1)) distanceTo(distance < 50) - program: send # Actual network message delivery - type: Event time-distribution: 1 actions: { type: LevyWalk, parameters: [1.4] }
- Search for the image in the file system via Kotlin
Click to show / hide code
incarnation: protelis variables: zoom: &zoom formula: 0.1 # Must be a valid Groovy snippet image_name: { formula: "'chiaravalle.png'" } image_path: &image_path language: kotlin # Pick whatever JSR223 language you like and add it to the classpath formula: | # The following is pure Kotlin code. Other variables can be referenced! import java.io.File fun File.findImage(): String? = walkTopDown().find { image_name in it.name }?.absolutePath fun File.findImageRecursively(): String = findImage() ?: File(this, "..").findImageRecursively() File(".").findImageRecursively() timeout: 5000 # Linear free variable walking_speed: &walk-speed { default: 1.4, min: 1, max: 2, step: 0.1 } seed: &seed { default: 0, min: 0, max: 99, step: 1 } # 100 samples scenario_seed: &scenario_seed { formula: (seed + 31) * seed } # Variable-dependent people_count: &people_count type: GeometricVariable # A variable scanning a space with geometric segmentation parameters: [300, 50, 500, 9] # default 300, minimum 50, maximum 100, 9 samples seeds: { simulation: *seed, scenario: *scenario_seed} export: type: CSVExporter parameters: fileNameRoot: "snippet-variables-export" data: - time - molecule: "default_module:default_program" aggregators: [ mean, max, min, variance, median ] # From Apache's UnivariateStatistic value-filter: onlyfinite # discards NaN and Infinity environment: { type: ImageEnvironment, parameters: [*image_path, *zoom] } network-model: { type: ObstaclesBreakConnection, parameters: [50] } deployments: type: Rectangle parameters: [*people_count, 62, 15, 95, 200] programs: - time-distribution: 1 program: > import protelis:coord:spreading let source = [110, 325] let vector = self.getCoordinates() - source let distance = hypot(vector.get(0), vector.get(1)) distanceTo(distance < 50) - program: send - { type: Event, time-distribution: 1, actions: { type: LevyWalk, parameters: [*walk-speed] } }