Commit 1b07a2e6 authored by Julian Zobel's avatar Julian Zobel
Browse files

Monitor logs for errors at attraction points

parent a563c995
......@@ -208,7 +208,7 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent {
/* Real World Starting Time:
* Block till we're allowed to start.
*/
if( realWorldStartTime != null ) {
if(realWorldStartTime != null ) {
try {
......@@ -234,9 +234,13 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent {
finishedWithoutError = true;
} catch (RuntimeException e) {
finishedWithoutError = false;
finishedWithoutError = false;
reason = e;
throw e;
} finally {
this.running = false;
// After a simulation start the mechanisms, which
// finalize a simulation
......@@ -248,10 +252,18 @@ public class Simulator implements RandomGeneratorComponent, GlobalComponent {
this.running = false;
if (finishedWithoutError) {
Monitor.log(Simulator.class, Level.INFO,
"Simulation successfully finished...");
"Simulation successfully finished :)");
} else {
if(reason == null) {
Monitor.log(Simulator.class, Level.ERROR,
"Simulation finished with unresolved errors ???");
}
else {
Monitor.log(Simulator.class, Level.ERROR,
"Simulation finished with errors...\n" + reason);
"Simulation finished with errors :( \n " +
reason.toString() + " : " + reason.getStackTrace());
}
}
long runTime = System.currentTimeMillis() - startTime;
long minutes = (long) Math.floor((runTime) / 60000);
......
......@@ -71,6 +71,8 @@ public class AttractionPointImpl extends BasicAttractionPoint {
@Override
public boolean equals(Object obj) {
if(obj == null)
return false;
if (this == obj)
return true;
if (getClass() != obj.getClass())
......
......@@ -23,6 +23,7 @@ package de.tud.kom.p2psim.impl.topology.movement.modularosm.attraction;
import java.util.LinkedList;
import java.util.List;
import de.tudarmstadt.maki.simonstrator.api.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
/**
......@@ -33,10 +34,15 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Attraction
*/
public interface IAttractionGenerator {
public static LinkedList<AttractionPoint> attractionPoints = new LinkedList<>();
// TODO make this private in JAVA >= 9
static LinkedList<AttractionPoint> attractionPoints = new LinkedList<>();
public List<AttractionPoint> getAttractionPoints();
/**
* Remove an {@link AttractionPoint} from the list
* @param ap
*/
default void removeAttractionPoint(AttractionPoint ap) {
if(Monitor.hasAnalyzer(AttractionPointMonitor.class)) {
......@@ -46,8 +52,18 @@ public interface IAttractionGenerator {
attractionPoints.remove(ap);
}
/**
* Add an {@link AttractionPoint} to the list
* @param ap
*/
default void addAttractionPoint(AttractionPoint ap) {
if(ap == null) {
Monitor.log(IAttractionGenerator.class, Level.ERROR, "IAttractionGenerator: Tried to add NULL as Attraction Point");
return;
}
if(Monitor.hasAnalyzer(AttractionPointMonitor.class)) {
Monitor.getOrNull(AttractionPointMonitor.class).addedAttractionPoint(ap);
}
......
......@@ -28,6 +28,8 @@ import de.tud.kom.p2psim.impl.topology.util.PositionVector;
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.Monitor;
import de.tudarmstadt.maki.simonstrator.api.Monitor.Level;
import de.tudarmstadt.maki.simonstrator.api.Randoms;
import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.AttractionPoint;
import de.tudarmstadt.maki.simonstrator.api.util.XMLConfigurableConstructor;
......@@ -99,6 +101,10 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
return attractionPoints;
}
/**
*
* @return an integer representing a randomly chosen number of attraction points within the allowed range of numbers
*/
private int randomNumberOfAttractionPoints() {
return minNumberOfAttractionPoints + rand.nextInt((maxNumberOfAttractionPoints - minNumberOfAttractionPoints) + 1);
}
......@@ -157,8 +163,8 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
* @return
*/
private AttractionPoint createAttractionPoint() {
// make a break counter to prevent more than 10 iterations and an infinity loop in general.
int c = 20;
// make a break counter to prevent more than 100 iterations and an infinity loop in general.
int c = 100;
create: for(int i = 0; i < c; i++) {
PositionVector posVec = createPosVec();
......@@ -194,7 +200,13 @@ public class RandomDynamicAttractionGenerator implements IAttractionGenerator {
return aPoint;
}
return null;
AttractionPoint ap = new AttractionPointImpl("AP-ERROR", new PositionVector(worldDimension.getX() / 2, worldDimension.getY() / 2));
ap.setRadius(0);
ap.setWeight(0);
Monitor.log(RandomDynamicAttractionGenerator.class, Level.WARN, "RandomDynamicAttractionGenerator could not find a suitable location for a new attraction point within 100 iterations.");
return ap;
}
......
......@@ -119,21 +119,28 @@ public class InAreaRoamingTransitionStrategy extends AbstractAttractionBasedTran
}
private AttractionPoint getNewAttractionPoint(SimLocationActuator component) {
double score = rnd.nextDouble();
private AttractionPoint getNewAttractionPoint(SimLocationActuator component) {
double score = rnd.nextDouble();
List<AttractionPoint> candidates = new LinkedList<>();
for (AttractionPoint ap : IAttractionGenerator.attractionPoints) {
if(ap == null) {
continue;
}
if (ap.getWeight() >= score) {
if(lastAssignments.get(component) == null || !ap.equals(lastAssignments.get(component))) {
candidates.add(ap);
}
}
}
if (candidates.isEmpty()) {
candidates.addAll(IAttractionGenerator.attractionPoints);
}
AttractionPoint assignment = candidates.get(rnd.nextInt(candidates.size()));
return assignment;
return assignment;
}
}
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