Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vadere
vadere
Commits
863ae060
Commit
863ae060
authored
Jan 17, 2020
by
Benedikt Kleinmeier
Browse files
Renamed class "Bang" to general term "Threat"
parent
c9e32eaf
Changes
15
Hide whitespace changes
Inline
Side-by-side
VadereSimulator/src/org/vadere/simulator/control/psychology/cognition/ICognitionModel.java
View file @
863ae060
...
...
@@ -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.
*/
...
...
VadereSimulator/src/org/vadere/simulator/control/psychology/cognition/ThreatCognitionModel.java
View file @
863ae060
...
...
@@ -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
());
...
...
VadereSimulator/src/org/vadere/simulator/control/psychology/perception/SimplePerceptionModel.java
View file @
863ae060
...
...
@@ -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
=
rankChangeTargetAnd
Bang
HigherThanWait
(
stimuli
,
pedestrian
);
Stimulus
mostImportantStimulus
=
rankChangeTargetAnd
Threat
HigherThanWait
(
stimuli
,
pedestrian
);
pedestrian
.
setMostImportantStimulus
(
mostImportantStimulus
);
}
}
private
Stimulus
rankChangeTargetAnd
Bang
HigherThanWait
(
List
<
Stimulus
>
stimuli
,
Pedestrian
pedestrian
)
{
private
Stimulus
rankChangeTargetAnd
Threat
HigherThanWait
(
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
>
bang
Stimuli
=
stimuli
.
stream
().
filter
(
stimulus
->
stimulus
instanceof
Bang
).
collect
(
Collectors
.
toList
());
List
<
Stimulus
>
threat
Stimuli
=
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
(
bang
Stimuli
.
size
()
>=
1
)
{
Stimulus
closest
Bang
=
selectClosestAndPerceptible
Bang
(
pedestrian
,
bang
Stimuli
);
}
else
if
(
threat
Stimuli
.
size
()
>=
1
)
{
Stimulus
closest
Threat
=
selectClosestAndPerceptible
Threat
(
pedestrian
,
threat
Stimuli
);
if
(
closest
Bang
!=
null
)
{
mostImportantStimulus
=
closest
Bang
;
if
(
closest
Threat
!=
null
)
{
mostImportantStimulus
=
closest
Threat
;
}
}
else
if
(
waitStimuli
.
size
()
>=
1
)
{
mostImportantStimulus
=
waitStimuli
.
get
(
0
);
...
...
@@ -65,30 +65,30 @@ public class SimplePerceptionModel implements IPerceptionModel {
return
mostImportantStimulus
;
}
private
Stimulus
selectClosestAndPerceptible
Bang
(
Pedestrian
pedestrian
,
List
<
Stimulus
>
bang
Stimuli
)
{
Bang
closestAndPerceptible
Bang
=
null
;
double
distanceToClosest
Bang
=
-
1
;
private
Stimulus
selectClosestAndPerceptible
Threat
(
Pedestrian
pedestrian
,
List
<
Stimulus
>
threat
Stimuli
)
{
Threat
closestAndPerceptible
Threat
=
null
;
double
distanceToClosest
Threat
=
-
1
;
for
(
Stimulus
stimulus
:
bang
Stimuli
)
{
Bang
current
Bang
=
(
Bang
)
stimulus
;
for
(
Stimulus
stimulus
:
threat
Stimuli
)
{
Threat
current
Threat
=
(
Threat
)
stimulus
;
VPoint
bang
Origin
=
topography
.
getTarget
(
current
Bang
.
getOriginAsTargetId
()).
getShape
().
getCentroid
();
double
distanceTo
Bang
=
bang
Origin
.
distance
(
pedestrian
.
getPosition
());
VPoint
threat
Origin
=
topography
.
getTarget
(
current
Threat
.
getOriginAsTargetId
()).
getShape
().
getCentroid
();
double
distanceTo
Threat
=
threat
Origin
.
distance
(
pedestrian
.
getPosition
());
if
(
distanceTo
Bang
<=
current
Bang
.
getRadius
())
{
if
(
closestAndPerceptible
Bang
==
null
)
{
closestAndPerceptible
Bang
=
current
Bang
;
distanceToClosest
Bang
=
distanceTo
Bang
;
if
(
distanceTo
Threat
<=
current
Threat
.
getRadius
())
{
if
(
closestAndPerceptible
Threat
==
null
)
{
closestAndPerceptible
Threat
=
current
Threat
;
distanceToClosest
Threat
=
distanceTo
Threat
;
}
else
{
if
(
distanceTo
Bang
<
distanceToClosest
Bang
)
{
closestAndPerceptible
Bang
=
current
Bang
;
distanceToClosest
Bang
=
distanceTo
Bang
;
if
(
distanceTo
Threat
<
distanceToClosest
Threat
)
{
closestAndPerceptible
Threat
=
current
Threat
;
distanceToClosest
Threat
=
distanceTo
Threat
;
}
}
}
}
return
closestAndPerceptible
Bang
;
return
closestAndPerceptible
Threat
;
}
private
Stimulus
selectWaitInAreaContainingPedestrian
(
Pedestrian
pedestrian
,
List
<
Stimulus
>
waitInAreaStimuli
)
{
...
...
VadereSimulator/src/org/vadere/simulator/models/osm/OSMBehaviorController.java
View file @
863ae060
...
...
@@ -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
()));
}
}
...
...
VadereSimulator/src/org/vadere/simulator/models/osm/updateScheme/UpdateSchemeEventDriven.java
View file @
863ae060
...
...
@@ -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.
...
...
VadereSimulator/src/org/vadere/simulator/models/osm/updateScheme/UpdateSchemeSequential.java
View file @
863ae060
...
...
@@ -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
);
...
...
VadereSimulator/src/org/vadere/simulator/models/psychology/selfcategorization/SelfCatThreatModel.java
View file @
863ae060
...
...
@@ -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>
...
...
VadereSimulator/src/org/vadere/simulator/models/psychology/selfcategorization/locomotion/OSMBehaviorController.java
View file @
863ae060
...
...
@@ -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
bang
Origin
=
topography
.
getTarget
(
bang
.
getOriginAsTargetId
());
if
(
perceivedThreat
instanceof
Threat
&&
pedestrian
.
getCombinedPotentialStrategy
()
instanceof
TargetAttractionStrategy
)
{
Threat
threat
=
(
Threat
)
perceivedThreat
;
Target
threat
Origin
=
topography
.
getTarget
(
threat
.
getOriginAsTargetId
());
LinkedList
<
Integer
>
nextTarget
=
new
LinkedList
<>();
nextTarget
.
add
(
bang
Origin
.
getId
());
nextTarget
.
add
(
threat
Origin
.
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
())))
...
...
VadereSimulator/tests/org/vadere/simulator/control/psychology/perception/SimplePerceptionModelTest.java
View file @
863ae060
...
...
@@ -118,13 +118,13 @@ public class SimplePerceptionModelTest {
}
@Test
public
void
updateRanks
Bang
HigherThanElapsedTime
()
{
public
void
updateRanks
Threat
HigherThanElapsedTime
()
{
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
updateUsesClosest
Bang
ForPedestrian
()
{
// Place
bangs
at (0,0) and (5,0) with radii 5 and
public
void
updateUsesClosest
Threat
ForPedestrian
()
{
// 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
));
...
...
VadereState/src/org/vadere/state/psychology/perception/presettings/StimulusPresettings.java
View file @
863ae060
...
...
@@ -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
)),
};
...
...
VadereState/src/org/vadere/state/psychology/perception/types/Stimulus.java
View file @
863ae060
...
...
@@ -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
{
...
...
VadereState/src/org/vadere/state/psychology/perception/types/StimulusFactory.java
View file @
863ae060
...
...
@@ -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
()))
{
...
...
VadereState/src/org/vadere/state/psychology/perception/types/
Bang
.java
→
VadereState/src/org/vadere/state/psychology/perception/types/
Threat
.java
View file @
863ae060
package
org.vadere.state.psychology.perception.types
;
/**
* Class signals agents a
bang - f
or instance something exploded.
* Class signals agents a
threat. F
or 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
);
}
}
VadereState/src/org/vadere/state/scenario/AbsorbingArea.java
View file @
863ae060
...
...
@@ -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
>
{
...
...
VadereState/tests/org/vadere/state/psychology/perception/types/StimulusTest.java
View file @
863ae060
...
...
@@ -14,19 +14,19 @@ public class StimulusTest {
public
static
double
ALLOWED_DOUBLE_TOLERANCE
=
10
e
-
3
;
@Test
public
void
test
Bang
Clone
()
{
public
void
test
Threat
Clone
()
{
double
expectedTime
=
1
;
int
expectedOriginAsTargetId
=
2
;
Bang
bang
Original
=
new
Bang
(
expectedTime
,
expectedOriginAsTargetId
);
Threat
threat
Original
=
new
Threat
(
expectedTime
,
expectedOriginAsTargetId
);
Bang
bang
Clone
=
bang
Original
.
clone
();
bang
Clone
.
setTime
(
3
);
bang
Clone
.
setOriginAsTargetId
(
4
);
Threat
threat
Clone
=
threat
Original
.
clone
();
threat
Clone
.
setTime
(
3
);
threat
Clone
.
setOriginAsTargetId
(
4
);
assertEquals
(
expectedTime
,
bang
Original
.
getTime
(),
ALLOWED_DOUBLE_TOLERANCE
);
assertEquals
(
expectedOriginAsTargetId
,
bang
Original
.
getOriginAsTargetId
());
assertEquals
(
bang
Original
.
getLoudness
(),
bang
Clone
.
getLoudness
(),
ALLOWED_DOUBLE_TOLERANCE
);
assertEquals
(
expectedTime
,
threat
Original
.
getTime
(),
ALLOWED_DOUBLE_TOLERANCE
);
assertEquals
(
expectedOriginAsTargetId
,
threat
Original
.
getOriginAsTargetId
());
assertEquals
(
threat
Original
.
getLoudness
(),
threat
Clone
.
getLoudness
(),
ALLOWED_DOUBLE_TOLERANCE
);
}
@Test
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment