Commit 0589a856 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Added "probabilityInGroupMembership" to "AttributesSelfCatThreat" and use it...

Added "probabilityInGroupMembership" to "AttributesSelfCatThreat" and use it in "SelfCatThreatModel" to assign pedestrian's group membership
parent b9bded7e
Pipeline #204062 passed with stages
in 126 minutes and 17 seconds
......@@ -92,7 +92,8 @@
"pedestrianPotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldPedestrianCompactSoftshell",
"obstaclePotentialModel" : "org.vadere.simulator.models.potential.PotentialFieldObstacleCompactSoftshell",
"submodels" : [ ]
}
},
"probabilityInGroupMembership" : 0.0
},
"org.vadere.state.attributes.models.AttributesPotentialCompactSoftshell" : {
"pedPotentialIntimateSpaceWidth" : 0.45,
......@@ -308,7 +309,8 @@
"psychologyStatus" : {
"mostImportantStimulus" : null,
"perceivedThreat" : null,
"selfCategory" : "TARGET_ORIENTED"
"selfCategory" : "TARGET_ORIENTED",
"groupMembership" : "OUT_GROUP"
},
"groupIds" : [ ],
"groupSizes" : [ ],
......
......@@ -35,7 +35,6 @@ public class ThreatCognitionModel implements ICognitionModel {
@Override
// TODO: Maybe, use also use cooperative behavior from "CooperativeCognitionModel".
// Refactor this long if-else cascade so that it is easier to read.
public void update(Collection<Pedestrian> pedestrians) {
for (Pedestrian pedestrian : pedestrians) {
if (pedestrian.getMostImportantStimulus() instanceof Bang) {
......
package org.vadere.simulator.models.psychology.selfcategorization;
import org.apache.commons.math3.distribution.BinomialDistribution;
import org.apache.commons.math3.random.JDKRandomGenerator;
import org.jetbrains.annotations.NotNull;
import org.vadere.annotation.factories.models.ModelClass;
import org.vadere.simulator.models.MainModel;
import org.vadere.simulator.models.Model;
import org.vadere.simulator.models.SpeedAdjuster;
import org.vadere.simulator.models.osm.optimization.StepCircleOptimizer;
import org.vadere.simulator.models.osm.updateScheme.UpdateSchemeOSM;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTarget;
import org.vadere.simulator.models.potential.fields.IPotentialFieldTargetGrid;
import org.vadere.simulator.models.potential.fields.PotentialFieldAgent;
......@@ -16,6 +17,7 @@ import org.vadere.state.attributes.Attributes;
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.scenario.DynamicElement;
import org.vadere.state.scenario.Pedestrian;
......@@ -56,6 +58,7 @@ public class SelfCatThreatModel implements MainModel {
// Static Variables
private final static Logger logger = Logger.getLogger(SelfCatThreatModel.class);
private static final int BINOMIAL_DISTRIBUTION_SUCCESS_VALUE = 1;
// Variables
private AttributesSelfCatThreat attributesSelfCatThreat;
......@@ -71,10 +74,13 @@ public class SelfCatThreatModel implements MainModel {
private StepCircleOptimizer stepCircleOptimizer;
private UpdateSchemeEventDriven updateSchemeEventDriven;
// These models are updated in actual simulation loop.
// These models are updated in the actual simulation loop.
private List<Model> models = new LinkedList<>();
private double lastSimTimeInSec;
// Distribution to assign pedestrians as IN_GROUP or OUT_GROUP members.
BinomialDistribution binomialDistribution;
@Override
public List<Model> getSubmodels() {
return models;
......@@ -100,14 +106,24 @@ public class SelfCatThreatModel implements MainModel {
attributesAgent, topography, random, potentialFieldTarget,
potentialFieldObstacle.copy(), potentialFieldPedestrian,
noSpeedAdjusters, stepCircleOptimizer.clone());
pedestrian.setPosition(position);
// TODO: Call "pedestrian.setGroupMembership()" based on a (binomial?) distribution
// which can be configured in JSON file (similar to "TargetChanger").
GroupMembership groupMembership = drawGroupMembershipFromDistribution();
pedestrian.setGroupMembership(groupMembership);
return pedestrian;
}
private GroupMembership drawGroupMembershipFromDistribution() {
int binomialDistributionSample = binomialDistribution.sample();
boolean inGroupMember = (binomialDistributionSample == BINOMIAL_DISTRIBUTION_SUCCESS_VALUE);
GroupMembership groupMembership = (inGroupMember) ? GroupMembership.IN_GROUP : GroupMembership.OUT_GROUP;
return groupMembership;
}
@Override
public VShape getDynamicElementRequiredPlace(@NotNull VPoint position) {
return createElement(position, new AttributesAgent(attributesPedestrian, -1)).getShape();
......@@ -130,6 +146,9 @@ public class SelfCatThreatModel implements MainModel {
models.add(potentialFieldTarget);
models.add(this);
int seed = random.nextInt();
this.binomialDistribution = createBinomialDistribution(seed, attributesSelfCatThreat.getProbabilityInGroupMembership());
}
private void initializeLocomotionLayer(List<Attributes> attributesList, Topography topography, AttributesAgent attributesPedestrian, Random random) {
......@@ -158,6 +177,14 @@ public class SelfCatThreatModel implements MainModel {
this.updateSchemeEventDriven = new UpdateSchemeEventDriven(topography);
}
private BinomialDistribution createBinomialDistribution(int seed, double probabilityForInGroupMembership) {
JDKRandomGenerator randomGenerator = new JDKRandomGenerator();
randomGenerator.setSeed(seed);
int trials = BINOMIAL_DISTRIBUTION_SUCCESS_VALUE; // I.e., possible outcomes are 0 and 1 when calling "sample()".
return new BinomialDistribution(randomGenerator, trials, probabilityForInGroupMembership);
}
@Override
public void preLoop(final double simTimeInSec) {
this.lastSimTimeInSec = simTimeInSec;
......
......@@ -5,9 +5,11 @@ import org.vadere.state.attributes.Attributes;
public class AttributesSelfCatThreat extends Attributes {
AttributesOSM attributesLocomotion = new AttributesOSM();
double probabilityInGroupMembership = 0.0;
public AttributesOSM getAttributesLocomotion() {
return attributesLocomotion;
}
public double getProbabilityInGroupMembership() { return probabilityInGroupMembership; }
}
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