Commit 314bc42d authored by Julian Zobel's avatar Julian Zobel
Browse files

Merge remote-tracking branch 'origin/jz/smartermovement' into jz/master

parents c0c9aa73 26bc14b8
......@@ -23,6 +23,7 @@ package de.tud.kom.p2psim.api.topology.movement;
import java.util.Set;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.impl.topology.movement.distributions.ISpeedDistributionProvider;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
/**
......@@ -97,5 +98,14 @@ public interface MovementModel {
* @param time
*/
public void setTimeBetweenMoveOperations(long time);
/**
* OPTIONAL: returns a movement speed provided by the model
*
* @return
*/
default public ISpeedDistributionProvider getMovementSpeedDistribution() {
throw new UnsupportedOperationException();
}
}
......@@ -98,8 +98,8 @@ public abstract class AbstractFilter<M extends MetricValue<?>>
}
if (incomingMetrics.isEmpty()) {
throw new AssertionError(
"No incoming metrics configured! Available metrics are: "
+ metrics.toString());
"["+this.getName()+"] No incoming metrics configured! Available metrics are: "
+ metrics.toString() );
}
onInitialize(incomingMetrics);
......
......@@ -25,12 +25,10 @@ import java.util.Set;
import de.tud.kom.p2psim.api.common.HostProperties;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.api.topology.TopologyComponent;
import de.tud.kom.p2psim.api.topology.movement.MovementModel;
import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.IAttractionPoint;
......@@ -48,7 +46,6 @@ public class DefaultTopologyComponent extends AbstractTopologyComponent {
private double currentMovementSpeed = -1;
/**
* Create a TopologyComponent for the current host.
*
......@@ -58,7 +55,7 @@ public class DefaultTopologyComponent extends AbstractTopologyComponent {
*/
public DefaultTopologyComponent(SimHost host, Topology topology,
MovementModel movementModel, PlacementModel placementModel, boolean registerAsInformationProviderInSiS) {
super(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
super(host, topology, movementModel, placementModel, registerAsInformationProviderInSiS);
}
@Override
......@@ -68,15 +65,28 @@ public class DefaultTopologyComponent extends AbstractTopologyComponent {
@Override
public double getMinMovementSpeed() {
HostProperties properties = getHost().getProperties();
return properties.getMinMovementSpeed();
try {
return movementModel.getMovementSpeedDistribution().getMinSpeed();
}
catch (UnsupportedOperationException e) {
// FIXME should not be used in the future anymore
// fallback
HostProperties properties = getHost().getProperties();
return properties.getMinMovementSpeed();
}
}
@Override
public double getMaxMovementSpeed() {
HostProperties properties = getHost().getProperties();
return properties.getMaxMovementSpeed();
public double getMaxMovementSpeed() {
try {
return movementModel.getMovementSpeedDistribution().getMaxSpeed();
}
catch (UnsupportedOperationException e) {
// FIXME should not be used in the future anymore
// fallback
HostProperties properties = getHost().getProperties();
return properties.getMaxMovementSpeed();
}
}
private void calcRandomMovementSpeed() {
......@@ -90,9 +100,18 @@ public class DefaultTopologyComponent extends AbstractTopologyComponent {
@Override
public double getMovementSpeed() {
if (currentMovementSpeed == -1) {
calcRandomMovementSpeed();
try {
if (currentMovementSpeed == -1) {
this.currentMovementSpeed = movementModel.getMovementSpeedDistribution().calculateSpeed();
}
}
catch (UnsupportedOperationException e) {
if (currentMovementSpeed == -1) {
calcRandomMovementSpeed();
}
}
return this.currentMovementSpeed;
}
......@@ -116,9 +135,10 @@ public class DefaultTopologyComponent extends AbstractTopologyComponent {
public Set<IAttractionPoint> getAllAttractionPoints() {
return movementModel.getAllAttractionPoints();
}
public static class Factory implements TopologyComponentFactory {
@Override
public TopologyComponent createTopologyComponent(SimHost host,
Topology topology, MovementModel movementModel,
......
......@@ -23,6 +23,7 @@ package de.tud.kom.p2psim.impl.topology.movement;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
......@@ -42,6 +43,7 @@ import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.Visualiza
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.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.Time;
import de.tudarmstadt.maki.simonstrator.api.component.LifecycleComponent;
......@@ -75,13 +77,17 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
private final LinkedHashMap<SimLocationActuator, LinkedList<Step>> components;
private final static LinkedHashMap<SimLocationActuator, Integer> componentToStepSize = new LinkedHashMap<SimLocationActuator, Integer>();
private final LinkedHashSet<SimLocationActuator> unusedComponents;
private LinkedList<File> tracefiles;
private boolean first = true;
public TracefileMovementModel() {
components = new LinkedHashMap<SimLocationActuator, LinkedList<Step>>();
tracefiles = new LinkedList<File>();
tracefiles = new LinkedList<File>();
unusedComponents = new LinkedHashSet<SimLocationActuator>();
}
public void initialize() {
......@@ -112,7 +118,7 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
initialized = true;
Event.scheduleWithDelay(timeBetweenMoveOperations, this, null, EVENT_MOVE);
Event.scheduleWithDelay(Time.SECOND * 10, this, null, EVENT_MOVE);
}
@Override
......@@ -127,7 +133,11 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
if(first) {
components.forEach((component, steps) -> {
shutdownComponent(component);
});
});
unusedComponents.forEach((component) -> {
shutdownComponent(component);
});
}
// as the files contain the timestamp in seconds, the current time needs to be converted in seconds
......@@ -292,7 +302,10 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
private void associateTracefile(SimLocationActuator actuator) {
if(tracefiles.isEmpty()) {
throw new UnsupportedOperationException("List of tracefiles is empty, thus cannot initiate the component!");
Monitor.log(this.getClass(), Level.WARN, "No unassociated trace file available. Skip.", actuator);
//throw new UnsupportedOperationException("List of tracefiles is empty, thus cannot initiate the component!");
unusedComponents.add(actuator);
return;
}
if(components.containsKey(actuator)) {
......@@ -364,7 +377,7 @@ public class TracefileMovementModel implements MovementModel, EventHandler {
this.attractionpointVisualization = viz;
}
public void setIAttractionGenerator(IAttractionProvider attractionGenerator) {
public void setIAttractionProvider(IAttractionProvider attractionGenerator) {
if (attractionGenerator == null) {
throw new ConfigurationException(
"AttractionGenerator is missing in ModularMovementModel!");
......
/*
* 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.distributions;
import java.util.Random;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
public class GaussianSpeedDistribution implements ISpeedDistributionProvider {
private Random random = Randoms.getRandom(GaussianSpeedDistribution.class);
private double std;
private double mean;
private double min = 0;
private double max = 10;
@Override
public double getMaxSpeed() {
return max;
}
@Override
public double getMinSpeed() {
return min;
}
@Override
public double calculateSpeed() {
double speed = random.nextGaussian() * std + mean;
Math.min(speed, max);
Math.max(speed, min);
return speed;
}
public void setStd(double std) {
this.std = std;
}
public void setMean(double mean) {
this.mean = mean;
}
public void setMin(double min) {
this.min = min;
}
public void setMax(double max) {
this.max = max;
}
}
/*
* 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.distributions;
/**
* Interface for the provision of speed distributions.
*
* @author Julian Zobel
* @version 1.0, 30.11.2020
*/
public interface ISpeedDistributionProvider {
/**
* Minimum speed provided by this distribution.
*
* @return
*/
public double getMinSpeed();
/**
* Maximum speed provided by this distribution.
*
* @return
*/
public double getMaxSpeed();
/**
* Draw a speed value from this speed distribution.
*
* @return
*/
public double calculateSpeed();
}
/*
* 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.distributions;
/**
* Static speed distribution provider, always returns 0.
*
* @author Julian Zobel
* @version 1.0, 30.11.2020
*/
public class StaticSpeedDistribution implements ISpeedDistributionProvider {
private double value = 0;
@Override
public double getMinSpeed() {
return value;
}
@Override
public double getMaxSpeed() {
return value;
}
@Override
public double calculateSpeed() {
return value;
}
public void setValue(double value) {
this.value = value;
}
}
/*
* 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.distributions;
import java.util.Random;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
public class UniformSpeedDistribution implements ISpeedDistributionProvider {
private Random random = Randoms.getRandom(UniformSpeedDistribution.class);
private double min;
private double max;
private boolean includeUpperBound = false;
@Override
public double getMinSpeed() {
return min;
}
@Override
public double getMaxSpeed() {
return max;
}
@Override
public double calculateSpeed() {
return min + random.nextDouble() * (max - min + (includeUpperBound ? Double.MIN_VALUE : 0));
}
public void setMin(double min) {
this.min = min;
}
public void setMax(double max) {
this.max = max;
}
public void setIncludeUpperBound(boolean bool) {
this.includeUpperBound = bool;
}
}
......@@ -246,14 +246,23 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
// alternatives for routing are allowed for distances bigger than 50
if(allowAlternativeRoutes && rsp.hasAlternatives() && rsp.getBest().getDistance() > 50) {
// alternative route is taken with a certain chance
if(random.nextDouble() <= probabilityForAlternativeRoute) {
List<PathWrapper> paths = rsp.getAll();
int pick = random.nextInt(paths.size() - 1) + 1;
pointList = rsp.getAll().get(pick).getPoints();
if(random.nextDouble() <= probabilityForAlternativeRoute) {
List<PathWrapper> paths = rsp.getAll();
// remove the best, we do not want this!
paths.remove(rsp.getBest());
PathWrapper choice;
if(paths.size() == 1) {
choice = paths.get(0);
}
else {
choice = paths.get(random.nextInt(paths.size() - 1) + 1);
}
pointList = choice.getPoints();
}
}
//PointList pointList = rsp.getBest().getPoints();
}
if (isCalculateRouteSegments()) {
/*
......@@ -262,7 +271,7 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
trajectory = new RouteImpl(comp.getRealPosition(),
destination, pointList,
routeSensor.getSegmentListeners(), routeSensor,
calculateSegments(rsp.getBest()));
calculateSegments(pointList));
} else {
trajectory = new RouteImpl(comp.getRealPosition(),
destination, pointList);
......@@ -479,6 +488,10 @@ public class RealWorldStreetsMovement extends AbstractLocalMovementStrategy {
}
}
public String getBlockedAreas() {
return this.blockedAreas;
}
public void setAllowAlternativeRoutes(boolean allowAlternativeRoutes) {
this.allowAlternativeRoutes = allowAlternativeRoutes;
}
......
......@@ -23,9 +23,7 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.Vector;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
......@@ -37,6 +35,7 @@ import de.tud.kom.p2psim.api.topology.placement.PlacementModel;
import de.tud.kom.p2psim.impl.simengine.Simulator;
import de.tud.kom.p2psim.impl.topology.DefaultTopology;
import de.tud.kom.p2psim.impl.topology.TopologyFactory;
import de.tud.kom.p2psim.impl.topology.movement.distributions.ISpeedDistributionProvider;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.AttractionPointViz;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionProvider;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.MobileAttractionPoint;
......@@ -106,6 +105,8 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
protected IAttractionAssigmentStrategy attractionAssigment;
protected IAttractionProvider attractionProvider;
protected ISpeedDistributionProvider speedProvider;
protected LocalMovementStrategy localMovementStrategy;
......@@ -229,7 +230,11 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
throw new ConfigurationException(
"TransitionStrategy is missing in ModularMovementModel!");
}
}
if(speedProvider == null) {
throw new ConfigurationException(
"SpeedDistributionProvider is missing in ModularMovementModel!");
}
}
@Override
public void addComponent(SimLocationActuator comp) {
......@@ -361,6 +366,11 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
}
}
@Override
public ISpeedDistributionProvider getMovementSpeedDistribution() {
return speedProvider;
}
/*
* =====================================================================================================
* === GETTER AND SETTER FUNCTIONS
......@@ -388,6 +398,15 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
}
this.attractionProvider = attractionProvider;
}
public void setISpeedDistributionProvider(ISpeedDistributionProvider speedDistributionProvider) {
if (speedDistributionProvider == null) {
throw new ConfigurationException(
"SpeedDistributionProvider is missing in ModularMovementModel!");
}
this.speedProvider = speedDistributionProvider;
}
public void setLocalMovementStrategy(LocalMovementStrategy localMovementStrategy) {
if (localMovementStrategy == null) {
......@@ -397,10 +416,10 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
this.localMovementStrategy = localMovementStrategy;
}
public void setITransitionStrategy(IAttractionAssigmentStrategy transition) {
public void setIAttractionAssigmentStrategy(IAttractionAssigmentStrategy transition) {
if (transition == null) {
throw new ConfigurationException(
"TransitionStrategy is missing in ModularMovementModel!");
"IAttractionAssigmentStrategy is missing in ModularMovementModel!");
}
this.attractionAssigment = transition;
}
......@@ -432,4 +451,8 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
public void setAttractionPointViz(AttractionPointViz viz) {
this.attractionPointViz = viz;
}
public LocalMovementStrategy getLocalMovementStrategy() {
return this.localMovementStrategy;
}
}
......@@ -185,33 +185,29 @@ public class ModularMovementModelViz extends JComponent
tVis.drawTrajectory(g2);
}
}
// g2.setColor(Color.black);
// PositionVector p1 = GPSCalculation.transformGPSWindowToOwnWorld(51.813680,8.783510);
// PositionVector p2 = GPSCalculation.transformGPSWindowToOwnWorld(51.806795,8.804239);
//
// g2.fillRect(VisualizationInjector.scaleValue(p1.getX()), VisualizationInjector.scaleValue(p1.getX()),
// VisualizationInjector.scaleValue(p2.getX()) - VisualizationInjector.scaleValue(p1.getX()),
// VisualizationInjector.scaleValue(p2.getY())- VisualizationInjector.scaleValue(p1.getY()));
//
// p1 = GPSCalculation.transformGPSWindowToOwnWorld(51.821036,8.771151);
// p2 = GPSCalculation.transformGPSWindowToOwnWorld(51.814987, 8.779090);
//
// g2.fillRect(VisualizationInjector.scaleValue(p1.getX()), VisualizationInjector.scaleValue(p1.getX()),
// VisualizationInjector.scaleValue(p2.getX() - p1.getX()),
// VisualizationInjector.scaleValue(p2.getY() - p1.getY()));
//
// for (PointList pointList : paths) {
// for (GHPoint3D temp : pointList) {
// PositionVector p = RealWorldStreetsMovement.transformGPSWindowToOwnWorld(temp.getLat(), temp.getLon());
//
// g2.fillOval(VisualizationInjector.scaleValue(p.getX()) - 2, VisualizationInjector.scaleValue(p.getY()) - 2, 4,4 );
// }
// }
if(this.movementModel.getLocalMovementStrategy() instanceof RealWorldStreetsMovement) {
RealWorldStreetsMovement mov = (RealWorldStreetsMovement) this.movementModel.getLocalMovementStrategy();
if(mov.getBlockedAreas() != null && !mov.getBlockedAreas().isEmpty()) {
g2.setColor(new Color(1f, 0f, 0f, 0.5f));
String[] split = mov.getBlockedAreas().split(";");
for (String s : split) {
String[] vals = s.split(",");
PositionVector p1 = GPSCalculation.transformGPSWindowToOwnWorld(Double.parseDouble(vals[0]), Double.parseDouble(vals[1]));
PositionVector p2 = GPSCalculation.transformGPSWindowToOwnWorld(Double.parseDouble(vals[2]), Double.parseDouble(vals[3]));
g2.fillRect(VisualizationInjector.scaleValue(p1.getX()), VisualizationInjector.scaleValue(p1.getY()),
VisualizationInjector.scaleValue(p2.getX()) - VisualizationInjector.scaleValue(p1.getX()),
VisualizationInjector.scaleValue(p2.getY())- VisualizationInjector.scaleValue(p1.getY()));
}
}
}
}
@Override
......
......@@ -228,7 +228,7 @@ public class ModularMultiTypeMovementModel extends ModularMovementModel
}
@Override
public void setITransitionStrategy(IAttractionAssigmentStrategy transition) {
public void setIAttractionAssigmentStrategy(IAttractionAssigmentStrategy transition) {
if(supportedTransitions.size() == 0) this.attractionAssigment = transition;
supportedTransitions.put(transition.getClass(), transition);
}
......
......@@ -34,6 +34,7 @@ import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.groupforming.I
import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.IAttractionAssigmentStrategy;
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.util.Either;
import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
......@@ -53,11 +54,11 @@ public class SocialGroupMovementModel extends ModularMovementModel {
protected MovementGroupContainer groupContainer;
protected IGroupFormingBehavior groupFormingBehavior;
protected IGroupEncounterBehavior groupEncounterBehavior;
protected IAttractionAssigmentStrategy groupAttractionAssignment;
private LinkedHashSet<SimLocationActuator> singleHosts = new LinkedHashSet<SimLocationActuator>();
private int numberOfSingleHosts;
private int numberOfSingleHosts;
@Override
public void initialize() {
......@@ -104,16 +105,39 @@ public class SocialGroupMovementModel extends ModularMovementModel {
attractionAssigment.addAttractionAssignmentListener(this);
attractionAssigment.setAttractionProvider(attractionProvider);
groupAttractionAssignment.addAttractionAssignmentListener(this);
groupAttractionAssignment.setAttractionProvider(attractionProvider);
// This adds the mobile hosts (smartphones/users) to the transition
// strategy
for (SimLocationActuator ms : moveableHosts) {
attractionAssigment.addComponent(ms);
if(placeNodesAtAP) {
IAttractionPoint assignment = attractionAssigment.getAssignment(ms);
ms.updateCurrentLocation(this.addOffset(new PositionVector(assignment),
(assignment.hasRadius() ? Math.max(assignment.getRadius(), 25.0) : 25.0)));
attractionAssigment.updateTargetAttractionPoint(ms, assignment);
}
if(singleHosts.contains(ms)) {
attractionAssigment.addComponent(ms);
if(placeNodesAtAP) {
IAttractionPoint assignment = attractionAssigment.getAssignment(ms);
ms.updateCurrentLocation(this.addOffset(new PositionVector(assignment),
(assignment.hasRadius() ? Math.max(assignment.getRadius(), 25.0) : 25.0)));
attractionAssigment.updateTargetAttractionPoint(ms, assignment);
}
}
else {
groupAttractionAssignment.addComponent(ms);
if(placeNodesAtAP) {
IAttractionPoint assignment = groupAttractionAssignment.getAssignment(ms);
ms.updateCurrentLocation(this.addOffset(new PositionVector(assignment),
(assignment.hasRadius() ? Math.max(assignment.getRadius(), 25.0) : 25.0)));
groupAttractionAssignment.updateTargetAttractionPoint(ms, assignment);
}
}
// //attractionAssigment.addComponent(ms);
// if(placeNodesAtAP) {
// IAttractionPoint assignment = attractionAssigment.getAssignment(ms);
// ms.updateCurrentLocation(this.addOffset(new PositionVector(assignment),
// (assignment.hasRadius() ? Math.max(assignment.getRadius(), 25.0) : 25.0)));
// attractionAssigment.updateTargetAttractionPoint(ms, assignment);
// }
}
setTimeBetweenMoveOperations(timeBetweenMoveOperation);
......@@ -173,7 +197,10 @@ public class SocialGroupMovementModel extends ModularMovementModel {
assert currentTargets.containsKey(host);
// Single Host Movement
if(singleHosts.contains(host) || !groupContainer.isGroupMember(host)) {
if(singleHosts.contains(host)) {
super.doLocalMovement(host, currentTargets.get(host));
}
else if( !groupContainer.isGroupMember(host)) {
doLocalMovement(host, currentTargets.get(host));
}
else if(groupContainer.isGroupMember(host)){
......@@ -194,6 +221,22 @@ public class SocialGroupMovementModel extends ModularMovementModel {
Event.scheduleWithDelay(timeBetweenMoveOperation, this, null, EVENT_MOVE);
}
@Override
protected void doLocalMovement(SimLocationActuator ms, PositionVector destination) {
Either<PositionVector, Boolean> either = localMovementStrategy.nextPosition(ms, destination);
if (either.hasLeft()) {
ms.updateCurrentLocation(either.getLeft());
if(!checkBoundaries(ms.getRealPosition())) {
System.err.println("Social Group Movement Model: Host moved outside of simulated area!");
}
}
else {
groupAttractionAssignment.reachedAttractionPoint(ms, ms.getCurrentTargetAttractionPoint());
}
}
/**
* Applies movement of the host according to different circumstances:
*
......@@ -272,6 +315,29 @@ public class SocialGroupMovementModel extends ModularMovementModel {
}
@Override
public void changeTargetLocation(SimLocationActuator actuator, IAttractionPoint ap) {
if(singleHosts.contains(actuator)) {
super.changeTargetLocation(actuator, ap);
}
else {
groupAttractionAssignment.updateTargetAttractionPoint(actuator, ap);
actuator.setMovementSpeed(this.speedProvider.calculateSpeed());
}
}
@Override
public IAttractionPoint getTargetLocation(SimLocationActuator actuator) {
if(singleHosts.contains(actuator)) {
return attractionAssigment.getAssignment(actuator);
}
else {
return groupAttractionAssignment.getAssignment(actuator);
}
}
/*
* =====================================================================================================
* === MEETING POINT FUNCTIONS
......@@ -376,7 +442,7 @@ public class SocialGroupMovementModel extends ModularMovementModel {
}
public IAttractionAssigmentStrategy getAttractionAssignmentStrategy() {
return attractionAssigment;
return this.groupAttractionAssignment;
}
public IGroupFormingBehavior getGroupFormingBehavior() {
......@@ -398,4 +464,13 @@ public class SocialGroupMovementModel extends ModularMovementModel {
public LinkedHashMap<SimLocationActuator, PositionVector> getCurrentTargets(){
return currentTargets;
}
public void setGroupAttractionAssignmentStrategy(IAttractionAssigmentStrategy groupAttractionAssignment) {
if (groupAttractionAssignment == null) {
throw new ConfigurationException(
"IAttractionAssigmentStrategy for Groups is missing in SocialGroupMovementModel!");
}
this.groupAttractionAssignment = groupAttractionAssignment;
}
}
......@@ -101,7 +101,7 @@ public class AttractionPointViz extends JComponent
drawAttractionPoints(g2);
}
if(true) {
if(false) {
drawClusters(g2);
}
}
......@@ -126,8 +126,13 @@ public class AttractionPointViz extends JComponent
for (LinkedList<SimHost> group : clusters) {
g2.setColor(colors.get(clusters.indexOf(group)));
try {
g2.setColor(colors.get(clusters.indexOf(group)));
}
catch (Exception e) {
g2.setColor(Color.black);
}
for (SimHost member : group) {
PositionVector p = member.getTopologyComponent().getRealPosition();
......
......@@ -24,7 +24,6 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;
import org.apache.commons.io.IOUtils;
import org.json.JSONArray;
import org.json.JSONException;
......@@ -138,15 +137,8 @@ public class JSONAttractionGenerator extends AbstractAttractionProvider {
}
// AP radius
if(allPOI.getJSONObject(i).getJSONObject("tags").has("radius")) {
double radius = allPOI.getJSONObject(i).getJSONObject("tags").getDouble("radius");
if(maximumRadius == -1) {
ap.setRadius(radius);
}
else {
ap.setRadius(Math.min(maximumRadius, radius));
}
if(allPOI.getJSONObject(i).getJSONObject("tags").has("radius")) {
ap.setRadius(allPOI.getJSONObject(i).getJSONObject("tags").getDouble("radius"));
}
if(allPOI.getJSONObject(i).getJSONObject("tags").has("pauseTimeMin") && allPOI.getJSONObject(i).getJSONObject("tags").has("pauseTimeMax")) {
......
......@@ -157,7 +157,7 @@ public class SocialMovementGroup {
@Override
public String toString() {
return "Social Group of #" + leader.getHost().getId() + " ("+ members.size() +")";
return "Social Group of Leader #" + leader.getHost().getId() + " ("+ members.size() +")";
}
......
......@@ -143,11 +143,11 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
if(!enableGroups) {
return;
}
for(int g = 0; g < maxNumberOfGroups; g++) {
long delay = Math.max(Time.MINUTE, (long) ((rand.nextDouble() * (Time.MINUTE * 45) + Time.MINUTE)));
//System.out.println("("+g+") Init Group Formation Time " + Time.getFormattedTime(delay) );
long delay = Math.max(Time.MINUTE, (long) ((groupFormationSetupDelay + rand.nextGaussian() * groupFormationSetupDelay )));
Monitor.log(this.getClass(), Monitor.Level.INFO, "Group: "+g+" Initial Group Formation Time", Time.getFormattedTime(delay));
Event.scheduleWithDelay(delay, new EventHandler() {
@Override
public void eventOccurred(Object content, int type) {
......
......@@ -23,9 +23,9 @@ 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.distributions.ISpeedDistributionProvider;
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;
......@@ -47,17 +47,26 @@ public class AttractionPointRoamingStrategy extends AbstractAttractionBasedAssig
ROAMING
}
protected ISpeedDistributionProvider roamSpeedProvider;
protected Map<SimLocationActuator, roamingTransitionState> roamingStates = new LinkedHashMap<>();
@XMLConfigurableConstructor({ "defaultPauseTimeMin", "defaultPauseTimeMax" })
public AttractionPointRoamingStrategy(long defaultPauseTimeMin, long defaultPauseTimeMax) {
protected long roamingPauseTime;
@XMLConfigurableConstructor({ "defaultPauseTimeMin", "defaultPauseTimeMax", "roamingPauseTime" })
public AttractionPointRoamingStrategy(long defaultPauseTimeMin, long defaultPauseTimeMax, long roamingPauseTime) {
super(defaultPauseTimeMin, defaultPauseTimeMax);
this.roamingPauseTime = roamingPauseTime;
}
@Override
public void addComponent(SimLocationActuator comp) {
this.roamingStates.put(comp, null);
IAttractionPoint nextAP = getNewAttractionPointAssignment(comp);
// trigger recalculation of speed
comp.setMovementSpeed(-1);
updateTargetAttractionPoint(comp, nextAP);
}
......@@ -82,14 +91,17 @@ public class AttractionPointRoamingStrategy extends AbstractAttractionBasedAssig
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);
long pause = (long) Math.max(0, rnd.nextGaussian() * (roamingPauseTime / 3)) + roamingPauseTime;
Event.scheduleWithDelay(pause, 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);
this.roamingStates.put(comp, roamingTransitionState.ROAMING);
comp.setMovementSpeed(roamSpeedProvider.calculateSpeed());
notifyListenersOfAssignmentUpdate(comp, currentAttractionPoint);
}
}
......@@ -108,4 +120,8 @@ public class AttractionPointRoamingStrategy extends AbstractAttractionBasedAssig
this.roamAroundAttractionPoint(comp);
}
}
public void setRoamingSpeedDistribution(ISpeedDistributionProvider dist) {
this.roamSpeedProvider = dist;
}
}
\ No newline at end of file
......@@ -23,9 +23,9 @@ 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.distributions.ISpeedDistributionProvider;
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;
......@@ -48,6 +48,8 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedAssi
TRANSITION
}
protected ISpeedDistributionProvider roamSpeedProvider;
protected Map<SimLocationActuator, roamingTransitionState> roamingStates = new LinkedHashMap<>();
protected final static int EVENT_ROAMING_PAUSE_ENDED = 2;
......@@ -63,6 +65,10 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedAssi
public void addComponent(SimLocationActuator comp) {
this.roamingStates.put(comp, roamingTransitionState.TRANSITION);
IAttractionPoint nextAP = getNewAttractionPointAssignment(comp);
// trigger recalculation of speed
comp.setMovementSpeed(-1);
updateTargetAttractionPoint(comp, nextAP);
}
......@@ -117,16 +123,11 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedAssi
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);
if(currentAttractionPoint.getRadius() > 0) {
this.roamingStates.put(comp, roamingTransitionState.ROAMING);
comp.setMovementSpeed(roamSpeedProvider.calculateSpeed());
updateTargetAttractionPoint(comp, currentAttractionPoint);
//notifyListenersOfAssignmentUpdate(comp, currentAttractionPoint);
}
}
}
......@@ -158,7 +159,10 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedAssi
public void setGaussianPauseTime(boolean useGaussian) {
useGaussianDistributedPauseTime = useGaussian;
}
public void setRoamingSpeedDistribution(ISpeedDistributionProvider dist) {
this.roamSpeedProvider = dist;
}
}
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