From 74c2e2f4df3a523bac26e25acb76b17a5a1da400 Mon Sep 17 00:00:00 2001 From: Julian Zobel Date: Mon, 11 Mar 2019 17:22:44 +0100 Subject: [PATCH] Random Dynamic Attraction Poins now provide full funcationality --- .../RandomDynamicAttractionGenerator.java | 43 +++++++++++-------- .../InAreaRoamingTransitionStrategy.java | 12 +++--- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/RandomDynamicAttractionGenerator.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/RandomDynamicAttractionGenerator.java index ad103914..44a37b32 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/RandomDynamicAttractionGenerator.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/attraction/RandomDynamicAttractionGenerator.java @@ -20,7 +20,6 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction; -import java.util.LinkedList; import java.util.List; import java.util.Random; import de.tud.kom.p2psim.api.scenario.ConfigurationException; @@ -30,18 +29,20 @@ import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.EventHandler; import de.tudarmstadt.maki.simonstrator.api.Randoms; -import de.tudarmstadt.maki.simonstrator.api.Time; -import de.tudarmstadt.maki.simonstrator.api.component.network.NetworkComponent.NetInterfaceName; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; /** * Implementation of the interface {@link AttractionGenerator}. * - * Generates the given number of {@link AttractionPoint}s + * Generates a random number (out of a given interval) of attraction points. The radius is chosen randomly from a given interval. + * Generated attraction points will most likely not overlay and be completely within the world dimensions. + * With a certain lifetime chosen from a given lifetime interval, attraction points are removed after time and the number of + * attraction points that will be in the area are recalculated. If necessary, attraction points are either removed + * or added. * * @author Julian Zobel - * @version 0.0 + * @version 1.0, March 2019 */ public class RandomDynamicAttractionGenerator implements IAttractionGenerator { @@ -81,6 +82,9 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator { this.minNumberOfAttractionPoints = minNumberOfAttractionPoints; this.maxNumberOfAttractionPoints = maxNumberOfAttractionPoints; + this.minimumRadius = minimumRadius; + this.maximumRadius = maximumRadius; + this.minDynamicIntervall = minDynamicIntervall; this.maxDynamicIntervall = maxDynamicIntervall; @@ -163,27 +167,28 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator { // set the radius of this attraction point // minimum radius is 10 meters double radius = Math.max(minimumRadius, rand.nextDouble() * maximumRadius); - + System.out.println(radius); + if(i < c) { // check if the attraction points would be completely within world dimensions (including radius!) if((posVec.getX() + radius) >= worldDimension.getX() || (posVec.getY() + radius) >= worldDimension.getY() || (posVec.getX() - radius) <= 0 || (posVec.getY() - radius) <= 0) { continue create; } - // is within world dimensions, so continue checking against other attraction points - else { - for (AttractionPoint ap : attractionPoints) { - // if this point is closer than the given minimum distance to another point, or the radii of the points would overlap, - // or if the radius would exceed the simulation area - // then discard this attraction point and create a new one - if(posVec.distanceTo(ap) < minimumDistance || (posVec.distanceTo(ap) - radius - ap.getRadius()) < 0) { - continue create; - } - } - } + + // if within world dimensions, continue checking against other attraction points + for (AttractionPoint ap : attractionPoints) { + // if this point is closer than the given minimum distance to another point, or the radii of the points would overlap, + // or if the radius would exceed the simulation area + // then discard this attraction point and create a new one + if(posVec.distanceTo(ap) < minimumDistance || (posVec.distanceTo(ap) - radius - ap.getRadius()) < 0) { + continue create; + } + } + } - else { - radius = 10; + else { + radius = 0; } AttractionPoint aPoint = new AttractionPointImpl("AP-" + rand.nextInt(), posVec); diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/InAreaRoamingTransitionStrategy.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/InAreaRoamingTransitionStrategy.java index 9dbc6c76..c796c462 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/InAreaRoamingTransitionStrategy.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/InAreaRoamingTransitionStrategy.java @@ -98,20 +98,18 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran if(type == EVENT_PAUSE_ENDED) { SimLocationActuator comp = (SimLocationActuator) content; - if(roamingStates.get(comp) == roamingTransitionState.TRANSITION) { - System.out.println("already in transition state!"); - } - else { + // 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; + SimLocationActuator comp = (SimLocationActuator) content; AttractionPoint currentAttractionPoint = this.assignments.get(comp); - if(!IAttractionGenerator.attractionPoints.contains(currentAttractionPoint)) { - System.out.println("Assigned AP not available!"); + // if the attraction point was removed in the meantime, go directly to transit state + if(!IAttractionGenerator.attractionPoints.contains(currentAttractionPoint)) { this.addComponent(comp); } else { -- GitLab