Commit d2e0cbd7 authored by Sebastian Vollbrecht's avatar Sebastian Vollbrecht

Added tests for the infeasible node placement.

Also renamed some classes again.
parent b7ee28b1
......@@ -40,7 +40,7 @@ import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.stream.IntStream;
public class InfeasibleCycleEdgePlanner implements Initializable {
public class InfeasibleEdgePlanner implements Initializable {
private final StartConfiguration startCfg;
private final InfeasibleConfiguration infeasibleCfg;
......@@ -48,8 +48,8 @@ public class InfeasibleCycleEdgePlanner implements Initializable {
private SeededRandom rng;
public InfeasibleCycleEdgePlanner(StartConfiguration startCfg, InfeasibleConfiguration infeasibleCfg,
SuffixConfiguration suffixCfg) {
public InfeasibleEdgePlanner(StartConfiguration startCfg, InfeasibleConfiguration infeasibleCfg,
SuffixConfiguration suffixCfg) {
this.startCfg = startCfg;
this.infeasibleCfg = infeasibleCfg;
this.suffixCfg = suffixCfg;
......
......@@ -164,7 +164,7 @@ public class InfeasibleMinIIProperty extends Property {
* either be the destination node or a zero node of the previous layer.
* Also create an incoming edge for every suffix node.
*/
InfeasibleCycleEdgePlanner edgePlanner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner edgePlanner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
edgePlanner.init(rng);
Set<PlannedEdge> plannedEdges = edgePlanner.getIncomingEdges();
......@@ -187,7 +187,7 @@ public class InfeasibleMinIIProperty extends Property {
*/
if (lastEdgeRepresentative.isPresent()) {
Map<ResourceNode, PlannedEdge> outgoingEdgesByNode = InfeasibleCycleEdgePlanner
Map<ResourceNode, PlannedEdge> outgoingEdgesByNode = InfeasibleEdgePlanner
.getOutgoingEdgesMap(plannedEdges, suffixCfg.getSuffixNodes());
int firstSuffixSlot = problematicTimeslot + infeasibleCfg
......@@ -388,7 +388,7 @@ public class InfeasibleMinIIProperty extends Property {
* could be replaced by zero nodes if a lower problematic node required one to
* be placed in the respective layer.
*/
InfeasibleCycleNodePlacer placer = new InfeasibleCycleNodePlacer(startCfg, infeasibleCfg);
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg);
placer.init(rng);
for (ResourceNode problematicNode : JavaUtils.asSortedList(infeasibleCfg.getProblematicNodes(), Comparator
......
......@@ -31,20 +31,26 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
public class InfeasibleCycleNodePlacer implements Initializable {
public class InfeasibleNodePlacer implements Initializable {
private final StartConfiguration startCfg;
private final InfeasibleConfiguration infeasibleCfg;
private SeededRandom rng;
public InfeasibleCycleNodePlacer(StartConfiguration startCfg, InfeasibleConfiguration infeasibleCfg) {
public InfeasibleNodePlacer(StartConfiguration startCfg, InfeasibleConfiguration infeasibleCfg) {
this.startCfg = startCfg;
this.infeasibleCfg = infeasibleCfg;
}
public Set<Integer> getPossibleLayers(ResourceNode problematicNode) {
if (!infeasibleCfg.getProblematicNodes().contains(problematicNode)) {
throw new IllegalArgumentException("Node " + problematicNode + " is not problematic.");
} else if (infeasibleCfg.getFixedNodes().contains(problematicNode)) {
throw new IllegalArgumentException("Node " + problematicNode + " has been fixed already.");
}
int remainingZeroNodes = infeasibleCfg.getRemainingZeroNodes().size();
Set<Integer> possibleLayers = new HashSet<>();
......@@ -147,6 +153,14 @@ public class InfeasibleCycleNodePlacer implements Initializable {
public void placeNode(ResourceNode problematicNode, Set<Integer> possibleLayers) {
if (possibleLayers.isEmpty()) {
throw new IllegalArgumentException("Possible layers must be non-empty.");
} else if (possibleLayers.stream().anyMatch(l -> l <= startCfg.getDestinationNodeLayer())) {
throw new IllegalArgumentException("Possible layers must be greater than the destination node's layer.");
} else if (!infeasibleCfg.getProblematicNodes().contains(problematicNode)) {
throw new IllegalArgumentException("Only problematic nodes must be placed in problematic spots.");
}
boolean useCurrentLayer = possibleLayers.contains(infeasibleCfg.getLayers().getDepth(problematicNode.getId()));
/*
......@@ -212,7 +226,6 @@ public class InfeasibleCycleNodePlacer implements Initializable {
}
}
@Override
public void init(SeededRandom rng) {
this.rng = rng;
......
......@@ -82,7 +82,7 @@ public class InfeasibilityInspectorTest {
infeasibleCfg.fixateNode(node2);
// Now try to place node 6 in different target layers.
InfeasibleCycleNodePlacer placer = new InfeasibleCycleNodePlacer(startCfg, infeasibleCfg);
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg);
assertEquals(JavaUtils.asSet(1, 2, 3, 4), placer.getPossibleLayers(node6));
// Now assume that node 6 has been fixed already - locking zero nodes 3 and 4 in place as well.
......@@ -139,7 +139,7 @@ public class InfeasibilityInspectorTest {
infeasibleCfg.fixateNode(node3);
// Now try to place node 2 in different target layers.
InfeasibleCycleNodePlacer placer = new InfeasibleCycleNodePlacer(startCfg, infeasibleCfg);
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg);
assertEquals(JavaUtils.asSet(2, 3, 4), placer.getPossibleLayers(node2));
// Now assume that node 6 has been fixed again - locking zero node 4 in place as well.
......@@ -197,7 +197,7 @@ public class InfeasibilityInspectorTest {
infeasibleCfg.fixateNode(node3);
// Now try to place node 2 in different target layers.
InfeasibleCycleNodePlacer placer = new InfeasibleCycleNodePlacer(startCfg, infeasibleCfg);
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg);
assertTrue(placer.getPossibleLayers(node2).isEmpty());
// Now assume that node 6 has been fixed again - locking zero node 4 in place as well.
......@@ -261,7 +261,7 @@ public class InfeasibilityInspectorTest {
// Assume that node 3 is a problematic destination node.
infeasibleCfg.fixateNode(node3);
InfeasibleCycleNodePlacer placer = new InfeasibleCycleNodePlacer(startCfg, infeasibleCfg);
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg);
try {
placer.getPossibleLayers(null);
......
......@@ -41,7 +41,7 @@ import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class InfeasibleCycleEdgePlannerTest {
public class InfeasibleEdgePlannerTest {
@Test
public void getProblematicTimeslots_ZeroDelay() {
......@@ -96,7 +96,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
// Calculate possible timeslots for the problematic nodes (relative to the destination node).
......@@ -167,7 +167,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
// Calculate possible timeslots for the problematic nodes (relative to the destination node).
......@@ -230,7 +230,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
// The problematic timeslot cannot be anything else but 2.
......@@ -294,7 +294,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
// Calculate possible timeslots for the problematic nodes (relative to the destination node).
......@@ -361,7 +361,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
// Calculate possible timeslots for the problematic nodes (relative to the destination node).
......@@ -428,7 +428,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
PlannedEdge edge3_4 = new PlannedEdge(node3, node4, 0, 0);
......@@ -500,7 +500,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
PlannedEdge edge3_4 = new PlannedEdge(node3, node4, 0, 0);
......@@ -571,7 +571,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
PlannedEdge edge3_4 = new PlannedEdge(node3, node4, 0, 0);
......@@ -638,7 +638,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
PlannedEdge edge3_4 = new PlannedEdge(node3, node4, 0, 0);
......@@ -709,7 +709,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
PlannedEdge edge3_4 = new PlannedEdge(node3, node4, 0, 0);
......@@ -786,7 +786,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
PlannedEdge edge2_5 = new PlannedEdge(node2, node5, 0, 0);
......@@ -874,7 +874,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
PlannedEdge edge3_4 = new PlannedEdge(node3, node4, 0, 0);
......@@ -953,7 +953,7 @@ public class InfeasibleCycleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);
backedgeSources.forEach(suffixCfg::addBackedgeSource);
InfeasibleCycleEdgePlanner planner = new InfeasibleCycleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
InfeasibleEdgePlanner planner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
planner.init(new SeededRandom(42));
PlannedEdge edge3_4 = new PlannedEdge(node3, node4, 0, 0);
......
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