Commit 60cc9b0d authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier

In all locomotion classes, throw exception if an event is not supported by...

In all locomotion classes, throw exception if an event is not supported by this model to inform the user.

Use new exception "NotSupportedEvent" or the static helper method "throwExceptionIfNotElapsedTimeEvent()".

VadereModelTests/TestBangEvent/scenarios/00-NotSupportedEventTest.scenario:
- Added this scenario to test if an exception pops up in GUI when combining a locomotion model and an unsupported event.
parent 5895e7ad
Pipeline #92945 failed with stages
in 4 minutes and 6 seconds
{
"name" : "00-NotSupportedEventTest",
"description" : "",
"release" : "0.7",
"processWriters" : {
"files" : [ {
"type" : "org.vadere.simulator.projects.dataprocessing.outputfile.TimestepPedestrianIdOutputFile",
"filename" : "postvis.trajectories",
"processors" : [ 1, 2 ]
}, {
"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.PedestrianPositionProcessor",
"id" : 1
}, {
"type" : "org.vadere.simulator.projects.dataprocessing.processor.PedestrianTargetIdProcessor",
"id" : 2
}, {
"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
}
} ],
"isTimestamped" : true,
"isWriteMetaData" : false
},
"scenario" : {
"mainModel" : "org.vadere.simulator.models.reynolds.ReynoldsSteeringModel",
"attributesModel" : {
"org.vadere.state.attributes.models.AttributesReynolds" : { }
},
"attributesSimulation" : {
"finishTime" : 50.0,
"simTimeStepLength" : 0.4,
"realTimeSimTimeRatio" : 0.1,
"writeSimulationData" : true,
"visualizationEnabled" : true,
"printFPS" : false,
"digitsPerCoordinate" : 2,
"useFixedSeed" : true,
"fixedSeed" : -2062305966864041707,
"simulationSeed" : 0
},
"topography" : {
"attributes" : {
"bounds" : {
"x" : 0.0,
"y" : 0.0,
"width" : 30.0,
"height" : 5.0
},
"boundingBoxWidth" : 0.5,
"bounded" : true
},
"obstacles" : [ ],
"stairs" : [ ],
"targets" : [ {
"id" : 1,
"absorbing" : true,
"shape" : {
"x" : 28.0,
"y" : 1.0,
"width" : 0.9,
"height" : 2.9,
"type" : "RECTANGLE"
},
"waitingTime" : 0.0,
"waitingTimeYellowPhase" : 0.0,
"parallelWaiters" : 0,
"individualWaiting" : true,
"deletionDistance" : 0.1,
"startingWithRedLight" : false,
"nextSpeed" : -1.0
} ],
"absorbingAreas" : [ ],
"sources" : [ ],
"dynamicElements" : [ {
"source" : null,
"targetIds" : [ 1 ],
"position" : {
"x" : 20.4,
"y" : 2.5
},
"velocity" : {
"x" : 0.0,
"y" : 0.0
},
"nextTargetListIndex" : 0,
"freeFlowSpeed" : 1.6,
"attributes" : {
"id" : -1,
"radius" : 0.2,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.5,
"maximumSpeed" : 2.2,
"acceleration" : 2.0
},
"idAsTarget" : -1,
"isChild" : false,
"isLikelyInjured" : false,
"mostImportantEvent" : null,
"groupIds" : [ ],
"trajectory" : {
"footSteps" : [ ]
},
"groupSizes" : [ ],
"modelPedestrianMap" : null,
"type" : "PEDESTRIAN"
} ],
"attributesPedestrian" : {
"radius" : 0.2,
"densityDependentSpeed" : false,
"speedDistributionMean" : 1.34,
"speedDistributionStandardDeviation" : 0.26,
"minimumSpeed" : 0.5,
"maximumSpeed" : 2.2,
"acceleration" : 2.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,
"length" : 4.5,
"width" : 1.7,
"direction" : {
"x" : 1.0,
"y" : 0.0
}
}
},
"eventInfos" : [ {
"eventTimeframe" : {
"startTime" : 0.0,
"endTime" : 0.4,
"repeat" : false,
"waitTimeBetweenRepetition" : 0.0
},
"events" : [ {
"type" : "BangEvent",
"targets" : [ ],
"originAsTargetId" : 1
} ]
} ]
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package org.vadere.simulator.models.bhm;
import org.vadere.state.attributes.models.AttributesBHM;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.events.exceptions.NotSupportedEvent;
import org.vadere.state.events.types.ElapsedTimeEvent;
import org.vadere.state.events.types.Event;
import org.vadere.state.events.types.WaitEvent;
......@@ -160,6 +161,8 @@ public class PedestrianBHM extends Pedestrian {
timeOfNextStep += durationNextStep;
} else if (mostImportantEvent instanceof WaitEvent || mostImportantEvent instanceof WaitInAreaEvent) {
timeOfNextStep += durationNextStep;
} else {
throw new NotSupportedEvent(mostImportantEvent, this.getClass());
}
getFootSteps().add(new FootStep(position, getPosition(), timeOfNextStep, timeOfNextStep + durationNextStep));
......
package org.vadere.simulator.models.bmm;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
import org.jetbrains.annotations.NotNull;
import org.vadere.annotation.factories.models.ModelClass;
import org.vadere.simulator.models.MainModel;
......@@ -13,6 +8,7 @@ import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.models.AttributesBHM;
import org.vadere.state.attributes.models.AttributesBMM;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.events.exceptions.NotSupportedEvent;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
......@@ -20,6 +16,11 @@ import org.vadere.state.simulation.FootStep;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VShape;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;
import java.util.stream.Collectors;
/**
*
* MainModel READY!
......@@ -96,6 +97,8 @@ public class BiomechanicsModel implements MainModel {
List<VPoint> positions = pedestriansBMM.stream().map(ped -> ped.getPosition()).collect(Collectors.toList());
NotSupportedEvent.throwExceptionIfNotElapsedTimeEvent(pedestriansBMM, this.getClass());
for (PedestrianBMM agent : pedestriansBMM) {
agent.update(simTimeInSec, deltaTime);
}
......
......@@ -14,6 +14,7 @@ import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.models.AttributesGNM;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.events.exceptions.NotSupportedEvent;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Target;
......@@ -147,6 +148,8 @@ public class GradientNavigationModel extends ODEModel<Pedestrian, AttributesAgen
Collection<Pedestrian> pedestrians = topography.getElements(Pedestrian.class);
NotSupportedEvent.throwExceptionIfNotElapsedTimeEvent(pedestrians, this.getClass());
// set gradient provider and pedestrians
equations.setElements(pedestrians);
......
......@@ -70,6 +70,8 @@ public class UpdateSchemeEventDriven implements UpdateSchemeOSM {
BangEvent bangEvent = (BangEvent) mostImportantEvent;
Target bangOrigin = topography.getTarget(bangEvent.getOriginAsTargetId());
// TODO: Just setting a new target does not work when using "EVENT_DRIVEN".
// Maybe, we have to clear the priority queue or something else (clarify with BZ).
LinkedList<Integer> nextTarget = new LinkedList<>();
nextTarget.add(bangOrigin.getId());
......
......@@ -19,6 +19,7 @@ import org.vadere.simulator.models.reynolds.behaviour.Wander;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.models.AttributesReynolds;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.events.exceptions.NotSupportedEvent;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
......@@ -75,6 +76,9 @@ public class ReynoldsSteeringModel implements MainModel {
@Override
public void update(final double simTimeInSec) {
Collection<Pedestrian> pedestrians = topography.getElements(Pedestrian.class);
NotSupportedEvent.throwExceptionIfNotElapsedTimeEvent(pedestrians, this.getClass());
Iterator<Pedestrian> it = pedestrians.iterator();
double maxSpeed = 3;
......
......@@ -12,6 +12,7 @@ import org.vadere.simulator.models.potential.fields.PotentialFieldObstacle;
import org.vadere.state.attributes.Attributes;
import org.vadere.state.attributes.models.AttributesSFM;
import org.vadere.state.attributes.scenario.AttributesAgent;
import org.vadere.state.events.exceptions.NotSupportedEvent;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Target;
......@@ -139,6 +140,8 @@ public class SocialForceModel extends ODEModel<Pedestrian, AttributesAgent> {
Collection<Pedestrian> pedestrians = topography.getElements(Pedestrian.class);
NotSupportedEvent.throwExceptionIfNotElapsedTimeEvent(pedestrians, this.getClass());
// set gradient provider and pedestrians
equations.setElements(pedestrians);
......
package org.vadere.state.events.exceptions;
import org.jetbrains.annotations.NotNull;
import org.vadere.state.events.types.ElapsedTimeEvent;
import org.vadere.state.events.types.Event;
import org.vadere.state.scenario.Pedestrian;
import java.util.Collection;
/**
* Use this exception if an event-handling class does not support a specific event.
*/
public class NotSupportedEvent extends RuntimeException {
public NotSupportedEvent(@NotNull Event unsupportedEvent, @NotNull Class implementingClass) {
super(String.format("Event \"%s\" not supported by class \"%s\"!",
unsupportedEvent.getClass().getSimpleName(),
implementingClass.getSimpleName())
);
}
public static void throwExceptionIfNotElapsedTimeEvent(Collection<? extends Pedestrian> pedestrians, Class caller) {
for (Pedestrian pedestrian : pedestrians) {
Event currentEvent = pedestrian.getMostImportantEvent();
if ((currentEvent instanceof ElapsedTimeEvent) == false) {
throw new NotSupportedEvent(currentEvent, caller);
}
}
}
}
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