24.09., 9:00 - 11:00: Due to updates GitLab will be unavailable for some minutes between 09:00 and 11:00.

Commit 9fe754e4 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

add checkUnusedTargets check

parent 20745e6e
......@@ -306,7 +306,7 @@ TopographyChecker.source.noTargetIdAndNoSpawn=No Target Ids set for Source with
TopographyChecker.source.idNotUnique=Multiple Sources have the same ID.
TopographyChecker.source.overlapWithObstacle=Source overlaps with Obstacle. This leads to pedestrians spawn in obstacle.
#TopographyChecker.stairs.wrongTreadDim"=
#TopographyChecker.target.unused=
TopographyChecker.target.unused=The target is not used in any source. Remove target to increase performance.
#TopographyChecker.obstacles.overlap=
#TopographyChecker.source.overlap=
#TopographyChecker.target.overlap=
......
......@@ -303,9 +303,9 @@ TopographyChecker.source.targetIdNotFound=Die folgenden Ziel-IDs wurden nicht im
TopographyChecker.source.noTargetIdSet=In der Quelle wurden keine Ziel Ids vergeben.
TopographyChecker.source.noTargetIdAndNoSpawn=In der Quelle wurden keine Ziel Ids vergeben, aber die Spawn Anzahl ist bei 0.
TopographyChecker.source.idNotUnique=Quellen haben keine eindeutige ID.
TopographyChecker.source.overlapWithObstacle=Source overlaps with Obstacle. This leads to pedestrians spawn in obstacle.
TopographyChecker.source.overlapWithObstacle=Quelle und Hinderniss \u00fcberlappen sich. Dies kann f\u00fcrt zuf\u00fchren, dass Personen im Hinderniss erzeugt werden.
#TopographyChecker.stairs.wrongTreadDim"=
#TopographyChecker.target.unused=
TopographyChecker.target.unused=Das Ziel wird von keiner Quelle verwendet. Entferne das Ziel um die Performance zu erh\u00fchen
#TopographyChecker.obstacles.overlap=
#TopographyChecker.source.overlap=
#TopographyChecker.target.overlap=
......
......@@ -108,8 +108,6 @@ public class ActionTopographyCheckerMenu extends TopographyAction implements Obs
private void msgToDocString(StringBuilder sb, TopographyCheckerMessage msg, MsgDocument doc) {
sb.append(Messages.getString(msg.getMsgType().getLocalTypeId())).append(": ");
sb.append("[");
msg.getMsgTarget().getTargets().forEach(t -> {
doc.makeLink(t, sb);
......
......@@ -67,9 +67,30 @@ public class TopographyChecker {
ret.addAll(checkValidTargetsInSource());
ret.addAll(checkUniqueSourceId());
ret.addAll(checkSourceObstacleOverlap());
ret.addAll(checkUnusedTargets());
return ret;
}
public List<TopographyCheckerMessage> checkUnusedTargets() {
List<TopographyCheckerMessage> ret = new ArrayList<>();
Set<Integer> usedTargetIds = new HashSet<>();
topography.getSources()
.forEach(s -> usedTargetIds.addAll(s.getAttributes().getTargetIds()));
topography.getTargets().forEach(t -> {
if (!usedTargetIds.contains(t.getId())){
ret.add(msgBuilder
.warning()
.reason(TopographyCheckerReason.TARGET_UNUSED)
.target(t)
.build());
}
});
return ret;
}
public List<TopographyCheckerMessage> checkValidTargetsInSource() {
List<TopographyCheckerMessage> ret = new ArrayList<>();
Set<Integer> targetIds = topography.getTargets().stream()
......
......@@ -151,7 +151,7 @@ public class TopographyCheckerTest {
assertEquals(1, out.size());
assertEquals(TopographyCheckerReason.SOURCE_NO_TARGET_ID_SET, out.get(0).getReason());
assertEquals(TopographyCheckerMessageType.ERROR, out.get(0).getMsgType());
isErrorMsg(out.get(0));
}
......@@ -174,7 +174,7 @@ public class TopographyCheckerTest {
assertEquals(1, out.size());
assertEquals(TopographyCheckerReason.SOURCE_TARGET_ID_NOT_FOUND, out.get(0).getReason());
assertEquals(TopographyCheckerMessageType.ERROR, out.get(0).getMsgType());
isErrorMsg(out.get(0));
}
@Test
......@@ -200,7 +200,7 @@ public class TopographyCheckerTest {
assertEquals(1, out.size());
assertEquals(TopographyCheckerReason.SOURCE_TARGET_ID_NOT_FOUND, out.get(0).getReason());
assertEquals(TopographyCheckerMessageType.ERROR, out.get(0).getMsgType());
isErrorMsg(out.get(0));
assertEquals("[2]", out.get(0).getReasonModifier());
}
......@@ -279,12 +279,63 @@ public class TopographyCheckerTest {
TopographyCheckerMessage msg = out.get(0);
assertEquals( 1, out.size());
assertEquals(TopographyCheckerMessageType.ERROR, msg.getMsgType());
isErrorMsg(msg);
assertEquals(TopographyCheckerReason.SOURCE_OVERLAP_WITH_OBSTACLE, msg.getReason());
assertEquals(testSource, msg.getMsgTarget().getTargets().get(0));
assertEquals(testObstacle, msg.getMsgTarget().getTargets().get(1));
}
// Test checkUnusedTargets
@Test
public void testCheckUnusedTargetsWithNoError(){
AttributesSourceBuilder attrSourceB = AttributesSourceBuilder.anAttributesSource();
builder.addSource(attrSourceB.targetIds(1,2).build());
builder.addSource(attrSourceB.targetIds(3).build());
builder.addTarget(1);
builder.addTarget(2);
builder.addTarget(3);
Topography topography = builder.build();
TopographyChecker checker = new TopographyChecker(topography);
List<TopographyCheckerMessage> out = checker.checkUnusedTargets();
assertEquals(0, out.size());
}
@Test
public void testCheckUnusedTargetsWithError(){
AttributesSourceBuilder attrSourceB = AttributesSourceBuilder.anAttributesSource();
builder.addSource(attrSourceB.targetIds(1,2).build());
builder.addTarget(1);
builder.addTarget(2);
builder.addTarget(3);
Topography topography = builder.build();
TopographyChecker checker = new TopographyChecker(topography);
List<TopographyCheckerMessage> out = checker.checkUnusedTargets();
assertEquals(1, out.size());
TopographyCheckerMessage msg = out.get(0);
isWarnMsg(msg);
assertEquals(TopographyCheckerReason.TARGET_UNUSED, msg.getReason());
}
private void isErrorMsg(TopographyCheckerMessage msg){
assertEquals(TopographyCheckerMessageType.ERROR, msg.getMsgType());
}
private void isWarnMsg(TopographyCheckerMessage msg){
assertEquals(TopographyCheckerMessageType.WARN, msg.getMsgType());
}
}
\ No newline at end of file
......@@ -82,6 +82,11 @@ public final class AttributesSourceBuilder {
return this;
}
public AttributesSourceBuilder targetIds(Integer... targetIds) {
this.targetIds = Arrays.asList(targetIds);
return this;
}
public AttributesSourceBuilder groupSizeDistribution(List<Double> groupSizeDistribution) {
this.groupSizeDistribution = groupSizeDistribution;
return this;
......
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