Commit 4c38ef02 authored by Christina Maria Mayr's avatar Christina Maria Mayr
Browse files

Merge branch 'bug_and_refactor' into 'master'

refactoring + bug fix

See merge request !164
parents ad56441d e95ffc21
Pipeline #618331 passed with stages
in 139 minutes and 47 seconds
...@@ -202,10 +202,11 @@ public class SimulationCommandHandler extends CommandHandler<SimulationVar> { ...@@ -202,10 +202,11 @@ public class SimulationCommandHandler extends CommandHandler<SimulationVar> {
Topography topography = state.getTopography(); Topography topography = state.getTopography();
boolean isUsePsychologyLayer = state.getScenarioStore().getAttributesPsychology().isUsePsychologyLayer(); boolean isUsePsychologyLayer = state.getScenarioStore().getAttributesPsychology().isUsePsychologyLayer();
ReactionModel reactionModel = new ReactionModel(reactionModelParameter); ReactionModel reactionModel = new ReactionModel(reactionModelParameter);
double simTimeStepLength = state.getScenarioStore().getAttributesSimulation().getSimTimeStepLength();
if (!iControlModelHashMap.containsKey(controlModelName)) { if (!iControlModelHashMap.containsKey(controlModelName)) {
IControlModel controlModel = ControlModelBuilder.getModel(controlModelType); IControlModel controlModel = ControlModelBuilder.getModel(controlModelType);
controlModel.init(topography, stimulusController, isUsePsychologyLayer, reactionModel); controlModel.init(topography, stimulusController, isUsePsychologyLayer, reactionModel, simTimeStepLength);
iControlModelHashMap.put(controlModelName, controlModel); iControlModelHashMap.put(controlModelName, controlModel);
} }
...@@ -244,9 +245,10 @@ public class SimulationCommandHandler extends CommandHandler<SimulationVar> { ...@@ -244,9 +245,10 @@ public class SimulationCommandHandler extends CommandHandler<SimulationVar> {
Topography topography = state.getTopography(); Topography topography = state.getTopography();
boolean isUsePsychologyLayer = state.getScenarioStore().getAttributesPsychology().isUsePsychologyLayer(); boolean isUsePsychologyLayer = state.getScenarioStore().getAttributesPsychology().isUsePsychologyLayer();
ReactionModel reactionModel = new ReactionModel(); ReactionModel reactionModel = new ReactionModel();
double simTimeStepLength = state.getScenarioStore().getAttributesSimulation().getSimTimeStepLength();
IControlModel controlModel = ControlModelBuilder.getModel(model_name); IControlModel controlModel = ControlModelBuilder.getModel(model_name);
controlModel.init(topography, stimulusController, isUsePsychologyLayer, reactionModel); controlModel.init(topography, stimulusController, isUsePsychologyLayer, reactionModel, simTimeStepLength);
iControlModelHashMap.put(model_name, controlModel); iControlModelHashMap.put(model_name, controlModel);
}); });
} }
......
...@@ -4,7 +4,6 @@ package org.vadere.simulator.control.external.models; ...@@ -4,7 +4,6 @@ package org.vadere.simulator.control.external.models;
import org.json.JSONObject; import org.json.JSONObject;
import org.vadere.simulator.control.external.reaction.ReactionModel; import org.vadere.simulator.control.external.reaction.ReactionModel;
import org.vadere.simulator.control.psychology.perception.StimulusController; import org.vadere.simulator.control.psychology.perception.StimulusController;
import org.vadere.simulator.projects.ScenarioStore;
import org.vadere.state.psychology.information.InformationState; import org.vadere.state.psychology.information.InformationState;
import org.vadere.state.scenario.Pedestrian; import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography; import org.vadere.state.scenario.Topography;
...@@ -26,6 +25,7 @@ public abstract class ControlModel implements IControlModel { ...@@ -26,6 +25,7 @@ public abstract class ControlModel implements IControlModel {
protected HashMap<Pedestrian,LinkedList<Integer>> processedAgents; protected HashMap<Pedestrian,LinkedList<Integer>> processedAgents;
protected StimulusController stimulusController; protected StimulusController stimulusController;
private boolean isUsePsychologyLayer = false; private boolean isUsePsychologyLayer = false;
private double simTimeStepLength;
public ControlModel(){ public ControlModel(){
...@@ -35,6 +35,18 @@ public abstract class ControlModel implements IControlModel { ...@@ -35,6 +35,18 @@ public abstract class ControlModel implements IControlModel {
} }
@Override
public void init(final Topography topography, final StimulusController stimulusController, final boolean isUsePsychologyLayer, final ReactionModel reactionModel, final double simTimeStepLength) {
processedAgents = new HashMap<>();
simTime = 0.0;
this.topography = topography;
this.stimulusController = stimulusController;
this.isUsePsychologyLayer = isUsePsychologyLayer;
this.reactionModel = reactionModel;
this.simTimeStepLength = simTimeStepLength;
}
@Override @Override
public void init(final Topography topography, final StimulusController stimulusController, final boolean isUsePsychologyLayer, final ReactionModel reactionModel) { public void init(final Topography topography, final StimulusController stimulusController, final boolean isUsePsychologyLayer, final ReactionModel reactionModel) {
processedAgents = new HashMap<>(); processedAgents = new HashMap<>();
...@@ -70,7 +82,7 @@ public abstract class ControlModel implements IControlModel { ...@@ -70,7 +82,7 @@ public abstract class ControlModel implements IControlModel {
public abstract boolean isPedReact(); public abstract boolean isPedReact();
protected abstract void triggerRedRaction(Pedestrian ped); protected abstract void triggerPedReaction(Pedestrian ped);
public void setProcessedAgents(Pedestrian ped, LinkedList<Integer> ids){ public void setProcessedAgents(Pedestrian ped, LinkedList<Integer> ids){
...@@ -155,7 +167,7 @@ public abstract class ControlModel implements IControlModel { ...@@ -155,7 +167,7 @@ public abstract class ControlModel implements IControlModel {
public void setAction(Pedestrian ped){ public void setAction(Pedestrian ped){
if (isPedReact()){ if (isPedReact()){
triggerRedRaction(ped); triggerPedReaction(ped);
} }
else{ else{
ped.getKnowledgeBase().setInformationState(InformationState.INFORMATION_UNCONVINCING_RECEIVED); ped.getKnowledgeBase().setInformationState(InformationState.INFORMATION_UNCONVINCING_RECEIVED);
...@@ -188,4 +200,20 @@ public abstract class ControlModel implements IControlModel { ...@@ -188,4 +200,20 @@ public abstract class ControlModel implements IControlModel {
public boolean isUsePsychologyLayer() { public boolean isUsePsychologyLayer() {
return isUsePsychologyLayer; return isUsePsychologyLayer;
} }
public double getSimTimeStepLength() {
return simTimeStepLength;
}
public void setSimTimeStepLength(final double simTimeStepLength) {
this.simTimeStepLength = simTimeStepLength;
}
public double getTimeOfNextStimulusAvailable(){
return getTimeOfNextStimulusAvailable(this.simTime);
}
public double getTimeOfNextStimulusAvailable(double currentSimTime){
return this.simTime + getSimTimeStepLength();
}
} }
...@@ -15,6 +15,8 @@ import org.vadere.state.scenario.Topography; ...@@ -15,6 +15,8 @@ import org.vadere.state.scenario.Topography;
public interface IControlModel { public interface IControlModel {
void init(final Topography topo, final StimulusController stimulusController, final boolean isUsePsychologyLayer, final ReactionModel reactionModel, final double simTimeStepLength);
void init(final Topography topo, final StimulusController stimulusController, final boolean isUsePsychologyLayer, final ReactionModel reactionModel); void init(final Topography topo, final StimulusController stimulusController, final boolean isUsePsychologyLayer, final ReactionModel reactionModel);
void init(final Topography topo, final StimulusController stimulusController, final boolean isUsePsychologyLayer); void init(final Topography topo, final StimulusController stimulusController, final boolean isUsePsychologyLayer);
void init(final Topography topo, final ReactionModel reactionModel); void init(final Topography topo, final ReactionModel reactionModel);
......
...@@ -52,21 +52,22 @@ public class RouteChoice extends ControlModel { ...@@ -52,21 +52,22 @@ public class RouteChoice extends ControlModel {
} }
@Override @Override
protected void triggerRedRaction(Pedestrian ped) { protected void triggerPedReaction(Pedestrian ped) {
LinkedList<Integer> oldTarget = ped.getTargets(); LinkedList<Integer> oldTarget = ped.getTargets();
if (isUsePsychologyLayer()) { if (isUsePsychologyLayer()) {
double timeCommandExecuted = this.simTime + 0.4; // in this case the targets are set in the next time step when updating the psychology layer
double timeCommandExecuted = getTimeOfNextStimulusAvailable();
this.stimulusController.setDynamicStimulus(ped, new ChangeTarget(timeCommandExecuted, newTargetList), timeCommandExecuted); this.stimulusController.setDynamicStimulus(ped, new ChangeTarget(timeCommandExecuted, newTargetList), timeCommandExecuted);
logger.debug("Pedestrian " + ped.getId() + ": created Stimulus ChangeTarget. New target list " + newTargetList); logger.debug("Pedestrian " + ped.getId() + ": created Stimulus ChangeTarget. New target list " + newTargetList);
}else{ }else{
ped.setTargets(newTargetList); ped.setTargets(newTargetList);
ped.getKnowledgeBase().setInformationState(InformationState.INFORMATION_CONVINCING_RECEIVED); ped.getKnowledgeBase().setInformationState(InformationState.INFORMATION_CONVINCING_RECEIVED);
// in this case the targets are set directly
logger.debug("Pedestrian " + ped.getId() + ": changed target list from " + oldTarget + " to " + newTargetList); logger.debug("Pedestrian " + ped.getId() + ": changed target list from " + oldTarget + " to " + newTargetList);
} }
} }
......
...@@ -164,6 +164,8 @@ public class StimulusController { ...@@ -164,6 +164,8 @@ public class StimulusController {
stimulusInfo.setTimeframe(new Timeframe(0, simTimeNextTimeStep, false, 0)); stimulusInfo.setTimeframe(new Timeframe(0, simTimeNextTimeStep, false, 0));
stimulusInfo.setStimuli(newStimulus); stimulusInfo.setStimuli(newStimulus);
stimuliList.add(stimulusInfo);
pedSpecificStimuli.put(ped, stimuliList); pedSpecificStimuli.put(ped, stimuliList);
} }
......
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