Commit 288e94c4 authored by Björn Richerzhagen's avatar Björn Richerzhagen
Browse files

MovementModel and Location updates

- deprecated MovementSupported
- used LocationSensor and LocationActuator
- decoupled nested listener structures used within the old models
parent 0001f6eb
/*
* 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.local;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy;
import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.util.Either;
public abstract class AbstractLocalMovementStrategy implements
LocalMovementStrategy {
protected WaypointModel waypointModel;
protected ObstacleModel obstacleModel;
private double scaleFactor = 1;
public double getMovementSpeed(MovementSupported ms) {
/*
* FIXME BR: why exactly is only the maxSpeed considered here?
*/
return ms.getMovementSpeed() * scaleFactor;
}
public void setScaleFactor(double scaleFactor) {
this.scaleFactor = scaleFactor;
}
@Override
public void setWaypointModel(WaypointModel model) {
this.waypointModel = model;
}
@Override
public void setObstacleModel(ObstacleModel model) {
this.obstacleModel = model;
}
@Override
public abstract Either<PositionVector, Boolean> nextPosition(
MovementSupported comp, PositionVector destination);
}
/*
* 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.local;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy;
import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.util.Either;
public abstract class AbstractLocalMovementStrategy implements
LocalMovementStrategy {
protected WaypointModel waypointModel;
protected ObstacleModel obstacleModel;
private double scaleFactor = 1;
public double getMovementSpeed(SimLocationActuator ms) {
/*
* FIXME BR: why exactly is only the maxSpeed considered here?
*/
return ms.getMovementSpeed() * scaleFactor;
}
public void setScaleFactor(double scaleFactor) {
this.scaleFactor = scaleFactor;
}
@Override
public void setWaypointModel(WaypointModel model) {
this.waypointModel = model;
}
@Override
public void setObstacleModel(ObstacleModel model) {
this.obstacleModel = model;
}
@Override
public abstract Either<PositionVector, Boolean> nextPosition(
SimLocationActuator comp, PositionVector destination);
}
......@@ -20,7 +20,7 @@
package de.tud.kom.p2psim.impl.topology.movement.local;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.util.Either;
import de.tud.kom.p2psim.impl.util.Left;
......@@ -34,7 +34,7 @@ import de.tud.kom.p2psim.impl.util.Left;
*/
public class LinearMovement extends AbstractLocalMovementStrategy {
public Either<PositionVector, Boolean> nextPosition(MovementSupported comp,
public Either<PositionVector, Boolean> nextPosition(SimLocationActuator comp,
PositionVector destination) {
PositionVector newPosition;
if (destination
......
......@@ -36,7 +36,7 @@ import com.graphhopper.util.shapes.GHPoint;
import com.graphhopper.util.shapes.GHPoint3D;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
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.GPSCalculation;
import de.tud.kom.p2psim.impl.util.Either;
......@@ -73,7 +73,7 @@ public class OnlineMapQuestMovement extends AbstractLocalMovementStrategy {
lonRight = GPSCalculation.getLonRight();
}
public Either<PositionVector, Boolean> nextPosition(MovementSupported comp,
public Either<PositionVector, Boolean> nextPosition(SimLocationActuator comp,
PositionVector destination) {
PositionVector newPosition = null;
......
......@@ -32,7 +32,7 @@ import com.graphhopper.util.shapes.GHPoint;
import com.graphhopper.util.shapes.GHPoint3D;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
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.GPSCalculation;
import de.tud.kom.p2psim.impl.util.Either;
......@@ -51,7 +51,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
private GraphHopper hopper;
private boolean init = false;
private static HashMap<MovementSupported, RealWorldMovementPoints> movementPoints = new HashMap<>();
private static HashMap<SimLocationActuator, RealWorldMovementPoints> movementPoints = new HashMap<>();
private String osmFileLocation; //use pbf-format, because osm-format causes problems (xml-problems)
private String graphFolderFiles;
......@@ -87,7 +87,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
init = true;
}
public Either<PositionVector, Boolean> nextPosition(MovementSupported comp,
public Either<PositionVector, Boolean> nextPosition(SimLocationActuator comp,
PositionVector destination) {
if(!init) init();
PositionVector newPosition = null;
......
/*
* 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.local;
import java.util.List;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint;
public class ShortestPathOffRoadWaypointMovement extends ShortestPathWaypointMovement {
@Override
protected void calculateNextMovementPath(MovementSupported comp, PositionVector finalDestination) {
super.calculateNextMovementPath(comp, finalDestination);
List<Waypoint> waypointList = dstPaths.get(comp);
waypointList.add(new WeakWaypoint(finalDestination));
}
}
/*
* 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.local;
import java.util.List;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.WeakWaypoint;
public class ShortestPathOffRoadWaypointMovement extends ShortestPathWaypointMovement {
@Override
protected void calculateNextMovementPath(SimLocationActuator comp, PositionVector finalDestination) {
super.calculateNextMovementPath(comp, finalDestination);
List<Waypoint> waypointList = dstPaths.get(comp);
waypointList.add(new WeakWaypoint(finalDestination));
}
}
......@@ -24,7 +24,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.WeakHashMap;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Path;
import de.tud.kom.p2psim.impl.topology.waypoints.graph.Waypoint;
......@@ -43,20 +43,20 @@ import de.tud.kom.p2psim.impl.util.Right;
public class ShortestPathWaypointMovement extends AbstractLocalMovementStrategy {
// Contains the shortest path and the currently used path
protected final WeakHashMap<MovementSupported, Integer> currentPath = new WeakHashMap<MovementSupported, Integer>();
protected final WeakHashMap<SimLocationActuator, Integer> currentPath = new WeakHashMap<SimLocationActuator, Integer>();
protected final WeakHashMap<MovementSupported, List<Waypoint>> dstPaths = new WeakHashMap<MovementSupported, List<Waypoint>>();
protected final WeakHashMap<SimLocationActuator, List<Waypoint>> dstPaths = new WeakHashMap<SimLocationActuator, List<Waypoint>>();
// Used to check if the destination was altered by the waypoint movement
// model
protected WeakHashMap<MovementSupported, PositionVector> currentDestination = new WeakHashMap<MovementSupported, PositionVector>();
protected WeakHashMap<SimLocationActuator, PositionVector> currentDestination = new WeakHashMap<SimLocationActuator, PositionVector>();
/**
* Calculates the next position of the given movement supported component by
* using the shortest path to the waypoint closest to the destination.
*/
@Override
public Either<PositionVector, Boolean> nextPosition(MovementSupported comp,
public Either<PositionVector, Boolean> nextPosition(SimLocationActuator comp,
PositionVector destination) {
if (currentDestination.get(comp) == null
......@@ -106,7 +106,7 @@ public class ShortestPathWaypointMovement extends AbstractLocalMovementStrategy
* @param comp
* @param finalDestination
*/
protected void calculateNextMovementPath(MovementSupported comp,
protected void calculateNextMovementPath(SimLocationActuator comp,
PositionVector finalDestination) {
// Required for shortest path calculation
Waypoint closestWaypointToCurrentPosition = waypointModel
......
......@@ -31,9 +31,8 @@ import java.util.Vector;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementListener;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
......@@ -104,11 +103,11 @@ public class ModularMovementModel implements MovementModel, EventHandler {
protected LocalMovementStrategy localMovementStrategy;
private Set<MovementListener> movementListeners = new LinkedHashSet<MovementListener>();
private Set<SimLocationActuator> movementListeners = new LinkedHashSet<SimLocationActuator>();
private Set<MovementSupported> moveableHosts = new LinkedHashSet<MovementSupported>();
private Set<SimLocationActuator> moveableHosts = new LinkedHashSet<SimLocationActuator>();
private Map<MovementSupported, PositionVector> offsetPosition = new LinkedHashMap<MovementSupported, PositionVector>();
private Map<SimLocationActuator, PositionVector> offsetPosition = new LinkedHashMap<SimLocationActuator, PositionVector>();
private boolean initialized = false;
......@@ -164,7 +163,7 @@ public class ModularMovementModel implements MovementModel, EventHandler {
}
transition.setAttractionPoints(attractionPoints);
for (MovementSupported ms : moveableHosts) {
for (SimLocationActuator ms : moveableHosts) {
transition.addComponent(ms);
}
......@@ -203,21 +202,11 @@ public class ModularMovementModel implements MovementModel, EventHandler {
}
@Override
public void addComponent(MovementSupported comp) {
public void addComponent(SimLocationActuator comp) {
moveableHosts.add(comp);
offsetPosition.put(comp, randomOffsetVector());
}
@Override
public void addMovementListener(MovementListener listener) {
movementListeners.add(listener);
}
@Override
public void removeMovementListener(MovementListener listener) {
movementListeners.add(listener);
}
@Override
public void setTimeBetweenMoveOperations(long time) {
if (time > 0) {
......@@ -236,11 +225,11 @@ public class ModularMovementModel implements MovementModel, EventHandler {
}
protected void move() {
Map<MovementSupported, AttractionPoint> assigns = transition
Map<SimLocationActuator, AttractionPoint> assigns = transition
.getAssignments();
for (Entry<MovementSupported, AttractionPoint> entry : assigns
for (Entry<SimLocationActuator, AttractionPoint> entry : assigns
.entrySet()) {
MovementSupported ms = entry.getKey();
SimLocationActuator ms = entry.getKey();
PositionVector attractionCenter = entry.getValue()
.getRealPosition();
PositionVector destination = new PositionVector(attractionCenter);
......@@ -263,22 +252,14 @@ public class ModularMovementModel implements MovementModel, EventHandler {
* @param ms
* @param destination
*/
private void doLocalMovement(MovementSupported ms,
private void doLocalMovement(SimLocationActuator ms,
PositionVector destination) {
Either<PositionVector, Boolean> either = localMovementStrategy
.nextPosition(ms, destination);
if (either.hasLeft()) {
ms.getRealPosition().replace(either.getLeft());
notifyPositionChange(ms);
}
}
protected void notifyPositionChange(MovementSupported comp) {
for (MovementListener listener : movementListeners) {
listener.afterComponentMoved(comp);
ms.updateCurrentLocation(either.getLeft().getLongitude(), either.getLeft().getLatitude());
}
comp.positionChanged();
}
public void setMovementModel(MovementModel mm) {
......
......@@ -23,21 +23,24 @@ package de.tud.kom.p2psim.impl.topology.movement.modular.attraction;
import java.util.Random;
import de.tud.kom.p2psim.api.topology.movement.MovementListener;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.PositionListener;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tud.kom.p2psim.impl.util.NotSupportedException;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationActuator;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationListener;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.LocationRequest;
/**
* This is the implementation of a AttractionPoint, which implements the
* {@link MovementSupported} interface. So a {@link AttractionPoint} has the
* {@link LocationActuator} interface. So a {@link AttractionPoint} has the
* ability to be moved.
*
* @author Christoph Muenker
* @version 1.0, 02.07.2013
*/
public class AttractionPoint implements MovementSupported {
public class AttractionPoint implements SimLocationActuator {
protected static Random rnd = Randoms.getRandom(AttractionPoint.class);
private PositionVector posVec;
......@@ -57,65 +60,76 @@ public class AttractionPoint implements MovementSupported {
}
@Override
public PositionVector getRealPosition() {
return posVec;
public double getMinMovementSpeed() {
return minSpeed;
}
@Override
public void positionChanged() {
// needed?
public double getMaxMovementSpeed() {
return maxSpeed;
}
@Override
public void addPositionListener(PositionListener listener) {
throw new NotSupportedException();
public void setMovementSpeed(double speed) {
this.currentSpeed = speed;
}
@Override
public void removePositionListener(PositionListener listener) {
throw new NotSupportedException();
public double getMovementSpeed() {
if (currentSpeed == -1) {
double min_speed = getMinMovementSpeed();
double max_speed = getMaxMovementSpeed();
double value = rnd.nextDouble();
this.currentSpeed = (value * (max_speed - min_speed)) + min_speed;
}
return currentSpeed;
}
@Override
public void addMovementListener(MovementListener listener) {
throw new NotSupportedException();
public Location getLastLocation() {
return posVec;
}
@Override
public void removeMovementListener(MovementListener listener) {
throw new NotSupportedException();
public void requestLocationUpdates(LocationRequest request,
LocationListener listener) {
throw new UnsupportedOperationException();
}
@Override
public boolean movementActive() {
return true;
public void removeLocationUpdates(LocationListener listener) {
throw new UnsupportedOperationException();
}
@Override
public double getMinMovementSpeed() {
return minSpeed;
public LocationRequest getLocationRequest() {
throw new UnsupportedOperationException();
}
@Override
public double getMaxMovementSpeed() {
return maxSpeed;
public void initialize() {
throw new UnsupportedOperationException();
}
@Override
public void setMovementSpeed(double speed) {
this.currentSpeed = speed;
public void shutdown() {
throw new UnsupportedOperationException();
}
@Override
public double getMovementSpeed() {
if (currentSpeed == -1) {
double min_speed = getMinMovementSpeed();
double max_speed = getMaxMovementSpeed();
public Host getHost() {
throw new UnsupportedOperationException();
}
double value = rnd.nextDouble();
this.currentSpeed = (value * (max_speed - min_speed)) + min_speed;
}
return currentSpeed;
@Override
public void updateCurrentLocation(double longitude, double latitude) {
posVec.setEntries(longitude, latitude);
}
@Override
public PositionVector getRealPosition() {
return posVec;
}
}
......@@ -26,39 +26,36 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Vector;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.common.SimHostComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.impl.simengine.Simulator;
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.CsvMovement;
import de.tud.kom.p2psim.impl.topology.movement.modular.ModularMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modular.attraction.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
/**
* A {@link TransitionStrategy} for a case in which nodes (
* {@link MovementSupported}) are affiliated to an {@link AttractionPoint} only
* in the beginning. No further transition will take place.
* A {@link TransitionStrategy} for a case in which nodes are affiliated to an
* {@link AttractionPoint} only in the beginning. No further transition will
* take place.
*
* @author Nils Richerzhagen
* @version 1.0, 04.08.2014
*/
public class FixedAssignmentStrategy implements TransitionStrategy {
private Random rnd;
private List<MovementSupported> comps = new LinkedList<MovementSupported>();
private List<SimLocationActuator> comps = new LinkedList<SimLocationActuator>();
private List<AttractionPoint> aPoints = new LinkedList<AttractionPoint>();
private Map<MovementSupported, AttractionPoint> assignments = new LinkedHashMap<MovementSupported, AttractionPoint>();
private Map<SimLocationActuator, AttractionPoint> assignments = new LinkedHashMap<SimLocationActuator, AttractionPoint>();
private Map<MovementSupported, SimHost> mappingMSHost = new LinkedHashMap<MovementSupported, SimHost>();
private Map<SimLocationActuator, SimHost> mappingMSHost = new LinkedHashMap<SimLocationActuator, SimHost>();
private Map<SimHost, MovementSupported> mappingHostMS = new LinkedHashMap<SimHost, MovementSupported>();
private Map<SimHost, SimLocationActuator> mappingHostMS = new LinkedHashMap<SimHost, SimLocationActuator>();
private Map<String, AttractionPoint> mappingGroupIdAP = new LinkedHashMap<String, AttractionPoint>();
......@@ -67,10 +64,10 @@ public class FixedAssignmentStrategy implements TransitionStrategy {
public FixedAssignmentStrategy() {
rnd = Randoms.getRandom(FixedAssignmentStrategy.class);
}
@Override
public Map<MovementSupported, AttractionPoint> getAssignments() {
return new HashMap<MovementSupported, AttractionPoint>(assignments);
public Map<SimLocationActuator, AttractionPoint> getAssignments() {
return new HashMap<SimLocationActuator, AttractionPoint>(assignments);
}
@Override
......@@ -79,10 +76,10 @@ public class FixedAssignmentStrategy implements TransitionStrategy {
}
@Override
public void addComponent(MovementSupported ms) {
public void addComponent(SimLocationActuator ms) {
comps.add(ms);
mappingHost(ms);
mappingHost(ms);
// No assignments been done before.
if (assignments.isEmpty()) {
AttractionPoint aPoint = aPoints.iterator().next();
......@@ -91,8 +88,8 @@ public class FixedAssignmentStrategy implements TransitionStrategy {
setStartPosition(ms, aPoint.getRealPosition());
}
// GroupId is not mapped.
else if (!mappingGroupIdAP.containsKey(mappingMSHost.get(ms)
.getProperties().getGroupID())) {
else if (!mappingGroupIdAP.containsKey(
mappingMSHost.get(ms).getProperties().getGroupID())) {
for (AttractionPoint actAP : aPoints) {
if (!mappingAPGroupId.containsKey(actAP)) {
assignments.put(ms, actAP);
......@@ -103,21 +100,19 @@ public class FixedAssignmentStrategy implements TransitionStrategy {
}
}
// GroupId is already mapped.
else if (mappingGroupIdAP.containsKey(mappingMSHost.get(ms)
.getProperties().getGroupID())) {
AttractionPoint aPoint = mappingGroupIdAP.get(mappingMSHost.get(ms)
.getProperties().getGroupID());
else if (mappingGroupIdAP.containsKey(
mappingMSHost.get(ms).getProperties().getGroupID())) {
AttractionPoint aPoint = mappingGroupIdAP
.get(mappingMSHost.get(ms).getProperties().getGroupID());
assignments.put(ms, aPoint);
setStartPosition(ms, aPoint.getRealPosition());
} else {
throw new Error("Should not happen.");
}
}
private void mappingHost(MovementSupported ms) {
private void mappingHost(SimLocationActuator ms) {
SimHostComponent comp = (SimHostComponent) ms;
SimHost host = comp.getHost();
......@@ -127,30 +122,30 @@ public class FixedAssignmentStrategy implements TransitionStrategy {
mappingMSHost.put(ms, host);
}
private void mappingGroupId(MovementSupported ms, AttractionPoint AP) {
private void mappingGroupId(SimLocationActuator ms, AttractionPoint AP) {
SimHostComponent comp = (SimHostComponent) ms;
SimHost host = comp.getHost();
assert host != null;
mappingAPGroupId.put(AP, mappingMSHost.get(ms).getProperties()
.getGroupID());
mappingGroupIdAP.put(
mappingMSHost.get(ms).getProperties().getGroupID(), AP);
mappingAPGroupId.put(AP,
mappingMSHost.get(ms).getProperties().getGroupID());
mappingGroupIdAP.put(mappingMSHost.get(ms).getProperties().getGroupID(),
AP);
}
private void setStartPosition(MovementSupported ms,
private void setStartPosition(SimLocationActuator ms,
PositionVector aPointReferencePosition) {
double minJitter = 50.0;
double maxJitter = 100.0;
PositionVector nodePosition = ms.getRealPosition();
nodePosition.replace(aPointReferencePosition);
double xJitter = (rnd.nextDouble() * (maxJitter - minJitter)) + minJitter;
double yJitter = (rnd.nextDouble() * (maxJitter - minJitter)) + minJitter;
double xJitter = (rnd.nextDouble() * (maxJitter - minJitter))
+ minJitter;
double yJitter = (rnd.nextDouble() * (maxJitter - minJitter))
+ minJitter;
PositionVector jitterVector = new PositionVector(xJitter, yJitter);
nodePosition.add(jitterVector);
ms.positionChanged();
PositionVector newPos = aPointReferencePosition.plus(jitterVector);
ms.updateCurrentLocation(newPos.getLongitude(), newPos.getLatitude());
}
/**
......
......@@ -38,6 +38,7 @@ import de.tud.kom.p2psim.api.common.SimHostComponent;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.social.SocialView;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
......@@ -85,17 +86,17 @@ public class SocialTransitionStrategy implements TransitionStrategy,
private SocialView socialView;
private List<MovementSupported> comps = new Vector<MovementSupported>();
private List<SimLocationActuator> comps = new Vector<SimLocationActuator>();
private List<AttractionPoint> aPoints = new Vector<AttractionPoint>();
private Map<MovementSupported, AttractionPoint> assignments = new HashMap<MovementSupported, AttractionPoint>();
private Map<SimLocationActuator, AttractionPoint> assignments = new HashMap<SimLocationActuator, AttractionPoint>();
private Map<MovementSupported, Set<AttractionPoint>> favoritePlaces = new HashMap<MovementSupported, Set<AttractionPoint>>();
private Map<SimLocationActuator, Set<AttractionPoint>> favoritePlaces = new HashMap<SimLocationActuator, Set<AttractionPoint>>();
private Map<MovementSupported, SimHost> mapMsHost = new HashMap<MovementSupported, SimHost>();
private Map<SimLocationActuator, SimHost> mapMsHost = new HashMap<SimLocationActuator, SimHost>();
private Map<SimHost, MovementSupported> mapHostMs = new HashMap<SimHost, MovementSupported>();
private Map<SimHost, SimLocationActuator> mapHostMs = new HashMap<SimHost, SimLocationActuator>();
private double minPauseTime = Simulator.MINUTE_UNIT * 0.5;
......@@ -146,8 +147,8 @@ public class SocialTransitionStrategy implements TransitionStrategy,
}
@Override
public Map<MovementSupported, AttractionPoint> getAssignments() {
return new HashMap<MovementSupported, AttractionPoint>(assignments);
public Map<SimLocationActuator, AttractionPoint> getAssignments() {
return new HashMap<SimLocationActuator, AttractionPoint>(assignments);
}
@Override
......@@ -157,7 +158,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
}
@Override
public void addComponent(MovementSupported ms) {
public void addComponent(SimLocationActuator ms) {
comps.add(ms);
mappingHost(ms);
// assign the ms to an attractionPoint, which is near to the ms
......@@ -179,7 +180,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
doTransition(ms);
}
public void doTransition(MovementSupported ms) {
public void doTransition(SimLocationActuator ms) {
List<AttractionPoint> apFavorites = getFavoritePlaces(ms);
List<AttractionPoint> apFriends = getFriendsPlaces(ms);
List<AttractionPoint> apClusters = getClusterPlaces(ms);
......@@ -201,7 +202,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
Event.scheduleWithDelay(getPauseTime(), this, ms, 0);
}
private AttractionPoint findHighestScore(MovementSupported ms,
private AttractionPoint findHighestScore(SimLocationActuator ms,
List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends,
List<AttractionPoint> apClusters, List<AttractionPoint> apRandom) {
Set<AttractionPoint> aps = new HashSet<AttractionPoint>();
......@@ -242,11 +243,10 @@ public class SocialTransitionStrategy implements TransitionStrategy,
* @param apRandom
* @return
*/
private double score(MovementSupported ms, AttractionPoint ap,
private double score(SimLocationActuator ms, AttractionPoint ap,
List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends,
List<AttractionPoint> apClusters, List<AttractionPoint> apRandom) {
double distance = ms.getRealPosition()
.distanceTo(ap.getRealPosition());
double distance = ms.getRealPosition().distanceTo(ap.getRealPosition());
double distanceScore = 1 - (distance / worldDimension.getLength());
double clusterScore = 0;
......@@ -292,7 +292,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
private int assignedToAp(AttractionPoint ap) {
int i = 1;
for (Entry<MovementSupported, AttractionPoint> entry : assignments
for (Entry<SimLocationActuator, AttractionPoint> entry : assignments
.entrySet()) {
if (entry.getValue().equals(ap)) {
i++;
......@@ -301,7 +301,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
return i;
}
private List<AttractionPoint> getRandomPlaces(MovementSupported ms,
private List<AttractionPoint> getRandomPlaces(SimLocationActuator ms,
int number) {
Collections.shuffle(aPoints);
List<AttractionPoint> result = new Vector<AttractionPoint>();
......@@ -313,12 +313,12 @@ public class SocialTransitionStrategy implements TransitionStrategy,
return result;
}
private List<AttractionPoint> getClusterPlaces(MovementSupported ms) {
private List<AttractionPoint> getClusterPlaces(SimLocationActuator ms) {
List<AttractionPoint> result = new Vector<AttractionPoint>();
SimHost msHost = mapMsHost.get(ms);
for (SimHost host : socialView.getCluster(msHost)) {
MovementSupported temp = mapHostMs.get(host);
SimLocationActuator temp = mapHostMs.get(host);
if (assignments.get(temp) != null) {
result.add(assignments.get(temp));
}
......@@ -327,12 +327,12 @@ public class SocialTransitionStrategy implements TransitionStrategy,
return result;
}
private List<AttractionPoint> getFriendsPlaces(MovementSupported ms) {
private List<AttractionPoint> getFriendsPlaces(SimLocationActuator ms) {
List<AttractionPoint> result = new Vector<AttractionPoint>();
SimHost msHost = mapMsHost.get(ms);
for (SimHost host : socialView.getNeighbors(msHost)) {
MovementSupported temp = mapHostMs.get(host);
SimLocationActuator temp = mapHostMs.get(host);
if (assignments.get(temp) != null) {
result.add(assignments.get(temp));
}
......@@ -341,16 +341,16 @@ public class SocialTransitionStrategy implements TransitionStrategy,
return result;
}
private List<AttractionPoint> getFavoritePlaces(MovementSupported ms) {
private List<AttractionPoint> getFavoritePlaces(SimLocationActuator ms) {
return new Vector<AttractionPoint>(favoritePlaces.get(ms));
}
private AttractionPoint getRandomPlace(MovementSupported ms) {
private AttractionPoint getRandomPlace(SimLocationActuator ms) {
Collections.shuffle(aPoints);
return aPoints.iterator().next();
}
private AttractionPoint getNearestPlace(MovementSupported ms,
private AttractionPoint getNearestPlace(SimLocationActuator ms,
List<AttractionPoint> aps) {
if (aps.isEmpty()) {
return null;
......@@ -368,7 +368,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
return nearest;
}
private AttractionPoint getNearestFavoritePlace(MovementSupported ms) {
private AttractionPoint getNearestFavoritePlace(SimLocationActuator ms) {
Set<AttractionPoint> fps = favoritePlaces.get(ms);
AttractionPoint nearest = fps.iterator().next();
......@@ -383,7 +383,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
return nearest;
}
private void assignFavoritePlaces(MovementSupported ms) {
private void assignFavoritePlaces(SimLocationActuator ms) {
Set<AttractionPoint> msFavoritePlaces = new HashSet<AttractionPoint>();
LinkedList<AttractionPoint> temp = new LinkedList<AttractionPoint>(
aPoints);
......@@ -396,7 +396,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
favoritePlaces.put(ms, msFavoritePlaces);
}
private void mappingHost(MovementSupported ms) {
private void mappingHost(SimLocationActuator ms) {
SimHostComponent comp = (SimHostComponent) ms;
SimHost host = comp.getHost();
......@@ -428,7 +428,7 @@ public class SocialTransitionStrategy implements TransitionStrategy,
@Override
public void eventOccurred(Object se, int type) {
doTransition((MovementSupported) se);
doTransition((SimLocationActuator) se);
}
public void setSocialFactor(double socialFactor) {
......
......@@ -23,18 +23,18 @@ package de.tud.kom.p2psim.impl.topology.movement.modular.transition;
import java.util.List;
import java.util.Map;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modular.ModularMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modular.attraction.AttractionPoint;
/**
* This is the interface for the Transition Strategy.<br>
* It derives automatically the assignments of the added
* {@link MovementSupported} to the {@link AttractionPoint}s. This mean, that
* {@link SimLocationActuator} to the {@link AttractionPoint}s. This mean, that
* the implementation must handle the new assignments after a certain time. The
* {@link ModularMovementModel}, will be only call the {@link #getAssignments()}
* in every MovementStep, to calculate the movement of the
* {@link MovementSupported} Objects, in respect to the Assignment.
* {@link SimLocationActuator} Objects, in respect to the Assignment.
*
* @author Christoph Muenker
* @version 1.0, 25.06.2013
......@@ -46,7 +46,7 @@ public interface TransitionStrategy {
*
* @return
*/
public Map<MovementSupported, AttractionPoint> getAssignments();
public Map<SimLocationActuator, AttractionPoint> getAssignments();
/**
* Should be called first, to add the Attraction Points for the assignment!
......@@ -56,11 +56,11 @@ public interface TransitionStrategy {
public void setAttractionPoints(List<AttractionPoint> attractionPoints);
/**
* Add the {@link MovementSupported} object and assign the MS to an
* Add the {@link SimLocationActuator} object and assign the MS to an
* {@link AttractionPoint}.
*
* @param ms
*/
public void addComponent(MovementSupported ms);
public void addComponent(SimLocationActuator ms);
}
......@@ -33,9 +33,8 @@ import javax.swing.JComponent;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementListener;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.movement.local.LocalMovementStrategy;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
......@@ -102,11 +101,9 @@ public class ModularMovementModel implements MovementModel, EventHandler {
protected IMapVisualization mapVisualization;
private Set<MovementListener> movementListeners = new LinkedHashSet<MovementListener>();
private Set<SimLocationActuator> moveableHosts = new LinkedHashSet<SimLocationActuator>();
private Set<MovementSupported> moveableHosts = new LinkedHashSet<MovementSupported>();
private Map<MovementSupported, PositionVector> offsetPosition = new LinkedHashMap<MovementSupported, PositionVector>();
private Map<SimLocationActuator, PositionVector> offsetPosition = new LinkedHashMap<SimLocationActuator, PositionVector>();
private boolean initialized = false;
......@@ -148,7 +145,7 @@ public class ModularMovementModel implements MovementModel, EventHandler {
transition.setAttractionPoints(attractionPoints);
//This adds the mobile hosts (smartphones/users) to the transition strategy
for (MovementSupported ms : moveableHosts) {
for (SimLocationActuator ms : moveableHosts) {
transition.addComponent(ms);
}
......@@ -177,21 +174,11 @@ public class ModularMovementModel implements MovementModel, EventHandler {
}
@Override
public void addComponent(MovementSupported comp) {
public void addComponent(SimLocationActuator comp) {
moveableHosts.add(comp);
offsetPosition.put(comp, randomOffsetVector());
}
@Override
public void addMovementListener(MovementListener listener) {
movementListeners.add(listener);
}
@Override
public void removeMovementListener(MovementListener listener) {
movementListeners.add(listener);
}
@Override
public void setTimeBetweenMoveOperations(long time) {
if (time > 0) {
......@@ -210,11 +197,11 @@ public class ModularMovementModel implements MovementModel, EventHandler {
}
protected void move() {
Map<MovementSupported, AttractionPoint> assigns = transition
Map<SimLocationActuator, AttractionPoint> assigns = transition
.getAssignments();
for (Entry<MovementSupported, AttractionPoint> entry : assigns
for (Entry<SimLocationActuator, AttractionPoint> entry : assigns
.entrySet()) {
MovementSupported ms = entry.getKey();
SimLocationActuator ms = entry.getKey();
PositionVector attractionCenter = entry.getValue()
.getRealPosition();
PositionVector destination = new PositionVector(attractionCenter);
......@@ -237,31 +224,23 @@ public class ModularMovementModel implements MovementModel, EventHandler {
* @param ms
* @param destination
*/
private void doLocalMovement(MovementSupported ms,
private void doLocalMovement(SimLocationActuator ms,
PositionVector destination) {
Either<PositionVector, Boolean> either = localMovementStrategy
.nextPosition(ms, destination);
if (either.hasLeft()) {
ms.getRealPosition().replace(either.getLeft());
ms.updateCurrentLocation(either.getLeft().getLongitude(), either.getLeft().getLatitude());
/*
* Check for negative or out of bound coordinates!
*/
assert ms.getRealPosition().getX() >= 0.0 && ms.getRealPosition().getX() <= Binder.getComponentOrNull(Topology.class).getWorldDimensions().getX();
assert ms.getRealPosition().getY() >= 0.0 && ms.getRealPosition().getY() <= Binder.getComponentOrNull(Topology.class).getWorldDimensions().getY();
notifyPositionChange(ms);
} else {
transition.reachedAttractionPoint(ms);
}
}
protected void notifyPositionChange(MovementSupported comp) {
for (MovementListener listener : movementListeners) {
listener.afterComponentMoved(comp);
}
comp.positionChanged();
}
public void setIAttractionGenerator(IAttractionGenerator attractionGenerator) {
this.attractionGenerator = attractionGenerator;
}
......
......@@ -25,15 +25,16 @@ import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.common.SimHostComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modular.transition.TransitionStrategy;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPoint;
/**
* A {@link TransitionStrategy} for a case in which nodes (
* {@link MovementSupported}) are affiliated to an {@link AttractionPoint} only
* A {@link TransitionStrategy} for a case in which nodes are affiliated to an {@link AttractionPoint} only
* in the beginning. No further transition will take place.
*
* @author Martin Hellwig
......@@ -41,23 +42,23 @@ import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.Attraction
*/
public class FixedAssignmentStrategy implements ITransitionStrategy {
private List<MovementSupported> comps = new LinkedList<MovementSupported>();
private List<SimLocationActuator> comps = new LinkedList<SimLocationActuator>();
private List<AttractionPoint> aPoints = new LinkedList<AttractionPoint>();
private Map<MovementSupported, AttractionPoint> assignments = new LinkedHashMap<MovementSupported, AttractionPoint>();
private Map<SimLocationActuator, AttractionPoint> assignments = new LinkedHashMap<SimLocationActuator, AttractionPoint>();
private Map<MovementSupported, SimHost> mappingMSHost = new LinkedHashMap<MovementSupported, SimHost>();
private Map<SimLocationActuator, SimHost> mappingMSHost = new LinkedHashMap<SimLocationActuator, SimHost>();
private Map<SimHost, MovementSupported> mappingHostMS = new LinkedHashMap<SimHost, MovementSupported>();
private Map<SimHost, SimLocationActuator> mappingHostMS = new LinkedHashMap<SimHost, SimLocationActuator>();
private Map<String, AttractionPoint> mappingGroupIdAP = new LinkedHashMap<String, AttractionPoint>();
private Map<AttractionPoint, String> mappingAPGroupId = new LinkedHashMap<AttractionPoint, String>();
@Override
public Map<MovementSupported, AttractionPoint> getAssignments() {
return new HashMap<MovementSupported, AttractionPoint>(assignments);
public Map<SimLocationActuator, AttractionPoint> getAssignments() {
return new HashMap<SimLocationActuator, AttractionPoint>(assignments);
}
@Override
......@@ -66,7 +67,7 @@ public class FixedAssignmentStrategy implements ITransitionStrategy {
}
@Override
public void addComponent(MovementSupported ms) {
public void addComponent(SimLocationActuator ms) {
comps.add(ms);
mappingHost(ms);
......@@ -102,11 +103,11 @@ public class FixedAssignmentStrategy implements ITransitionStrategy {
}
@Override
public void reachedAttractionPoint(MovementSupported ms) {
public void reachedAttractionPoint(SimLocationActuator ms) {
// don't care, as no further assignment takes place.
}
private void mappingHost(MovementSupported ms) {
private void mappingHost(SimLocationActuator ms) {
SimHostComponent comp = (SimHostComponent) ms;
SimHost host = comp.getHost();
......@@ -116,7 +117,7 @@ public class FixedAssignmentStrategy implements ITransitionStrategy {
mappingMSHost.put(ms, host);
}
private void mappingGroupId(MovementSupported ms, AttractionPoint AP) {
private void mappingGroupId(SimLocationActuator ms, AttractionPoint AP) {
SimHostComponent comp = (SimHostComponent) ms;
SimHost host = comp.getHost();
......
......@@ -23,7 +23,7 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition;
import java.util.List;
import java.util.Map;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPoint;
/**
......@@ -39,7 +39,7 @@ public interface ITransitionStrategy {
*
* @return
*/
public Map<MovementSupported, AttractionPoint> getAssignments();
public Map<SimLocationActuator, AttractionPoint> getAssignments();
/**
* Should be called first, to add the Attraction Points for the assignment!
......@@ -49,17 +49,17 @@ public interface ITransitionStrategy {
public void setAttractionPoints(List<AttractionPoint> attractionPoints);
/**
* Add the {@link MovementSupported} object and assign the MS to an
* Add the object and assign the MS to an
* {@link AttractionPoint}.
*
* @param ms
*/
public void addComponent(MovementSupported ms);
public void addComponent(SimLocationActuator ms);
/**
* Notify the TransitionStrategy, that the component has reached an attraction point.
* @param ms
*/
public void reachedAttractionPoint(MovementSupported ms);
public void reachedAttractionPoint(SimLocationActuator ms);
}
......@@ -38,7 +38,7 @@ import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.common.SimHostComponent;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.movement.MovementSupported;
import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator;
import de.tud.kom.p2psim.api.topology.social.SocialView;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.PositionVector;
......@@ -52,7 +52,7 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
/**
* 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
* to assignment the given {@link MovementSupported} objects to the given
* to assignment the given objects to the given
* {@link AttractionPoint}s. For the {@link SocialView}, it is required a
* {@link #socialId}, to find the right {@link SocialView}.
*
......@@ -66,7 +66,7 @@ import de.tudarmstadt.maki.simonstrator.api.Randoms;
* {@link AttractionPoint}. For that, it will be used only the AttractionPoints,
* 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
* in {@link #score(MovementSupported, AttractionPoint, List, List, List, List)}
* in score.
* .
*
* <br>
......@@ -87,19 +87,19 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
private SocialView socialView;
private List<MovementSupported> comps = new Vector<MovementSupported>();
private List<SimLocationActuator> comps = new Vector<SimLocationActuator>();
private List<AttractionPoint> aPoints = new Vector<AttractionPoint>();
private Map<MovementSupported, AttractionPoint> assignments = new HashMap<MovementSupported, AttractionPoint>();
private Map<SimLocationActuator, AttractionPoint> assignments = new HashMap<SimLocationActuator, AttractionPoint>();
private Set<MovementSupported> arrivedAtAttractionPoint = new LinkedHashSet<>();
private Set<SimLocationActuator> arrivedAtAttractionPoint = new LinkedHashSet<>();
private Map<MovementSupported, Set<AttractionPoint>> favoritePlaces = new HashMap<MovementSupported, Set<AttractionPoint>>();
private Map<SimLocationActuator, Set<AttractionPoint>> favoritePlaces = new HashMap<SimLocationActuator, Set<AttractionPoint>>();
private Map<MovementSupported, SimHost> mapMsHost = new HashMap<MovementSupported, SimHost>();
private Map<SimLocationActuator, SimHost> mapMsHost = new HashMap<SimLocationActuator, SimHost>();
private Map<SimHost, MovementSupported> mapHostMs = new HashMap<SimHost, MovementSupported>();
private Map<SimHost, SimLocationActuator> mapHostMs = new HashMap<SimHost, SimLocationActuator>();
private double minPauseTime = Simulator.MINUTE_UNIT * 0.5;
......@@ -150,7 +150,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
}
@Override
public Map<MovementSupported, AttractionPoint> getAssignments() {
public Map<SimLocationActuator, AttractionPoint> getAssignments() {
// FIXME why new? return new HashMap<MovementSupported,
// AttractionPoint>(assignments);
return assignments;
......@@ -163,7 +163,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
}
@Override
public void addComponent(MovementSupported ms) {
public void addComponent(SimLocationActuator ms) {
comps.add(ms);
mappingHost(ms);
// assign the ms to an attractionPoint, which is near to the ms
......@@ -186,14 +186,14 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
}
@Override
public void reachedAttractionPoint(MovementSupported ms) {
public void reachedAttractionPoint(SimLocationActuator ms) {
if (!arrivedAtAttractionPoint.contains(ms)) {
Event.scheduleWithDelay(getPauseTime(), this, ms, 0);
arrivedAtAttractionPoint.add(ms);
}
}
public void doTransition(MovementSupported ms) {
public void doTransition(SimLocationActuator ms) {
List<AttractionPoint> apFavorites = getFavoritePlaces(ms);
List<AttractionPoint> apFriends = getFriendsPlaces(ms);
List<AttractionPoint> apClusters = getClusterPlaces(ms);
......@@ -214,7 +214,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
arrivedAtAttractionPoint.remove(ms);
}
private AttractionPoint findHighestScore(MovementSupported ms,
private AttractionPoint findHighestScore(SimLocationActuator ms,
List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends,
List<AttractionPoint> apClusters, List<AttractionPoint> apRandom) {
Set<AttractionPoint> aps = new HashSet<AttractionPoint>();
......@@ -238,7 +238,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
}
/**
* Score the given AttractionPoint for the given {@link MovementSupported}. <br>
* Score the given AttractionPoint for the given SimLocationActuator. <br>
* (clusterScore/#NodesInAp + friendsScore + 1/#NodesInAp) * socialFactor +
* (distanceScore + penalty) + (1-socialFactor) <br>
*
......@@ -255,7 +255,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
* @param apRandom
* @return
*/
private double score(MovementSupported ms, AttractionPoint ap,
private double score(SimLocationActuator ms, AttractionPoint ap,
List<AttractionPoint> apFavorites, List<AttractionPoint> apFriends,
List<AttractionPoint> apClusters, List<AttractionPoint> apRandom) {
double distance = ms.getRealPosition().distanceTo(ap.getRealPosition());
......@@ -304,7 +304,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
private int assignedToAp(AttractionPoint ap) {
int i = 1;
for (Entry<MovementSupported, AttractionPoint> entry : assignments
for (Entry<SimLocationActuator, AttractionPoint> entry : assignments
.entrySet()) {
if (entry.getValue().equals(ap)) {
i++;
......@@ -313,7 +313,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
return i;
}
private List<AttractionPoint> getRandomPlaces(MovementSupported ms,
private List<AttractionPoint> getRandomPlaces(SimLocationActuator ms,
int number) {
Collections.shuffle(aPoints);
List<AttractionPoint> result = new Vector<AttractionPoint>();
......@@ -325,12 +325,12 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
return result;
}
private List<AttractionPoint> getClusterPlaces(MovementSupported ms) {
private List<AttractionPoint> getClusterPlaces(SimLocationActuator ms) {
List<AttractionPoint> result = new Vector<AttractionPoint>();
SimHost msHost = mapMsHost.get(ms);
for (SimHost host : socialView.getCluster(msHost)) {
MovementSupported temp = mapHostMs.get(host);
SimLocationActuator temp = mapHostMs.get(host);
if (assignments.get(temp) != null) {
result.add(assignments.get(temp));
}
......@@ -339,12 +339,12 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
return result;
}
private List<AttractionPoint> getFriendsPlaces(MovementSupported ms) {
private List<AttractionPoint> getFriendsPlaces(SimLocationActuator ms) {
List<AttractionPoint> result = new Vector<AttractionPoint>();
SimHost msHost = mapMsHost.get(ms);
for (SimHost host : socialView.getNeighbors(msHost)) {
MovementSupported temp = mapHostMs.get(host);
SimLocationActuator temp = mapHostMs.get(host);
if (assignments.get(temp) != null) {
result.add(assignments.get(temp));
}
......@@ -353,11 +353,11 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
return result;
}
private List<AttractionPoint> getFavoritePlaces(MovementSupported ms) {
private List<AttractionPoint> getFavoritePlaces(SimLocationActuator ms) {
return new Vector<AttractionPoint>(favoritePlaces.get(ms));
}
private void assignFavoritePlaces(MovementSupported ms) {
private void assignFavoritePlaces(SimLocationActuator ms) {
Set<AttractionPoint> msFavoritePlaces = new HashSet<AttractionPoint>();
LinkedList<AttractionPoint> temp = new LinkedList<AttractionPoint>(
aPoints);
......@@ -370,7 +370,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
favoritePlaces.put(ms, msFavoritePlaces);
}
private void mappingHost(MovementSupported ms) {
private void mappingHost(SimLocationActuator ms) {
SimHostComponent comp = (SimHostComponent) ms;
SimHost host = comp.getHost();
......@@ -402,7 +402,7 @@ public class SocialTransitionStrategy implements ITransitionStrategy,
@Override
public void eventOccurred(Object se, int type) {
doTransition((MovementSupported) se);
doTransition((SimLocationActuator) se);
}
public void setSocialFactor(double socialFactor) {
......
......@@ -40,6 +40,7 @@ import de.tud.kom.p2psim.api.topology.views.DropProbabilityDeterminator;
import de.tud.kom.p2psim.api.topology.views.LatencyDeterminator;
import de.tud.kom.p2psim.api.topology.views.TopologyView;
import de.tud.kom.p2psim.impl.topology.PositionVector;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.Rate;
......@@ -320,9 +321,9 @@ public abstract class AbstractTopologyView<L extends DefaultLink> implements
}
long timeLastMovement = 0;
@Override
public void afterComponentMoved(MovementSupported comp) {
public void onLocationChanged(Host host, Location location) {
if (Time.getCurrentTime() != timeLastMovement) {
timeLastMovement = Time.getCurrentTime();
/*
......
......@@ -42,6 +42,7 @@ import de.tudarmstadt.maki.simonstrator.api.EventHandler;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.handover.HandoverSensor;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
import edu.emory.mathcs.backport.java.util.Arrays;
......@@ -243,8 +244,8 @@ public class FiveGTopologyView extends AbstractTopologyView<CellLink> {
long lastMovementTimestamp = 0;
@Override
public void afterComponentMoved(MovementSupported comp) {
super.afterComponentMoved(comp);
public void onLocationChanged(Host host, Location location) {
super.onLocationChanged(host, location);
if (lastMovementTimestamp != Time.getCurrentTime()) {
lastMovementTimestamp = Time.getCurrentTime();
checkAPAssociations();
......
......@@ -39,7 +39,9 @@ import de.tud.kom.p2psim.api.topology.obstacles.ObstacleModel;
import de.tud.kom.p2psim.api.topology.waypoints.WaypointModel;
import de.tud.kom.p2psim.impl.util.LiveMonitoring;
import de.tud.kom.p2psim.impl.util.LiveMonitoring.ProgressValue;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
/**
......@@ -216,8 +218,8 @@ public class RangedTopologyView extends AbstractTopologyView<RangedLink> {
long lastMovementTime = 0;
@Override
public void afterComponentMoved(MovementSupported comp) {
super.afterComponentMoved(comp);
public void onLocationChanged(Host host, Location location) {
super.onLocationChanged(host, location);
if (lastMovementTime != Time.getCurrentTime()) {
lastMovementTime = Time.getCurrentTime();
/*
......
......@@ -78,6 +78,7 @@ import de.tud.kom.p2psim.impl.topology.views.visualization.world.TopologyCompone
import de.tud.kom.p2psim.impl.topology.views.visualization.world.WeakWaypointComponentVis;
import de.tud.kom.p2psim.impl.util.NotSupportedException;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.common.graph.INodeID;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
......@@ -267,7 +268,7 @@ public class VisualizationTopologyView extends JFrame implements TopologyView,
long lastMove = 0;
@Override
public void afterComponentMoved(MovementSupported comp) {
public void onLocationChanged(Host host, Location location) {
if (lastMove != Time.getCurrentTime()) {
worldPanel.invalidate();
lastMove = Time.getCurrentTime();
......
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