Commit 89e2b3ee authored by Sebastian Vollbrecht's avatar Sebastian Vollbrecht

JavaDoc fixes and changes regarding the way the generation process is logged.

Also some other minimal changes.
parent 152176dd
...@@ -64,32 +64,17 @@ public class Pair<T1, T2> { ...@@ -64,32 +64,17 @@ public class Pair<T1, T2> {
} }
@Override @Override
public int hashCode() { public boolean equals(Object o) {
final int prime = 31; if (this == o)
int result = 1;
result = prime * result + ((first == null) ? 0 : first.hashCode());
result = prime * result + ((second == null) ? 0 : second.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true; return true;
if (obj == null) if (o == null || getClass() != o.getClass())
return false;
if (!(obj instanceof Pair))
return false; return false;
Pair<?, ?> other = (Pair<?, ?>) obj; Pair<?, ?> pair = (Pair<?, ?>) o;
if (first == null) { return Objects.equals(first, pair.first) && Objects.equals(second, pair.second);
if (other.first != null)
return false;
} else if (!first.equals(other.first))
return false;
if (second == null) {
return other.second == null;
} else
return second.equals(other.second);
} }
@Override
public int hashCode() {
return Objects.hash(first, second);
}
} }
...@@ -84,6 +84,17 @@ public class SeededRandom { ...@@ -84,6 +84,17 @@ public class SeededRandom {
return rng.nextDouble(); return rng.nextDouble();
} }
/**
* Returns a random long value.
*
* @return the random long value
* @throws UnsupportedOperationException if this instance has not yet been seeded
*/
public long nextLong() {
checkSeededStatus();
return rng.nextLong();
}
/** /**
* Returns the wrapped random instance. * Returns the wrapped random instance.
* *
......
...@@ -105,6 +105,8 @@ public abstract class ValueComputer implements EdgeCreationComponent, StrictComp ...@@ -105,6 +105,8 @@ public abstract class ValueComputer implements EdgeCreationComponent, StrictComp
/** /**
* Tells the value computer which value it is actually computing. This edge value is then used used to determine (in * Tells the value computer which value it is actually computing. This edge value is then used used to determine (in
* strict mode) whether or not a created edge is illegal. * strict mode) whether or not a created edge is illegal.
*
* @param edgeValue the edge value whose computation this value computer is used for
*/ */
public final void setEdgeValue(EdgeValue edgeValue) { public final void setEdgeValue(EdgeValue edgeValue) {
this.edgeValue = edgeValue; this.edgeValue = edgeValue;
......
...@@ -57,7 +57,7 @@ public class GeneratedLayerStructure extends LayerStructure implements StrictCom ...@@ -57,7 +57,7 @@ public class GeneratedLayerStructure extends LayerStructure implements StrictCom
} }
/** /**
* Swaps the two IDs with each other (see {@link LayerStructure#swapIDs(int, int)}). * Swaps the two IDs with each other.
* *
* @throws IllegalSwapException if an illegal swap is detected, i.e. if the IDs are connected with an edge during a * @throws IllegalSwapException if an illegal swap is detected, i.e. if the IDs are connected with an edge during a
* graph creation phase and if the swap would violate the layer structure implied by * graph creation phase and if the swap would violate the layer structure implied by
......
...@@ -176,12 +176,17 @@ public abstract class MinIIProperty<C extends MinIICycleConfiguration> extends P ...@@ -176,12 +176,17 @@ public abstract class MinIIProperty<C extends MinIICycleConfiguration> extends P
* It is the lower bound of the RecMinII formula's ceiling function and can be retrieved like so: * It is the lower bound of the RecMinII formula's ceiling function and can be retrieved like so:
* <pre>RecMinII = ceil((minInnerDelay + backedgeDelay) / backedgeDistance)</pre> * <pre>RecMinII = ceil((minInnerDelay + backedgeDelay) / backedgeDistance)</pre>
* It follows that * It follows that
* <pre>(minInnerDelay + backedgeDelay) / backedgeDistance > RecMinII - 1</pre> * <pre>(minInnerDelay + backedgeDelay) / backedgeDistance &gt; RecMinII - 1</pre>
* and * and
* <pre>minInnerDelay > backedgeDistance * (RecMinII - 1) - backedgeDelay</pre><p> * <pre>minInnerDelay &gt; backedgeDistance * (RecMinII - 1) - backedgeDelay</pre><p>
* Because the inner delay is an integer value, the smallest possible value which still fulfills the inequality is * Because the inner delay is an integer value, the smallest possible value which still fulfills the inequality is
* the result of adding 1 to the right-hand side. * the result of adding 1 to the right-hand side.
* *
* @param minII the MinII which needs to be ensured
* @param backedgeDelay the delay of possible RecMinII-ensuring backedges
* @param backedgeDistance the distance of possible RecMinII-ensuring backedges
* @return the minimum inner delay a cycle containing such RecMinII-ensuring backedges can have while still ensuring
* the specified MinII
* @throws IllegalArgumentException if the MinII is not greater than zero, if the delay is negative, if the distance * @throws IllegalArgumentException if the MinII is not greater than zero, if the delay is negative, if the distance
* is not greater than zero or if the backedge parameters already exceed the * is not greater than zero or if the backedge parameters already exceed the
* specified MinII * specified MinII
...@@ -202,6 +207,11 @@ public abstract class MinIIProperty<C extends MinIICycleConfiguration> extends P ...@@ -202,6 +207,11 @@ public abstract class MinIIProperty<C extends MinIICycleConfiguration> extends P
* and * and
* <pre>RecMinII * backedgeDistance - backedgeDelay = maxInnerDelay</pre> * <pre>RecMinII * backedgeDistance - backedgeDelay = maxInnerDelay</pre>
* *
* @param minII the MinII which needs to be ensured
* @param backedgeDelay the delay of possible RecMinII-ensuring backedges
* @param backedgeDistance the distance of possible RecMinII-ensuring backedges
* @return the maximum inner delay a cycle containing such RecMinII-ensuring backedges can have while still ensuring
* the specified MinII
* @throws IllegalArgumentException if the MinII is not greater than zero, if the delay is negative, if the distance * @throws IllegalArgumentException if the MinII is not greater than zero, if the delay is negative, if the distance
* is not greater than zero or if the backedge parameters already exceed the * is not greater than zero or if the backedge parameters already exceed the
* specified MinII * specified MinII
......
...@@ -154,7 +154,6 @@ public class InfeasibleMinIIProperty extends MinIIProperty<InfeasibleConfigurati ...@@ -154,7 +154,6 @@ public class InfeasibleMinIIProperty extends MinIIProperty<InfeasibleConfigurati
ResourceNode dstNode; ResourceNode dstNode;
/* Immediately choose a destination node to avoid listing all possibilities (see method doc). */
if (!nodesInCurrentLayer.isEmpty()) { if (!nodesInCurrentLayer.isEmpty()) {
dstNode = JavaUtils.pickRandomElement(nodesInCurrentLayer, rng); dstNode = JavaUtils.pickRandomElement(nodesInCurrentLayer, rng);
} else { } else {
......
...@@ -52,6 +52,8 @@ public class LookupTables { ...@@ -52,6 +52,8 @@ public class LookupTables {
case BACKEDGE_DISTANCE: case BACKEDGE_DISTANCE:
probabilityMapping.put(1, 1.0); probabilityMapping.put(1, 1.0);
break; break;
default:
throw new UnsupportedOperationException(edgeValue.toString());
} }
return new DeterministicDistribution<>(probabilityMapping); return new DeterministicDistribution<>(probabilityMapping);
......
...@@ -54,15 +54,11 @@ public class GraphFileUtils { ...@@ -54,15 +54,11 @@ public class GraphFileUtils {
/** /**
* Sanitizes a name so that it can be used as a filename without causing problems. For example:<br> * Sanitizes a name so that it can be used as a filename without causing problems. For example:<br>
* <p> * <p>
* <code> * {@code sanitizeFilename("#thisIsATestGraph????!!") }
* sanitizeFilename("#thisIsATestGraph????!!")
* </code>
* <p> * <p>
* would be sanitized to * would be sanitized to
* <p> * <p>
* <code> * {@code "_thisIsATestGraph_" }
* "_thisIsATestGraph_"
* </code>
* <p> * <p>
* <b>Warning</b>: collisions can occur. * <b>Warning</b>: collisions can occur.
* *
...@@ -76,15 +72,11 @@ public class GraphFileUtils { ...@@ -76,15 +72,11 @@ public class GraphFileUtils {
/** /**
* Julianizes a path. For example:<br> * Julianizes a path. For example:<br>
* <p> * <p>
* <code> * {@code julianizePath("./foo/bar/jpeg_export/graph46.graphml") }
* julianizePath("./foo/bar/jpeg_export/graph46.graphml")
* </code>
* <p> * <p>
* would be julianized to * would be julianized to
* <p> * <p>
* <code> * {@code "jpeg::graph46" }
* "jpeg::graph46"
* </code>
* <p> * <p>
* <b>Warning</b>: collisions can occur. * <b>Warning</b>: collisions can occur.
* *
...@@ -301,8 +293,7 @@ public class GraphFileUtils { ...@@ -301,8 +293,7 @@ public class GraphFileUtils {
* Generates java code to create a {@link MoovacFormulation} from scratch for the given graph. The generated code is * Generates java code to create a {@link MoovacFormulation} from scratch for the given graph. The generated code is
* written to the provided print stream. * written to the provided print stream.
* <p> * <p>
* Use <code>new PrintStream(new FileOutputStream(new File(filename))</code> to immediately write the code to a * Use {@code new PrintStream(new FileOutputStream(new File(filename))} to immediately write the code to a file.
* file.
* *
* @param graph the graph to create the formulation code for * @param graph the graph to create the formulation code for
* @param problemName the formulation's problem name * @param problemName the formulation's problem name
......
...@@ -228,11 +228,7 @@ public class JavaUtils { ...@@ -228,11 +228,7 @@ public class JavaUtils {
* @param key the key to insert or increment * @param key the key to insert or increment
*/ */
public static <K> void insertOrIncValue(Map<? super K, Integer> map, K key) { public static <K> void insertOrIncValue(Map<? super K, Integer> map, K key) {
if (!Objects.requireNonNull(map).containsKey(key)) { map.put(Objects.requireNonNull(key), map.getOrDefault(key, 0) + 1);
map.put(key, 1);
} else {
map.put(key, map.get(key) + 1);
}
} }
/** /**
...@@ -245,12 +241,7 @@ public class JavaUtils { ...@@ -245,12 +241,7 @@ public class JavaUtils {
* @throws IllegalArgumentException if min is greater than max * @throws IllegalArgumentException if min is greater than max
*/ */
public static int pickBounded(int min, int max, SeededRandom rng) { public static int pickBounded(int min, int max, SeededRandom rng) {
requireLessOrEqual(min, max);
if (min > max) {
throw new IllegalArgumentException(
"Min value must be less than or equal to the max value.\nMin: " + min + "\nMax: " + max);
}
return rng.nextInt(max - min + 1) + min; return rng.nextInt(max - min + 1) + min;
} }
......
...@@ -34,6 +34,7 @@ import modsched.MoovacFormulation; ...@@ -34,6 +34,7 @@ import modsched.MoovacFormulation;
import modsched.Node; import modsched.Node;
import modsched.Schedule; import modsched.Schedule;
import java.io.OutputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
...@@ -57,6 +58,12 @@ public class SchedulingUtils { ...@@ -57,6 +58,12 @@ public class SchedulingUtils {
*/ */
public static final long TIMELIMIT_CANDIDATE = 3600L; public static final long TIMELIMIT_CANDIDATE = 3600L;
/**
* The output stream which CPLEX writes its output to. If set to null, CPLEX won't print any output (see {@link
* ilog.cplex.IloCplex#setOut(OutputStream)}).
*/
public static OutputStream out = System.out;
/** /**
* Schedules the provided graph using the specified formulation. The solution limit specifies how many solutions * Schedules the provided graph using the specified formulation. The solution limit specifies how many solutions
* should be computed by CPLEX before the best one will be returned. * should be computed by CPLEX before the best one will be returned.
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package modsched; package modsched;
import graphgen.util.SchedulingUtils;
import ilog.concert.IloException; import ilog.concert.IloException;
import ilog.concert.IloIntExpr; import ilog.concert.IloIntExpr;
import ilog.concert.IloIntVar; import ilog.concert.IloIntVar;
...@@ -57,6 +58,7 @@ public final class EichenbergerFormulation<O, R> extends IterativeFormulation<O, ...@@ -57,6 +58,7 @@ public final class EichenbergerFormulation<O, R> extends IterativeFormulation<O,
List<Edge<EichenbergerNode>> E = edges; List<Edge<EichenbergerNode>> E = edges;
IloCplex cp = new IloCplex(); IloCplex cp = new IloCplex();
cp.setOut(SchedulingUtils.out);
// construct some constants // construct some constants
IloIntExpr _0 = cp.constant(0); IloIntExpr _0 = cp.constant(0);
......
...@@ -40,7 +40,6 @@ public abstract class IterativeFormulation<O, R, N extends Node> extends Formula ...@@ -40,7 +40,6 @@ public abstract class IterativeFormulation<O, R, N extends Node> extends Formula
try { try {
for (int candII = minII, nAttempts = 0; candII <= maxII && nAttempts < attemptLimit; for (int candII = minII, nAttempts = 0; candII <= maxII && nAttempts < attemptLimit;
++candII, ++nAttempts) { ++candII, ++nAttempts) {
System.out.println("Trying II: " + candII);
if (constructionTimeout) { if (constructionTimeout) {
// if formulation signals a construction timout, all // if formulation signals a construction timout, all
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package modsched; package modsched;
import graphgen.util.SchedulingUtils;
import ilog.concert.IloException; import ilog.concert.IloException;
import ilog.concert.IloIntExpr; import ilog.concert.IloIntExpr;
import ilog.concert.IloIntVar; import ilog.concert.IloIntVar;
...@@ -41,6 +42,7 @@ public class MinII { ...@@ -41,6 +42,7 @@ public class MinII {
int recMII = -1; int recMII = -1;
try { try {
IloCplex cp = new IloCplex(); IloCplex cp = new IloCplex();
cp.setOut(SchedulingUtils.out);
Map<N, IloIntVar> startTimes = new LinkedHashMap<>(); Map<N, IloIntVar> startTimes = new LinkedHashMap<>();
for (N i : nodes) { for (N i : nodes) {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package modsched; package modsched;
import graphgen.util.SchedulingUtils;
import ilog.concert.IloException; import ilog.concert.IloException;
import ilog.concert.IloIntExpr; import ilog.concert.IloIntExpr;
import ilog.concert.IloIntVar; import ilog.concert.IloIntVar;
...@@ -60,6 +61,7 @@ public final class MoovacFormulation<O, R> extends IterativeFormulation<O, R, Mo ...@@ -60,6 +61,7 @@ public final class MoovacFormulation<O, R> extends IterativeFormulation<O, R, Mo
long constructionBegin = System.nanoTime(); long constructionBegin = System.nanoTime();
IloCplex cp = new IloCplex(); IloCplex cp = new IloCplex();
cp.setOut(SchedulingUtils.out);
// construct some constants // construct some constants
IloIntExpr _0 = cp.constant(0); IloIntExpr _0 = cp.constant(0);
......
...@@ -52,8 +52,10 @@ import graphgen.util.SchedulingUtils; ...@@ -52,8 +52,10 @@ import graphgen.util.SchedulingUtils;
import graphgen.util.TestUtils; import graphgen.util.TestUtils;
import modsched.Edge; import modsched.Edge;
import modsched.Schedule; import modsched.Schedule;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.OutputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
...@@ -62,6 +64,16 @@ import static org.junit.Assert.fail; ...@@ -62,6 +64,16 @@ import static org.junit.Assert.fail;
public class FeasibleMinIIPropertyTest { public class FeasibleMinIIPropertyTest {
@Before
public void init() {
SchedulingUtils.out = new OutputStream() {
@Override
public void write(int b) {
// Do nothing, thus getting rid of CPLEX output.
}
};
}
@Test @Test
public void fail_ResMinIITooBig() { public void fail_ResMinIITooBig() {
...@@ -943,7 +955,7 @@ public class FeasibleMinIIPropertyTest { ...@@ -943,7 +955,7 @@ public class FeasibleMinIIPropertyTest {
ModuloSchedulingFormulation formulation) { ModuloSchedulingFormulation formulation) {
try { try {
graphGenerator.setVerbose(System.out); graphGenerator.setOut(System.out);
Graph<ResourceNode> graph = graphGenerator.createGraph(seed); Graph<ResourceNode> graph = graphGenerator.createGraph(seed);
TestUtils.assertEquals(minII, SchedulingUtils.getMinII(graph), seed); TestUtils.assertEquals(minII, SchedulingUtils.getMinII(graph), seed);
......
...@@ -49,8 +49,10 @@ import graphgen.util.SchedulingUtils; ...@@ -49,8 +49,10 @@ import graphgen.util.SchedulingUtils;
import graphgen.util.TestUtils; import graphgen.util.TestUtils;
import ilog.cplex.IloCplex.Status; import ilog.cplex.IloCplex.Status;
import modsched.Schedule; import modsched.Schedule;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.OutputStream;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
...@@ -60,6 +62,16 @@ import static org.junit.Assert.fail; ...@@ -60,6 +62,16 @@ import static org.junit.Assert.fail;
public class InfeasibleMinIIPropertyTest { public class InfeasibleMinIIPropertyTest {
@Before
public void init() {
SchedulingUtils.out = new OutputStream() {
@Override
public void write(int b) {
// Do nothing, thus getting rid of CPLEX output.
}
};
}
@Test @Test
public void fail_ResMinIITooBig() { public void fail_ResMinIITooBig() {
...@@ -1844,9 +1856,9 @@ public class InfeasibleMinIIPropertyTest { ...@@ -1844,9 +1856,9 @@ public class InfeasibleMinIIPropertyTest {
private Graph<ResourceNode> assertInfeasibility(GraphGenerator graphGenerator, int minII, long seed, private Graph<ResourceNode> assertInfeasibility(GraphGenerator graphGenerator, int minII, long seed,
ModuloSchedulingFormulation formulation) { ModuloSchedulingFormulation formulation) {
graphGenerator.setVerbose(System.out);
try { try {
graphGenerator.setOut(System.out);
Graph<ResourceNode> graph = graphGenerator.createGraph(seed); Graph<ResourceNode> graph = graphGenerator.createGraph(seed);
TestUtils.assertEquals(minII, SchedulingUtils.getMinII(graph), seed); TestUtils.assertEquals(minII, SchedulingUtils.getMinII(graph), seed);
......
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