Commit 48af126d authored by Julian Zobel's avatar Julian Zobel
Browse files

Group Forming now uses the config values.

Fixed some errors with random value picking.
parent d4a3e7bd
......@@ -26,6 +26,7 @@ import java.util.List;
import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.impl.topology.movement.TracefileMovementModel;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.ModularMovementModel;
import de.tudarmstadt.maki.simonstrator.api.Host;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Oracle;
......@@ -101,7 +102,7 @@ public class MetricAnalyzer implements Analyzer {
System.out.println(" 60..120 >> " + TracefileMovementModel.SIXTY_TO_120);
System.out.println(" 120..300 >> " + TracefileMovementModel._120_TO_300);
System.out.println(" 300..600 >> " + TracefileMovementModel._300_TO_600);
System.out.println(" 600 ++ >> " + TracefileMovementModel.ABOVE_600);
System.out.println(" 600 ++ >> " + TracefileMovementModel.ABOVE_600);
}
/**
......
......@@ -35,6 +35,7 @@ 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.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.modularosm.attraction.AttractionPointViz;
import de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction.IAttractionGenerator;
......@@ -181,10 +182,9 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
attractionAssigment.addComponent(ms);
if(placeNodesAtAP) {
IAttractionPoint assignment = attractionAssigment.getAssignment(ms);
double apRadius = (assignment.hasRadius() ? Math.max(assignment.getRadius(), 25.0) : 25.0);
ms.updateCurrentLocation(this.addGaussianOffsetToPosition(new PositionVector(assignment), apRadius / 3));
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);
}
}
......@@ -258,7 +258,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
int tries = 0;
do {
destination = addGaussianOffsetToPosition(attractionCenter, apRadius / 3);
destination = addOffset(attractionCenter, apRadius);
// Check constraints
if (!checkBoundaries(destination)) {
destination = null;
......@@ -281,12 +281,33 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
Event.scheduleWithDelay(timeBetweenMoveOperation, this, null,
EVENT_MOVE);
}
public PositionVector addGaussianOffsetToPosition(PositionVector position, double std) {
/**
* Add a random gaussian offset to the given position. The offset will be within the given radius
* around the given position with a standard deviation of a third of the radius. Thus, the returned
* positions are more clustered around the position center.
*
* @param position
* @param radius
* @return
*/
public PositionVector addOffset(PositionVector position, double radius) {
/*
* This function will use a gaussian offset from the center. Most values are therefore more clustered around the position,
* only a few on the outskirts of the circle.
*
* For a uniform distribution, see for example https://stackoverflow.com/a/50746409
*/
PositionVector offsetPosition = new PositionVector(position);
// Gaussian with std = 1 --> >99% of nodes
PositionVector offset = new PositionVector(rand.nextGaussian() * std, rand.nextGaussian() * std);
double rad = Math.min(rand.nextGaussian() * radius / 3, radius);
double angle = rand.nextDouble() * 2 * Math.PI;
PositionVector offset = new PositionVector(rad * Math.cos(angle), rad * Math.sin(angle));
offsetPosition.add(offset);
return offsetPosition;
}
......@@ -324,13 +345,7 @@ public class ModularMovementModel implements MovementModel, EventHandler, Attrac
*
*/
public boolean checkBoundaries(PositionVector position) {
if(position.getX() >= 0.0
&& position.getX() <= Binder.getComponentOrNull(Topology.class).getWorldDimensions().getX()
&& position.getY() >= 0.0
&& position.getY() <= Binder.getComponentOrNull(Topology.class).getWorldDimensions().getY())
return true;
else
return false;
return DefaultTopology.isWithinWorldBoundaries(position);
}
@Override
......
......@@ -113,9 +113,8 @@ public class SocialGroupMovementModel extends ModularMovementModel {
attractionAssigment.addComponent(ms);
if(placeNodesAtAP) {
IAttractionPoint assignment = attractionAssigment.getAssignment(ms);
double apRadius = (assignment.hasRadius() ? Math.max(assignment.getRadius(), 25.0) : 25.0);
ms.updateCurrentLocation(this.addGaussianOffsetToPosition(new PositionVector(assignment), apRadius / 3));
ms.updateCurrentLocation(this.addOffset(new PositionVector(assignment),
(assignment.hasRadius() ? Math.max(assignment.getRadius(), 25.0) : 25.0)));
attractionAssigment.updateTargetAttractionPoint(ms, assignment);
}
}
......
......@@ -57,8 +57,9 @@ public class Wait extends AbstractGroupEncounter{
}
protected long getRandomWaitTime() {
return (long) Math.max(Time.MINUTE, (rand.nextDouble() + 0.5) * timeToWait);
}
return (long) (rand.nextDouble() * (timeToWait + 1 - Time.MINUTE ) + Time.MINUTE);
}
/*
* GETTERS AND SETTERS
......
......@@ -42,22 +42,24 @@ public class WaitSmartMerge extends Wait{
@Override
public void handleGroupEncounter(SocialMovementGroup group1, SocialMovementGroup group2) {
long pauseTime = getRandomWaitTime();
if(groupCon.waitingGroups.containsKey(group1) && !groupCon.waitingGroups.containsKey(group2)) {
pauseTime = getRemainingGroupWaitTime(group1);
}
else if(!groupCon.waitingGroups.containsKey(group1) && groupCon.waitingGroups.containsKey(group2)) {
pauseTime = getRemainingGroupWaitTime(group2);
}
if(group1.getLeader().getCurrentTargetAttractionPoint() == group2.getLeader().getCurrentTargetAttractionPoint()) {
SocialMovementGroup merged = mergeGroupsFully(group1, group2);
wait(merged, pauseTime);
wait(merged, Time.MINUTE);
}
else if(decide() == DECISION_WAIT) {
else if(decide() == DECISION_WAIT) {
long pauseTime = 0;
if(groupCon.waitingGroups.containsKey(group1) && !groupCon.waitingGroups.containsKey(group2)) {
pauseTime = getRemainingGroupWaitTime(group1);
}
else if(!groupCon.waitingGroups.containsKey(group1) && groupCon.waitingGroups.containsKey(group2)) {
pauseTime = getRemainingGroupWaitTime(group2);
}
else {
pauseTime = getRandomWaitTime();
}
wait(group1, pauseTime);
wait(group2, pauseTime);
}
......
......@@ -137,22 +137,10 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
for(SimLocationActuator host : movementModel.getAllLocationActuators()) {
stayDuration.put(host.getHost().getId(), new Tuple<Long, Long>(0L, Time.getCurrentTime()));
}
for(int g = 0; g < 20; g++) {
// FIXME random Gauß distribution?
long std = (long) (4.3 * Time.MINUTE);
long mean = (long) (7.38 * Time.MINUTE);
long delay = (long) (rand.nextGaussian() * std + mean);
delay = (long) ((rand.nextDouble() * (Time.MINUTE * 45) + Time.MINUTE));
if(delay < Time.MINUTE) {
delay = Time.MINUTE;
}
// System.out.println(Time.getFormattedTime(delay) );
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) );
Event.scheduleWithDelay(delay, new EventHandler() {
@Override
......@@ -194,8 +182,8 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
return minGroupSize;
else {
// int groupsize = (int) Math.max(1, rand.nextGaussian() * 0.93 + 2.76);
int groupsize = rand.nextInt(5) + 1;
System.out.println(groupsize);
int groupsize = rand.nextInt(maxGroupSize - minGroupSize + 1) + minGroupSize;
System.out.println("[AbstractGroupForming] Group Size: " + groupsize + " ("+minGroupSize+"/"+maxGroupSize+")");
return groupsize;
}
//return rand.nextInt(maxGroupSize - minGroupSize) + minGroupSize;
......@@ -215,7 +203,7 @@ public abstract class AbstractGroupForming implements IGroupFormingBehavior {
IAttractionPoint targetDestination = movementModel.getAttractionAssignmentStrategy().getAssignment(group.getLeader());
// Add Offset to group destination
PositionVector destination = movementModel.addGaussianOffsetToPosition(new PositionVector(targetDestination),
PositionVector destination = movementModel.addOffset(new PositionVector(targetDestination),
targetDestination.getRadius() / 3);
group.setDestination(destination);
......
......@@ -80,8 +80,10 @@ public class AttractionPointRoamingStrategy extends AbstractAttractionBasedAssig
}
this.roamingStates.put(comp, roamingTransitionState.PAUSE);
// schedule roaming
Event.scheduleWithDelay(getPauseTime(attractionPoint), this, comp, 0);
long roamingPauseTime = (long) (rnd.nextDouble() * Time.MINUTE * 5) + Time.MINUTE * 5;
Event.scheduleWithDelay(roamingPauseTime, this, comp, 0);
}
private void roamAroundAttractionPoint(SimLocationActuator comp) {
......
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