Commit f102241f authored by Sebastian Vollbrecht's avatar Sebastian Vollbrecht

More code movements.

parent d2e0cbd7
......@@ -119,7 +119,4 @@ public abstract class Property implements Observer<Edge<ResourceNode>>, Initiali
this.rng = rng;
}
@Override
public abstract void reset();
}
......@@ -18,7 +18,6 @@
package graphgen.generator.components.properties.infeasibleMinII;
import graphgen.datastructures.SeededRandom;
import graphgen.generator.components.Initializable;
import graphgen.generator.components.properties.infeasibleMinII.configuration.InfeasibleConfiguration;
import graphgen.generator.components.properties.infeasibleMinII.configuration.StartConfiguration;
import graphgen.generator.components.properties.infeasibleMinII.configuration.SuffixConfiguration;
......@@ -40,19 +39,19 @@ import java.util.function.BiFunction;
import java.util.function.Predicate;
import java.util.stream.IntStream;
public class InfeasibleEdgePlanner implements Initializable {
public class InfeasibleEdgePlanner {
private final StartConfiguration startCfg;
private final InfeasibleConfiguration infeasibleCfg;
private final SuffixConfiguration suffixCfg;
private SeededRandom rng;
private final SeededRandom rng;
public InfeasibleEdgePlanner(StartConfiguration startCfg, InfeasibleConfiguration infeasibleCfg,
SuffixConfiguration suffixCfg) {
SuffixConfiguration suffixCfg, SeededRandom rng) {
this.startCfg = startCfg;
this.infeasibleCfg = infeasibleCfg;
this.suffixCfg = suffixCfg;
this.rng = rng;
}
public Set<Integer> getProblematicTimeslots() {
......@@ -382,16 +381,6 @@ public class InfeasibleEdgePlanner implements Initializable {
}
@Override
public void init(SeededRandom rng) {
this.rng = rng;
}
@Override
public void reset() {
// Do nothing.
}
public static Map<ResourceNode, PlannedEdge> getIncomingEdgesMap(Set<PlannedEdge> edges,
Collection<ResourceNode> relevantNodes) {
Map<ResourceNode, PlannedEdge> incomingEdgesByNode = new HashMap<>();
......
......@@ -148,86 +148,11 @@ public class InfeasibleMinIIProperty extends Property {
StartConfiguration startCfg = chooseStartConfiguration(getProblematicResources());
/* If the destination node's layer is currently not the chosen layer, we'll have to move the node
to the destined layer by swapping it with any of the destined layer's nodes. */
if (layers.getDepth(startCfg.getDestinationNode().getId()) != startCfg.getDestinationNodeLayer()) {
int nodeToSwapWith = JavaUtils.pickRandomElement(layers.getLayer(startCfg.getDestinationNodeLayer()), rng);
layers.swapIDs(startCfg.getDestinationNode().getId(), nodeToSwapWith);
}
InfeasibleConfiguration infeasibleCfg = chooseInfeasibleConfiguration(startCfg);
SuffixConfiguration suffixCfg = chooseSuffixConfiguration(startCfg, infeasibleCfg);
/*
* We need to create an incoming edge for all fixed nodes. The source node can
* either be the destination node or a zero node of the previous layer.
* Also create an incoming edge for every suffix node.
*/
InfeasibleEdgePlanner edgePlanner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg);
edgePlanner.init(rng);
Set<PlannedEdge> plannedEdges = edgePlanner.getIncomingEdges();
/* Choose the timeslot of the problematic nodes (relative to the destination node). */
Set<Integer> possibleTimeslots = edgePlanner.getProblematicTimeslots();
int problematicTimeslot = JavaUtils.pickRandomElement(possibleTimeslots, rng);
/*
* Update the delay of the created incoming edges so that the problematic nodes will share
* the chosen timeslot. The remaining inner delay will also be distributed over the
* non-problematic edges (e.g. the suffix edges).
*/
Optional<PlannedEdge> lastEdgeRepresentative = edgePlanner.distributeDelay(problematicTimeslot, plannedEdges);
/*
* Adjust the suffix nodes' offsets (i.e. ASAP-wise from the destination node)
* based on the freshly distributed delay of the edges among them. These are
* useful for the creation of the cycle's required outgoing edges below.
*/
if (lastEdgeRepresentative.isPresent()) {
Map<ResourceNode, PlannedEdge> outgoingEdgesByNode = InfeasibleEdgePlanner
.getOutgoingEdgesMap(plannedEdges, suffixCfg.getSuffixNodes());
int firstSuffixSlot = problematicTimeslot + infeasibleCfg
.getProblematicResource().delay + lastEdgeRepresentative.get().delay;
suffixCfg.setInitialOffset(firstSuffixSlot);
for (int i = 0; i < suffixCfg.getSuffixNodes().size() - 1; i++) {
ResourceNode src = suffixCfg.getSuffixNodes().get(i);
suffixCfg.addPlannedEdge(outgoingEdgesByNode.get(src));
}
}
/*
* Create the required outgoing edges.
* Note that there is no need to create edges for problematic nodes which have
* been connected to other nodes already (this can happen if they are zero
* nodes themselves).
*/
Predicate<ResourceNode> needsOutgoingEdge = n -> plannedEdges.stream().noneMatch(e -> e.src == n);
Set<PlannedEdge> outgoingEdges = edgePlanner
.getOutgoingEdges(problematicTimeslot, needsOutgoingEdge, edgeCreator::computeEdgeDelay);
plannedEdges.addAll(outgoingEdges);
/*
* Finalize the edges.
*/
plannedEdges.forEach(e -> edgeCreator.createEdge(e.src, e.dst, e.delay));
/*
* Finally, create the backedges going to the destination node. The backedge
* source selection depends on whether or not a suffix exists.
*/
if (suffixCfg.getSuffixNodes().isEmpty()) {
for (ResourceNode endNode : suffixCfg.getBackedgeSources()) {
edgeCreator.createBackedge(endNode, startCfg.getDestinationNode(), backedgeDelay, backedgeDistance);
}
} else {
ResourceNode lastSuffixNode = suffixCfg.getSuffixNodes().get(suffixCfg.getSuffixNodes().size() - 1);
edgeCreator.createBackedge(lastSuffixNode, startCfg.getDestinationNode(), backedgeDelay, backedgeDistance);
}
createNeededEdges(startCfg, infeasibleCfg, suffixCfg);
}
......@@ -346,24 +271,25 @@ public class InfeasibleMinIIProperty extends Property {
Resource problematicResource = startCfg.getProblematicResource();
/*
* Now we have to place some of the problematic nodes in a way which allows for
* an infeasible RecMinII. This is done by ensuring that they all are going to
* end up in the same slot.
*/
int nodesToPlace = problematicResource.limit + 1;
/*
* If and only if the following conditions are met, the destination node can be
* counted as a problematic node, since it then won't shift the subsequent
* layers' time slots.
* layers' time slots (where other problematic nodes might need to be placed).
*/
if (startCfg.getDestinationNode().resource == problematicResource && problematicResource.delay == 0) {
infeasibleCfg.addProblematicNode(startCfg.getDestinationNode());
nodesToPlace--;
}
infeasibleCfg.fixateNode(startCfg.getDestinationNode());
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg, rng);
/*
* If the destination node's layer is currently not the chosen layer, we'll have
* to move the node to the destined layer by swapping it with any of the destined
* layer's nodes.
*/
if (layers.getDepth(startCfg.getDestinationNode().getId()) != startCfg.getDestinationNodeLayer()) {
placer.placeNode(startCfg.getDestinationNode(), JavaUtils.asSet(startCfg.getDestinationNodeLayer()));
}
/*
* Gather all remaining nodes which use the problematic resource and randomly
......@@ -376,7 +302,7 @@ public class InfeasibleMinIIProperty extends Property {
}
}
for (int i = 0; i < nodesToPlace; i++) {
for (int i = 0; i < infeasibleCfg.howManyLeftToPlace(); i++) {
ResourceNode problematicNode = JavaUtils.removeRandomElement(problematicCandidates, rng);
infeasibleCfg.addProblematicNode(problematicNode);
}
......@@ -388,9 +314,6 @@ 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.
*/
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg);
placer.init(rng);
for (ResourceNode problematicNode : JavaUtils.asSortedList(infeasibleCfg.getProblematicNodes(), Comparator
.comparingInt(n -> layers.getDepth(n.getId())))) {
......@@ -416,8 +339,7 @@ public class InfeasibleMinIIProperty extends Property {
SuffixConfiguration suffixCfg = new SuffixConfiguration(startCfg, infeasibleCfg);
int remainingInnerDelay = maxInnerDelay - startCfg.getProblematicResource().delay - startCfg
.getDestinationNode().getDelay();
int remainingInnerDelay = suffixCfg.getRemainingInnerDelay();
/*
* Append suffix nodes to the cycle as long as possible. The suffix layers begin
......@@ -461,4 +383,77 @@ public class InfeasibleMinIIProperty extends Property {
return suffixCfg;
}
private void createNeededEdges(StartConfiguration startCfg, InfeasibleConfiguration infeasibleCfg,
SuffixConfiguration suffixCfg) {
/*
* We need to create an incoming edge for all fixed nodes. The source node can
* either be the destination node or a zero node of the previous layer.
* Also create an incoming edge for every suffix node.
*/
InfeasibleEdgePlanner edgePlanner = new InfeasibleEdgePlanner(startCfg, infeasibleCfg, suffixCfg, rng);
Set<PlannedEdge> plannedEdges = edgePlanner.getIncomingEdges();
/* Choose the timeslot of the problematic nodes (relative to the destination node). */
Set<Integer> possibleTimeslots = edgePlanner.getProblematicTimeslots();
int problematicTimeslot = JavaUtils.pickRandomElement(possibleTimeslots, rng);
/*
* Update the delay of the created incoming edges so that the problematic nodes will share
* the chosen timeslot. The remaining inner delay will also be distributed over the
* non-problematic edges (e.g. the suffix edges).
*/
Optional<PlannedEdge> lastEdgeRepresentative = edgePlanner.distributeDelay(problematicTimeslot, plannedEdges);
/*
* Adjust the suffix nodes' offsets (i.e. ASAP-wise from the destination node)
* based on the freshly distributed delay of the edges among them. These are
* useful for the creation of the cycle's required outgoing edges below.
*/
if (lastEdgeRepresentative.isPresent()) {
Map<ResourceNode, PlannedEdge> outgoingEdgesByNode = InfeasibleEdgePlanner
.getOutgoingEdgesMap(plannedEdges, suffixCfg.getSuffixNodes());
int firstSuffixSlot = problematicTimeslot + infeasibleCfg
.getProblematicResource().delay + lastEdgeRepresentative.get().delay;
suffixCfg.setInitialOffset(firstSuffixSlot);
for (int i = 0; i < suffixCfg.getSuffixNodes().size() - 1; i++) {
ResourceNode src = suffixCfg.getSuffixNodes().get(i);
suffixCfg.addPlannedEdge(outgoingEdgesByNode.get(src));
}
}
/*
* Create the required outgoing edges.
* Note that there is no need to create edges for problematic nodes which have
* been connected to other nodes already (this can happen if they are zero
* nodes themselves).
*/
Predicate<ResourceNode> needsOutgoingEdge = n -> plannedEdges.stream().noneMatch(e -> e.src == n);
Set<PlannedEdge> outgoingEdges = edgePlanner
.getOutgoingEdges(problematicTimeslot, needsOutgoingEdge, edgeCreator::computeEdgeDelay);
plannedEdges.addAll(outgoingEdges);
/*
* Finalize the edges.
*/
plannedEdges.forEach(e -> edgeCreator.createEdge(e.src, e.dst, e.delay));
/*
* Finally, create the backedges going to the destination node. The backedge
* source selection depends on whether or not a suffix exists.
*/
if (suffixCfg.getSuffixNodes().isEmpty()) {
for (ResourceNode endNode : suffixCfg.getBackedgeSources()) {
edgeCreator.createBackedge(endNode, startCfg.getDestinationNode(), backedgeDelay, backedgeDistance);
}
} else {
ResourceNode lastSuffixNode = suffixCfg.getSuffixNodes().get(suffixCfg.getSuffixNodes().size() - 1);
edgeCreator.createBackedge(lastSuffixNode, startCfg.getDestinationNode(), backedgeDelay, backedgeDistance);
}
}
}
\ No newline at end of file
......@@ -18,7 +18,6 @@
package graphgen.generator.components.properties.infeasibleMinII;
import graphgen.datastructures.SeededRandom;
import graphgen.generator.components.Initializable;
import graphgen.generator.components.properties.infeasibleMinII.configuration.InfeasibleConfiguration;
import graphgen.generator.components.properties.infeasibleMinII.configuration.StartConfiguration;
import graphgen.graph.LayerStructure;
......@@ -31,21 +30,21 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
public class InfeasibleNodePlacer implements Initializable {
public class InfeasibleNodePlacer {
private final StartConfiguration startCfg;
private final InfeasibleConfiguration infeasibleCfg;
private final SeededRandom rng;
private SeededRandom rng;
public InfeasibleNodePlacer(StartConfiguration startCfg, InfeasibleConfiguration infeasibleCfg) {
public InfeasibleNodePlacer(StartConfiguration startCfg, InfeasibleConfiguration infeasibleCfg, SeededRandom rng) {
this.startCfg = startCfg;
this.infeasibleCfg = infeasibleCfg;
this.rng = rng;
}
public Set<Integer> getPossibleLayers(ResourceNode problematicNode) {
if (!infeasibleCfg.getProblematicNodes().contains(problematicNode)) {
if (!infeasibleCfg.getProblematicNodes().contains(Objects.requireNonNull(problematicNode))) {
throw new IllegalArgumentException("Node " + problematicNode + " is not problematic.");
} else if (infeasibleCfg.getFixedNodes().contains(problematicNode)) {
throw new IllegalArgumentException("Node " + problematicNode + " has been fixed already.");
......@@ -56,7 +55,7 @@ public class InfeasibleNodePlacer implements Initializable {
Set<Integer> possibleLayers = new HashSet<>();
LayerStructure layers = infeasibleCfg.getLayers();
if (Objects.requireNonNull(problematicNode).getDelay() == 0) {
if (problematicNode.getDelay() == 0) {
remainingZeroNodes--;
}
......@@ -155,10 +154,13 @@ public class InfeasibleNodePlacer implements Initializable {
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.");
} else if (problematicNode != startCfg.getDestinationNode()) {
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()));
......@@ -226,16 +228,6 @@ public class InfeasibleNodePlacer implements Initializable {
}
}
@Override
public void init(SeededRandom rng) {
this.rng = rng;
}
@Override
public void reset() {
// Do nothing.
}
private void moveNodeToLayer(ResourceNode node, int layer) {
Set<Integer> swappableIDs = new HashSet<>();
......
......@@ -17,266 +17,21 @@
package graphgen.generator.components.properties.infeasibleMinII;
import graphgen.generator.components.properties.infeasibleMinII.configuration.InfeasibleConfiguration;
import graphgen.generator.components.properties.infeasibleMinII.configuration.StartConfiguration;
import graphgen.generator.exceptions.InfeasibilityImpossibleException;
import graphgen.graph.LayerStructure;
import graphgen.graph.Resource;
import graphgen.graph.ResourceNode;
import graphgen.util.JavaUtils;
import modsched.Node;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
public class InfeasibilityInspectorTest {
@Test
public void possibleLayers_ZeroDelay() {
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);
LayerStructure layers = new LayerStructure(depthsByID);
Resource problematic = new Resource("problematic", 0, 3);
Resource unlimited = new Resource("unlimited", 0);
ResourceNode node2 = new ResourceNode(2, problematic);
ResourceNode node3 = new ResourceNode(3, unlimited);
ResourceNode node4 = new ResourceNode(4, unlimited);
ResourceNode node5 = new ResourceNode(5, unlimited);
ResourceNode node6 = new ResourceNode(6, problematic);
ResourceNode node7 = new ResourceNode(7, problematic);
ResourceNode node8 = new ResourceNode(8, problematic);
Set<ResourceNode> nodes = JavaUtils.asSet(node2, node3, node4, node5, node6, node7, node8);
Map<Integer, ResourceNode> nodeTable = nodes.stream().collect(Collectors.toMap(Node::getId, n -> n));
StartConfiguration startCfg = new StartConfiguration(layers, nodeTable, problematic, 0);
startCfg.setDestinationNode(node2);
startCfg.setDestinationNodeLayer(0);
InfeasibleConfiguration infeasibleCfg = new InfeasibleConfiguration(startCfg);
infeasibleCfg.addProblematicNode(node2);
infeasibleCfg.addProblematicNode(node6);
infeasibleCfg.addProblematicNode(node7);
infeasibleCfg.addProblematicNode(node8);
// Assume that node 2 is a problematic destination node.
infeasibleCfg.fixateNode(node2);
// Now try to place node 6 in different target layers.
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.
infeasibleCfg.fixateNode(node3);
infeasibleCfg.fixateNode(node4);
infeasibleCfg.fixateNode(node6);
assertEquals(JavaUtils.asSet(2, 3, 4), placer.getPossibleLayers(node7));
// Now assume that node 7 has been fixed as well (using zero nodes 3 and 4 as well).
infeasibleCfg.fixateNode(node7);
assertEquals(JavaUtils.asSet(2, 4), placer.getPossibleLayers(node8));
}
@Test
public void possibleLayers_NonZeroDelay_Possible() {
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);
LayerStructure layers = new LayerStructure(depthsByID);
Resource problematic = new Resource("problematic", 1, 2);
Resource unlimited = new Resource("unlimited", 0);
ResourceNode node2 = new ResourceNode(2, problematic);
ResourceNode node3 = new ResourceNode(3, unlimited);
ResourceNode node4 = new ResourceNode(4, unlimited);
ResourceNode node5 = new ResourceNode(5, unlimited);
ResourceNode node6 = new ResourceNode(6, problematic);
ResourceNode node7 = new ResourceNode(7, problematic);
ResourceNode node8 = new ResourceNode(8, problematic);
Set<ResourceNode> nodes = JavaUtils.asSet(node2, node3, node4, node5, node6, node7, node8);
Map<Integer, ResourceNode> nodeTable = nodes.stream().collect(Collectors.toMap(Node::getId, n -> n));
StartConfiguration startCfg = new StartConfiguration(layers, nodeTable, problematic, 1);
startCfg.setDestinationNode(node3);
startCfg.setDestinationNodeLayer(0);
InfeasibleConfiguration infeasibleCfg = new InfeasibleConfiguration(startCfg);
infeasibleCfg.addProblematicNode(node2);
infeasibleCfg.addProblematicNode(node6);
infeasibleCfg.addProblematicNode(node7);
// Assume that node 3 is an unproblematic destination node.
infeasibleCfg.fixateNode(node3);
// Now try to place node 2 in different target layers.
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.
infeasibleCfg.fixateNode(node4);
infeasibleCfg.fixateNode(node6);
assertEquals(JavaUtils.asSet(2, 3, 4), placer.getPossibleLayers(node2));
// Now assume that node 7 has been fixed as well in layer 2 (using zero/destination node 3).
layers.swapIDs(5, 7);
infeasibleCfg.fixateNode(node7);
assertEquals(JavaUtils.asSet(3, 4), placer.getPossibleLayers(node2));
}
@Test
public void possibleLayers_NonZeroDelay_Impossible() {
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);
LayerStructure layers = new LayerStructure(depthsByID);
Resource problematic = new Resource("problematic", 1, 3);
Resource unlimited = new Resource("unlimited", 0);
ResourceNode node2 = new ResourceNode(2, problematic);
ResourceNode node3 = new ResourceNode(3, unlimited);
ResourceNode node4 = new ResourceNode(4, unlimited);
ResourceNode node5 = new ResourceNode(5, unlimited);
ResourceNode node6 = new ResourceNode(6, problematic);
ResourceNode node7 = new ResourceNode(7, problematic);
ResourceNode node8 = new ResourceNode(8, problematic);
Set<ResourceNode> nodes = JavaUtils.asSet(node2, node3, node4, node5, node6, node7, node8);
Map<Integer, ResourceNode> nodeTable = nodes.stream().collect(Collectors.toMap(Node::getId, n -> n));
StartConfiguration startCfg = new StartConfiguration(layers, nodeTable, problematic, 1);
startCfg.setDestinationNode(node3);
startCfg.setDestinationNodeLayer(0);
InfeasibleConfiguration infeasibleCfg = new InfeasibleConfiguration(startCfg);
infeasibleCfg.addProblematicNode(node2);
infeasibleCfg.addProblematicNode(node6);
infeasibleCfg.addProblematicNode(node7);
infeasibleCfg.addProblematicNode(node8);
// Assume that node 3 is an unproblematic destination node.
infeasibleCfg.fixateNode(node3);
// Now try to place node 2 in different target layers.
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.
infeasibleCfg.fixateNode(node4);
infeasibleCfg.fixateNode(node6);
assertTrue(placer.getPossibleLayers(node2).isEmpty());
// Now assume that node 7 has been fixed as well in layer 2 (using zero/destination node 3).
layers.swapIDs(5, 7);
infeasibleCfg.fixateNode(node7);
assertTrue(placer.getPossibleLayers(node2).isEmpty());
// Now assume that node 2 has been fixed as well in layer 3 (using zero node 4).
layers.swapIDs(2, 5);
infeasibleCfg.fixateNode(node2);
// Assert that node 8 cannot be placed in layer 4 anymore.
assertTrue(placer.getPossibleLayers(node8).isEmpty());
}
@Test
public void possibleLayers_BogusArguments() {
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);
LayerStructure layers = new LayerStructure(depthsByID);
Resource problematic = new Resource("problematic", 0, 3);
Resource unlimited = new Resource("unlimited", 0);
ResourceNode node2 = new ResourceNode(2, problematic);
ResourceNode node3 = new ResourceNode(3, unlimited);
ResourceNode node4 = new ResourceNode(4, unlimited);
ResourceNode node5 = new ResourceNode(5, unlimited);
ResourceNode node6 = new ResourceNode(6, problematic);
ResourceNode node7 = new ResourceNode(7, problematic);
ResourceNode node8 = new ResourceNode(8, problematic);
Set<ResourceNode> nodes = JavaUtils.asSet(node2, node3, node4, node5, node6, node7, node8);
Map<Integer, ResourceNode> nodeTable = nodes.stream().collect(Collectors.toMap(Node::getId, n -> n));
StartConfiguration startCfg = new StartConfiguration(layers, nodeTable, problematic, 0);
startCfg.setDestinationNode(node2);
startCfg.setDestinationNodeLayer(0);
InfeasibleConfiguration infeasibleCfg = new InfeasibleConfiguration(startCfg);
infeasibleCfg.addProblematicNode(node2);
infeasibleCfg.addProblematicNode(node6);
infeasibleCfg.addProblematicNode(node7);
infeasibleCfg.addProblematicNode(node8);
// Assume that node 3 is a problematic destination node.
infeasibleCfg.fixateNode(node3);
InfeasibleNodePlacer placer = new InfeasibleNodePlacer(startCfg, infeasibleCfg);
try {
placer.getPossibleLayers(null);
fail("This call should have failed!");
} catch (NullPointerException expected) {
}
try {
placer.getPossibleLayers(node3);
fail("This call should have failed!");
} catch (IllegalArgumentException expected) {
}
}
@Test
public void problematicResources_Limits() {
Resource problematic1 = new Resource("problematic1", 0, 1);
......
......@@ -27,6 +27,7 @@ import graphgen.graph.Resource;
import graphgen.graph.ResourceNode;
import graphgen.util.JavaUtils;
import modsched.Node;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
......@@ -43,6 +44,13 @@ import static org.junit.Assert.assertTrue;
public class InfeasibleEdgePlannerTest {
private SeededRandom rng;
@Before
public void init() {
rng = new SeededRandom(42);
}
@Test
public void getProblematicTimeslots_ZeroDelay() {
......@@ -96,8 +104,7 @@ public class InfeasibleEdgePlannerTest {
suffixNodes.forEach(suffixCfg::appendSuffixNode);