Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
vadere
vadere
Commits
73c02c94
Commit
73c02c94
authored
Apr 05, 2019
by
Benedikt Kleinmeier
Browse files
Use class "SalientBehaviorCognition" in "Simulation".
parent
23220a13
Pipeline
#103240
passed with stages
in 135 minutes and 29 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereSimulator/src/org/vadere/simulator/control/Simulation.java
View file @
73c02c94
package
org.vadere.simulator.control
;
import
org.vadere.simulator.control.cognition.EventCognition
;
import
org.vadere.simulator.control.cognition.SalientBehaviorCognition
;
import
org.vadere.simulator.control.events.EventController
;
import
org.vadere.simulator.control.factory.SourceControllerFactory
;
import
org.vadere.simulator.models.DynamicElementFactory
;
...
...
@@ -71,6 +72,7 @@ public class Simulation {
private
SimulationResult
simulationResult
;
private
final
EventController
eventController
;
private
final
EventCognition
eventCognition
;
private
final
SalientBehaviorCognition
salientBehaviorCognition
;
public
Simulation
(
MainModel
mainModel
,
double
startTimeInSec
,
final
String
name
,
ScenarioStore
scenarioStore
,
List
<
PassiveCallback
>
passiveCallbacks
,
Random
random
,
ProcessorManager
processorManager
,
...
...
@@ -102,6 +104,7 @@ public class Simulation {
// "eventController" is final. Therefore, create object here and not in helper method.
this
.
eventController
=
new
EventController
(
scenarioStore
);
this
.
eventCognition
=
new
EventCognition
();
this
.
salientBehaviorCognition
=
new
SalientBehaviorCognition
(
topography
);
createControllers
(
topography
,
mainModel
,
random
);
...
...
@@ -317,7 +320,9 @@ public class Simulation {
step
++;
Collection
<
Pedestrian
>
pedestrians
=
topography
.
getElements
(
Pedestrian
.
class
);
eventCognition
.
prioritizeEventsForPedestrians
(
events
,
pedestrians
);
salientBehaviorCognition
.
setSalientBehaviorForPedestrians
(
pedestrians
,
simTimeInSec
);
for
(
Model
m
:
models
)
{
List
<
SourceController
>
stillSpawningSource
=
this
.
sourceControllers
.
stream
().
filter
(
s
->
!
s
.
isSourceFinished
(
simTimeInSec
)).
collect
(
Collectors
.
toList
());
...
...
VadereSimulator/src/org/vadere/simulator/control/cognition/SalientBehaviorCognition.java
View file @
73c02c94
...
...
@@ -5,6 +5,7 @@ import org.vadere.state.behavior.SalientBehavior;
import
org.vadere.state.events.types.Event
;
import
org.vadere.state.scenario.Pedestrian
;
import
org.vadere.state.scenario.Topography
;
import
org.vadere.state.simulation.LastFootSteps
;
import
java.util.Collection
;
import
java.util.List
;
...
...
@@ -13,7 +14,7 @@ import java.util.List;
* The SalientBehaviorCognition class should provide logic to change the salient behavior of a pedestrian
* (e.g., change to cooperative behavior when no movement is possible for n steps).
*
* Watch out: The {@link EventCognition} should be finished before using methods in this class because usually
* Watch out: The {@link EventCognition} should be finished before using methods in this class because
,
usually
,
* first an event occurs and then pedestrians decide about their behavior. E.g., first a {@link BangEvent} occurs
* and then a pedestrian decides to follow a {@link SalientBehavior#COOPERATIVE} behavior.
*/
...
...
@@ -27,11 +28,23 @@ public class SalientBehaviorCognition {
}
public
void
setSalientBehaviorForPedestrians
(
Collection
<
Pedestrian
>
pedestrians
,
double
simTimeInSec
)
{
// TODO: Set salient behavior for each pedestrian individually based on the most important event and/or if
// the pedestrian could not move for several time steps.
for
(
Pedestrian
pedestrian
:
pedestrians
)
{
// TODO: Set salient behavior for each pedestrian individually based on the most important event and/or if
// the pedestrian could not move for several time steps.
// TODO: Maybe, add following variables as attribute to "AttributesAgent".
int
requiredFootSteps
=
5
;
double
requiredSpeedInMetersPerSecondToBeCooperative
=
0.05
;
LastFootSteps
lastFootSteps
=
pedestrian
.
getFootSteps
().
getLastFootSteps
();
// TODO: Use pedestrian.getFootSteps() to calculate average velocity for last
if
(
lastFootSteps
.
size
()
>=
requiredFootSteps
)
{
// Adapt behavior only if we have seen some footsteps in the past
if
(
lastFootSteps
.
getAverageSpeedInMeterPerSecond
()
<=
requiredSpeedInMetersPerSecondToBeCooperative
)
{
pedestrian
.
setSalientBehavior
(
SalientBehavior
.
COOPERATIVE
);
}
else
{
pedestrian
.
setSalientBehavior
(
SalientBehavior
.
TARGET_ORIENTED
);
}
}
}
}
}
VadereState/src/org/vadere/state/scenario/Pedestrian.java
View file @
73c02c94
...
...
@@ -4,6 +4,7 @@ import org.vadere.state.attributes.scenario.AttributesAgent;
import
org.vadere.state.behavior.SalientBehavior
;
import
org.vadere.state.events.types.Event
;
import
org.vadere.state.simulation.FootStep
;
import
org.vadere.state.simulation.LastFootSteps
;
import
org.vadere.state.simulation.VTrajectory
;
import
org.vadere.state.types.ScenarioElementType
;
...
...
@@ -83,13 +84,6 @@ public class Pedestrian extends Agent {
trajectory
=
other
.
trajectory
;
}
public
void
clearFootSteps
()
{
trajectory
.
clear
();
}
public
VTrajectory
getFootSteps
()
{
return
trajectory
;
}
// Getter
public
int
getIdAsTarget
()
{
return
this
.
idAsTarget
;
...
...
@@ -111,6 +105,9 @@ public class Pedestrian extends Agent {
public
ScenarioElementType
getType
()
{
return
ScenarioElementType
.
PEDESTRIAN
;
}
public
VTrajectory
getFootSteps
()
{
return
trajectory
;
}
// Setter
public
void
setIdAsTarget
(
int
id
)
{
this
.
idAsTarget
=
id
;
}
...
...
@@ -142,6 +139,12 @@ public class Pedestrian extends Agent {
groupSizes
.
add
(
size
);
}
public
void
clearFootSteps
()
{
trajectory
.
clear
();
}
// Overridden Methods
@Override
public
Pedestrian
clone
()
{
return
new
Pedestrian
(
this
);
...
...
VadereState/src/org/vadere/state/simulation/LastFootSteps.java
View file @
73c02c94
...
...
@@ -23,6 +23,7 @@ public class LastFootSteps {
// Getters
public
int
getCapacity
()
{
return
capacity
;
}
public
ArrayList
<
FootStep
>
getFootSteps
()
{
return
footSteps
;
}
public
int
size
()
{
return
footSteps
.
size
();
}
// Methods
public
boolean
add
(
FootStep
footStep
)
{
...
...
VadereState/src/org/vadere/state/simulation/VTrajectory.java
View file @
73c02c94
...
...
@@ -14,9 +14,11 @@ import java.util.stream.Stream;
public
class
VTrajectory
implements
Iterable
<
FootStep
>
{
// Variables
private
LinkedList
<
FootStep
>
footSteps
;
private
transient
LastFootSteps
lastFootSteps
;
// Constructors
public
VTrajectory
(){
this
(
10
);
}
...
...
@@ -26,6 +28,16 @@ public class VTrajectory implements Iterable<FootStep> {
lastFootSteps
=
new
LastFootSteps
(
lastFootStepCapacity
);
}
// Getters
public
LinkedList
<
FootStep
>
getFootSteps
()
{
return
new
LinkedList
<>(
footSteps
);
}
public
LastFootSteps
getLastFootSteps
()
{
return
lastFootSteps
;
}
// Methods
public
Optional
<
Double
>
speed
(
@NotNull
final
VRectangle
rectangle
)
{
VTrajectory
cutting
=
clone
();
cutting
.
cut
(
rectangle
);
...
...
@@ -162,14 +174,12 @@ public class VTrajectory implements Iterable<FootStep> {
}
public
VTrajectory
clone
()
{
LinkedList
<
FootStep
>
copy
=
new
LinkedList
<>(
footSteps
);
VTrajectory
clone
=
new
VTrajectory
();
clone
.
footSteps
=
copy
;
return
clone
;
}
VTrajectory
newTrajectory
=
new
VTrajectory
();
public
LinkedList
<
FootStep
>
getFootSteps
()
{
return
new
LinkedList
<>(
footSteps
);
LinkedList
<
FootStep
>
footStepCopy
=
new
LinkedList
<>(
footSteps
);
newTrajectory
.
footSteps
=
footStepCopy
;
return
newTrajectory
;
}
public
VTrajectory
cut
(
final
double
startTime
,
final
double
endTime
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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