Commit eff5d429 authored by Julian Zobel's avatar Julian Zobel 🦄
Browse files

Merge branch 'master' into 'cherry-pick-7698d9d7'

# Conflicts:
#   src/de/tud/kom/p2psim/impl/analyzer/metric/output/MetricOutputDAO.java
#   src/de/tud/kom/p2psim/impl/util/db/dao/DAO.java
parents 1c7f20ec 37020b44
...@@ -39,8 +39,8 @@ import javax.swing.JComponent; ...@@ -39,8 +39,8 @@ import javax.swing.JComponent;
import javax.swing.JMenu; import javax.swing.JMenu;
import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation; import de.tud.kom.p2psim.impl.topology.movement.modularosm.GPSCalculation;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector; import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
......
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.Random;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.IAttractionBasedMovementAnalyzer;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
/**
* Abstract base class for Transition Strategies ({@link IAttractionAssigmentStrategy}s) using {@link IAttractionPoint}s.
*
* @author Julian Zobel
* @version 1.0, 23.01.2019
*/
public abstract class AbstractAttractionBasedAssignmentStrategy implements IAttractionAssigmentStrategy {
protected Random rnd = Randoms.getRandom(AbstractAttractionBasedAssignmentStrategy.class);
protected IAttractionProvider attractionProvider;
protected LinkedHashMap<SimLocationActuator, IAttractionPoint> assignments = new LinkedHashMap<>();
protected LinkedHashMap<SimLocationActuator, IAttractionPoint> lastAssignments = new LinkedHashMap<>();
private LinkedList<AttractionAssignmentListener> listeners = new LinkedList<>();
protected long defaultPauseTimeMin = 0;
protected long defaultPauseTimeMax = 0;
protected final static int EVENT_PAUSE_ENDED = 1;
public AbstractAttractionBasedAssignmentStrategy(long defaultPauseTimeMin, long defaultPauseTimeMax) {
assert defaultPauseTimeMax >= 0 && defaultPauseTimeMin >= 0;
assert defaultPauseTimeMax >= defaultPauseTimeMin;
this.defaultPauseTimeMax = defaultPauseTimeMax;
this.defaultPauseTimeMin = defaultPauseTimeMin;
}
public void setAttractionProvider(IAttractionProvider attractionProvider) {
this.attractionProvider = attractionProvider;
}
@Override
public IAttractionPoint getAssignment(SimLocationActuator host) {
return assignments.get(host);
}
@Override
public IAttractionPoint getLastAssignment(SimLocationActuator host) {
return lastAssignments.get(host);
}
@Override
public void addAttractionAssignmentListener(
AttractionAssignmentListener listener) {
listeners.add(listener);
}
@Override
public void removeAttractionAssignmentListener(
AttractionAssignmentListener listener) {
listeners.remove(listener);
}
/**
* Notify all listeners of an updated attraction point assignment for the given component
*
* @param comp
* @param attractionPoint
*/
protected void notifyListenersOfAssignmentUpdate(SimLocationActuator comp,
IAttractionPoint attractionPoint) {
listeners.forEach(listener -> listener.updatedAttractionAssignment(comp, attractionPoint));
// also iInform analyzer of assigment update
if(Monitor.hasAnalyzer(IAttractionBasedMovementAnalyzer.class)) {
Monitor.getOrNull(IAttractionBasedMovementAnalyzer.class).onUpdateAttractionAssignment(comp, attractionPoint);
}
}
@Override
public void updateTargetAttractionPoint(SimLocationActuator comp,
IAttractionPoint attractionPoint) {
if(assignments.containsKey(comp)) {
this.lastAssignments.put(comp, this.assignments.remove(comp));
}
this.assignments.put(comp, attractionPoint);
notifyListenersOfAssignmentUpdate(comp, attractionPoint);
}
private long getRandomUniformDistributionPauseTime(IAttractionPoint attractionPoint) {
// if attraction point has own pause time use it, otherwise use default values
if(attractionPoint != null && attractionPoint.hasPauseTime()) {
return (long) (rnd.nextDouble() * (attractionPoint.getPauseTimeMax() - attractionPoint.getPauseTimeMin())) + attractionPoint.getPauseTimeMin();
}
else {
return (long) (rnd.nextDouble() * (defaultPauseTimeMax - defaultPauseTimeMin)) + defaultPauseTimeMin;
}
}
public long getPauseTime(IAttractionPoint attractionPoint) {
long pause = getRandomUniformDistributionPauseTime(attractionPoint);
//System.out.println(Time.getFormattedTime(pause));
return pause;
}
/**
* Get a new assignment for this component, that is not the last assignment
*
* @param host
* @return
*/
protected IAttractionPoint getNewAttractionPointAssignment(SimLocationActuator host) {
double score = rnd.nextDouble();
LinkedList<IAttractionPoint> candidates = new LinkedList<>();
for (IAttractionPoint ap : attractionProvider.getAttractionPoints()) {
// skip null values (should never occur!)
if(ap == null) {
continue;
}
// fast skip forward if the attraction point would not be considered due to its score
if (score >= ap.getWeight()) {
continue;
}
// skip attraction points that are currently assigned to the host
if(assignments.containsKey(host) && ap.equals(assignments.get(host))) {
continue;
}
// add the attraction point to the list of candidates, if no attraction point was
// previously visited, or if currently no attraction point is assigned and the last
// assignment was not this attraction point (this prevents that, if the current attraction
// point was already set to the last assignment, the last visited attraction point is also considered)
if(lastAssignments.get(host) == null ||
(!assignments.containsKey(host) && !ap.equals(lastAssignments.get(host)))) {
candidates.add(ap);
}
}
// fallback: if no attraction point is considered, randomly select one, except the current assignment
if (candidates.isEmpty()) {
candidates.addAll(attractionProvider.getAttractionPoints());
if(assignments.containsKey(host) && candidates.size() > 1) {
candidates.remove(assignments.get(host));
}
}
IAttractionPoint assignment = candidates.get(rnd.nextInt(candidates.size()));
return assignment;
}
@Override
public boolean hostInAttractionPointArea(SimLocationActuator host) {
for(IAttractionPoint ap : attractionProvider.getAttractionPoints()) {
if(ap.distanceTo(host.getRealPosition()) <= ap.getRadius()) {
return true;
}
}
return false;
}
}
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.LinkedHashMap;
import java.util.Map;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ISocialGroupMovementAnalyzer;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* With this transition strategy, nodes are roaming around {@link IAttractionPoint}s, without transitions between them. As the {@link ModularMovementModel}
* uses a Gauss function to add jitter and offsets to the movement, some nodes may also roam outside of the circle's radius (this is intended to make it more realistic)
*
* @author Julian Zobel
* @version 10.02.2020
*/
public class AttractionPointRoamingStrategy extends AbstractAttractionBasedAssignmentStrategy implements EventHandler {
public static enum roamingTransitionState {
PAUSE,
ROAMING
}
protected Map<SimLocationActuator, roamingTransitionState> roamingStates = new LinkedHashMap<>();
@XMLConfigurableConstructor({ "defaultPauseTimeMin", "defaultPauseTimeMax" })
public AttractionPointRoamingStrategy(long defaultPauseTimeMin, long defaultPauseTimeMax) {
super(defaultPauseTimeMin, defaultPauseTimeMax);
}
@Override
public void addComponent(SimLocationActuator comp) {
this.roamingStates.put(comp, null);
IAttractionPoint nextAP = getNewAttractionPointAssignment(comp);
updateTargetAttractionPoint(comp, nextAP);
}
@Override
public void updateTargetAttractionPoint(SimLocationActuator comp,
IAttractionPoint attractionPoint) {
this.roamingStates.put(comp, null);
super.updateTargetAttractionPoint(comp, attractionPoint);
}
@Override
public void reachedAttractionPoint(SimLocationActuator comp, IAttractionPoint attractionPoint) {
if(roamingStates.get(comp) == roamingTransitionState.PAUSE) {
return;
}
if(Monitor.hasAnalyzer(ISocialGroupMovementAnalyzer.class)) {
Monitor.getOrNull(ISocialGroupMovementAnalyzer.class).onNodeReachedAttractionPoint(comp, attractionPoint);
}
this.roamingStates.put(comp, roamingTransitionState.PAUSE);
// schedule roaming
long roamingPauseTime = (long) (rnd.nextDouble() * Time.MINUTE * 5) + Time.MINUTE * 5;
Event.scheduleWithDelay(roamingPauseTime, this, comp, 0);
}
private void roamAroundAttractionPoint(SimLocationActuator comp) {
if(roamingStates.get(comp) == roamingTransitionState.PAUSE) {
IAttractionPoint currentAttractionPoint = this.assignments.get(comp);
this.roamingStates.put(comp, roamingTransitionState.ROAMING);
notifyListenersOfAssignmentUpdate(comp, currentAttractionPoint);
}
}
@Override
public void eventOccurred(Object content, int type) {
SimLocationActuator comp = (SimLocationActuator) content;
IAttractionPoint currentAttractionPoint = this.assignments.get(comp);
// if the attraction point was removed in the meantime, go directly to transit state
if(currentAttractionPoint == null || !attractionProvider.getAttractionPoints().contains(currentAttractionPoint)) {
this.addComponent(comp);
}
else {
this.roamAroundAttractionPoint(comp);
}
}
}
\ No newline at end of file
...@@ -20,74 +20,41 @@ ...@@ -20,74 +20,41 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition; package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.common.SimHostComponent; import de.tud.kom.p2psim.api.common.SimHostComponent;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel; import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.ITransitionStrategy.AttractionAssignmentListener; import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
/** /**
* A {@link TransitionStrategy} for a case in which nodes are affiliated to an {@link AttractionPoint} only * A {@link TransitionStrategy} for a case in which nodes are affiliated to an {@link IAttractionPoint} only
* in the beginning. No further transition will take place. * in the beginning. No further transition will take place.
* *
* @author Martin Hellwig * @author Martin Hellwig
* @version 1.0, 07.07.2015 * @version 1.0, 07.07.2015
*/ */
public class FixedAssignmentStrategy implements ITransitionStrategy { public class FixedAssignmentStrategy extends AbstractAttractionBasedAssignmentStrategy {
private List<SimLocationActuator> comps = new LinkedList<SimLocationActuator>(); public FixedAssignmentStrategy() {
super(0, 0);
private LinkedHashSet<AttractionPoint> aPoints = new LinkedHashSet<AttractionPoint>(); }
private Map<SimLocationActuator, AttractionPoint> assignments = new LinkedHashMap<SimLocationActuator, AttractionPoint>();
private List<SimLocationActuator> comps = new LinkedList<SimLocationActuator>();
private Map<SimLocationActuator, SimHost> mappingMSHost = new LinkedHashMap<SimLocationActuator, SimHost>(); private Map<SimLocationActuator, SimHost> mappingMSHost = new LinkedHashMap<SimLocationActuator, SimHost>();
private Map<SimHost, SimLocationActuator> mappingHostMS = new LinkedHashMap<SimHost, SimLocationActuator>(); private Map<SimHost, SimLocationActuator> mappingHostMS = new LinkedHashMap<SimHost, SimLocationActuator>();
private Map<String, AttractionPoint> mappingGroupIdAP = new LinkedHashMap<String, AttractionPoint>(); private Map<String, IAttractionPoint> mappingGroupIdAP = new LinkedHashMap<String, IAttractionPoint>();
private Map<AttractionPoint, String> mappingAPGroupId = new LinkedHashMap<AttractionPoint, String>();
private List<AttractionAssignmentListener> listeners = new LinkedList<>();
@Override
public AttractionPoint getAssignment(SimLocationActuator comp) {
return assignments.get(comp);
}
@Override
public void setAttractionPoints(Collection<AttractionPoint> attractionPoints) {
aPoints.addAll(attractionPoints);
}
@Override
public Set<AttractionPoint> getAllAttractionPoints() {
return aPoints;
}
@Override private Map<IAttractionPoint, String> mappingAPGroupId = new LinkedHashMap<IAttractionPoint, String>();
public void addAttractionAssignmentListener(
AttractionAssignmentListener listener) {
listeners.add(listener);
}
@Override
public void removeAttractionAssignmentListener(
AttractionAssignmentListener listener) {
listeners.remove(listener);
}
@Override @Override
public void addComponent(SimLocationActuator ms) { public void addComponent(SimLocationActuator ms) {
comps.add(ms); comps.add(ms);
...@@ -95,14 +62,14 @@ public class FixedAssignmentStrategy implements ITransitionStrategy { ...@@ -95,14 +62,14 @@ public class FixedAssignmentStrategy implements ITransitionStrategy {
// No assignments been done before. // No assignments been done before.
if (assignments.isEmpty()) { if (assignments.isEmpty()) {
AttractionPoint aPoint = aPoints.iterator().next(); IAttractionPoint aPoint = attractionProvider.getAttractionPoints().iterator().next();
assignments.put(ms, aPoint); assignments.put(ms, aPoint);
mappingGroupId(ms, aPoint); mappingGroupId(ms, aPoint);
} }
// GroupId is not mapped. // GroupId is not mapped.
else if (!mappingGroupIdAP.containsKey(mappingMSHost.get(ms) else if (!mappingGroupIdAP.containsKey(mappingMSHost.get(ms)
.getProperties().getGroupID())) { .getProperties().getGroupID())) {
for (AttractionPoint actAP : aPoints) { for (IAttractionPoint actAP : attractionProvider.getAttractionPoints()) {
if (!mappingAPGroupId.containsKey(actAP)) { if (!mappingAPGroupId.containsKey(actAP)) {
assignments.put(ms, actAP); assignments.put(ms, actAP);
mappingGroupId(ms, actAP); mappingGroupId(ms, actAP);
...@@ -113,27 +80,27 @@ public class FixedAssignmentStrategy implements ITransitionStrategy { ...@@ -113,27 +80,27 @@ public class FixedAssignmentStrategy implements ITransitionStrategy {
// GroupId is already mapped. // GroupId is already mapped.
else if (mappingGroupIdAP.containsKey(mappingMSHost.get(ms) else if (mappingGroupIdAP.containsKey(mappingMSHost.get(ms)
.getProperties().getGroupID())) { .getProperties().getGroupID())) {
AttractionPoint aPoint = mappingGroupIdAP.get(mappingMSHost.get(ms) IAttractionPoint aPoint = mappingGroupIdAP.get(mappingMSHost.get(ms)
.getProperties().getGroupID()); .getProperties().getGroupID());
assignments.put(ms, aPoint); assignments.put(ms, aPoint);
} else { } else {
throw new Error("Should not happen."); throw new Error("Should not happen.");
} }
listeners.forEach(listener -> listener.updatedAttractionAssignment(ms, assignments.get(ms))); notifyListenersOfAssignmentUpdate(ms, assignments.get(ms));
} }
@Override @Override
public void reachedAttractionPoint(SimLocationActuator ms) { public void reachedAttractionPoint(SimLocationActuator ms, IAttractionPoint attractionPoint) {
// don't care, as no further assignment takes place. // don't care, as no further assignment takes place.
} }
@Override @Override
public void updateTargetAttractionPoint(SimLocationActuator comp, public void updateTargetAttractionPoint(SimLocationActuator comp,
AttractionPoint attractionPoint) { IAttractionPoint attractionPoint) {
assignments.put(comp, attractionPoint); assignments.put(comp, attractionPoint);
listeners.forEach(listener -> listener.updatedAttractionAssignment(comp, attractionPoint)); notifyListenersOfAssignmentUpdate(comp, attractionPoint);
} }
private void mappingHost(SimLocationActuator ms) { private void mappingHost(SimLocationActuator ms) {
...@@ -146,7 +113,7 @@ public class FixedAssignmentStrategy implements ITransitionStrategy { ...@@ -146,7 +113,7 @@ public class FixedAssignmentStrategy implements ITransitionStrategy {
mappingMSHost.put(ms, host); mappingMSHost.put(ms, host);
} }
private void mappingGroupId(SimLocationActuator ms, AttractionPoint AP) { private void mappingGroupId(SimLocationActuator ms, IAttractionPoint AP) {
SimHostComponent comp = (SimHostComponent) ms; SimHostComponent comp = (SimHostComponent) ms;
SimHost host = comp.getHost(); SimHost host = comp.getHost();
...@@ -160,13 +127,13 @@ public class FixedAssignmentStrategy implements ITransitionStrategy { ...@@ -160,13 +127,13 @@ public class FixedAssignmentStrategy implements ITransitionStrategy {
/** /**
* Used by the MobilityModel (M1) of the {@link ModularMovementModel} to get * Used by the MobilityModel (M1) of the {@link ModularMovementModel} to get
* the groupId of the affiliated nodes to that {@link AttractionPoint}. Once * the groupId of the affiliated nodes to that {@link IAttractionPoint}. Once
* the groupId is known nodes can be set <b>offline</b> or <b>online</b>. * the groupId is known nodes can be set <b>offline</b> or <b>online</b>.
* *
* @param attractionPoint * @param attractionPoint
* @return * @return
*/ */
public String getGroupIdOfAttractionPoint(AttractionPoint attractionPoint) { public String getGroupIdOfAttractionPoint(IAttractionPoint attractionPoint) {
return mappingAPGroupId.get(attractionPoint); return mappingAPGroupId.get(attractionPoint);
} }
} }
...@@ -20,19 +20,22 @@ ...@@ -20,19 +20,22 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition; package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.Collection;
import java.util.Set;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
/** /**
* This is the interface for the Transition Strategy.<br> * This is the interface for the Transition Strategy.<br>
* *
* @author Martin Hellwig * @author Martin Hellwig
* @version 1.0, 03.07.2015 * @version 1.0, 03.07.2015
*
*
*
* @author Julian Zobel
* @version 1.1, 27.01.2020
*/ */
public interface ITransitionStrategy { public interface IAttractionAssigmentStrategy {
/** /**
* Currently assigned attraction point. * Currently assigned attraction point.
...@@ -40,33 +43,22 @@ public interface ITransitionStrategy { ...@@ -40,33 +43,22 @@ public interface ITransitionStrategy {
* @param comp * @param comp
* @return * @return
*/ */
public AttractionPoint getAssignment(SimLocationActuator comp); public IAttractionPoint getAssignment(SimLocationActuator host);
public IAttractionPoint getLastAssignment(SimLocationActuator host);
public void addAttractionAssignmentListener(AttractionAssignmentListener listener); public void addAttractionAssignmentListener(AttractionAssignmentListener listener);
public void removeAttractionAssignmentListener(AttractionAssignmentListener listener); public void removeAttractionAssignmentListener(AttractionAssignmentListener listener);
public void setAttractionProvider(IAttractionProvider attractionProvider);
/** /**
* Should be called first, to add the Attraction Points for the assignment! * Add the object and assign the MS to an {@link IAttractionPoint}.
*
* @param attractionPoints
*/
public void setAttractionPoints(
Collection<AttractionPoint> attractionPoints);
/**
* Return a set of all attraction points
*
* @return
*/
public Set<AttractionPoint> getAllAttractionPoints();
/**
* Add the object and assign the MS to an {@link AttractionPoint}.
* *
* @param ms * @param ms
*/ */
public void addComponent(SimLocationActuator ms); public void addComponent(SimLocationActuator host);
/** /**
* Notify the TransitionStrategy, that the component has reached an * Notify the TransitionStrategy, that the component has reached an
...@@ -74,7 +66,7 @@ public interface ITransitionStrategy { ...@@ -74,7 +66,7 @@ public interface ITransitionStrategy {
* *
* @param ms * @param ms
*/ */
public void reachedAttractionPoint(SimLocationActuator ms); public void reachedAttractionPoint(SimLocationActuator host, IAttractionPoint attractionPoint);
/** /**
* Updates the target attraction point of a component * Updates the target attraction point of a component
...@@ -82,7 +74,7 @@ public interface ITransitionStrategy { ...@@ -82,7 +74,7 @@ public interface ITransitionStrategy {
* @param attractionPoint * @param attractionPoint
*/ */
public void updateTargetAttractionPoint(SimLocationActuator comp, public void updateTargetAttractionPoint(SimLocationActuator comp,
AttractionPoint attractionPoint); IAttractionPoint attractionPoint);
public interface AttractionAssignmentListener { public interface AttractionAssignmentListener {
...@@ -93,9 +85,12 @@ public interface ITransitionStrategy { ...@@ -93,9 +85,12 @@ public interface ITransitionStrategy {
* @param component * @param component
* @param newAssignment * @param newAssignment
*/ */
public void updatedAttractionAssignment(SimLocationActuator component, public void updatedAttractionAssignment(SimLocationActuator host,
AttractionPoint newAssignment); IAttractionPoint newAssignment);
} }
public boolean hostInAttractionPointArea(SimLocationActuator host);
public long getPauseTime(IAttractionPoint attractionPoint);
} }
/*
* Copyright (c) 2005-2010 KOM – Multimedia Communications Lab
*
* This file is part of PeerfactSim.KOM.
*
* PeerfactSim.KOM is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* PeerfactSim.KOM is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PeerfactSim.KOM. If not, see <http://www.gnu.org/licenses/>.
*
*/
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.LinkedHashMap;
import java.util.Map;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ISocialGroupMovementAnalyzer;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
* With this transition strategy, nodes are roaming around {@link IAttractionPoint}s that have a radius. As the {@link ModularMovementModel}
* uses a Gauss function to add jitter and offsets to the movement, some nodes may also roam outside of the circle's radius (this is intended to make it more realistic)
*
* @author Julian Zobel
* @version 1.0, 24.01.2019
*/
public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedAssignmentStrategy implements EventHandler {
public static enum roamingTransitionState {
PAUSE,
ROAMING,
TRANSITION
}
protected Map<SimLocationActuator, roamingTransitionState> roamingStates = new LinkedHashMap<>();
protected final static int EVENT_ROAMING_PAUSE_ENDED = 2;
private boolean useGaussianDistributedPauseTime = false;
@XMLConfigurableConstructor({ "defaultPauseTimeMin", "defaultPauseTimeMax" })
public InAreaRoamingTransitionStrategy(long defaultPauseTimeMin, long defaultPauseTimeMax) {
super(defaultPauseTimeMin, defaultPauseTimeMax);
}
@Override
public void addComponent(SimLocationActuator comp) {
this.roamingStates.put(comp, roamingTransitionState.TRANSITION);
IAttractionPoint nextAP = getNewAttractionPointAssignment(comp);
updateTargetAttractionPoint(comp, nextAP);
}
@Override
public void reachedAttractionPoint(SimLocationActuator comp, IAttractionPoint attractionPoint) {
if(roamingStates.get(comp) == roamingTransitionState.PAUSE) {
return;
}
if(Monitor.hasAnalyzer(ISocialGroupMovementAnalyzer.class)) {
Monitor.getOrNull(ISocialGroupMovementAnalyzer.class).onNodeReachedAttractionPoint(comp, attractionPoint);
}
// start roaming if the AP was reached
if(roamingStates.get(comp) == roamingTransitionState.TRANSITION) {
// schedule the end of the roaming phase, which will make a new transition
Event.scheduleWithDelay(getPauseTime(attractionPoint), this, comp, EVENT_PAUSE_ENDED);
}
this.roamingStates.put(comp, roamingTransitionState.PAUSE);
// schedule roaming
//Event.scheduleWithDelay(gaussianDistributionPauseTime(5 * Time.MINUTE, Time.MINUTE), this, comp, EVENT_ROAMING_PAUSE_ENDED);
Event.scheduleWithDelay(15 * Time.SECOND, this, comp, EVENT_ROAMING_PAUSE_ENDED);
}
@Override
public long getPauseTime(IAttractionPoint attractionPoint) {
if(useGaussianDistributedPauseTime) {
return gaussianDistributionPauseTime(defaultPauseTimeMax - defaultPauseTimeMin, 0.5*(defaultPauseTimeMax - defaultPauseTimeMin));
}
else {
return super.getPauseTime(attractionPoint);
}
}
/**
* Use a gaussian distribution for the pause time interval generation, using a mean value and a standard deviation
*
* @return
*/
private long gaussianDistributionPauseTime(double mean, double std) {
double x = rnd.nextGaussian() * std + mean;
if(x <= 0) return gaussianDistributionPauseTime(mean, std*0.9);
return (long) x;
}
private void roamAroundAttractionPoint(SimLocationActuator comp) {
if(roamingStates.get(comp) != roamingTransitionState.TRANSITION) {
IAttractionPoint currentAttractionPoint = this.assignments.get(comp);
if(currentAttractionPoint == null) {
System.err.println("AP roaming failed: no AP");
}
if(currentAttractionPoint.getRadius() > 0)
{
this.roamingStates.put(comp, roamingTransitionState.ROAMING);
updateTargetAttractionPoint(comp, currentAttractionPoint);
//notifyListenersOfAssignmentUpdate(comp, currentAttractionPoint);
}
}
}
@Override
public void eventOccurred(Object content, int type) {
if(type == EVENT_PAUSE_ENDED) {
SimLocationActuator comp = (SimLocationActuator) content;
// if the transit was triggered beforehand (e.g., attraction point moved), then do nothing.
if(roamingStates.get(comp) != roamingTransitionState.TRANSITION) {
this.addComponent(comp);
}
}
else if(type == EVENT_ROAMING_PAUSE_ENDED) {
SimLocationActuator comp = (SimLocationActuator) content;
IAttractionPoint currentAttractionPoint = this.assignments.get(comp);
// if the attraction point was removed in the meantime, go directly to transit state
if(currentAttractionPoint == null || !attractionProvider.getAttractionPoints().contains(currentAttractionPoint)) {
this.addComponent(comp);
}
else {
this.roamAroundAttractionPoint(comp);
}
}
}
public void setGaussianPauseTime(boolean useGaussian) {
useGaussianDistributedPauseTime = useGaussian;
}
}
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition; package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import java.util.*; import java.util.*;
/** /**
* This {@link ITransitionStrategy} works with manual assignments. Initially components will be assigned * This {@link IAttractionAssigmentStrategy} works with manual assignments. Initially components will be assigned
* one of the attraction points, but at any further point, the set list of attraction points doesn't really matter. * one of the attraction points, but at any further point, the set list of attraction points doesn't really matter.
* New target can be assigned by using the {@link #updateTargetAttractionPoint(SimLocationActuator, AttractionPoint)} method, * New target can be assigned by using the {@link #updateTargetAttractionPoint(SimLocationActuator, IAttractionPoint)} method,
* otherwise the components will stop moving upon reaching their target. * otherwise the components will stop moving upon reaching their target.
* *
* @author Clemens Krug * @author Clemens Krug
*/ */
public class ManualAssignmentStrategy implements ITransitionStrategy public class ManualAssignmentStrategy extends AbstractAttractionBasedAssignmentStrategy
{ {
private LinkedHashSet<AttractionPoint> aPoints = new LinkedHashSet<>(); public ManualAssignmentStrategy() {
super(0, 0);
}
private Map<SimLocationActuator, AttractionPoint> assignments = new HashMap<>(); private LinkedHashSet<IAttractionPoint> aPoints = new LinkedHashSet<>();
private List<AttractionAssignmentListener> listeners = new LinkedList<>(); private Map<SimLocationActuator, IAttractionPoint> assignments = new HashMap<>();
@Override
public AttractionPoint getAssignment(SimLocationActuator comp)
{
return assignments.get(comp);
}
@Override
public void addAttractionAssignmentListener(AttractionAssignmentListener listener)
{
listeners.add(listener);
}
@Override private List<AttractionAssignmentListener> listeners = new LinkedList<>();
public void removeAttractionAssignmentListener(AttractionAssignmentListener listener)
{
listeners.remove(listener);
}
@Override public void setAttractionPoints(Collection<IAttractionPoint> attractionPoints) {
public void setAttractionPoints(Collection<AttractionPoint> attractionPoints) {
aPoints.addAll(attractionPoints); aPoints.addAll(attractionPoints);
} }
@Override
public Set<AttractionPoint> getAllAttractionPoints() {
return aPoints;
}
@Override @Override
public void addComponent(SimLocationActuator ms) { public void addComponent(SimLocationActuator ms) {
if(!assignments.containsKey(ms)) if(!assignments.containsKey(ms))
{ {
AttractionPoint aPoint = aPoints.iterator().next(); IAttractionPoint aPoint = aPoints.iterator().next();
assignments.put(ms, aPoint); assignments.put(ms, aPoint);
} }
listeners.forEach(listener -> listener.updatedAttractionAssignment(ms, assignments.get(ms))); listeners.forEach(listener -> listener.updatedAttractionAssignment(ms, assignments.get(ms)));
} }
@Override @Override
public void reachedAttractionPoint(SimLocationActuator ms) { public void reachedAttractionPoint(SimLocationActuator ms, IAttractionPoint attractionPoint) {
//Nothing to do. //Nothing to do.
} }
@Override @Override
public void updateTargetAttractionPoint(SimLocationActuator comp, AttractionPoint attractionPoint) { public void updateTargetAttractionPoint(SimLocationActuator comp, IAttractionPoint attractionPoint) {
assignments.put(comp, attractionPoint); assignments.put(comp, attractionPoint);
listeners.forEach(listener -> listener.updatedAttractionAssignment(comp, attractionPoint)); listeners.forEach(listener -> listener.updatedAttractionAssignment(comp, attractionPoint));
} }
} }
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition; package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Random;
import java.util.Set;
import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.BasicAttractionPoint; import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.BasicAttractionPoint;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
/** /**
* This {@link ITransitionStrategy} makes clients move around randomly in a specified area. You can specify the target * This {@link IAttractionAssigmentStrategy} makes clients move around randomly in a specified area. You can specify the target
* area center via the {@link #updateTargetAttractionPoint(SimLocationActuator, AttractionPoint)} method. The client will then start * area center via the {@link #updateTargetAttractionPoint(SimLocationActuator, IAttractionPoint)} method. The client will then start
* to roam the area randomly till a new target area is assigned. * to roam the area randomly till a new target area is assigned.
* *
* @author Clemens Krug * @author Clemens Krug
*
* Made the transition strategy extend the {@link AbstractAttractionBasedAssignmentStrategy} for a more generalized approach on
* the {@link IAttractionAssigmentStrategy} implementation for attraction point based strategies.
*
* @author Julian Zobel
* @version 1.1, January 2019
*/ */
public class RandomInAreaTransitionStrategy extends AbstractAttractionBasedAssignmentStrategy
{
public RandomInAreaTransitionStrategy() {
super(0, 0);
}
/**
public class RandomInAreaTransitionStrategy implements ITransitionStrategy
{
private final Random random = Randoms
.getRandom(RandomInAreaTransitionStrategy.class);
private LinkedHashSet<AttractionPoint> aPoints = new LinkedHashSet<>();
/**
* These are the target area centers the clients have assigned.
*/
private Map<SimLocationActuator, AttractionPoint> assignments = new HashMap<>();
/**
* These are the current spots inside the target area where the client is currently heading. * These are the current spots inside the target area where the client is currently heading.
*/ */
private Map<SimLocationActuator, AttractionPoint> currentTarget = new HashMap<>(); private Map<SimLocationActuator, IAttractionPoint> currentTarget = new HashMap<>();
private Map<SimLocationActuator, Integer> currentSearchRadius = new HashMap<>(); private Map<SimLocationActuator, Integer> currentSearchRadius = new HashMap<>();
private List<AttractionAssignmentListener> listeners = new LinkedList<>();
/** /**
* The radius the target area should have. Should be set via XML config file. * The radius the target area should have. Should be set via XML config file.
*/ */
private int defaultRadius; private int defaultRadius;
@Override
public AttractionPoint getAssignment(SimLocationActuator comp)
{
return currentTarget.get(comp);
}
@Override
public void addAttractionAssignmentListener(AttractionAssignmentListener listener)
{
listeners.add(listener);
}
@Override
public void removeAttractionAssignmentListener(AttractionAssignmentListener listener)
{
listeners.remove(listener);
}
@Override
public void setAttractionPoints(Collection<AttractionPoint> attractionPoints) {
aPoints.addAll(attractionPoints);
}
@Override
public Set<AttractionPoint> getAllAttractionPoints() {
return aPoints;
}
@Override @Override
public void addComponent(SimLocationActuator ms) { public void addComponent(SimLocationActuator ms) {
if(!assignments.containsKey(ms)) if(!assignments.containsKey(ms))
{ {
AttractionPoint aPoint = aPoints.iterator().next(); IAttractionPoint aPoint = attractionProvider.getAttractionPoints().iterator().next();
assignments.put(ms, aPoint); assignments.put(ms, aPoint);
currentTarget.put(ms, nextRandomPosition(aPoint, defaultRadius)); currentTarget.put(ms, nextRandomPosition(aPoint, defaultRadius));
currentSearchRadius.put(ms, defaultRadius); currentSearchRadius.put(ms, defaultRadius);
} }
listeners.forEach(listener -> listener.updatedAttractionAssignment(ms, currentTarget.get(ms))); notifyListenersOfAssignmentUpdate(ms, currentTarget.get(ms));
} }
@Override @Override
public void reachedAttractionPoint(SimLocationActuator ms) { public void reachedAttractionPoint(SimLocationActuator ms, IAttractionPoint attractionPoint) {
currentTarget.put(ms, nextRandomPosition(assignments.get(ms), currentSearchRadius.get(ms))); currentTarget.put(ms, nextRandomPosition(assignments.get(ms), currentSearchRadius.get(ms)));
listeners.forEach(listener -> listener.updatedAttractionAssignment(ms, currentTarget.get(ms))); notifyListenersOfAssignmentUpdate(ms, currentTarget.get(ms));
} }
@Override @Override
public void updateTargetAttractionPoint(SimLocationActuator comp, AttractionPoint attractionPoint) { public void updateTargetAttractionPoint(SimLocationActuator comp, IAttractionPoint attractionPoint) {
assignments.put(comp, attractionPoint); assignments.put(comp, attractionPoint);
currentTarget.put(comp, nextRandomPosition(attractionPoint, currentSearchRadius.get(comp))); currentTarget.put(comp, nextRandomPosition(attractionPoint, currentSearchRadius.get(comp)));
listeners.forEach(listener -> listener.updatedAttractionAssignment(comp, attractionPoint)); notifyListenersOfAssignmentUpdate(comp, attractionPoint);
} }
public void setSearchRadiusForComponent(SimLocationActuator ms, int radius) public void setSearchRadiusForComponent(SimLocationActuator ms, int radius) {
{
currentSearchRadius.put(ms, radius); currentSearchRadius.put(ms, radius);
} }
public void setDefaultRadius(int radius) public void setDefaultRadius(int radius) {
{
this.defaultRadius = radius; this.defaultRadius = radius;
} }
...@@ -123,12 +82,11 @@ public class RandomInAreaTransitionStrategy implements ITransitionStrategy ...@@ -123,12 +82,11 @@ public class RandomInAreaTransitionStrategy implements ITransitionStrategy
* @param radius The radius of the area. * @param radius The radius of the area.
* @return A random position within the area. * @return A random position within the area.
*/ */
private BasicAttractionPoint nextRandomPosition(Location center, int radius) private BasicAttractionPoint nextRandomPosition(Location center, int radius) {
{
assert radius > 0 : "An area radius must be specified for the RandomInAreaTransitionStrategy! Did you set the 'DefaultRadius' property for this transition?"; assert radius > 0 : "An area radius must be specified for the RandomInAreaTransitionStrategy! Did you set the 'DefaultRadius' property for this transition?";
double x = center.getLongitude(); double x = center.getLongitudeOrX();
double y = center.getLatitude(); double y = center.getLatitudeOrY();
double newX = -1; double newX = -1;
double newY = -1; double newY = -1;
...@@ -138,8 +96,8 @@ public class RandomInAreaTransitionStrategy implements ITransitionStrategy ...@@ -138,8 +96,8 @@ public class RandomInAreaTransitionStrategy implements ITransitionStrategy
while(newX < 0.0 || newX > Binder.getComponentOrNull(Topology.class).getWorldDimensions().getX() while(newX < 0.0 || newX > Binder.getComponentOrNull(Topology.class).getWorldDimensions().getX()
|| newY < 0.0 || newY > Binder.getComponentOrNull(Topology.class).getWorldDimensions().getY()) || newY < 0.0 || newY > Binder.getComponentOrNull(Topology.class).getWorldDimensions().getY())
{ {
double calcRadius = random.nextDouble() * radius; double calcRadius = rnd.nextDouble() * radius;
double calcAngle = random.nextDouble() * 360; double calcAngle = rnd.nextDouble() * 360;
newX = x + Math.sin(calcAngle) * calcRadius; newX = x + Math.sin(calcAngle) * calcRadius;
newY = y + Math.cos(calcAngle) * calcRadius; newY = y + Math.cos(calcAngle) * calcRadius;
...@@ -151,6 +109,5 @@ public class RandomInAreaTransitionStrategy implements ITransitionStrategy ...@@ -151,6 +109,5 @@ public class RandomInAreaTransitionStrategy implements ITransitionStrategy
Monitor.log(this.getClass(), Monitor.Level.DEBUG, "Next random position is " + newX + " / " + newY); Monitor.log(this.getClass(), Monitor.Level.DEBUG, "Next random position is " + newX + " / " + newY);
return new BasicAttractionPoint("RNDPOS", new PositionVector(newX, newY)); return new BasicAttractionPoint("RNDPOS", new PositionVector(newX, newY));
} }
} }
...@@ -21,38 +21,33 @@ ...@@ -21,38 +21,33 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition; package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Random;
import java.util.Set; import java.util.Set;
import java.util.Vector; import java.util.Vector;
import de.tud.kom.p2psim.api.common.SimHost; import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.common.SimHostComponent; import de.tud.kom.p2psim.api.common.SimHostComponent;
import de.tud.kom.p2psim.api.scenario.ConfigurationException; import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.social.SocialView; import de.tud.kom.p2psim.api.topology.social.SocialView;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.ITransitionStrategy.AttractionAssignmentListener;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/** /**
* This is a {@link TransitionStrategy} for the Social Case. It will be try to * This is a {@link TransitionStrategy} for the Social Case. It will be try to
* build groups based on the {@link SocialView} information. For this, it tries * build groups based on the {@link SocialView} information. For this, it tries
* to assignment the given objects to the given {@link AttractionPoint}s. For * to assignment the given objects to the given {@link IAttractionPoint}s. For
* the {@link SocialView}, it is required a {@link #socialId}, to find the right * the {@link SocialView}, it is required a {@link #socialId}, to find the right
* {@link SocialView}. * {@link SocialView}.
* *
...@@ -61,65 +56,58 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction ...@@ -61,65 +56,58 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
* The Strategy has the parameter of {@link #socialFactor}, * The Strategy has the parameter of {@link #socialFactor},
* {@link #minPauseTime} and {@link #maxPauseTime}. The socialFactor should be a * {@link #minPauseTime} and {@link #maxPauseTime}. The socialFactor should be a
* value between 0 and 1. It gives the probability for a social based transition * value between 0 and 1. It gives the probability for a social based transition
* or the transition to a random {@link AttractionPoint}. If the social based * or the transition to a random {@link IAttractionPoint}. If the social based
* transition is selected, then will be used a scoring to find the right * transition is selected, then will be used a scoring to find the right
* {@link AttractionPoint}. For that, it will be used only the AttractionPoints, * {@link IAttractionPoint}. For that, it will be used only the AttractionPoints,
* of the hosts, which are in the same SocialCluster or are SocialNeighbors. For * of the hosts, which are in the same SocialCluster or are SocialNeighbors. For
* this AttractionPoints it will be find the highest scoring, which is to found * this AttractionPoints it will be find the highest scoring, which is to found
* in score. . * in score. .
* *
* <br> * <br>
* *
* After the finding of the next {@link AttractionPoint}, it will be scheduled * After the finding of the next {@link IAttractionPoint}, it will be scheduled
* an Event, with a delay between min- and maxPauseTime. After this delay, it * an Event, with a delay between min- and maxPauseTime. After this delay, it
* will be tried to assign a new {@link AttractionPoint} like the described * will be tried to assign a new {@link IAttractionPoint} like the described
* above. * above.
* *
*
* @author Christoph Muenker * @author Christoph Muenker
* @version 1.0, 02.07.2013 * @version 1.0, 02.07.2013
*
* <hr>
*
*
*
*/ */
public class SocialTransitionStrategy public class SocialTransitionStrategy extends AbstractAttractionBasedAssignmentStrategy implements EventHandler {
implements ITransitionStrategy, EventHandler {
private String socialId = null; private String socialId = null;
private SocialView socialView; private SocialView socialView;
private List<SimLocationActuator> comps = new Vector<SimLocationActuator>(); private List<SimLocationActuator> comps = new Vector<SimLocationActuator>();
private LinkedHashSet<AttractionPoint> aPoints = new LinkedHashSet<AttractionPoint>();
private Map<SimLocationActuator, AttractionPoint> assignments = new HashMap<SimLocationActuator, AttractionPoint>();
private Set<SimLocationActuator> arrivedAtAttractionPoint = new LinkedHashSet<>(); private Set<SimLocationActuator> arrivedAtAttractionPoint = new LinkedHashSet<>();
private Map<SimLocationActuator, Set<AttractionPoint>> favoritePlaces = new HashMap<SimLocationActuator, Set<AttractionPoint>>(); private Map<SimLocationActuator, Set<IAttractionPoint>> favoritePlaces = new HashMap<SimLocationActuator, Set<IAttractionPoint>>();
private Map<SimLocationActuator, SimHost> mapMsHost = new HashMap<SimLocationActuator, SimHost>(); private Map<SimLocationActuator, SimHost> mapMsHost = new HashMap<SimLocationActuator, SimHost>();
private Map<SimHost, SimLocationActuator> mapHostMs = new HashMap<SimHost, SimLocationActuator>(); private Map<SimHost, SimLocationActuator> mapHostMs = new HashMap<SimHost, SimLocationActuator>();
private List<AttractionAssignmentListener> listeners = new LinkedList<>();
private double minPauseTime = Simulator.MINUTE_UNIT * 0.5;
private double maxPauseTime = Simulator.MINUTE_UNIT * 100;
private double socialFactor = 0.8; private double socialFactor = 0.8;
private long numberOfFavoritePlaces = 4; private long numberOfFavoritePlaces = 4;
private Random rand;
private PositionVector worldDimension; private PositionVector worldDimension;
private boolean init = false; private boolean init = false;
public SocialTransitionStrategy() { @XMLConfigurableConstructor({ "defaultPauseTimeMin", "defaultPauseTimeMax" })
this.rand = Randoms.getRandom(SocialTransitionStrategy.class); public SocialTransitionStrategy(long defaultPauseTimeMin, long defaultPauseTimeMax) {
super(defaultPauseTimeMin, defaultPauseTimeMax);
} }
private void init() { private void init() {
if (!init) { if (!init) {
if (socialId == null) { if (socialId == null) {
...@@ -135,7 +123,7 @@ public class SocialTransitionStrategy ...@@ -135,7 +123,7 @@ public class SocialTransitionStrategy
"Cannot find the right socialView. Is the socialId correct?"); "Cannot find the right socialView. Is the socialId correct?");
} }
if (minPauseTime > maxPauseTime) { if (defaultPauseTimeMin > defaultPauseTimeMax) {
throw new ConfigurationException( throw new ConfigurationException(
"MinPauseTime should be smaller then maxPauseTime."); "MinPauseTime should be smaller then maxPauseTime.");
} }
...@@ -149,36 +137,7 @@ public class SocialTransitionStrategy ...@@ -149,36 +137,7 @@ public class SocialTransitionStrategy
public void setSocialId(String socialId) { public void setSocialId(String socialId) {
this.socialId = socialId; this.socialId = socialId;
} }
@Override
public AttractionPoint getAssignment(SimLocationActuator comp) {
return assignments.get(comp);
}
@Override
public void addAttractionAssignmentListener(
AttractionAssignmentListener listener) {
listeners.add(listener);
}
@Override
public void removeAttractionAssignmentListener(
AttractionAssignmentListener listener) {
listeners.remove(listener);
}
@Override
public void setAttractionPoints(Collection<AttractionPoint> attractionPoints) {
init();
aPoints.addAll(attractionPoints);
}
@Override
public Set<AttractionPoint> getAllAttractionPoints() {
return aPoints;
}
@Override @Override
public void addComponent(SimLocationActuator ms) { public void addComponent(SimLocationActuator ms) {
comps.add(ms); comps.add(ms);
...@@ -187,8 +146,8 @@ public class SocialTransitionStrategy ...@@ -187,8 +146,8 @@ public class SocialTransitionStrategy
// position. // position.
// TODO: needed? We do Transition as next, and this will delete the // TODO: needed? We do Transition as next, and this will delete the
// assignment.. // assignment..
AttractionPoint nearest = aPoints.iterator().next(); IAttractionPoint nearest = attractionProvider.getAttractionPoints().iterator().next();
for (AttractionPoint aPoint : aPoints) { for (IAttractionPoint aPoint : attractionProvider.getAttractionPoints()) {
if (nearest.distanceTo(ms.getRealPosition()) > aPoint if (nearest.distanceTo(ms.getRealPosition()) > aPoint
.distanceTo(ms.getRealPosition())) { .distanceTo(ms.getRealPosition())) {
nearest = aPoint; nearest = aPoint;
...@@ -203,56 +162,54 @@ public class SocialTransitionStrategy ...@@ -203,56 +162,54 @@ public class SocialTransitionStrategy
@Override @Override
public void updateTargetAttractionPoint(SimLocationActuator comp, public void updateTargetAttractionPoint(SimLocationActuator comp,
AttractionPoint attractionPoint) { IAttractionPoint attractionPoint) {
arrivedAtAttractionPoint.remove(comp); arrivedAtAttractionPoint.remove(comp);
assignments.put(comp, attractionPoint); assignments.put(comp, attractionPoint);
listeners.forEach(listener -> listener.updatedAttractionAssignment(comp, attractionPoint)); notifyListenersOfAssignmentUpdate(comp, attractionPoint);
} }
@Override @Override
public void reachedAttractionPoint(SimLocationActuator ms) { public void reachedAttractionPoint(SimLocationActuator ms, IAttractionPoint attractionPoint) {
if (!arrivedAtAttractionPoint.contains(ms)) { if (!arrivedAtAttractionPoint.contains(ms)) {
Event.scheduleWithDelay(getPauseTime(), this, ms, 0); Event.scheduleWithDelay(getPauseTime(attractionPoint), this, ms, 0);
arrivedAtAttractionPoint.add(ms); arrivedAtAttractionPoint.add(ms);
} }
} }
public void doTransition(SimLocationActuator ms) { public void doTransition(SimLocationActuator ms) {
List<AttractionPoint> apFavorites = getFavoritePlaces(ms); List<IAttractionPoint> apFavorites = getFavoritePlaces(ms);
List<AttractionPoint> apFriends = getFriendsPlaces(ms); List<IAttractionPoint> apFriends = getFriendsPlaces(ms);
List<AttractionPoint> apClusters = getClusterPlaces(ms); List<IAttractionPoint> apClusters = getClusterPlaces(ms);
List<AttractionPoint> apRandom = getRandomPlaces(ms, List<IAttractionPoint> apRandom = getRandomPlaces(ms,
(int) Math.max(aPoints.size() * 0.2, 5)); (int) Math.max(attractionProvider.getAttractionPoints().size() * 0.2, 5));
AttractionPoint ap = null; IAttractionPoint ap = null;
if (rand.nextDouble() < socialFactor) { if (rnd.nextDouble() < socialFactor) {
ap = findHighestScore(ms, apFavorites, apFriends, apClusters, ap = findHighestScore(ms, apFavorites, apFriends, apClusters,
apRandom); apRandom);
} else { } else {
List<AttractionPoint> aps = new ArrayList<AttractionPoint>(); List<IAttractionPoint> aps = new ArrayList<IAttractionPoint>();
aps.addAll(apRandom); aps.addAll(apRandom);
aps.addAll(apFavorites); aps.addAll(apFavorites);
ap = aps.get(rand.nextInt(apRandom.size())); ap = aps.get(rnd.nextInt(apRandom.size()));
} }
assignments.put(ms, ap); assignments.put(ms, ap);
arrivedAtAttractionPoint.remove(ms); arrivedAtAttractionPoint.remove(ms);
for (AttractionAssignmentListener listener : listeners) { notifyListenersOfAssignmentUpdate(ms, ap);
listener.updatedAttractionAssignment(ms, ap);
}
} }
private AttractionPoint findHighestScore(SimLocationActuator ms, private IAttractionPoint findHighestScore(SimLocationActuator ms,
List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends, List<IAttractionPoint> apFavorites, List<IAttractionPoint> apFriends,
List<AttractionPoint> apClusters, List<AttractionPoint> apRandom) { List<IAttractionPoint> apClusters, List<IAttractionPoint> apRandom) {
Set<AttractionPoint> aps = new LinkedHashSet<AttractionPoint>(); Set<IAttractionPoint> aps = new LinkedHashSet<IAttractionPoint>();
aps.addAll(apFavorites); aps.addAll(apFavorites);
aps.addAll(apFriends); aps.addAll(apFriends);
aps.addAll(apClusters); aps.addAll(apClusters);
aps.addAll(apRandom); aps.addAll(apRandom);
double maxScore = 0; double maxScore = 0;
AttractionPoint maxAp = null; IAttractionPoint maxAp = null;
for (AttractionPoint ap : aps) { for (IAttractionPoint ap : aps) {
double score = score(ms, ap, apFavorites, apFriends, apClusters, double score = score(ms, ap, apFavorites, apFriends, apClusters,
apRandom); apRandom);
// System.out.println(score); // System.out.println(score);
...@@ -282,9 +239,9 @@ public class SocialTransitionStrategy ...@@ -282,9 +239,9 @@ public class SocialTransitionStrategy
* @param apRandom * @param apRandom
* @return * @return
*/ */
private double score(SimLocationActuator ms, AttractionPoint ap, private double score(SimLocationActuator ms, IAttractionPoint ap,
List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends, List<IAttractionPoint> apFavorites, List<IAttractionPoint> apFriends,
List<AttractionPoint> apClusters, List<AttractionPoint> apRandom) { List<IAttractionPoint> apClusters, List<IAttractionPoint> apRandom) {
double distance = ms.getRealPosition().distanceTo(ap); double distance = ms.getRealPosition().distanceTo(ap);
double distanceScore = 1 - (distance / worldDimension.getLength()); double distanceScore = 1 - (distance / worldDimension.getLength());
...@@ -319,9 +276,9 @@ public class SocialTransitionStrategy ...@@ -319,9 +276,9 @@ public class SocialTransitionStrategy
} }
// counts the number of the AttractionPoint in the list // counts the number of the AttractionPoint in the list
private int occurence(AttractionPoint ap, List<AttractionPoint> aps) { private int occurence(IAttractionPoint ap, List<IAttractionPoint> aps) {
int i = 0; int i = 0;
for (AttractionPoint a : aps) { for (IAttractionPoint a : aps) {
if (a.equals(ap)) { if (a.equals(ap)) {
i++; i++;
} }
...@@ -329,9 +286,9 @@ public class SocialTransitionStrategy ...@@ -329,9 +286,9 @@ public class SocialTransitionStrategy
return i; return i;
} }
private int assignedToAp(AttractionPoint ap) { private int assignedToAp(IAttractionPoint ap) {
int i = 1; int i = 1;
for (Entry<SimLocationActuator, AttractionPoint> entry : assignments for (Entry<SimLocationActuator, IAttractionPoint> entry : assignments
.entrySet()) { .entrySet()) {
if (entry.getValue().equals(ap)) { if (entry.getValue().equals(ap)) {
i++; i++;
...@@ -340,15 +297,15 @@ public class SocialTransitionStrategy ...@@ -340,15 +297,15 @@ public class SocialTransitionStrategy
return i; return i;
} }
private List<AttractionPoint> getRandomPlaces(SimLocationActuator ms, private List<IAttractionPoint> getRandomPlaces(SimLocationActuator ms,
int number) { int number) {
List<AttractionPoint> result = new Vector<AttractionPoint>(aPoints); List<IAttractionPoint> result = new Vector<IAttractionPoint>(attractionProvider.getAttractionPoints());
Collections.shuffle(result, rand); Collections.shuffle(result, rnd);
return result.subList(0, Math.min(result.size(), number)); return result.subList(0, Math.min(result.size(), number));
} }
private List<AttractionPoint> getClusterPlaces(SimLocationActuator ms) { private List<IAttractionPoint> getClusterPlaces(SimLocationActuator ms) {
List<AttractionPoint> result = new Vector<AttractionPoint>(); List<IAttractionPoint> result = new Vector<IAttractionPoint>();
SimHost msHost = mapMsHost.get(ms); SimHost msHost = mapMsHost.get(ms);
for (SimHost host : socialView.getCluster(msHost)) { for (SimHost host : socialView.getCluster(msHost)) {
...@@ -361,8 +318,8 @@ public class SocialTransitionStrategy ...@@ -361,8 +318,8 @@ public class SocialTransitionStrategy
return result; return result;
} }
private List<AttractionPoint> getFriendsPlaces(SimLocationActuator ms) { private List<IAttractionPoint> getFriendsPlaces(SimLocationActuator ms) {
List<AttractionPoint> result = new Vector<AttractionPoint>(); List<IAttractionPoint> result = new Vector<IAttractionPoint>();
SimHost msHost = mapMsHost.get(ms); SimHost msHost = mapMsHost.get(ms);
for (SimHost host : socialView.getNeighbors(msHost)) { for (SimHost host : socialView.getNeighbors(msHost)) {
...@@ -375,15 +332,15 @@ public class SocialTransitionStrategy ...@@ -375,15 +332,15 @@ public class SocialTransitionStrategy
return result; return result;
} }
private List<AttractionPoint> getFavoritePlaces(SimLocationActuator ms) { private List<IAttractionPoint> getFavoritePlaces(SimLocationActuator ms) {
return new Vector<AttractionPoint>(favoritePlaces.get(ms)); return new Vector<IAttractionPoint>(favoritePlaces.get(ms));
} }
private void assignFavoritePlaces(SimLocationActuator ms) { private void assignFavoritePlaces(SimLocationActuator ms) {
Set<AttractionPoint> msFavoritePlaces = new LinkedHashSet<AttractionPoint>(); Set<IAttractionPoint> msFavoritePlaces = new LinkedHashSet<IAttractionPoint>();
LinkedList<AttractionPoint> temp = new LinkedList<AttractionPoint>( LinkedList<IAttractionPoint> temp = new LinkedList<IAttractionPoint>(
aPoints); attractionProvider.getAttractionPoints());
Collections.shuffle(temp, rand); Collections.shuffle(temp, rnd);
for (int i = 0; i < numberOfFavoritePlaces; i++) { for (int i = 0; i < numberOfFavoritePlaces; i++) {
if (!temp.isEmpty()) { if (!temp.isEmpty()) {
msFavoritePlaces.add(temp.removeFirst()); msFavoritePlaces.add(temp.removeFirst());
...@@ -401,28 +358,7 @@ public class SocialTransitionStrategy ...@@ -401,28 +358,7 @@ public class SocialTransitionStrategy
mapHostMs.put(host, ms); mapHostMs.put(host, ms);
mapMsHost.put(ms, host); mapMsHost.put(ms, host);
} }
protected long getPauseTime() {
return (long) ((rand.nextDouble() * (maxPauseTime - minPauseTime))
+ minPauseTime);
}
public void setMinPauseTime(long minPauseTime) {
if (minPauseTime < 0) {
throw new ConfigurationException(
"MinPauseTime should be bigger then 0!");
}
this.minPauseTime = minPauseTime;
}
public void setMaxPauseTime(long maxPauseTime) {
if (maxPauseTime < 0) {
throw new ConfigurationException(
"MaxPauseTime should be bigger then 0!");
}
this.maxPauseTime = maxPauseTime;
}
@Override @Override
public void eventOccurred(Object se, int type) { public void eventOccurred(Object se, int type) {
if (arrivedAtAttractionPoint.contains(se)) { if (arrivedAtAttractionPoint.contains(se)) {
......
...@@ -20,143 +20,57 @@ ...@@ -20,143 +20,57 @@
package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition; package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/** /**
* A simplified transition strategy taking only the weights of an AP into account. * A simplified transition strategy taking only the weights of an AP into account.
* *
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, Jan 16, 2017 * @version 1.0, Jan 16, 2017
*
* Made the transition strategy extend the {@link AbstractAttractionBasedAssignmentStrategy} for a more generalized approach on
* the {@link IAttractionAssigmentStrategy} implementation for attraction point based strategies.
*
* @author Julian Zobel
* @version 1.1, January 2019
*
*/ */
public class WeightedTransitionStrategy implements ITransitionStrategy, EventHandler { public class WeightedTransitionStrategy extends AbstractAttractionBasedAssignmentStrategy implements EventHandler {
private Set<AttractionPoint> aps = new LinkedHashSet<>(); @XMLConfigurableConstructor({ "defaultPauseTimeMin", "defaultPauseTimeMax" })
public WeightedTransitionStrategy(long defaultPauseTimeMin, long defaultPauseTimeMax) {
private Map<SimLocationActuator, AttractionPoint> assignments = new LinkedHashMap<>(); super(defaultPauseTimeMin, defaultPauseTimeMax);
private Map<SimLocationActuator, AttractionPoint> lastAssignments = new LinkedHashMap<>();
private List<AttractionAssignmentListener> listeners = new LinkedList<>();
private long pauseTimeMin = 0;
private long pauseTimeMax = 0;
private Random rnd = Randoms.getRandom(WeightedTransitionStrategy.class);
private final static int EVENT_PAUSE_ENDED = 1;
@Override
public AttractionPoint getAssignment(SimLocationActuator comp) {
return assignments.get(comp);
}
@Override
public void addAttractionAssignmentListener(
AttractionAssignmentListener listener) {
listeners.add(listener);
} }
@Override
public void removeAttractionAssignmentListener(
AttractionAssignmentListener listener) {
listeners.remove(listener);
}
@Override
public void setAttractionPoints(
Collection<AttractionPoint> attractionPoints) {
this.aps.addAll(attractionPoints);
}
@Override
public Set<AttractionPoint> getAllAttractionPoints() {
return Collections.unmodifiableSet(aps);
}
@Override @Override
public void addComponent(SimLocationActuator ms) { public void addComponent(SimLocationActuator ms) {
this.assignments.put(ms, getNewAssignment(ms)); IAttractionPoint nextAP = getNewAttractionPointAssignment(ms);
} updateTargetAttractionPoint(ms, nextAP);
private AttractionPoint getNewAssignment(SimLocationActuator component) {
double score = rnd.nextDouble();
List<AttractionPoint> candidates = new LinkedList<>();
for (AttractionPoint ap : aps) {
if (ap.getWeight() >= score) {
candidates.add(ap);
}
}
if (candidates.isEmpty()) {
candidates.addAll(aps);
}
AttractionPoint assignment = candidates.get(rnd.nextInt(candidates.size()));
listeners.forEach(listener -> listener.updatedAttractionAssignment(component, assignment));
return assignment;
}
private long getPauseTime(SimLocationActuator component) {
return (long) (rnd.nextDouble() * (pauseTimeMax-pauseTimeMin)) + pauseTimeMin;
} }
@Override @Override
public void eventOccurred(Object content, int type) { public void eventOccurred(Object content, int type) {
assert type == EVENT_PAUSE_ENDED; assert type == EVENT_PAUSE_ENDED;
SimLocationActuator comp = (SimLocationActuator) content; SimLocationActuator comp = (SimLocationActuator) content;
if (!this.assignments.containsKey(comp)) { if (!this.assignments.containsKey(comp)) {
// maybe someone assigned a new AP in the meantime. ignore. // maybe someone assigned a new AP in the meantime. ignore.
this.assignments.put(comp, getNewAssignment(comp)); this.assignments.put(comp, getNewAttractionPointAssignment(comp));
} }
} }
@Override @Override
public void reachedAttractionPoint(SimLocationActuator ms) { public void reachedAttractionPoint(SimLocationActuator ms, IAttractionPoint attractionPoint) {
// JZ: Added this to prevent multiple calls while pausing // JZ: Added this to prevent multiple calls while pausing (otherwise most nodes will not wait more the minimum pause time)
if (!this.assignments.containsKey(ms)) { if (!this.assignments.containsKey(ms)) {
return; return;
} }
this.lastAssignments.put(ms, this.assignments.remove(ms)); this.lastAssignments.put(ms, this.assignments.remove(ms));
Event.scheduleWithDelay(getPauseTime(ms), this, ms, EVENT_PAUSE_ENDED); Event.scheduleWithDelay(getPauseTime(attractionPoint), this, ms, EVENT_PAUSE_ENDED);
}
@Override
public void updateTargetAttractionPoint(SimLocationActuator comp,
AttractionPoint attractionPoint) {
this.lastAssignments.put(comp, this.assignments.remove(comp));
this.assignments.put(comp, attractionPoint);
listeners.forEach(listener -> listener.updatedAttractionAssignment(comp, attractionPoint));
}
public void setMinPauseTime(long minPauseTime) {
if (minPauseTime < 0) {
throw new ConfigurationException(
"MinPauseTime should be >= 0!");
}
this.pauseTimeMin = minPauseTime;
}
public void setMaxPauseTime(long maxPauseTime) {
if (maxPauseTime < 0) {
throw new ConfigurationException(
"MaxPauseTime should be >= 0!");
}
this.pauseTimeMax = maxPauseTime;
} }
} }
...@@ -52,4 +52,8 @@ public class VehicleInformationContainer { ...@@ -52,4 +52,8 @@ public class VehicleInformationContainer {
public RoadNetworkRoute getRoute() { public RoadNetworkRoute getRoute() {
return _route; return _route;
} }
public void setRoute(RoadNetworkRoute pRoute) {
_route = pRoute;
}
} }
\ No newline at end of file
...@@ -7,7 +7,7 @@ import java.util.ArrayList; ...@@ -7,7 +7,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Scanner; import java.util.Scanner;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class RoadSideUnitInformationHandler { public class RoadSideUnitInformationHandler {
...@@ -27,8 +27,8 @@ public class RoadSideUnitInformationHandler { ...@@ -27,8 +27,8 @@ public class RoadSideUnitInformationHandler {
List<Location> result = new ArrayList<>(); List<Location> result = new ArrayList<>();
for (Location position : _positions) { for (Location position : _positions) {
if (_startX <= position.getLongitude() && position.getLongitude() <= _endX && _startY <= position.getLatitude() && position.getLatitude() <= _endY) { if (_startX <= position.getLongitudeOrX() && position.getLongitudeOrX() <= _endX && _startY <= position.getLatitudeOrY() && position.getLatitudeOrY() <= _endY) {
result.add(new PositionVector(position.getLongitude() - _startX, position.getLatitude() - _startY, 0)); result.add(new PositionVector(position.getLongitudeOrX() - _startX, position.getLatitudeOrY() - _startY, 0));
} }
} }
......
...@@ -12,13 +12,15 @@ import java.util.HashMap; ...@@ -12,13 +12,15 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Random; import java.util.Random;
import de.tud.kom.p2psim.api.simengine.SimulatorObserver; import de.tud.kom.p2psim.api.simengine.SimulatorObserver;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.EdgeController; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.EdgeController;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
...@@ -31,6 +33,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road ...@@ -31,6 +33,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.Road
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.SerializableRoadNetwork; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.SerializableRoadNetwork;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoAdditionalRouteAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoAdditionalRouteAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoExitAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.exception.NoExitAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTracker;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.paths.VehiclePathTrackerFactory;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.DijkstraAlgorithm; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.DijkstraAlgorithm;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.RoutingAlgorithm; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.roadnetwork.routing.RoutingAlgorithm;
import de.tudresden.sumo.cmd.Edge; import de.tudresden.sumo.cmd.Edge;
...@@ -54,7 +58,9 @@ import it.polito.appeal.traci.SumoTraciConnection; ...@@ -54,7 +58,9 @@ import it.polito.appeal.traci.SumoTraciConnection;
* *
*/ */
public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController, SimulatorObserver { public class TraciSimulationController implements VehicleController, SimulationSetupExtractor, EdgeController, SimulatorObserver {
private static final File TEMP_FILE = new File(new File(System.getProperty("java.io.tmpdir")), "road_network.tmp"); private static final File TEMP_FILE = new File(new File(System.getProperty("user.home") + "/.simonstrator"), "road_network.tmp");
private static final boolean TRAIN_PATH_PROBABILITIES = false;
private Random _random = Randoms.getRandom(getClass()); private Random _random = Randoms.getRandom(getClass());
...@@ -75,6 +81,8 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -75,6 +81,8 @@ public class TraciSimulationController implements VehicleController, SimulationS
private double _endX; private double _endX;
private double _endY; private double _endY;
private int _startTime = 0;
private Map<String, VehicleInformationContainer> _positons = new HashMap<>(); private Map<String, VehicleInformationContainer> _positons = new HashMap<>();
private boolean _initalized = false; private boolean _initalized = false;
...@@ -87,16 +95,23 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -87,16 +95,23 @@ public class TraciSimulationController implements VehicleController, SimulationS
private RoutingAlgorithm _algorithm = new DijkstraAlgorithm(); private RoutingAlgorithm _algorithm = new DijkstraAlgorithm();
public static synchronized TraciSimulationController createSimulationController(String pSumoExe, String pConfigFile) { private int _timestepRatio;
public static synchronized TraciSimulationController createSimulationController(String pSumoExe, String pConfigFile, int pTimestepRatio) {
if (!CONTROLLER.containsKey(pConfigFile)) { if (!CONTROLLER.containsKey(pConfigFile)) {
CONTROLLER.put(pConfigFile, new TraciSimulationController(pSumoExe, pConfigFile)); CONTROLLER.put(pConfigFile, new TraciSimulationController(pSumoExe, pConfigFile, pTimestepRatio));
} }
return CONTROLLER.get(pConfigFile); return CONTROLLER.get(pConfigFile);
} }
private TraciSimulationController(String pSumoExe, String pConfigFile) { private TraciSimulationController(String pSumoExe, String pConfigFile, int pTimestepRatio) {
_sumoExe = pSumoExe; _sumoExe = pSumoExe;
_configFile = pConfigFile; _configFile = pConfigFile;
_timestepRatio = pTimestepRatio;
}
public void setStartTime(int pStartTime) {
_startTime = pStartTime;
} }
public static VehicleController getSimulationController() { public static VehicleController getSimulationController() {
...@@ -104,7 +119,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -104,7 +119,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
} }
@Override @Override
public synchronized void init() { public synchronized void init(long pTimeScale) {
if (!_initalized) { if (!_initalized) {
Random random = Randoms.getRandom("SUMO"); Random random = Randoms.getRandom("SUMO");
...@@ -115,6 +130,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -115,6 +130,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
* prevent vehicles form teleporting (http://sumo.dlr.de/wiki/Simulation/Why_Vehicles_are_teleporting) * prevent vehicles form teleporting (http://sumo.dlr.de/wiki/Simulation/Why_Vehicles_are_teleporting)
*/ */
_connection.addOption("time-to-teleport", Integer.toString(-1)); _connection.addOption("time-to-teleport", Integer.toString(-1));
_connection.addOption("step-length", String.valueOf(pTimeScale / (double)Time.SECOND));
try { try {
_connection.runServer(); _connection.runServer();
...@@ -127,6 +143,26 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -127,6 +143,26 @@ public class TraciSimulationController implements VehicleController, SimulationS
Simulator.getInstance().addObserver(this); Simulator.getInstance().addObserver(this);
_initalized = true; _initalized = true;
for (int i = 0; i < _startTime; i++) {
System.out.println("Pre-Start Setup: " + i + " of " + _startTime + " steps done.");
if (TRAIN_PATH_PROBABILITIES) {
Map<String, VehicleInformationContainer> positions = nextStep();
for (Entry<String, VehicleInformationContainer> entry : positions.entrySet()) {
VehiclePathTrackerFactory.getVehiclePathTracker().setEdge(entry.getKey(), entry.getValue().getRoute().getStart(), i * pTimeScale);
}
} else {
try {
_connection.do_timestep();
} catch (Exception e) {
throw new AssertionError(e);
}
}
}
if (TRAIN_PATH_PROBABILITIES) {
VehiclePathTrackerFactory.getVehiclePathTracker().disableTracking();
}
} }
} }
...@@ -146,6 +182,13 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -146,6 +182,13 @@ public class TraciSimulationController implements VehicleController, SimulationS
return _positons.get(pVehicleID).getPosition(); return _positons.get(pVehicleID).getPosition();
} }
@Override
public double getVehicleLength(String pVehicleID) {
SumoCommand lengthCommand = Vehicle.getLength(pVehicleID);
Object requestObject = requestObject(lengthCommand);
return (Double) requestObject;
}
@Override @Override
public double getVehicleHeading(String pVehicleID) { public double getVehicleHeading(String pVehicleID) {
return _positons.get(pVehicleID).getHeading(); return _positons.get(pVehicleID).getHeading();
...@@ -176,10 +219,10 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -176,10 +219,10 @@ public class TraciSimulationController implements VehicleController, SimulationS
if (_observedAreaSet) { if (_observedAreaSet) {
if (_startX <= sumoPosition.x && sumoPosition.x <= _endX && _startY <= sumoPosition.y && sumoPosition.y <= _endY) { if (_startX <= sumoPosition.x && sumoPosition.x <= _endX && _startY <= sumoPosition.y && sumoPosition.y <= _endY) {
result.add(new PositionVector(sumoPosition.x - _startX, sumoPosition.y - _startY, 0)); result.add(new PositionVector(sumoPosition.x - _startX, sumoPosition.y - _startY));
} }
} else { } else {
result.add(new PositionVector(sumoPosition.x, sumoPosition.y, 0)); result.add(new PositionVector(sumoPosition.x, sumoPosition.y));
} }
} }
...@@ -205,54 +248,63 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -205,54 +248,63 @@ public class TraciSimulationController implements VehicleController, SimulationS
return result; return result;
} }
@Override private Map<String, VehicleInformationContainer> nextStep() {
public boolean nextStep() { try {
if (Simulator.getEndTime() == Simulator.getCurrentTime()) { for (int i = 0; i < _timestepRatio; i++) {
return false; _connection.do_timestep();
} }
try {
_connection.do_timestep();
try { try {
synchronized (_positons) { Map<String, VehicleInformationContainer> vehiclePositions = new HashMap<>();
_positons.clear();
int temp = (Integer) _connection.do_job_get(Simulation.getCurrentTime()); List<String> allVehicles = requestAllVehicles();
for (String vehicle : allVehicles) {
Location position = requestVehiclePosition(vehicle);
if (position != null) {
double heading = requestVehicleHeading(vehicle);
double speed = requestVehicleSpeed(vehicle);
RoadNetworkRoute route = requestVehicleRoute(vehicle);
_step = temp / 1000.0; VehicleInformationContainer informationContainer = new VehicleInformationContainer(position, heading, speed, route);
if (_start == -1) { vehiclePositions.put(vehicle, informationContainer);
_start = _step; }
} }
return vehiclePositions;
} catch (Exception e) {
throw new AssertionError(e);
}
} catch (Exception e) {
throw new AssertionError(e);
}
}
Map<String, VehicleInformationContainer> vehiclePositions = new HashMap<>(); @Override
public boolean nextStep(long pTimeScale) {
if (Simulator.getEndTime() == Simulator.getCurrentTime()) {
return false;
}
Map<String, VehicleInformationContainer> vehiclePositions = nextStep();
List<String> allVehicles = requestAllVehicles(); try {
for (String vehicle : allVehicles) { int temp = (Integer) _connection.do_job_get(Simulation.getCurrentTime());
Location position = requestVehiclePosition(vehicle);
if (position != null) {
double heading = requestVehicleHeading(vehicle);
double speed = requestVehicleSpeed(vehicle);
RoadNetworkRoute route = requestVehicleRoute(vehicle);
VehicleInformationContainer informationContainer = new VehicleInformationContainer(position, heading, speed, route); _step = temp / (pTimeScale / (double)Time.MILLISECOND);
vehiclePositions.put(vehicle, informationContainer); if (_start == -1) {
} _start = _step;
} }
_positons = vehiclePositions; } catch (Exception e) {
} throw new AssertionError(e);
} catch (Exception e) { }
e.printStackTrace();
}
return true; if (vehiclePositions != null) {
} catch (RuntimeException e) { _positons = vehiclePositions;
throw e; return true;
} catch (Exception e) { } else {
e.printStackTrace(); _positons.clear();
return false;
} }
return false;
} }
private Location requestVehiclePosition(String pVehicleID) { private Location requestVehiclePosition(String pVehicleID) {
...@@ -272,7 +324,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -272,7 +324,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
if (_observedAreaSet) { if (_observedAreaSet) {
if (_startX <= sumoPosition.x && sumoPosition.x <= _endX && _startY <= sumoPosition.y && sumoPosition.y <= _endY) { if (_startX <= sumoPosition.x && sumoPosition.x <= _endX && _startY <= sumoPosition.y && sumoPosition.y <= _endY) {
return new PositionVector(sumoPosition.x - _startX, sumoPosition.y - _startY, 0); return new PositionVector(sumoPosition.x - _startX, sumoPosition.y - _startY);
} else { } else {
double diffX = _startX - sumoPosition.x; double diffX = _startX - sumoPosition.x;
if (diffX < 0 || sumoPosition.x - _endX < diffX) { if (diffX < 0 || sumoPosition.x - _endX < diffX) {
...@@ -297,7 +349,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -297,7 +349,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
return null; return null;
} }
} else { } else {
return new PositionVector(sumoPosition.x, sumoPosition.y, 0); return new PositionVector(sumoPosition.x, sumoPosition.y);
} }
} }
...@@ -314,7 +366,6 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -314,7 +366,6 @@ public class TraciSimulationController implements VehicleController, SimulationS
Object angleObject = requestObject(angleCommand); Object angleObject = requestObject(angleCommand);
if (angleObject != null) { if (angleObject != null) {
return (Double) angleObject; return (Double) angleObject;
} }
...@@ -408,7 +459,11 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -408,7 +459,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
add = true; add = true;
} }
if (add) { if (add) {
streets.add(_roadNetwork.getEdge(street)); RoadNetworkEdge edge = _roadNetwork.getEdge(street);
streets.add(edge);
if (!edge.isUsable()) {
break;
}
} }
} }
...@@ -484,8 +539,12 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -484,8 +539,12 @@ public class TraciSimulationController implements VehicleController, SimulationS
SumoCommand netBoundaryCommand = Simulation.getNetBoundary(); SumoCommand netBoundaryCommand = Simulation.getNetBoundary();
try { try {
SumoBoundingBox netBoundary = (SumoBoundingBox) _connection.do_job_get(netBoundaryCommand); SumoBoundingBox netBoundary = (SumoBoundingBox) _connection.do_job_get(netBoundaryCommand);
return Math.max(netBoundary.x_max - netBoundary.x_min, 10); if (_observedAreaSet) {
return Math.max(Math.min(netBoundary.x_max, _endX) - Math.max(netBoundary.x_min, _startX), 10);
} else {
return Math.max(netBoundary.x_max - netBoundary.x_min, 10);
}
} catch (Exception e) { } catch (Exception e) {
//Nothing to do //Nothing to do
} }
...@@ -498,7 +557,11 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -498,7 +557,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
try { try {
SumoBoundingBox netBoundary = (SumoBoundingBox) _connection.do_job_get(netBoundaryCommand); SumoBoundingBox netBoundary = (SumoBoundingBox) _connection.do_job_get(netBoundaryCommand);
return Math.max(netBoundary.y_max - netBoundary.y_min, 10); if (_observedAreaSet) {
return Math.max(Math.min(netBoundary.y_max, _endY) - Math.max(netBoundary.y_min, _startY), 10);
} else {
return Math.max(netBoundary.y_max - netBoundary.y_min, 10);
}
} catch (Exception e) { } catch (Exception e) {
//Nothing to do //Nothing to do
} }
...@@ -610,6 +673,7 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -610,6 +673,7 @@ public class TraciSimulationController implements VehicleController, SimulationS
routeEdges.add(edge.getEdgeID()); routeEdges.add(edge.getEdgeID());
} }
execute(Vehicle.setRoute(pVehicle, routeEdges)); execute(Vehicle.setRoute(pVehicle, routeEdges));
_positons.get(pVehicle).setRoute(pRoute);
} }
@Override @Override
...@@ -707,12 +771,14 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -707,12 +771,14 @@ public class TraciSimulationController implements VehicleController, SimulationS
_roadNetwork = new RoadNetwork(roadNetwork, this, true); _roadNetwork = new RoadNetwork(roadNetwork, this, true);
try { try {
ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(TEMP_FILE)); if (TEMP_FILE.getParentFile().exists() || TEMP_FILE.getParentFile().mkdirs()) {
ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(TEMP_FILE));
outputStream.writeObject(new SerializableRoadNetwork(_roadNetwork)); outputStream.writeObject(new SerializableRoadNetwork(_roadNetwork));
outputStream.flush(); outputStream.flush();
outputStream.close(); outputStream.close();
}
} catch (IOException e) { } catch (IOException e) {
//Nothing to do //Nothing to do
e.printStackTrace(); e.printStackTrace();
...@@ -749,19 +815,19 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -749,19 +815,19 @@ public class TraciSimulationController implements VehicleController, SimulationS
public List<Location> getLaneShape(String pLaneID) { public List<Location> getLaneShape(String pLaneID) {
List<Location> positions = new ArrayList<>(); List<Location> positions = new ArrayList<>();
boolean set = true; boolean set = false;
SumoCommand laneShapeCommand = Lane.getShape(pLaneID); SumoCommand laneShapeCommand = Lane.getShape(pLaneID);
SumoGeometry geometry = (SumoGeometry)requestObject(laneShapeCommand); SumoGeometry geometry = (SumoGeometry)requestObject(laneShapeCommand);
for (SumoPosition2D location : geometry.coords) { for (SumoPosition2D location : geometry.coords) {
if (!isObservedAreaSet()) { if (!isObservedAreaSet()) {
positions.add(new PositionVector(location.x, location.y)); positions.add(new PositionVector(location.x, location.y));
set = true;
} else { } else {
if (_startX <= location.x && location.x <= _endX && _startY <= location.y && location.y <= _endY) { if (_startX <= location.x && location.x <= _endX && _startY <= location.y && location.y <= _endY) {
positions.add(new PositionVector(location.x - _startX, location.y - _startY));
} else {
set = true; set = true;
} }
positions.add(new PositionVector(location.x - _startX, location.y - _startY));
} }
} }
...@@ -786,8 +852,8 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -786,8 +852,8 @@ public class TraciSimulationController implements VehicleController, SimulationS
int count = 0; int count = 0;
for (Location position : positions) { for (Location position : positions) {
x += position.getLongitude(); x += position.getLongitudeOrX();
y += position.getLatitude(); y += position.getLatitudeOrY();
count++; count++;
} }
...@@ -830,8 +896,11 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -830,8 +896,11 @@ public class TraciSimulationController implements VehicleController, SimulationS
length += (double) object; length += (double) object;
} }
if ((_roadNetwork.getEdge(pEdgeID).getLaneAmount()) != 0) {
return length / (_roadNetwork.getEdge(pEdgeID).getLaneAmount()); return length / (_roadNetwork.getEdge(pEdgeID).getLaneAmount());
} else {
return 0.0;
}
} }
@Override @Override
...@@ -839,10 +908,12 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -839,10 +908,12 @@ public class TraciSimulationController implements VehicleController, SimulationS
if (_observedAreaSet) { if (_observedAreaSet) {
List<RoadNetworkLane> lanes = _roadNetwork.getEdge(pEdgeID).getLanes(); List<RoadNetworkLane> lanes = _roadNetwork.getEdge(pEdgeID).getLanes();
if (lanes.size() > 0) { if (lanes.size() > 0) {
List<Location> laneShape = getLaneShape(lanes.get(0).getLaneID()); for (RoadNetworkLane lane : lanes) {
if (laneShape.size() > 1) { List<Location> laneShape = getLaneShape(lane.getLaneID());
return true; if (laneShape.size() > 1) {
} return true;
}
}
} }
return false; return false;
} }
......
...@@ -4,7 +4,7 @@ import org.xml.sax.Attributes; ...@@ -4,7 +4,7 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
public class SimulationSetupInformationHandler extends DefaultHandler { public class SimulationSetupInformationHandler extends DefaultHandler {
......
...@@ -6,8 +6,8 @@ import org.xml.sax.Attributes; ...@@ -6,8 +6,8 @@ import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.DefaultHandler;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer;
import de.tud.kom.p2psim.impl.topology.util.PositionVector;
public class VehicleDataInformationHandler extends DefaultHandler { public class VehicleDataInformationHandler extends DefaultHandler {
private boolean _next = true; private boolean _next = true;
......
...@@ -12,6 +12,7 @@ import javax.xml.parsers.SAXParserFactory; ...@@ -12,6 +12,7 @@ import javax.xml.parsers.SAXParserFactory;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.VehicleInformationContainer;
import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.csv.RoadSideUnitInformationHandler; import de.tud.kom.p2psim.impl.topology.movement.vehicular.sumo.simulation.controller.csv.RoadSideUnitInformationHandler;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.SimulationSetupExtractor;
import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController; import de.tudarmstadt.maki.simonstrator.api.component.vehicular.api.VehicleController;
...@@ -49,7 +50,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -49,7 +50,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet
} }
@Override @Override
public void init() { public void init(long timeBetweenMoveOperations) {
if (!_initalized) { if (!_initalized) {
if (_vehicleDataPath != null) { if (_vehicleDataPath != null) {
...@@ -57,7 +58,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -57,7 +58,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet
thread.start(); thread.start();
for (int i = 0; i < _futureInformation; i++) { for (int i = 0; i < _futureInformation; i++) {
nextStep(); nextStep(Time.SECOND);
} }
} }
if (_roadSideUnitDataPath != null) { if (_roadSideUnitDataPath != null) {
...@@ -77,7 +78,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -77,7 +78,7 @@ public class XMLSimulationController implements VehicleController, SimulationSet
} }
@Override @Override
public boolean nextStep() { public boolean nextStep(long pTimeScale) {
_vehicleDataInformationHandler.readNext(); _vehicleDataInformationHandler.readNext();
_step = _vehicleDataInformationHandler.getStep() - _futureInformation; _step = _vehicleDataInformationHandler.getStep() - _futureInformation;
...@@ -171,6 +172,11 @@ public class XMLSimulationController implements VehicleController, SimulationSet ...@@ -171,6 +172,11 @@ public class XMLSimulationController implements VehicleController, SimulationSet
return -1; return -1;
} }
@Override
public double getVehicleLength(String pVehicleID) {
throw new UnsupportedOperationException("This method is not supported for " + getClass().getSimpleName());
}
@Override @Override
public RoadNetworkRoute getCurrentRoute(String pVehicleID) { public RoadNetworkRoute getCurrentRoute(String pVehicleID) {
throw new UnsupportedOperationException("This method is not supported for " + getClass().getSimpleName()); throw new UnsupportedOperationException("This method is not supported for " + getClass().getSimpleName());
......
...@@ -39,7 +39,7 @@ import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel; ...@@ -39,7 +39,7 @@ import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.api.util.geo.maps.Map; import de.tud.kom.p2psim.api.util.geo.maps.Map;
import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.Configure; import de.tud.kom.p2psim.impl.scenario.simcfg2.annotations.Configure;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.util.Tuple; import de.tud.kom.p2psim.impl.util.Tuple;
import de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener; import de.tud.kom.p2psim.impl.util.geo.maps.MapChangeListener;
import de.tud.kom.p2psim.impl.util.geo.maps.MapLoader; import de.tud.kom.p2psim.impl.util.geo.maps.MapLoader;
......
...@@ -32,7 +32,7 @@ import com.vividsolutions.jts.geom.LineString; ...@@ -32,7 +32,7 @@ import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.MultiLineString; import com.vividsolutions.jts.geom.MultiLineString;
import com.vividsolutions.jts.geom.Polygon; import com.vividsolutions.jts.geom.Polygon;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
/** /**
* This Obstacle is build from a list of coordinates that form a Polygon. The * This Obstacle is build from a list of coordinates that form a Polygon. The
......
...@@ -27,7 +27,7 @@ import com.google.common.collect.Lists; ...@@ -27,7 +27,7 @@ import com.google.common.collect.Lists;
import de.tud.kom.p2psim.api.topology.TopologyComponent; import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.obstacles.Obstacle; import de.tud.kom.p2psim.api.topology.obstacles.Obstacle;
import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel; import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Host; import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException; import de.tudarmstadt.maki.simonstrator.api.component.ComponentNotAvailableException;
import de.tudarmstadt.maki.simonstrator.api.component.HostComponent; import de.tudarmstadt.maki.simonstrator.api.component.HostComponent;
......
...@@ -31,7 +31,7 @@ import java.util.Vector; ...@@ -31,7 +31,7 @@ import java.util.Vector;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
import de.tud.kom.p2psim.impl.simengine.Simulator; import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
public class BonnMotionPositionDistribution extends PositionDistribution { public class BonnMotionPositionDistribution extends PositionDistribution {
......
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