diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModel.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModel.java index 954478c92ee893f5e92ff6ed7c7101f1fcc828e1..d5154b47f08c42464bf900458a84e126cf34dc2c 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModel.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/ModularMovementModel.java @@ -230,12 +230,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac int tries = 0; do { - destination = new PositionVector(attractionCenter); - // Gaussian with std = 1 --> >99% of nodes - PositionVector offset = new PositionVector( - rand.nextGaussian() * apRadius / 3, - rand.nextGaussian() * apRadius / 3); - destination.add(offset); + destination = addGaussianOffsetToPosition(attractionCenter, apRadius / 3); // Check constraints if (!checkBoundaries(destination)) { destination = null; @@ -257,6 +252,14 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac Event.scheduleWithDelay(timeBetweenMoveOperation, this, null, EVENT_MOVE); } + + public PositionVector addGaussianOffsetToPosition(PositionVector position, double std) { + PositionVector offsetPosition = new PositionVector(position); + // Gaussian with std = 1 --> >99% of nodes + PositionVector offset = new PositionVector(rand.nextGaussian() * std, rand.nextGaussian() * std); + offsetPosition.add(offset); + return offsetPosition; + } /** * diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/SocialGroupMovementModel.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/SocialGroupMovementModel.java index 07672cea95e39d466c04bd1356af53db50cc1d2a..5890d43f83d915dea3bce49c575af38db59a8cfe 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/SocialGroupMovementModel.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/SocialGroupMovementModel.java @@ -111,9 +111,8 @@ public class SocialGroupMovementModel extends ModularMovementModel { // Check POIs if groups can be created. Delete groups, if destination reached. groupFormingBehavior.manageGroups(); - // Checks if groups encounter each other and applies a specified action to these groups. - Set encounteringGroups = groupEncounterBehavior.getEncounteringGroups(); - groupEncounterBehavior.handleEncounters(encounteringGroups); + // Checks if groups encounter each other and applies a specified action to these groups. + groupEncounterBehavior.handleEncounters(); /* * Moves all nodes according to definition in group movement method diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/MovementGroupContainer.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/MovementGroupContainer.java index 36e39685e8afde2d34e6785c369ec7161d687fd1..24caeb8f413afa76e81f5722ced3b66154f8240f 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/MovementGroupContainer.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/MovementGroupContainer.java @@ -89,6 +89,10 @@ public class MovementGroupContainer { public void addGroup(SocialMovementGroup group) { groups.add(group); } + + public boolean hasGroup(SocialMovementGroup group) { + return groups.contains(group); + } /** * Removes a group from the set of groups and sets the leftGroupAtTime variable for all group members. diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/AbstractGroupEncounter.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/AbstractGroupEncounter.java index a9e9c53f096c2cd03d8c653268469cb87d9d5352..1dd5eec7e64163dbf546d6104d92fbcf4398e2c7 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/AbstractGroupEncounter.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/AbstractGroupEncounter.java @@ -32,13 +32,14 @@ import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.SocialMovement import de.tud.kom.p2psim.impl.topology.util.PositionVector; import de.tudarmstadt.maki.simonstrator.api.Randoms; import de.tudarmstadt.maki.simonstrator.api.Time; +import de.tudarmstadt.maki.simonstrator.api.common.datastructures.Pair; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; /** * This class contains methods used by all encounter strategies. * - * @author Marcel Verst - * @version 1.0, 22.11.2018 + * @author Marcel Verst, Julian Zobel + * @version 1.1, 30.01.2020 */ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior { @@ -79,6 +80,7 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior @Override public void initialize(SocialGroupMovementModel movementModel) { + this.movementModel = movementModel; groupCon = MovementGroupContainer.getInstance(); for(SimLocationActuator host : movementModel.getAllLocationActuators()) { @@ -86,61 +88,77 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior } } - public Set getEncounteringGroups() { + @Override + public Set> getEncounteringGroups() { if(!enableGroupEncounters) return null; - Set encounteringGroups = new LinkedHashSet<>(); + Set> encounteringGroups = new LinkedHashSet<>(); Set alreadyProcessed = new LinkedHashSet<>(); Set allGroups = groupCon.getGroups(); + for(SocialMovementGroup group1 : allGroups) { for(SocialMovementGroup group2 : allGroups) { - if(group1 != group2) { - if(!(alreadyProcessed.contains(group1) && alreadyProcessed.contains(group2))) { - if(getDistanceBetweenGroups(group1, group2) <= groupEncounterMeetingDistance) { - SimLocationActuator g1Leader = group1.getLeader(); - if(!groupCon.getHasMerged().get(g1Leader)) { - SocialMovementGroup[] groups = new SocialMovementGroup[2]; - groups[0] = group1; - groups[1] = group2; - encounteringGroups.add(groups); - - alreadyProcessed.add(group1); - alreadyProcessed.add(group2); - } - else { - if(waitedLongEnoughAfterMerging(g1Leader)) { - SocialMovementGroup[] groups = new SocialMovementGroup[2]; - groups[0] = group1; - groups[1] = group2; - encounteringGroups.add(groups); - - alreadyProcessed.add(group1); - alreadyProcessed.add(group2); - } - } - } - } + if(group1 == group2) { + continue; } + + // skip if at least one of the groups is in the area of an attraction point + if(movementModel.getAttractionAssignmentStrategy().hostInAttractionPointArea(group1.getLeader()) + || movementModel.getAttractionAssignmentStrategy().hostInAttractionPointArea(group2.getLeader())) { + continue; + } + + if(!(alreadyProcessed.contains(group1) && alreadyProcessed.contains(group2))) { + + if(getDistanceBetweenGroups(group1, group2) <= groupEncounterMeetingDistance) { + SimLocationActuator g1Leader = group1.getLeader(); + + if(!groupCon.getHasMerged().get(g1Leader) || waitedLongEnoughAfterMerging(g1Leader) ) { + + Pair encounter = new Pair(group1, group2); + encounteringGroups.add(encounter); + + alreadyProcessed.add(group1); + alreadyProcessed.add(group2); + } + } + } } } return encounteringGroups; } - /** - * {@inheritDoc} - */ - public void handleEncounters(Set encounteringGroups) { + + public void handleEncounters() { + + if(!enableGroupEncounters) + return; + + Set> encounteringGroups = getEncounteringGroups(); + if(encounteringGroups == null || encounteringGroups.isEmpty()) { return; } - for(SocialMovementGroup[] groups : encounteringGroups) { - handleGroupEncounter(groups[0], groups[1]); + + for(Pair encounter : encounteringGroups) { + if(groupCon.hasGroup(encounter.getFirst()) && groupCon.hasGroup(encounter.getSecond())) { + handleGroupEncounter(encounter.getFirst(), encounter.getSecond()); + } } } - + + /** + * Defines what to do with both groups in case they encountered. + * + * @param SocialMovementGroup The first group. + * @param SocialMovementGroup The second group. + * + */ + protected abstract void handleGroupEncounter(SocialMovementGroup group1, SocialMovementGroup group2); + /** * Returns the distance between two groups based on their leaders position. * @@ -236,9 +254,8 @@ public abstract class AbstractGroupEncounter implements IGroupEncounterBehavior SocialMovementGroup large = getLargerGroup(group1, group2); SocialMovementGroup small = getSmallerGroup(group1, group2); - Set toRemove = new LinkedHashSet<>(); - toRemove.addAll(small.getMembers()); - + Set toRemove = new LinkedHashSet<>(small.getMembers()); + for(SimLocationActuator participant : toRemove) { small.removeHostFromGroup(participant); groupCon.addLeftGroupAtTimeEntry(participant, Time.getCurrentTime()); diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/IGroupEncounterBehavior.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/IGroupEncounterBehavior.java index 5650d4bf69d7838b461ade1fea52116fac7d3029..e271149bea8438081ee82e50d348b69c5191f0dc 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/IGroupEncounterBehavior.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/IGroupEncounterBehavior.java @@ -22,9 +22,9 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.groupencounte import java.util.Set; -import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel; import de.tud.kom.p2psim.impl.topology.movement.modularosm.SocialGroupMovementModel; import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.SocialMovementGroup; +import de.tudarmstadt.maki.simonstrator.api.common.datastructures.Pair; /** * Handles group encounters. Check group encounters based on the leaders location of {@link SocialMovementGroup}s. @@ -37,35 +37,22 @@ public interface IGroupEncounterBehavior { /** * Initializes class variables. * - * @author Marcel Verst */ void initialize(SocialGroupMovementModel movementModel); /** * Checks if any of the current groups come in a close range which is equivalent to a group meeting. * Calls the handleGroupEncounters(Group, Group) method to define the group behavior. - * - * @author Marcel Verst + * * @return */ - Set getEncounteringGroups(); + Set> getEncounteringGroups(); /** * Applies an encountering action to each detected encountering groups. * - * @param Set The set of encountering groups. - * - * @author Marcel Verst */ - void handleEncounters(Set encounteringGroups); + public void handleEncounters(); + - /** - * Defines what to do with both groups in case they encountered. - * - * @param SocialMovementGroup The first group. - * @param SocialMovementGroup The second group. - * - * @author Marcel Verst - */ - void handleGroupEncounter(SocialMovementGroup group1, SocialMovementGroup group2); } \ No newline at end of file diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/Wait.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/Wait.java index 31510e1342375bdd84d43afd42042b9310902267..06ea758667ba68aea291b492dc1277c69d912147 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/Wait.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupencounter/Wait.java @@ -66,12 +66,9 @@ public class Wait extends AbstractGroupEncounter{ */ private void wait(SocialMovementGroup group1, SocialMovementGroup group2) { // Do not apply waiting process if one of both groups is already waiting - if(groupCon.waitingGroups.containsKey(group1) && !groupCon.waitingGroups.containsKey(group2)) { + if(groupCon.waitingGroups.containsKey(group1) ^ groupCon.waitingGroups.containsKey(group2)) { return; - } - if(!groupCon.waitingGroups.containsKey(group1) && groupCon.waitingGroups.containsKey(group2)) { - return; - } + } // If both groups are not waiting, declare them as waiting groups for a duration of timeToWait if(!groupCon.waitingGroups.containsKey(group1) && !groupCon.waitingGroups.containsKey(group2)) { diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/AbstractGroupForming.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/AbstractGroupForming.java index 4e4600c80060e340d1724ccc12bec94ca7a71194..ac4740975cc5ab3691dfcc380ac4f768728edd5a 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/AbstractGroupForming.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/AbstractGroupForming.java @@ -193,12 +193,9 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior { } while(nextDestination == leaderTarget); // Add Offset to destination - PositionVector destination = new PositionVector(nextDestination); - double apRadius = nextDestination.getRadius(); - - PositionVector offset = new PositionVector(rand.nextGaussian() * apRadius / 3, rand.nextGaussian() * apRadius / 3); - destination.plus(offset); - + PositionVector destination = movementModel.addGaussianOffsetToPosition(new PositionVector(nextDestination), + nextDestination.getRadius() / 3); + group.setDestination(destination); setGroupMeetingPoint(group); @@ -350,23 +347,13 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior { /** * Checks if a host has waited long enough before he is allowed to join groups again. - * Returns true, if the host has waited long enough, false else. + * Returns true, if the host has waited long enough, false otherwise. * * @param SimLocationActuator The host to be checked. - * @param int The current time. * @return boolean - * - * @author Marcel Verst */ - protected boolean groupRejoinTimerExpired(SimLocationActuator host) { - long t = groupCon.getTimeSinceHostLeftLastGroup(host); - - System.out.println(host.getHost().getId() + " | "+Time.getFormattedTime() - +" | Wait for:" +Time.getFormattedTime(t) + ", req is " + Time.getFormattedTime(groupRejoinWaitTime) ); - - boolean dec = t >= groupRejoinWaitTime; - - return dec; + protected boolean groupRejoinTimerExpired(SimLocationActuator host) { + return groupCon.getTimeSinceHostLeftLastGroup(host) >= groupRejoinWaitTime; } /** @@ -374,8 +361,6 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior { * * @param SimLocacationActuator The host to be checked. * @return Boolean - * - * @author Marcel Verst */ protected boolean beenInGroup(SimLocationActuator host) { return groupCon.hostWasGroupMember(host); @@ -391,13 +376,12 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior { * the group members first have to meet at the meeting point. * * @param SocialMovementGroup The group to set the meeting point. - * - * @author Marcel Verst, Julian Zobel */ protected void setGroupMeetingPoint(SocialMovementGroup group) { PositionVector leaderPos = group.getLeader().getRealPosition(); - BasicAttractionPoint meetingPoint = new BasicAttractionPoint("Group Movement Meeting Point of Leader #"+group.getLeader().getHost().getId(), leaderPos); + BasicAttractionPoint meetingPoint = + new BasicAttractionPoint("Group Movement Meeting Point of Leader #"+group.getLeader().getHost().getId(), leaderPos); group.setMeetingPoint(meetingPoint); @@ -405,7 +389,7 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior { for(SimLocationActuator participant : group.getMembers()) { movementModel.getAttractionAssignmentStrategy().updateTargetAttractionPoint(participant, meetingPoint); } - } + } @Override public int getMinGroupSize() { diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/DefaultGroupForming.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/DefaultGroupForming.java index 7a01caeb768b66a89827fee52da85866e65b83b3..7b1fa69f2daca73ce22e12bf15205d9c2dd95fff 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/DefaultGroupForming.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/DefaultGroupForming.java @@ -20,12 +20,13 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.groupforming; +import java.util.Collections; import java.util.LinkedHashSet; +import java.util.LinkedList; import java.util.Set; 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.topology.movement.modularosm.attraction.IAttractionGenerator; import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.SocialMovementGroup; import de.tud.kom.p2psim.impl.topology.movement.modularosm.transition.IAttractionAssigmentStrategy; import de.tud.kom.p2psim.impl.topology.util.PositionVector; @@ -36,7 +37,6 @@ import de.tudarmstadt.maki.simonstrator.api.EventHandler; 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.AttractionPoint; -import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor; /** @@ -103,43 +103,45 @@ public class DefaultGroupForming extends AbstractGroupForming { int numberOfHostsInAttractionPoint = hostCounter.getHostCountOfAttractionPoint(apCandidate); int groupSize = this.rndGroupSize(numberOfHostsInAttractionPoint); - - + Set groupCandidates = new LinkedHashSet<>(); - Set hostsOfPoi = hostCounter.getHostsOfAttractionPoint(apCandidate); + // shuffle the hosts at the attraction point (more randomness ftw!) + LinkedList randomShuffledHostsAtAttractionPoint = new LinkedList<>(hostCounter.getHostsOfAttractionPoint(apCandidate)); + Collections.shuffle(randomShuffledHostsAtAttractionPoint, rand); - for (SimLocationActuator m : hostsOfPoi) { + for (SimLocationActuator m : randomShuffledHostsAtAttractionPoint) { + + // skip already added hosts (should never happen) if(groupCandidates.contains(m)) { - System.err.println("Cannot be???"); continue; } + // skip single hosts if(movementModel.getSingleHosts().contains(m)) { - System.out.println("ACM Single Host is not added"); continue; } + // skip hosts that are already part of a group if(groupCon.isGroupMember(m)) { - System.out.println("No members allowed"); continue; } + // test if the host wants and also is allowed to join this group if(wantsToJoin()) { if(!beenInGroup(m) || groupRejoinTimerExpired(m)) { groupCandidates.add(m); } } + // do not continue if enough group members are gathered if(groupCandidates.size() == groupSize) { - System.out.println("Group full, now go!"); break; } } - if(groupCandidates.isEmpty() || groupCandidates == null) { - System.out.println("--no cands"); - + // if there are no candidates, wait a minute until asking again + if(groupCandidates.isEmpty() || groupCandidates == null) { Event.scheduleWithDelay(Time.MINUTE, new EventHandler() { @Override public void eventOccurred(Object content, int type) { @@ -149,13 +151,12 @@ public class DefaultGroupForming extends AbstractGroupForming { break; } - - System.out.println("Group creation: " + groupCandidates.size() + " => " + apCandidate); - + for(SimLocationActuator candidate : groupCandidates) { INodeID id = candidate.getHost().getId(); stayDuration.put(id, new Tuple(0L, Time.getCurrentTime())); // FIXME why? - } + } + createGroup(groupCandidates); } } @@ -214,18 +215,8 @@ public class DefaultGroupForming extends AbstractGroupForming { for(SimLocationActuator component : movementModel.getAllLocationActuators()) { INodeID id = component.getHost().getId(); - // Check if host is in an AP area - boolean isInAp = false; - for(AttractionPoint ap : IAttractionGenerator.attractionPoints) { - Location hostLocation = component.getLastLocation(); - if(ap.distanceTo(hostLocation) <= ap.getRadius()) { - isInAp = true; - break; - } - } - // In AP, increase stayDuration - if(isInAp) { + if(movementModel.getAttractionAssignmentStrategy().hostInAttractionPointArea(component)) { Tuple timeInfo = stayDuration.get(id); long delta = Time.getCurrentTime() - timeInfo.getB(); @@ -242,4 +233,6 @@ public class DefaultGroupForming extends AbstractGroupForming { + + } diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/IGroupFormingBehavior.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/IGroupFormingBehavior.java index e481a57fc4398b193dd8d1326c4227f462385f60..19c0f404ba1c779d54434cf5a7691bcfafac7890 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/IGroupFormingBehavior.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/groups/groupforming/IGroupFormingBehavior.java @@ -20,6 +20,7 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.groupforming; +import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; import de.tud.kom.p2psim.impl.topology.movement.modularosm.SocialGroupMovementModel; /** @@ -59,7 +60,7 @@ public interface IGroupFormingBehavior { * @author Marcel Verst */ void runGroupDeletionProcess(); - + public int getMinGroupSize(); public int getMaxGroupSize(); } \ No newline at end of file diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/AbstractAttractionBasedAssignmentStrategy.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/AbstractAttractionBasedAssignmentStrategy.java index a0aa73ae3bb6503dab9d8c6377edf6aa76bac627..d6b9f67fd75a5230ad4e35fcebcaece867433bea 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/AbstractAttractionBasedAssignmentStrategy.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/AbstractAttractionBasedAssignmentStrategy.java @@ -128,4 +128,16 @@ public abstract class AbstractAttractionBasedAssignmentStrategy implements IAttr AttractionPoint assignment = candidates.get(rnd.nextInt(candidates.size())); return assignment; } + + + @Override + public boolean hostInAttractionPointArea(SimLocationActuator host) { + for(AttractionPoint ap : IAttractionGenerator.attractionPoints) { + if(ap.distanceTo(host.getRealPosition()) <= ap.getRadius()) { + return true; + } + } + + return false; + } } diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/IAttractionAssigmentStrategy.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/IAttractionAssigmentStrategy.java index 3918d619b3d72329dc79af569f222241fed2a41b..7ced070b606d095428af50dd8c5a0269284356f1 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/IAttractionAssigmentStrategy.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/IAttractionAssigmentStrategy.java @@ -84,5 +84,6 @@ public interface IAttractionAssigmentStrategy { AttractionPoint newAssignment); } - + + public boolean hostInAttractionPointArea(SimLocationActuator host); } diff --git a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/ManualAssignmentStrategy.java b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/ManualAssignmentStrategy.java index 7743264227f575cf8932ca2459dcfca0d4e3a6ee..6271fa6d5bed3a40ee623cd62cd0b0a4822387a5 100644 --- a/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/ManualAssignmentStrategy.java +++ b/src/de/tud/kom/p2psim/impl/topology/movement/modularosm/transition/ManualAssignmentStrategy.java @@ -1,6 +1,7 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.transition; import de.tud.kom.p2psim.api.topology.movement.SimLocationActuator; +import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator; import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint; import java.util.*; @@ -68,4 +69,15 @@ public class ManualAssignmentStrategy implements IAttractionAssigmentStrategy assignments.put(comp, attractionPoint); listeners.forEach(listener -> listener.updatedAttractionAssignment(comp, attractionPoint)); } + + @Override + public boolean hostInAttractionPointArea(SimLocationActuator host) { + for(AttractionPoint ap : IAttractionGenerator.attractionPoints) { + if(ap.distanceTo(host.getRealPosition()) <= ap.getRadius()) { + return true; + } + } + + return false; + } }