Commit 285b637b authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Added boolean variable "isCurrentTargetAnAgent" to "Agent" and use it in...

Added boolean variable "isCurrentTargetAnAgent" to "Agent" and use it in "TargetChangerController" and "PedestrianOSM"
parent 3f31ebc3
{
"name" : "Test-TargetChanger-ChangesToStaticTarget",
"description" : "",
"release" : "1.4",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.EventtimePedestrianIdOutputFile",
"filename" : "postvis.traj",
"processors" : [ 5, 6 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOverlapOutputFile",
"filename" : "overlaps.csv",
"processors" : [ 3 ]
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.NoDataKeyOutputFile",
"filename" : "overlapCount.txt",
"processors" : [ 4 ]
} ],
"processors" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianOverlapProcessor",
"id" : 3
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.NumberOverlapsProcessor",
"id" : 4,
"attributesType" : "org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor",
"attributes" : {
"pedestrianOverlapProcessorId" : 3
}
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.FootStepProcessor",
"id" : 5
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.FootStepTargetIDProcessor",
"id" : 6
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
},
"scenario" : {
"mainModel" : "org.vadere.simulator.models.osm.OptimalStepsModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesOSM" : {
"stepCircleResolution" : 4,
"numberOfCircles" : 1,
"optimizationType" : "NELDER_MEAD",
"varyStepDirection" : true,
"movementType" : "ARBITRARY",
"stepLengthIntercept" : 0.4625,
"stepLengthSlopeSpeed" : 0.2345,
"stepLengthSD" : 0.036,
"movementThreshold" : 0.0,
"minStepLength" : 0.1,
"minimumStepLength" : true,
"maxStepDuration" : 1.7976931348623157E308,
"dynamicStepLength" : true,
"updateType" : "EVENT_DRIVEN",
"seeSmallWalls" : false,
"targetPotentialModel" : "org.vadere.simulator.models.potential.fields.PotentialFieldTargetGrid",
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompactSoftshell",
"obstaclePotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldObstacleCompactSoftshell",
"submodels" : [ ]
},
"org.vadere.state.attributes.models.AttributesPotentialCompactSoftshell" : {
"pedPotentialIntimateSpaceWidth" : 0.45,
"pedPotentialPersonalSpaceWidth" : 1.2,
"pedPotentialHeight" : 50.0,
"obstPotentialWidth" : 0.8,
"obstPotentialHeight" : 6.0,
"intimateSpaceFactor" : 1.2,
"personalSpacePower" : 1,
"intimateSpacePower" : 1
},
"org.vadere.state.attributes.models.AttributesFloorField" : {
"createMethod" : "HIGH_ACCURACY_FAST_MARCHING",
"potentialFieldResolution" : 0.1,
"obstacleGridPenalty" : 0.1,
"targetAttractionStrength" : 1.0,
"cacheType" : "NO_CACHE",
"cacheDir" : "",
"timeCostAttributes" : {
"standardDeviation" : 0.7,
"type" : "UNIT",
"obstacleDensityWeight" : 3.5,
"pedestrianSameTargetDensityWeight" : 3.5,
"pedestrianOtherTargetDensityWeight" : 3.5,
"pedestrianWeight" : 3.5,
"queueWidthLoading" : 1.0,
"pedestrianDynamicWeight" : 6.0,
"loadingType" : "CONSTANT",
"width" : 0.2,
"height" : 1.0
}
}
},
"attributesSimulation" : {
"finishTime" : 100.0,
"simTimeStepLength" : 0.4,
"realTimeSimTimeRatio" : 0.1,
"writeSimulationData" : true,
"visualizationEnabled" : true,
"printFPS" : false,
"digitsPerCoordinate" : 2,
"useFixedSeed" : true,
"fixedSeed" : -3989740141114319444,
"simulationSeed" : 0,
"useSalientBehavior" : false
},
"topography" : {
"attributes" : {
"bounds" : {
"x" : 0.0,
"y" : 0.0,
"width" : 20.0,
"height" : 10.0
},
"boundingBoxWidth" : 0.5,
"bounded" : true,
"referenceCoordinateSystem" : null
},
"obstacles" : [ ],
"measurementAreas" : [ ],
"stairs" : [ ],
"targets" : [ {
"id" : 1,
"absorbing" : true,
"shape" : {
"x" : 18.0,
"y" : 8.0,
"width" : 1.0,
"height" : 1.0,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
}, {
"id" : 2,
"absorbing" : true,
"shape" : {
"x" : 18.0,
"y" : 1.0,
"width" : 1.1,
"height" : 1.0,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
}, {
"id" : 3,
"absorbing" : true,
"shape" : {
"x" : 18.0,
"y" : 4.5,
"width" : 1.0,
"height" : 1.0,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
} ],
"targetChangers" : [ {
"id" : 5,
"shape" : {
"x" : 7.9,
"y" : 0.4801097393689986,
"width" : 0.8242798353909446,
"height" : 8.97119341563786,
"type" : "RECTANGLE"
},
"reachDistance" : 0.0,
"nextTargetIsPedestrian" : false,
"nextTarget" : 3,
"probabilityToChangeTarget" : 0.0
} ],
"absorbingAreas" : [ ],
"sources" : [ {
"id" : 3,
"shape" : {
"x" : 1.0,
"y" : 8.0,
"width" : 1.0,
"height" : 1.0,
"type" : "RECTANGLE"
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"spawnNumber" : 1,
"maxSpawnNumberTotal" : -1,
"startTime" : 0.0,
"endTime" : 0.0,
"spawnAtRandomPositions" : false,
"useFreeSpaceOnly" : true,
"targetIds" : [ 1 ],
"groupSizeDistribution" : [ 1.0 ],
"dynamicElementType" : "PEDESTRIAN"
}, {
"id" : 4,
"shape" : {
"x" : 1.0,
"y" : 0.9,
"width" : 1.1,
"height" : 1.1,
"type" : "RECTANGLE"
},
"interSpawnTimeDistribution" : "org.vadere.state.scenario.ConstantDistribution",
"distributionParameters" : [ 1.0 ],
"spawnNumber" : 1,
"maxSpawnNumberTotal" : -1,
"startTime" : 0.0,
"endTime" : 0.0,
"spawnAtRandomPositions" : false,
"useFreeSpaceOnly" : true,
"targetIds" : [ 2 ],
"groupSizeDistribution" : [ 1.0 ],
"dynamicElementType" : "PEDESTRIAN"
} ],
"dynamicElements" : [ ],
"attributesPedestrian" : {
"radius" : 0.2,
"densityDependentSpeed" : false,
"speedDistributionMean" : 0.5,
"speedDistributionStandardDeviation" : 0.1,
"minimumSpeed" : 0.5,
"maximumSpeed" : 2.2,
"acceleration" : 2.0,
"footstepHistorySize" : 4,
"searchRadius" : 1.0,
"angleCalculationType" : "USE_CENTER",
"targetOrientationAngleThreshold" : 45.0
},
"teleporter" : null,
"attributesCar" : {
"id" : -1,
"radius" : 0.2,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.5,
"maximumSpeed" : 2.2,
"acceleration" : 2.0,
"footstepHistorySize" : 4,
"searchRadius" : 1.0,
"angleCalculationType" : "USE_CENTER",
"targetOrientationAngleThreshold" : 45.0,
"length" : 4.5,
"width" : 1.7,
"direction" : {
"x" : 1.0,
"y" : 0.0
}
}
},
"eventInfos" : [ ]
}
}
\ No newline at end of file
......@@ -145,9 +145,7 @@ public class TargetChangerController {
topography.addTarget(targetPedestrian);
// Make "agent" a follower of "pedToFollow".
LinkedList<Integer> nextTargetAsList = new LinkedList<>();
nextTargetAsList.add(pedToFollow.getId());
agent.setTargets(nextTargetAsList);
agent.setSingleTarget(pedToFollow.getId(), true);
}
private void useStaticTargetForAgent(Agent agent) {
......
......@@ -147,10 +147,15 @@ public class TargetController {
}
private boolean isNextTargetForAgent(Agent agent) {
boolean isNextTargetForAgent = false;
if (agent.hasNextTarget()) {
return agent.getNextTargetId() == target.getId();
if (agent.getNextTargetId() == target.getId()
&& agent.isCurrentTargetAnAgent() == false)
isNextTargetForAgent = true;
}
return false;
return isNextTargetForAgent;
}
// TODO [priority=high] [task=deprecation] removing the target from the list is deprecated, but still very frequently used everywhere.
......
......@@ -132,7 +132,7 @@ public class PedestrianOSM extends Pedestrian {
// }
} else if (!hasNextTarget() || getDurationNextStep() > getAttributesOSM().getMaxStepDuration()) {
this.nextPosition = getPosition();
} else if (topography.getTarget(getNextTargetId()).getShape().contains(getPosition())) {
} else if (isCurrentTargetAnAgent() == false && topography.getTarget(getNextTargetId()).getShape().contains(getPosition())) {
this.nextPosition = getPosition();
} else {
VCircle reachableArea = new VCircle(getPosition(), getDesiredStepSize());
......
......@@ -16,35 +16,38 @@ import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.math.TruncatedNormalDistribution;
public abstract class Agent extends DynamicElement {
// Member Variables
private AttributesAgent attributes;
/**
* Source where the agent was spawned. The SourceController should
* set this field. It may be <code>null</code> when the agent is created
* in different way.
*/
private Source source;
private LinkedList<Integer> targetIds;
private int nextTargetListIndex;
/** Indicates if current target is an agent or a (static) target. */
private boolean isCurrentTargetAnAgent;
private VPoint position;
private Vector2D velocity;
private int nextTargetListIndex;
private double freeFlowSpeed;
private AttributesAgent attributes;
// TODO: Maybe, add also a List<Agent> of followers for an agent.
// Constructors
public Agent(AttributesAgent attributesAgent) {
attributes = attributesAgent;
position = new VPoint(0, 0);
velocity = new Vector2D(0, 0);
targetIds = new LinkedList<>();
nextTargetListIndex = 0;
attributes = attributesAgent;
isCurrentTargetAnAgent = false;
}
public Agent(AttributesAgent attributesAgent, Random random) {
this(attributesAgent);
......@@ -67,14 +70,64 @@ public abstract class Agent extends DynamicElement {
this.setTargets(new LinkedList<>(other.targetIds));
this.setNextTargetListIndex(other.nextTargetListIndex);
this.isCurrentTargetAnAgent = other.isCurrentTargetAnAgent;
this.position = other.position;
this.velocity = other.velocity;
this.freeFlowSpeed = other.freeFlowSpeed;
}
public LinkedList<Integer> getTargets() {
return targetIds;
}
// Getters
@Override
public AttributesAgent getAttributes() {
return attributes;
}
@Override
public int getId() {
return attributes.getId();
}
public Source getSource() {
return source;
}
public LinkedList<Integer> getTargets() {
return targetIds;
}
/**
* Get the index pointing to the next target in the target list.
*
* Usually this index is >= 0 and <= {@link #getTargets()}<code>.size()</code>. Targets are
* never removed from the target list. This index is incremented instead.
*
* In deprecated usage this index is -1. This means, the next target is always the first target
* in the list. Once a target is reached it is remove from the list.
*
*/
public int getNextTargetListIndex() {
return nextTargetListIndex;
}
/**
* Get the id of the next target. Please call {@link #hasNextTarget()} first, to check if there
* is a next target. If there is no next target, an exception is thrown.
*
*/
public int getNextTargetId() {
// Deprecated target list usage
if (nextTargetListIndex == -1) {
return targetIds.getFirst();
}
// The right way:
return targetIds.get(nextTargetListIndex);
}
public boolean isCurrentTargetAnAgent() {
return isCurrentTargetAnAgent;
}
public Vector2D getVelocity() {
return velocity;
......@@ -101,130 +154,42 @@ public abstract class Agent extends DynamicElement {
return position;
}
@Override
public void setShape(VShape newShape) {
position = newShape.getCentroid();
}
@Override
public VShape getShape() {
return new VCircle(position, attributes.getRadius());
}
public Source getSource() {
return source;
}
/**
* Initially set pedestrians will not have source id set.
*/
public boolean hasSource(){
return source != null;
}
@Override
public int getId() {
return attributes.getId();
}
/**
* Converts a Iterable of Agent to a List of VPoint positions.
*
* @param agents
* @return a List of VPoint positions of the agents
*/
public static List<VPoint> getPositions(final Iterable<Agent> agents) {
List<VPoint> agentPositions = new ArrayList<>();
if (agents != null) {
for (Agent agent : agents) {
agentPositions.add(agent.getPosition());
}
}
return agentPositions;
}
// Getters...
/**
* Get the index pointing to the next target in the target list.
*
* Usually this index is >= 0 and <= {@link #getTargets()}<code>.size()</code>. Targets are
* never removed from the target list. This index is incremented instead.
*
* In deprecated usage this index is -1. This means, the next target is always the first target
* in the list. Once a target is reached it is remove from the list.
*
*/
public int getNextTargetListIndex() {
return nextTargetListIndex;
}
/**
* Get the id of the next target. Please call {@link #hasNextTarget()} first, to check if there
* is a next target. If there is no next target, an exception is thrown.
*
*/
public int getNextTargetId() {
// Deprecated target list usage
if (nextTargetListIndex == -1) {
return targetIds.getFirst();
}
// The right way:
return targetIds.get(nextTargetListIndex);
}
public boolean hasNextTarget() {
// Deprecated target list usage
if (nextTargetListIndex == -1) {
return !targetIds.isEmpty();
}
// The right way:
return nextTargetListIndex < targetIds.size();
}
@Override
public AttributesAgent getAttributes() {
return attributes;
}
// Setters...
// Setters
@Override
public void setAttributes(Attributes attributes) {
this.attributes = (AttributesAgent) attributes;
}
/**
* Set the index pointing to the next target in the target list.
*
* Set the index to 0 to set the first target in the target list as next target. Use
* {@link #incrementNextTargetListIndex()} to proceed to the next target.
*
* Set the index to -1 if you really have to use the deprecated target list approach.
*
* @see #getNextTargetListIndex()
*/
public void setNextTargetListIndex(int nextTargetListIndex) {
this.nextTargetListIndex = nextTargetListIndex;
}
public void setSource(Source source) {
this.source = source;
}
public void incrementNextTargetListIndex() {
// Deprecated target list usage
if (nextTargetListIndex == -1) {
throw new IllegalStateException("nextTargetListIndex is -1. this indicates the deprecated usage of "
+ "the target list. you have to set the index to 0 before you can start incrementing.");
}
nextTargetListIndex++;
}
public void setTargets(LinkedList<Integer> targetIds) {
this.targetIds = targetIds;
}
/**
* Set the index pointing to the next target in the target list.
*
* Set the index to 0 to set the first target in the target list as next target. Use
* {@link #incrementNextTargetListIndex()} to proceed to the next target.
*
* Set the index to -1 if you really have to use the deprecated target list approach.
*
* @see #getNextTargetListIndex()
*/
public void setNextTargetListIndex(int nextTargetListIndex) {
this.nextTargetListIndex = nextTargetListIndex;
}
public void setIsCurrentTargetAnAgent(boolean isCurrentTargetAnAgent) {
this.isCurrentTargetAnAgent = isCurrentTargetAnAgent;
}
public void setPosition(VPoint position) {
this.position = position;
......@@ -234,18 +199,75 @@ public abstract class Agent extends DynamicElement {
this.velocity = velocity;
}
public void setTargets(LinkedList<Integer> targetIds) {
this.targetIds = targetIds;
}
public void addTarget(Target target) {
targetIds.add(target.getId());
}
// TODO [task=refactoring] remove again!
public void setFreeFlowSpeed(double freeFlowSpeed) {
this.freeFlowSpeed = freeFlowSpeed;
}
public abstract Agent clone();
@Override
public void setShape(VShape newShape) {
position = newShape.getCentroid();