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);
......
/*
* Copyright 2018 Sebastian Vollbrecht, Julian Oppermann
* Embedded Systems and Applications Group, TU Darmstadt
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package graphgen.generator.components.properties.infeasibleMinII;
import graphgen.datastructures.SeededRandom;
import graphgen.generator.components.properties.infeasibleMinII.configuration.InfeasibleConfiguration;
import graphgen.generator.components.properties.infeasibleMinII.configuration.StartConfiguration;
import graphgen.graph.LayerStructure;
import graphgen.graph.Resource;
import graphgen.graph.ResourceNode;
import graphgen.util.JavaUtils;
import modsched.Node;
import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class InfeasibleNodePlacerTest {
@Test
public void getPossibleLayers_NonZeroDelay() {
Resource problematic = new Resource("problematic", 2, 2);
Resource unlimited = new Resource("unlimited", 0);
Map<Integer, Integer> depthsByID = new HashMap<>();
depthsByID.put(2, 0);
depthsByID.put(3, 1);
depthsByID.put(4, 2);
depthsByID.put(5, 2);
depthsByID.put(6, 3);
depthsByID.put(7, 3);
depthsByID.put(8, 4);
depthsByID.put(9, 5);
LayerStructure layers = new LayerStructure(depthsByID);
ResourceNode node2 = new ResourceNode(2, unlimited);
ResourceNode node3 = new ResourceNode(3, unlimited);
ResourceNode node4 = new ResourceNode(4, problematic);
ResourceNode node5 = new ResourceNode(5, unlimited);
ResourceNode node6 = new ResourceNode(6, problematic);
ResourceNode node7 = new ResourceNode(7, unlimited);
ResourceNode node8 = new ResourceNode(8, problematic);
ResourceNode node9 = new ResourceNode(9, unlimited);
Set<ResourceNode> nodes = JavaUtils.asSet(node2, node3, node4, node5, node6, node7, node8, node9);
Map<Integer, ResourceNode> nodeTable = nodes.stream().collect(Collectors.toMap(Node::getId, n -> n));
/* Assume a MinII of 5 with the RecMinII-ensuring backedge having a delay of 1 and a distance of 1.*/
StartConfiguration startCfg = new StartConfiguration(layers, nodeTable, problematic, 4);
startCfg.setDestinationNode(node3);
startCfg.setDestinationNodeLayer(1);
InfeasibleConfiguration infeasibleCfg = new InfeasibleConfiguration(startCfg);
infeasibleCfg.addProblematicNode(node4);
infeasibleCfg.addProblematicNode(node6);
infeasibleCfg.addProblematicNode(node8);
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg);
placer.init(new SeededRandom(42));
infeasibleCfg.fixateNode(node3);
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node4));
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node6));
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node8));
infeasibleCfg.fixateNode(node6);
infeasibleCfg.fixateNode(node5);
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node4));
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node8));
infeasibleCfg.fixateNode(node8);
infeasibleCfg.fixateNode(node7);
assertEquals(JavaUtils.asSet(2), placer.getPossibleLayers(node4));
}
@Test
public void getPossibleLayers_NonZeroDelay_WithSwap() {
Resource problematic = new Resource("problematic", 2, 2);
Resource unlimited = new Resource("unlimited", 0);
Map<Integer, Integer> depthsByID = new HashMap<>();
depthsByID.put(2, 0);
depthsByID.put(3, 1);
depthsByID.put(4, 2);
depthsByID.put(5, 2);
depthsByID.put(6, 3);
depthsByID.put(7, 3);
depthsByID.put(8, 4);
depthsByID.put(9, 5);
LayerStructure layers = new LayerStructure(depthsByID);
ResourceNode node2 = new ResourceNode(2, unlimited);
ResourceNode node3 = new ResourceNode(3, unlimited);
ResourceNode node4 = new ResourceNode(4, problematic);
ResourceNode node5 = new ResourceNode(5, unlimited);
ResourceNode node6 = new ResourceNode(6, problematic);
ResourceNode node7 = new ResourceNode(7, unlimited);
ResourceNode node8 = new ResourceNode(8, problematic);
ResourceNode node9 = new ResourceNode(9, unlimited);
Set<ResourceNode> nodes = JavaUtils.asSet(node2, node3, node4, node5, node6, node7, node8, node9);
Map<Integer, ResourceNode> nodeTable = nodes.stream().collect(Collectors.toMap(Node::getId, n -> n));
/* Assume a MinII of 5 with the RecMinII-ensuring backedge having a delay of 1 and a distance of 1.*/
StartConfiguration startCfg = new StartConfiguration(layers, nodeTable, problematic, 4);
startCfg.setDestinationNode(node3);
startCfg.setDestinationNodeLayer(1);
InfeasibleConfiguration infeasibleCfg = new InfeasibleConfiguration(startCfg);
infeasibleCfg.addProblematicNode(node4);
infeasibleCfg.addProblematicNode(node6);
infeasibleCfg.addProblematicNode(node8);
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg);
placer.init(new SeededRandom(42));
infeasibleCfg.fixateNode(node3);
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node4));
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node6));
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node8));
infeasibleCfg.fixateNode(node6);
infeasibleCfg.fixateNode(node5);
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node4));
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node8));
layers.swapIDs(7, 8);
infeasibleCfg.fixateNode(node8);
assertEquals(JavaUtils.asSet(2), placer.getPossibleLayers(node4));
}
@Test
public void getPossibleLayers_NonZeroDelay_ThreeResources() {
Resource problematic = new Resource("problematic", 2, 2);
Resource delayed = new Resource("delayed", 10);
Resource unlimited = new Resource("unlimited", 0);
Map<Integer, Integer> depthsByID = new HashMap<>();
depthsByID.put(2, 0);
depthsByID.put(3, 1);
depthsByID.put(4, 2);
depthsByID.put(5, 2);
depthsByID.put(6, 3);
depthsByID.put(7, 3);
depthsByID.put(8, 4);
depthsByID.put(9, 5);
LayerStructure layers = new LayerStructure(depthsByID);
ResourceNode node2 = new ResourceNode(2, unlimited);
ResourceNode node3 = new ResourceNode(3, unlimited);
ResourceNode node4 = new ResourceNode(4, problematic);
ResourceNode node5 = new ResourceNode(5, delayed);
ResourceNode node6 = new ResourceNode(6, problematic);
ResourceNode node7 = new ResourceNode(7, delayed);
ResourceNode node8 = new ResourceNode(8, problematic);
ResourceNode node9 = new ResourceNode(9, delayed);
Set<ResourceNode> nodes = JavaUtils.asSet(node2, node3, node4, node5, node6, node7, node8, node9);
Map<Integer, ResourceNode> nodeTable = nodes.stream().collect(Collectors.toMap(Node::getId, n -> n));
/* Assume a MinII of 5 with the RecMinII-ensuring backedge having a delay of 1 and a distance of 1.*/
StartConfiguration startCfg = new StartConfiguration(layers, nodeTable, problematic, 4);
startCfg.setDestinationNode(node3);
startCfg.setDestinationNodeLayer(1);
InfeasibleConfiguration infeasibleCfg = new InfeasibleConfiguration(startCfg);
infeasibleCfg.addProblematicNode(node4);
infeasibleCfg.addProblematicNode(node6);
infeasibleCfg.addProblematicNode(node8);
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg);
placer.init(new SeededRandom(42));
infeasibleCfg.fixateNode(node3);
assertEquals(JavaUtils.asSet(2, 3), placer.getPossibleLayers(node4));
assertEquals(JavaUtils.asSet(2, 3), placer.getPossibleLayers(node6));
assertEquals(JavaUtils.asSet(2, 3), placer.getPossibleLayers(node8));
infeasibleCfg.fixateNode(node6);
layers.swapIDs(2, 5);
infeasibleCfg.fixateNode(node2);
assertEquals(JavaUtils.asSet(2, 3), placer.getPossibleLayers(node4));
assertEquals(JavaUtils.asSet(2, 3), placer.getPossibleLayers(node8));
layers.swapIDs(7, 8);
infeasibleCfg.fixateNode(node8);
assertEquals(JavaUtils.asSet(2), placer.getPossibleLayers(node4));
}
@Test
public void getPossibleLayers_ZeroDelay() {
Resource problematic = new Resource("problematic", 0, 2);
Resource unlimited = new Resource("unlimited", 0);
Map<Integer, Integer> depthsByID = new HashMap<>();
depthsByID.put(2, 0);
depthsByID.put(3, 1);
depthsByID.put(4, 2);
depthsByID.put(5, 2);
depthsByID.put(6, 3);
depthsByID.put(7, 3);
depthsByID.put(8, 4);
depthsByID.put(9, 5);
LayerStructure layers = new LayerStructure(depthsByID);
ResourceNode node2 = new ResourceNode(2, unlimited);
ResourceNode node3 = new ResourceNode(3, unlimited);
ResourceNode node4 = new ResourceNode(4, problematic);
ResourceNode node5 = new ResourceNode(5, unlimited);
ResourceNode node6 = new ResourceNode(6, problematic);
ResourceNode node7 = new ResourceNode(7, unlimited);
ResourceNode node8 = new ResourceNode(8, problematic);
ResourceNode node9 = new ResourceNode(9, unlimited);
Set<ResourceNode> nodes = JavaUtils.asSet(node2, node3, node4, node5, node6, node7, node8, node9);
Map<Integer, ResourceNode> nodeTable = nodes.stream().collect(Collectors.toMap(Node::getId, n -> n));
/* Assume a MinII of 5 with the RecMinII-ensuring backedge having a delay of 1 and a distance of 1.*/
StartConfiguration startCfg = new StartConfiguration(layers, nodeTable, problematic, 4);
startCfg.setDestinationNode(node3);
startCfg.setDestinationNodeLayer(1);
InfeasibleConfiguration infeasibleCfg = new InfeasibleConfiguration(startCfg);
infeasibleCfg.addProblematicNode(node4);
infeasibleCfg.addProblematicNode(node6);
infeasibleCfg.addProblematicNode(node8);
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg);
placer.init(new SeededRandom(42));
infeasibleCfg.fixateNode(node3);
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node4));
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node6));
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node8));
infeasibleCfg.fixateNode(node6);
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node4));
assertEquals(JavaUtils.asSet(2, 3, 4, 5), placer.getPossibleLayers(node8));
infeasibleCfg.fixateNode(node8);
assertEquals(JavaUtils.asSet(2, 3, 5), placer.getPossibleLayers(node4));
}
@Test
public void getPossibleLayers_ZeroDelay_ProblematicDestinationNode() {
Resource problematic = new Resource("problematic", 0, 2);
Resource unlimited = new Resource("unlimited", 0);
Map<Integer, Integer> depthsByID = new HashMap<>();
depthsByID.put(2, 0);
depthsByID.put(3, 1);
depthsByID.put(4, 2);
depthsByID.put(5, 2);
depthsByID.put(6, 3);
depthsByID.put(7, 3);
depthsByID.put(8, 4);
depthsByID.put(9, 5);
LayerStructure layers = new LayerStructure(depthsByID);
ResourceNode node2 = new ResourceNode(2, unlimited);
ResourceNode node3 = new ResourceNode(3, unlimited);
ResourceNode node4 = new ResourceNode(4, problematic);
ResourceNode node5 = new ResourceNode(5, unlimited);
ResourceNode node6 = new ResourceNode(6, problematic);
ResourceNode node7 = new ResourceNode(7, unlimited);
ResourceNode node8 = new ResourceNode(8, problematic);
ResourceNode node9 = new ResourceNode(9, unlimited);
Set<ResourceNode> nodes = JavaUtils.asSet(node2, node3, node4, node5, node6, node7, node8, node9);
Map<Integer, ResourceNode> nodeTable = nodes.stream().collect(Collectors.toMap(Node::getId, n -> n));
/* Assume a MinII of 5 with the RecMinII-ensuring backedge having a delay of 1 and a distance of 1.*/
StartConfiguration startCfg = new StartConfiguration(layers, nodeTable, problematic, 4);
startCfg.setDestinationNode(node4);
startCfg.setDestinationNodeLayer(2);
InfeasibleConfiguration infeasibleCfg = new InfeasibleConfiguration(startCfg);
infeasibleCfg.addProblematicNode(node4);
infeasibleCfg.addProblematicNode(node6);
infeasibleCfg.addProblematicNode(node8);
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg);
placer.init(new SeededRandom(42));
infeasibleCfg.fixateNode(node4);
assertEquals(JavaUtils.asSet(3, 4), placer.getPossibleLayers(node6));
assertEquals(JavaUtils.asSet(3, 4), placer.getPossibleLayers(node8));
infeasibleCfg.fixateNode(node6);
assertEquals(JavaUtils.asSet(3, 4), placer.getPossibleLayers(node8));
}
@Test
public void placeNode_ProblematicDestinationNode() {
Resource problematic = new Resource("problematic", 0, 2);
Resource unlimited = new Resource("unlimited", 0);
Map<Integer, Integer> depthsByID = new HashMap<>();
depthsByID.put(2, 0);
depthsByID.put(3, 1);
depthsByID.put(4, 2);
depthsByID.put(5, 2);
depthsByID.put(6, 3);
depthsByID.put(7, 3);
depthsByID.put(8, 4);
depthsByID.put(9, 5);
LayerStructure layers = new LayerStructure(depthsByID);
ResourceNode node2 = new ResourceNode(2, unlimited);
ResourceNode node3 = new ResourceNode(3, unlimited);
ResourceNode node4 = new ResourceNode(4, problematic);
ResourceNode node5 = new ResourceNode(5, unlimited);
ResourceNode node6 = new ResourceNode(6, problematic);
ResourceNode node7 = new ResourceNode(7, unlimited);
ResourceNode node8 = new ResourceNode(8, problematic);
ResourceNode node9 = new ResourceNode(9, unlimited);
Set<ResourceNode> nodes = JavaUtils.asSet(node2, node3, node4, node5, node6, node7, node8, node9);
Map<Integer, ResourceNode> nodeTable = nodes.stream().collect(Collectors.toMap(Node::getId, n -> n));
/* Assume a MinII of 5 with the RecMinII-ensuring backedge having a delay of 1 and a distance of 1.*/
StartConfiguration startCfg = new StartConfiguration(layers, nodeTable, problematic, 4);
startCfg.setDestinationNode(node4);
startCfg.setDestinationNodeLayer(2);
InfeasibleConfiguration infeasibleCfg = new InfeasibleConfiguration(startCfg);