Commit aad65d61 authored by Julian Zobel's avatar Julian Zobel
Browse files

separated assignment strategy for single nodes and social groups to allow for single node movement

parent 1562bfc2
...@@ -34,6 +34,7 @@ import de.tud.kom.p2psim.impl.topology.movement.modularosm.groups.groupforming.I ...@@ -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.movement.modularosm.transition.IAttractionAssigmentStrategy;
import de.tud.kom.p2psim.impl.topology.util.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector; import de.tud.kom.p2psim.impl.topology.views.VisualizationTopologyView.VisualizationInjector;
import de.tud.kom.p2psim.impl.util.Either;
import de.tudarmstadt.maki.simonstrator.api.Binder; import de.tudarmstadt.maki.simonstrator.api.Binder;
import de.tudarmstadt.maki.simonstrator.api.Event; import de.tudarmstadt.maki.simonstrator.api.Event;
import de.tudarmstadt.maki.simonstrator.api.Monitor; import de.tudarmstadt.maki.simonstrator.api.Monitor;
...@@ -53,7 +54,10 @@ public class SocialGroupMovementModel extends ModularMovementModel { ...@@ -53,7 +54,10 @@ public class SocialGroupMovementModel extends ModularMovementModel {
protected MovementGroupContainer groupContainer; protected MovementGroupContainer groupContainer;
protected IGroupFormingBehavior groupFormingBehavior; protected IGroupFormingBehavior groupFormingBehavior;
protected IGroupEncounterBehavior groupEncounterBehavior; protected IGroupEncounterBehavior groupEncounterBehavior;
protected IAttractionAssigmentStrategy groupAttractionAssignment;
private LinkedHashSet<SimLocationActuator> singleHosts = new LinkedHashSet<SimLocationActuator>(); private LinkedHashSet<SimLocationActuator> singleHosts = new LinkedHashSet<SimLocationActuator>();
private int numberOfSingleHosts; private int numberOfSingleHosts;
...@@ -104,16 +108,39 @@ public class SocialGroupMovementModel extends ModularMovementModel { ...@@ -104,16 +108,39 @@ public class SocialGroupMovementModel extends ModularMovementModel {
attractionAssigment.addAttractionAssignmentListener(this); attractionAssigment.addAttractionAssignmentListener(this);
attractionAssigment.setAttractionProvider(attractionProvider); attractionAssigment.setAttractionProvider(attractionProvider);
groupAttractionAssignment.addAttractionAssignmentListener(this);
groupAttractionAssignment.setAttractionProvider(attractionProvider);
// This adds the mobile hosts (smartphones/users) to the transition // This adds the mobile hosts (smartphones/users) to the transition
// strategy // strategy
for (SimLocationActuator ms : moveableHosts) { for (SimLocationActuator ms : moveableHosts) {
attractionAssigment.addComponent(ms); if(singleHosts.contains(ms)) {
if(placeNodesAtAP) { attractionAssigment.addComponent(ms);
IAttractionPoint assignment = attractionAssigment.getAssignment(ms);
ms.updateCurrentLocation(this.addOffset(new PositionVector(assignment), if(placeNodesAtAP) {
(assignment.hasRadius() ? Math.max(assignment.getRadius(), 25.0) : 25.0))); IAttractionPoint assignment = attractionAssigment.getAssignment(ms);
attractionAssigment.updateTargetAttractionPoint(ms, assignment); 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); setTimeBetweenMoveOperations(timeBetweenMoveOperation);
...@@ -173,7 +200,10 @@ public class SocialGroupMovementModel extends ModularMovementModel { ...@@ -173,7 +200,10 @@ public class SocialGroupMovementModel extends ModularMovementModel {
assert currentTargets.containsKey(host); assert currentTargets.containsKey(host);
// Single Host Movement // 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)); doLocalMovement(host, currentTargets.get(host));
} }
else if(groupContainer.isGroupMember(host)){ else if(groupContainer.isGroupMember(host)){
...@@ -194,6 +224,22 @@ public class SocialGroupMovementModel extends ModularMovementModel { ...@@ -194,6 +224,22 @@ public class SocialGroupMovementModel extends ModularMovementModel {
Event.scheduleWithDelay(timeBetweenMoveOperation, this, null, EVENT_MOVE); 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: * Applies movement of the host according to different circumstances:
* *
...@@ -272,6 +318,28 @@ public class SocialGroupMovementModel extends ModularMovementModel { ...@@ -272,6 +318,28 @@ public class SocialGroupMovementModel extends ModularMovementModel {
} }
@Override
public void changeTargetLocation(SimLocationActuator actuator, IAttractionPoint ap) {
if(singleHosts.contains(actuator)) {
attractionAssigment.updateTargetAttractionPoint(actuator, ap);
}
else {
groupAttractionAssignment.updateTargetAttractionPoint(actuator, ap);
}
}
@Override
public IAttractionPoint getTargetLocation(SimLocationActuator actuator) {
if(singleHosts.contains(actuator)) {
return attractionAssigment.getAssignment(actuator);
}
else {
return groupAttractionAssignment.getAssignment(actuator);
}
}
/* /*
* ===================================================================================================== * =====================================================================================================
* === MEETING POINT FUNCTIONS * === MEETING POINT FUNCTIONS
...@@ -376,7 +444,7 @@ public class SocialGroupMovementModel extends ModularMovementModel { ...@@ -376,7 +444,7 @@ public class SocialGroupMovementModel extends ModularMovementModel {
} }
public IAttractionAssigmentStrategy getAttractionAssignmentStrategy() { public IAttractionAssigmentStrategy getAttractionAssignmentStrategy() {
return attractionAssigment; return this.groupAttractionAssignment;
} }
public IGroupFormingBehavior getGroupFormingBehavior() { public IGroupFormingBehavior getGroupFormingBehavior() {
...@@ -398,4 +466,14 @@ public class SocialGroupMovementModel extends ModularMovementModel { ...@@ -398,4 +466,14 @@ public class SocialGroupMovementModel extends ModularMovementModel {
public LinkedHashMap<SimLocationActuator, PositionVector> getCurrentTargets(){ public LinkedHashMap<SimLocationActuator, PositionVector> getCurrentTargets(){
return currentTargets; return currentTargets;
} }
public void setGroupAttractionAssignmentStrategy(IAttractionAssigmentStrategy groupAttractionAssignment) {
if (groupAttractionAssignment == null) {
throw new ConfigurationException(
"IAttractionAssigmentStrategy for Groups is missing in SocialGroupMovementModel!");
}
this.groupAttractionAssignment = groupAttractionAssignment;
}
} }
...@@ -157,7 +157,7 @@ public class SocialMovementGroup { ...@@ -157,7 +157,7 @@ public class SocialMovementGroup {
@Override @Override
public String toString() { public String toString() {
return "Social Group of #" + leader.getHost().getId() + " ("+ members.size() +")"; return "Social Group of Leader #" + leader.getHost().getId() + " ("+ members.size() +")";
} }
......
...@@ -145,7 +145,7 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior { ...@@ -145,7 +145,7 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
} }
for(int g = 0; g < maxNumberOfGroups; g++) { for(int g = 0; g < maxNumberOfGroups; g++) {
long delay = Math.max(Time.MINUTE, (long) ((rand.nextDouble() * (Time.MINUTE * 45) + Time.MINUTE))); long delay = Math.max(Time.MINUTE, (long) ((rand.nextDouble() * (Time.MINUTE * 30) + Time.MINUTE)));
//System.out.println("("+g+") Init Group Formation Time " + Time.getFormattedTime(delay) ); //System.out.println("("+g+") Init Group Formation Time " + Time.getFormattedTime(delay) );
Event.scheduleWithDelay(delay, new EventHandler() { Event.scheduleWithDelay(delay, new EventHandler() {
......
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