Commit 67ebbf55 authored by Julian Zobel's avatar Julian Zobel
Browse files

Random attraction generator now also gives a randomly generated radius to all...

Random attraction generator now also gives a randomly generated radius to all APs. APs cannot have overlapping Radii
parent 5bf93e39
...@@ -24,6 +24,7 @@ import java.util.LinkedList; ...@@ -24,6 +24,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import de.tud.kom.p2psim.api.application.WorkloadListener;
import de.tud.kom.p2psim.api.scenario.ConfigurationException; import de.tud.kom.p2psim.api.scenario.ConfigurationException;
import de.tud.kom.p2psim.api.topology.Topology; import de.tud.kom.p2psim.api.topology.Topology;
import de.tud.kom.p2psim.impl.topology.util.PositionVector; import de.tud.kom.p2psim.impl.topology.util.PositionVector;
...@@ -90,23 +91,39 @@ public class RandomAttractionGenerator implements IAttractionGenerator { ...@@ -90,23 +91,39 @@ public class RandomAttractionGenerator implements IAttractionGenerator {
private void createAttractionPoints() { private void createAttractionPoints() {
List<AttractionPoint> result = new LinkedList<AttractionPoint>(); List<AttractionPoint> result = new LinkedList<AttractionPoint>();
// make a break counter to prevent more than 10 iterations and an infinity loop in general.
int c = 0;
create: for (int i = 0; i < numberOfAttractionPoints; i++) { create: for (int i = 0; i < numberOfAttractionPoints; i++) {
PositionVector posVec = createPosVec(); PositionVector posVec = createPosVec();
AttractionPoint aPoint = new AttractionPointImpl("AP-"+i, posVec);
// set the radius of this attraction point // set the radius of this attraction point
// minimum radius is 10 meters // minimum radius is 10 meters
aPoint.setRadius(Math.max(10, rand.nextDouble() * maximumRadius)); double radius = Math.max(10, rand.nextDouble() * maximumRadius);
for (AttractionPoint ap : result) { if(c < 20)
// if this point is closer than the given minimum distance to another point, or the radii of the points would overlap, {
// then discard this attraction point and create a new one for (AttractionPoint ap : result) {
if(aPoint.distanceTo(ap) < minimumDistance || (aPoint.distanceTo(ap) - aPoint.getRadius() - ap.getRadius()) < 0) { // if this point is closer than the given minimum distance to another point, or the radii of the points would overlap,
i--; // or if the radius would exceed the simulation area
continue create; // then discard this attraction point and create a new one
} if(posVec.distanceTo(ap) < minimumDistance || (posVec.distanceTo(ap) - radius - ap.getRadius()) < 0
|| posVec.getX() + radius > worldDimension.getX() || posVec.getY() + radius > worldDimension.getY()
|| posVec.getX() - radius < 0 || posVec.getY() - radius < 0) {
i--;
c++;
continue create;
}
}
} }
else
{
radius = 10;
}
AttractionPoint aPoint = new AttractionPointImpl("AP-"+i, posVec);
aPoint.setRadius(radius);
c = 0;
result.add(aPoint); result.add(aPoint);
} }
......
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