Commit 27569975 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

In "TargetPedestrian", implemented "getId()" properly so that follower behavior works

"TargetPedestrian.getId()" is now used by "TargetChangerController" to implement follower behavior.

Furthermore, deleted unnecessary code in following files:
- VadereSimulator/src/org/vadere/simulator/models/osm/OptimalStepsModel.java
- VadereSimulator/src/org/vadere/simulator/models/osm/PedestrianOSM.java
parent b525cd91
......@@ -138,14 +138,14 @@ public class TargetChangerController {
}
private void agentFollowsOtherPedestrian(Agent agent, Pedestrian pedToFollow) {
// Create necessary target wrapper object.
// Watch out: The main simulation loop creates the necessary
// "TargetController" object in the next simulation step.
// Create the necessary TargetPedestrian wrapper object.
// The simulation loop creates the corresponding controller objects
// in the next simulation loop based on the exisiting targets in the topography.
TargetPedestrian targetPedestrian = new TargetPedestrian(pedToFollow);
topography.addTarget(targetPedestrian);
// Make "agent" a follower of "pedToFollow".
agent.setSingleTarget(pedToFollow.getId(), true);
agent.setSingleTarget(targetPedestrian.getId(), true);
pedToFollow.getFollowers().add(agent);
}
......
......@@ -284,19 +284,10 @@ public class OptimalStepsModel implements MainModel, PotentialFieldModel {
@Override
public void update(final double simTimeInSec) {
double timeStepInSec = simTimeInSec - this.lastSimTimeInSec;
// TODO: Update followers
updateSchemeOSM.update(timeStepInSec, simTimeInSec);
lastSimTimeInSec = simTimeInSec;
}
private void updateTargetPotentialsOfFollowers() {
for (Target target : topography.getTargets()) {
if (target.isTargetPedestrian()) {
// TODO: follower.setTargetPotential().
}
}
}
/*
* At the moment all pedestrians also the initalPedestrians get this.attributesPedestrain!!!
*/
......
......@@ -319,10 +319,6 @@ public class PedestrianOSM extends Pedestrian {
this.relevantPedestrians = relevantPedestrians;
}
public void setPotentialFieldTarget(IPotentialFieldTarget potentialFieldTarget) {
this.potentialFieldTarget = potentialFieldTarget;
}
public void setCombinedPotentialStrategy(CombinedPotentialStrategy newStrategy) {
if (newStrategy == CombinedPotentialStrategy.TARGET_ATTRACTION_STRATEGY) {
this.combinedPotentialStrategy = new TargetAttractionStrategy(this.potentialFieldTarget,
......
......@@ -14,114 +14,114 @@ import java.util.*;
*/
public class TargetChanger extends ScenarioElement implements Comparable<TargetChanger> {
// Variables
private AttributesTargetChanger attributes;
private final Map<Integer, Double> enteringTimes;
/**
* Collection of listeners - unordered because it's order is not predictable
* (at least not for clients).
*/
private final Collection<TargetChangerListener> targetChangerListeners = new LinkedList<>();
// Constructors
public TargetChanger(AttributesTargetChanger attributes) {
this(attributes, new HashMap<>());
}
public TargetChanger(AttributesTargetChanger attributes, Map<Integer, Double> enteringTimes) {
this.attributes = attributes;
this.enteringTimes = enteringTimes;
}
// Getters
public Map<Integer, Double> getEnteringTimes() {
return enteringTimes;
}
@Override
public int getId() {
return attributes.getId();
}
@Override
public VShape getShape() {
return attributes.getShape();
}
@Override
public ScenarioElementType getType() {
return ScenarioElementType.TARGET_CHANGER;
}
@Override
public AttributesTargetChanger getAttributes() {
return attributes;
}
// Setters
@Override
public void setShape(VShape newShape) {
attributes.setShape(newShape);
}
@Override
public void setAttributes(Attributes attributes) {
this.attributes = (AttributesTargetChanger) attributes;
}
// Other Methods
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof TargetChanger)) {
return false;
}
TargetChanger other = (TargetChanger) obj;
if (attributes == null) {
if (other.attributes != null) {
return false;
}
} else if (!attributes.equals(other.attributes)) {
return false;
}
return true;
}
@Override
public int compareTo(TargetChanger otherTarget) {
return this.getId() - otherTarget.getId();
}
/** Models can register a target listener. */
public void addListener(TargetChangerListener listener) {
targetChangerListeners.add(listener);
}
public boolean removeListener(TargetChangerListener listener) {
return targetChangerListeners.remove(listener);
}
/** Returns an unmodifiable collection. */
public Collection<TargetChangerListener> getTargetChangerListeners() {
return Collections.unmodifiableCollection(targetChangerListeners);
}
@Override
public TargetChanger clone() {
return new TargetChanger((AttributesTargetChanger) attributes.clone());
}
// Member Variables
private AttributesTargetChanger attributes;
private final Map<Integer, Double> enteringTimes;
/**
* Collection of listeners - unordered because it's order is not predictable
* (at least not for clients).
*/
private final Collection<TargetChangerListener> targetChangerListeners = new LinkedList<>();
// Constructors
public TargetChanger(AttributesTargetChanger attributes) {
this(attributes, new HashMap<>());
}
public TargetChanger(AttributesTargetChanger attributes, Map<Integer, Double> enteringTimes) {
this.attributes = attributes;
this.enteringTimes = enteringTimes;
}
// Getters
public Map<Integer, Double> getEnteringTimes() {
return enteringTimes;
}
@Override
public int getId() {
return attributes.getId();
}
@Override
public VShape getShape() {
return attributes.getShape();
}
@Override
public ScenarioElementType getType() {
return ScenarioElementType.TARGET_CHANGER;
}
@Override
public AttributesTargetChanger getAttributes() {
return attributes;
}
// Setters
@Override
public void setShape(VShape newShape) {
attributes.setShape(newShape);
}
@Override
public void setAttributes(Attributes attributes) {
this.attributes = (AttributesTargetChanger) attributes;
}
// Other Methods
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (!(obj instanceof TargetChanger)) {
return false;
}
TargetChanger other = (TargetChanger) obj;
if (attributes == null) {
if (other.attributes != null) {
return false;
}
} else if (!attributes.equals(other.attributes)) {
return false;
}
return true;
}
@Override
public int compareTo(TargetChanger otherTarget) {
return this.getId() - otherTarget.getId();
}
/** Models can register a target listener. */
public void addListener(TargetChangerListener listener) {
targetChangerListeners.add(listener);
}
public boolean removeListener(TargetChangerListener listener) {
return targetChangerListeners.remove(listener);
}
/** Returns an unmodifiable collection. */
public Collection<TargetChangerListener> getTargetChangerListeners() {
return Collections.unmodifiableCollection(targetChangerListeners);
}
@Override
public TargetChanger clone() {
return new TargetChanger((AttributesTargetChanger) attributes.clone());
}
}
......@@ -5,18 +5,32 @@ import org.vadere.util.geometry.shapes.VShape;
public class TargetPedestrian extends Target implements DynamicElementRemoveListener<Pedestrian> {
// Static Variables
/**
* {@link Target}s and {@link TargetPedestrian}s share the same address space for ids!
* This can cause conflicts when the target potential is retrieved
* in "PotentialFieldTarget.getPotential()". "PotentialFieldTarget"
* stores potentials in a map<targetId, potentials>. Therefore, use
* a fixed offset to discriminate {@link Target}s and {@link TargetPedestrian}s.
*/
public static final int UNIQUE_ID_OFFSET = 100000;
// Member Variables
private final Pedestrian pedestrian;
private boolean isDeleted;
// Constructors
public TargetPedestrian(Pedestrian pedestrian) {
super(new AttributesTarget(pedestrian));
this.pedestrian = pedestrian;
this.isDeleted = false;
}
// Getters
@Override
public void setShape(VShape newShape) {
pedestrian.setShape(newShape);
public int getId() {
int targetId = pedestrian.getId() + TargetPedestrian.UNIQUE_ID_OFFSET;
return targetId;
}
@Override
......@@ -42,6 +56,13 @@ public class TargetPedestrian extends Target implements DynamicElementRemoveList
isDeleted = true;
}
// Setters
@Override
public void setShape(VShape newShape) {
pedestrian.setShape(newShape);
}
// Methods
@Override
public boolean equals(Object o) {
if (this == o)
......
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