Commit 863ae060 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Renamed class "Bang" to general term "Threat"

parent c9e32eaf
......@@ -2,14 +2,11 @@ package org.vadere.simulator.control.psychology.cognition;
import org.vadere.simulator.models.Model;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.Bang;
import org.vadere.state.psychology.perception.types.ElapsedTime;
import org.vadere.state.psychology.perception.types.Stimulus;
import org.vadere.state.psychology.perception.types.Threat;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import java.util.Collection;
import java.util.List;
/**
* Interface for a cognition model.
......@@ -30,7 +27,7 @@ import java.util.List;
*
* Watch out: The perception phase should be finished before using
* methods in this class because, usually, first a stimulus is processed and
* then pedestrians decide which behavior to follow. E.g., first a {@link Bang}
* then pedestrians decide which behavior to follow. E.g., first a {@link Threat}
* occurs and then a pedestrian decides to follow a {@link SelfCategory#TARGET_ORIENTED}
* behavior.
*/
......
......@@ -2,7 +2,7 @@ package org.vadere.simulator.control.psychology.cognition;
import org.vadere.state.psychology.cognition.GroupMembership;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.Bang;
import org.vadere.state.psychology.perception.types.Threat;
import org.vadere.state.psychology.perception.types.ElapsedTime;
import org.vadere.state.psychology.perception.types.Stimulus;
import org.vadere.state.scenario.Pedestrian;
......@@ -14,7 +14,7 @@ import java.util.List;
import java.util.stream.Collectors;
/**
* Suppose a threat (a {@link Bang}) occurred.
* Suppose a threat (a {@link Threat}) occurred.
*
* Check following conditions for a pedestrian:
* <ol>
......@@ -37,12 +37,12 @@ public class ThreatCognitionModel implements ICognitionModel {
// TODO: Maybe, use also use cooperative behavior from "CooperativeCognitionModel".
public void update(Collection<Pedestrian> pedestrians) {
for (Pedestrian pedestrian : pedestrians) {
if (pedestrian.getMostImportantStimulus() instanceof Bang) {
if (pedestrian.getMostImportantStimulus() instanceof Threat) {
handleThreat(pedestrian, pedestrian.getMostImportantStimulus());
} else if (pedestrian.getMostImportantStimulus() instanceof ElapsedTime) {
handleElapsedTime(pedestrian);
} else {
throw new IllegalArgumentException("Can only process \"Bang\" and \"ElapsedTime\" stimuli!");
throw new IllegalArgumentException("Can only process \"Threat\" and \"ElapsedTime\" stimuli!");
}
}
}
......@@ -69,7 +69,7 @@ public class ThreatCognitionModel implements ICognitionModel {
}
private void testIfInsideOrOutsideThreatArea(Pedestrian pedestrian) {
Bang threat = (Bang) pedestrian.getPerceivedThreat();
Threat threat = (Threat) pedestrian.getPerceivedThreat();
VPoint threatOrigin = topography.getTarget(threat.getOriginAsTargetId()).getShape().getCentroid();
double distanceToThreat = threatOrigin.distance(pedestrian.getPosition());
......
......@@ -12,7 +12,7 @@ import java.util.stream.Collectors;
/**
* Use a very simple strategy to rank stimulus priority:
*
* ChangeTarget > Bang > Wait > WaitInArea
* ChangeTarget > Threat > Wait > WaitInArea
*/
public class SimplePerceptionModel implements IPerceptionModel {
......@@ -26,12 +26,12 @@ public class SimplePerceptionModel implements IPerceptionModel {
@Override
public void update(Collection<Pedestrian> pedestrians, List<Stimulus> stimuli) {
for (Pedestrian pedestrian : pedestrians) {
Stimulus mostImportantStimulus = rankChangeTargetAndBangHigherThanWait(stimuli, pedestrian);
Stimulus mostImportantStimulus = rankChangeTargetAndThreatHigherThanWait(stimuli, pedestrian);
pedestrian.setMostImportantStimulus(mostImportantStimulus);
}
}
private Stimulus rankChangeTargetAndBangHigherThanWait(List<Stimulus> stimuli, Pedestrian pedestrian) {
private Stimulus rankChangeTargetAndThreatHigherThanWait(List<Stimulus> stimuli, Pedestrian pedestrian) {
// Assume the "ElapsedTime" is the most important stimulus
// unless there is something more important.
Stimulus mostImportantStimulus = stimuli.stream()
......@@ -41,16 +41,16 @@ public class SimplePerceptionModel implements IPerceptionModel {
List<Stimulus> waitStimuli = stimuli.stream().filter(stimulus -> stimulus instanceof Wait).collect(Collectors.toList());
List<Stimulus> waitInAreaStimuli = stimuli.stream().filter(stimulus -> stimulus instanceof WaitInArea).collect(Collectors.toList());
List<Stimulus> bangStimuli = stimuli.stream().filter(stimulus -> stimulus instanceof Bang).collect(Collectors.toList());
List<Stimulus> threatStimuli = stimuli.stream().filter(stimulus -> stimulus instanceof Threat).collect(Collectors.toList());
List<Stimulus> changeTargetStimuli = stimuli.stream().filter(stimulus -> stimulus instanceof ChangeTarget).collect(Collectors.toList());
if (changeTargetStimuli.size() >= 1) {
mostImportantStimulus = changeTargetStimuli.get(0);
} else if (bangStimuli.size() >= 1) {
Stimulus closestBang = selectClosestAndPerceptibleBang(pedestrian, bangStimuli);
} else if (threatStimuli.size() >= 1) {
Stimulus closestThreat = selectClosestAndPerceptibleThreat(pedestrian, threatStimuli);
if (closestBang != null) {
mostImportantStimulus = closestBang;
if (closestThreat != null) {
mostImportantStimulus = closestThreat;
}
} else if (waitStimuli.size() >= 1) {
mostImportantStimulus = waitStimuli.get(0);
......@@ -65,30 +65,30 @@ public class SimplePerceptionModel implements IPerceptionModel {
return mostImportantStimulus;
}
private Stimulus selectClosestAndPerceptibleBang(Pedestrian pedestrian, List<Stimulus> bangStimuli) {
Bang closestAndPerceptibleBang = null;
double distanceToClosestBang = -1;
private Stimulus selectClosestAndPerceptibleThreat(Pedestrian pedestrian, List<Stimulus> threatStimuli) {
Threat closestAndPerceptibleThreat = null;
double distanceToClosestThreat = -1;
for (Stimulus stimulus : bangStimuli) {
Bang currentBang = (Bang) stimulus;
for (Stimulus stimulus : threatStimuli) {
Threat currentThreat = (Threat) stimulus;
VPoint bangOrigin = topography.getTarget(currentBang.getOriginAsTargetId()).getShape().getCentroid();
double distanceToBang = bangOrigin.distance(pedestrian.getPosition());
VPoint threatOrigin = topography.getTarget(currentThreat.getOriginAsTargetId()).getShape().getCentroid();
double distanceToThreat = threatOrigin.distance(pedestrian.getPosition());
if (distanceToBang <= currentBang.getRadius()) {
if (closestAndPerceptibleBang == null) {
closestAndPerceptibleBang = currentBang;
distanceToClosestBang = distanceToBang;
if (distanceToThreat <= currentThreat.getRadius()) {
if (closestAndPerceptibleThreat == null) {
closestAndPerceptibleThreat = currentThreat;
distanceToClosestThreat = distanceToThreat;
} else {
if (distanceToBang < distanceToClosestBang) {
closestAndPerceptibleBang = currentBang;
distanceToClosestBang = distanceToBang;
if (distanceToThreat < distanceToClosestThreat) {
closestAndPerceptibleThreat = currentThreat;
distanceToClosestThreat = distanceToThreat;
}
}
}
}
return closestAndPerceptibleBang;
return closestAndPerceptibleThreat;
}
private Stimulus selectWaitInAreaContainingPedestrian(Pedestrian pedestrian, List<Stimulus> waitInAreaStimuli) {
......
......@@ -6,7 +6,7 @@ import org.jetbrains.annotations.Nullable;
import org.vadere.simulator.models.potential.combinedPotentials.CombinedPotentialStrategy;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.Bang;
import org.vadere.state.psychology.perception.types.Threat;
import org.vadere.state.psychology.perception.types.ChangeTarget;
import org.vadere.state.psychology.perception.types.Stimulus;
import org.vadere.state.scenario.Pedestrian;
......@@ -110,16 +110,16 @@ public class OSMBehaviorController {
pedestrian.setTimeOfNextStep(pedestrian.getTimeOfNextStep() + timeStepInSec);
}
// Watch out: A bang event changes only the "CombinedPotentialStrategy".
// Watch out: A threat stimulus changes only the "CombinedPotentialStrategy".
// I.e., a new target is set for the agent. The agent does not move here!
// Therefore, trigger only a single bang event and then use "ElapsedTime" afterwards
// to let the agent walk.
// Therefore, trigger only a single threat stimulus and then use "ElapsedTime"
// afterwards to let the agent walk.
public void reactToBang(PedestrianOSM pedestrian, Topography topography) {
Stimulus mostImportantStimulus = pedestrian.getMostImportantStimulus();
if (mostImportantStimulus instanceof Bang) {
Bang bang = (Bang) pedestrian.getMostImportantStimulus();
Target bangOrigin = topography.getTarget(bang.getOriginAsTargetId());
if (mostImportantStimulus instanceof Threat) {
Threat threat = (Threat) pedestrian.getMostImportantStimulus();
Target bangOrigin = topography.getTarget(threat.getOriginAsTargetId());
LinkedList<Integer> nextTarget = new LinkedList<>();
nextTarget.add(bangOrigin.getId());
......@@ -128,7 +128,7 @@ public class OSMBehaviorController {
pedestrian.setCombinedPotentialStrategy(CombinedPotentialStrategy.TARGET_REPULSION_STRATEGY);
} else {
logger.debug(String.format("Expected: %s, Received: %s",
Bang.class.getSimpleName(),
Threat.class.getSimpleName(),
mostImportantStimulus.getClass().getSimpleName()));
}
}
......
......@@ -77,7 +77,7 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
}
} else if (mostImportantStimulus instanceof Wait || mostImportantStimulus instanceof WaitInArea) {
osmBehaviorController.wait(pedestrian, timeStepInSec);
} else if (mostImportantStimulus instanceof Bang) {
} else if (mostImportantStimulus instanceof Threat) {
osmBehaviorController.reactToBang(pedestrian, topography);
// Set time of next step. Otherwise, the internal OSM event queue hangs endlessly.
......
......@@ -64,7 +64,7 @@ public class UpdateSchemeSequential implements UpdateSchemeOSM {
}
} else if (mostImportantStimulus instanceof Wait || mostImportantStimulus instanceof WaitInArea) {
osmBehaviorController.wait(pedestrian, timeStepInSec);
} else if (mostImportantStimulus instanceof Bang) {
} else if (mostImportantStimulus instanceof Threat) {
osmBehaviorController.reactToBang(pedestrian, topography);
} else if (mostImportantStimulus instanceof ChangeTarget) {
osmBehaviorController.reactToTargetChange(pedestrian, topography);
......
......@@ -18,7 +18,7 @@ import org.vadere.state.attributes.models.AttributesOSM;
import org.vadere.state.attributes.models.AttributesSelfCatThreat;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.psychology.cognition.GroupMembership;
import org.vadere.state.psychology.perception.types.Bang;
import org.vadere.state.psychology.perception.types.Threat;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
......@@ -32,12 +32,12 @@ import java.util.List;
import java.util.Random;
/**
* This class models how agents react to a perceived threat (a loud bang) while considering the
* This class models how agents react to a perceived threat (e.g., a loud bang) while considering the
* self-categorization theory ("reicher-2010").
*
* Please, note:
* <ul>
* <li>A {@link Bang} has a loudness and a radius.</li>
* <li>A {@link Threat} has a loudness and a radius.</li>
* <li>We use the self-categorization theory to divide the agents into in- and out-group members.
* In-group members imitate the behavior of other in-group members. Out-group members ignore the
* behavior of in-group members.</li>
......@@ -46,9 +46,9 @@ import java.util.Random;
* Implement following behavior:
*
* <ol>
* <li>If agent A is within the bang radius, escape (i.e., first maximize distance to the bang and then
* <li>If agent A is within the threat radius, escape (i.e., first maximize distance to the threat and then
* go to a safe zone).</li>
* <li>If agent A is outside bang radius, check if "searchRadius" contains an escaping in-group member.
* <li>If agent A is outside threat radius, check if "searchRadius" contains an escaping in-group member.
* If yes, escape also. Otherwise, go to original target.</li>
* <li>Out-group members use the locomotion layer to go to a target (i.e., keep their original behavior).</li>
* </ol>
......
......@@ -10,7 +10,7 @@ import org.vadere.simulator.models.potential.combinedPotentials.TargetAttraction
import org.vadere.simulator.models.potential.combinedPotentials.TargetRepulsionStrategy;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.psychology.cognition.SelfCategory;
import org.vadere.state.psychology.perception.types.Bang;
import org.vadere.state.psychology.perception.types.Threat;
import org.vadere.state.psychology.perception.types.ChangeTarget;
import org.vadere.state.psychology.perception.types.Stimulus;
import org.vadere.state.scenario.Pedestrian;
......@@ -125,12 +125,12 @@ public class OSMBehaviorController {
public void maximizeDistanceToThreatAndIncreaseSpeed(PedestrianOSM pedestrian, Topography topography) {
Stimulus perceivedThreat = pedestrian.getPerceivedThreat();
if (perceivedThreat instanceof Bang && pedestrian.getCombinedPotentialStrategy() instanceof TargetAttractionStrategy) {
Bang bang = (Bang) perceivedThreat;
Target bangOrigin = topography.getTarget(bang.getOriginAsTargetId());
if (perceivedThreat instanceof Threat && pedestrian.getCombinedPotentialStrategy() instanceof TargetAttractionStrategy) {
Threat threat = (Threat) perceivedThreat;
Target threatOrigin = topography.getTarget(threat.getOriginAsTargetId());
LinkedList<Integer> nextTarget = new LinkedList<>();
nextTarget.add(bangOrigin.getId());
nextTarget.add(threatOrigin.getId());
pedestrian.setTargets(nextTarget);
pedestrian.setCombinedPotentialStrategy(CombinedPotentialStrategy.TARGET_REPULSION_STRATEGY);
......@@ -141,7 +141,7 @@ public class OSMBehaviorController {
} else {
logger.debug(String.format("Expected: %s, Received: %s",
Bang.class.getSimpleName(),
Threat.class.getSimpleName(),
perceivedThreat.getClass().getSimpleName()));
}
}
......@@ -158,7 +158,7 @@ public class OSMBehaviorController {
if (pedestrian.getCombinedPotentialStrategy() instanceof TargetRepulsionStrategy) {
ScenarioElement searchPosition = (pedestrian.getSource() == null) ? pedestrian : pedestrian.getSource();
Target closestTarget = findClosestTarget(topography, searchPosition, (Bang) pedestrian.getPerceivedThreat());
Target closestTarget = findClosestTarget(topography, searchPosition, (Threat) pedestrian.getPerceivedThreat());
assert closestTarget != null;
......@@ -170,11 +170,11 @@ public class OSMBehaviorController {
}
}
private Target findClosestTarget(Topography topography, ScenarioElement scenarioElement, Bang bang) {
private Target findClosestTarget(Topography topography, ScenarioElement scenarioElement, Threat threat) {
VPoint sourceCentroid = scenarioElement.getShape().getCentroid();
List<Target> sortedTargets = topography.getTargets().stream()
.filter(target -> target.getId() != bang.getOriginAsTargetId())
.filter(target -> target.getId() != threat.getOriginAsTargetId())
.sorted((target1, target2) -> Double.compare(
sourceCentroid.distance(target1.getShape().getCentroid()),
sourceCentroid.distance(target2.getShape().getCentroid())))
......
......@@ -118,13 +118,13 @@ public class SimplePerceptionModelTest {
}
@Test
public void updateRanksBangHigherThanElapsedTime() {
public void updateRanksThreatHigherThanElapsedTime() {
Topography topography = createTopography();
Target target = createTarget(new VPoint(0, 0), 5, 1);
topography.addTarget(target);
double expectedTime = 0.123;
Stimulus expectedStimulus = new Bang(expectedTime, target.getId());
Stimulus expectedStimulus = new Threat(expectedTime, target.getId());
List<Pedestrian> pedestrians = createPedestrians(2);
List<Stimulus> stimuli = new ArrayList<>();
......@@ -143,8 +143,8 @@ public class SimplePerceptionModelTest {
}
@Test
public void updateUsesClosestBangForPedestrian() {
// Place bangs at (0,0) and (5,0) with radii 5 and
public void updateUsesClosestThreatForPedestrian() {
// Place threat at (0,0) and (5,0) with radii 5 and
// place pedestrians at (1,0) and (4,0) and check result.
Topography topography = createTopography();
......@@ -153,8 +153,8 @@ public class SimplePerceptionModelTest {
double expectedTime1 = 0.1;
double expectedTime2 = 0.2;
Stimulus expectedStimulusPed1 = new Bang(expectedTime1, targets.get(0).getId());
Stimulus expectedStimulusPed2 = new Bang(expectedTime2, targets.get(1).getId());
Stimulus expectedStimulusPed1 = new Threat(expectedTime1, targets.get(0).getId());
Stimulus expectedStimulusPed2 = new Threat(expectedTime2, targets.get(1).getId());
List<Pedestrian> pedestrians = createPedestrians(2);
pedestrians.get(0).setPosition(new VPoint(1, 0));
......
......@@ -19,7 +19,7 @@ import java.util.Map;
* This class can be used as helper for GUI elements.
*/
public class StimulusPresettings {
/** Map an event class (e.g., Bang) to a JSON string. */
/** Map an event class (e.g., Threat) to a JSON string. */
public static Map<Class, String> PRESETTINGS_MAP;
// Static initializer for "PRESETTINGS_MAP".
......@@ -27,7 +27,7 @@ public class StimulusPresettings {
PRESETTINGS_MAP = new HashMap<>();
Stimulus[] stimuliToUse = new Stimulus[] {
new Bang(),
new Threat(),
new Wait(),
new WaitInArea(0, new VRectangle(0, 0, 10, 10)),
};
......
......@@ -14,8 +14,8 @@ import java.util.List;
*
* The additional information depend on the type of the stimulus and should be
* added by subclasses. For instance, a stimulus "ElapsedTime" can provide
* the current time. A stimulus "Bang" can have a loudness and a polygon
* which describes where the bang can be perceived.
* the current time. A stimulus "Threat" can have a loudness and a polygon
* which describes where the threat can be perceived.
*
* This class and its subclasses should be de-/serialized as JSON. Therefore,
* provide some annotations so that serialized objects do not reveal Java
......@@ -31,13 +31,13 @@ import java.util.List;
include = JsonTypeInfo.As.PROPERTY,
property = "type")
@JsonSubTypes({
@Type(value = Bang.class, name = "Bang"),
@Type(value = Threat.class, name = "Threat"),
@Type(value = ElapsedTime.class, name = "ElapsedTime"),
@Type(value = Wait.class, name = "Wait"),
@Type(value = WaitInArea.class, name = "WaitInArea"),
@Type(value = ChangeTarget.class, name = "ChangeTarget")
})
// "time" is set when the stimulus is actually into the simulation and must not be de-/serialized.
// "time" is set when the stimulus is injected into the simulation run and must not be de-/serialized.
@JsonIgnoreProperties({ "time" })
public abstract class Stimulus implements Cloneable {
......
......@@ -12,8 +12,8 @@ public class StimulusFactory {
public static Stimulus stringToStimulus(@NotNull String stimulusAsString) {
Stimulus stimulusObject = null;
if (stimulusAsString.matches(Bang.class.getSimpleName())) {
stimulusObject = new Bang();
if (stimulusAsString.matches(Threat.class.getSimpleName())) {
stimulusObject = new Threat();
} else if (stimulusAsString.matches(ElapsedTime.class.getSimpleName())) {
stimulusObject = new ElapsedTime();
} else if (stimulusAsString.matches(Wait.class.getSimpleName())) {
......
package org.vadere.state.psychology.perception.types;
/**
* Class signals agents a bang - for instance something exploded.
* Class signals agents a threat. For instance that something exploded.
*
* This stimulus holds one additional information: a target id
* which represents the origin of the bang.
* which represents the origin of the threat.
*/
public class Bang extends Stimulus {
// TODO: Maybe, rename "Bang" to general term "Threat".
public class Threat extends Stimulus {
// Member Variables
private int originAsTargetId = -1;
......@@ -17,19 +15,19 @@ public class Bang extends Stimulus {
// Constructors
// Default constructor required for JSON de-/serialization.
public Bang() { super(); }
public Threat() { super(); }
public Bang(double time) {
public Threat(double time) {
super(time);
}
public Bang(double time, int originAsTargetId) {
public Threat(double time, int originAsTargetId) {
super(time);
this.originAsTargetId = originAsTargetId;
}
public Bang(Bang other) {
public Threat(Threat other) {
super(other);
this.originAsTargetId = other.getOriginAsTargetId();
......@@ -48,7 +46,7 @@ public class Bang extends Stimulus {
public void setRadius(double radius) { this.radius = radius; }
@Override
public Bang clone() {
return new Bang(this);
public Threat clone() {
return new Threat(this);
}
}
......@@ -13,7 +13,7 @@ import java.util.Map;
/**
* An area with an arbitrary shape that absorbs agents event if they have not reached their target.
* This can be useful when agents run away from targets (e.g., after a bang event).
* This can be useful when agents run away from targets (e.g., after a threat stimulus).
*/
public class AbsorbingArea extends ScenarioElement implements Comparable<AbsorbingArea> {
......
......@@ -14,19 +14,19 @@ public class StimulusTest {
public static double ALLOWED_DOUBLE_TOLERANCE = 10e-3;
@Test
public void testBangClone() {
public void testThreatClone() {
double expectedTime = 1;
int expectedOriginAsTargetId = 2;
Bang bangOriginal = new Bang(expectedTime, expectedOriginAsTargetId);
Threat threatOriginal = new Threat(expectedTime, expectedOriginAsTargetId);
Bang bangClone = bangOriginal.clone();
bangClone.setTime(3);
bangClone.setOriginAsTargetId(4);
Threat threatClone = threatOriginal.clone();
threatClone.setTime(3);
threatClone.setOriginAsTargetId(4);
assertEquals(expectedTime, bangOriginal.getTime(), ALLOWED_DOUBLE_TOLERANCE);
assertEquals(expectedOriginAsTargetId, bangOriginal.getOriginAsTargetId());
assertEquals(bangOriginal.getLoudness(), bangClone.getLoudness(), ALLOWED_DOUBLE_TOLERANCE);
assertEquals(expectedTime, threatOriginal.getTime(), ALLOWED_DOUBLE_TOLERANCE);
assertEquals(expectedOriginAsTargetId, threatOriginal.getOriginAsTargetId());
assertEquals(threatOriginal.getLoudness(), threatClone.getLoudness(), ALLOWED_DOUBLE_TOLERANCE);
}
@Test
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment