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> {
}
@Override
public int hashCode() {
final int prime = 31;
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)
public boolean equals(Object o) {
if (this == o)
return true;
if (obj == null)
return false;
if (!(obj instanceof Pair))
if (o == null || getClass() != o.getClass())
return false;
Pair<?, ?> other = (Pair<?, ?>) obj;
if (first == null) {
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);
Pair<?, ?> pair = (Pair<?, ?>) o;
return Objects.equals(first, pair.first) && Objects.equals(second, pair.second);
}
@Override
public int hashCode() {
return Objects.hash(first, second);
}
}
......@@ -84,6 +84,17 @@ public class SeededRandom {
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.
*
......
......@@ -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
* 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) {
this.edgeValue = edgeValue;
......
......@@ -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
* 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
* 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>
* It follows that
* <pre>(minInnerDelay + backedgeDelay) / backedgeDistance > RecMinII - 1</pre>
* <pre>(minInnerDelay + backedgeDelay) / backedgeDistance &gt; RecMinII - 1</pre>
* 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
* 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
* is not greater than zero or if the backedge parameters already exceed the
* specified MinII
......@@ -202,6 +207,11 @@ public abstract class MinIIProperty<C extends MinIICycleConfiguration> extends P
* and
* <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
* is not greater than zero or if the backedge parameters already exceed the
* specified MinII
......
......@@ -154,7 +154,6 @@ public class InfeasibleMinIIProperty extends MinIIProperty<InfeasibleConfigurati
ResourceNode dstNode;
/* Immediately choose a destination node to avoid listing all possibilities (see method doc). */
if (!nodesInCurrentLayer.isEmpty()) {
dstNode = JavaUtils.pickRandomElement(nodesInCurrentLayer, rng);
} else {
......
......@@ -52,6 +52,8 @@ public class LookupTables {
case BACKEDGE_DISTANCE:
probabilityMapping.put(1, 1.0);
break;
default:
throw new UnsupportedOperationException(edgeValue.toString());
}
return new DeterministicDistribution<>(probabilityMapping);
......
......@@ -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>
* <p>
* <code>
* sanitizeFilename("#thisIsATestGraph????!!")
* </code>
* {@code sanitizeFilename("#thisIsATestGraph????!!") }
* <p>
* would be sanitized to
* <p>
* <code>
* "_thisIsATestGraph_"
* </code>
* {@code "_thisIsATestGraph_" }
* <p>
* <b>Warning</b>: collisions can occur.
*
......@@ -76,15 +72,11 @@ public class GraphFileUtils {
/**
* Julianizes a path. For example:<br>
* <p>
* <code>
* julianizePath("./foo/bar/jpeg_export/graph46.graphml")
* </code>
* {@code julianizePath("./foo/bar/jpeg_export/graph46.graphml") }
* <p>
* would be julianized to
* <p>
* <code>
* "jpeg::graph46"
* </code>
* {@code "jpeg::graph46" }
* <p>
* <b>Warning</b>: collisions can occur.
*
......@@ -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
* written to the provided print stream.
* <p>
* Use <code>new PrintStream(new FileOutputStream(new File(filename))</code> to immediately write the code to a
* file.
* Use {@code new PrintStream(new FileOutputStream(new File(filename))} to immediately write the code to a file.
*
* @param graph the graph to create the formulation code for
* @param problemName the formulation's problem name
......
......@@ -228,11 +228,7 @@ public class JavaUtils {
* @param key the key to insert or increment
*/
public static <K> void insertOrIncValue(Map<? super K, Integer> map, K key) {
if (!Objects.requireNonNull(map).containsKey(key)) {
map.put(key, 1);
} else {
map.put(key, map.get(key) + 1);
}
map.put(Objects.requireNonNull(key), map.getOrDefault(key, 0) + 1);
}
/**
......@@ -245,12 +241,7 @@ public class JavaUtils {
* @throws IllegalArgumentException if min is greater than max
*/
public static int pickBounded(int min, int max, SeededRandom rng) {
if (min > max) {
throw new IllegalArgumentException(
"Min value must be less than or equal to the max value.\nMin: " + min + "\nMax: " + max);
}
requireLessOrEqual(min, max);
return rng.nextInt(max - min + 1) + min;
}
......
......@@ -34,6 +34,7 @@ import modsched.MoovacFormulation;
import modsched.Node;
import modsched.Schedule;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
......@@ -57,6 +58,12 @@ public class SchedulingUtils {
*/
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
* should be computed by CPLEX before the best one will be returned.
......
......@@ -17,6 +17,7 @@
package modsched;
import graphgen.util.SchedulingUtils;
import ilog.concert.IloException;
import ilog.concert.IloIntExpr;
import ilog.concert.IloIntVar;
......@@ -57,6 +58,7 @@ public final class EichenbergerFormulation<O, R> extends IterativeFormulation<O,
List<Edge<EichenbergerNode>> E = edges;
IloCplex cp = new IloCplex();
cp.setOut(SchedulingUtils.out);
// construct some constants
IloIntExpr _0 = cp.constant(0);
......
......@@ -40,7 +40,6 @@ public abstract class IterativeFormulation<O, R, N extends Node> extends Formula
try {
for (int candII = minII, nAttempts = 0; candII <= maxII && nAttempts < attemptLimit;
++candII, ++nAttempts) {
System.out.println("Trying II: " + candII);
if (constructionTimeout) {
// if formulation signals a construction timout, all
......
......@@ -17,6 +17,7 @@
package modsched;
import graphgen.util.SchedulingUtils;
import ilog.concert.IloException;
import ilog.concert.IloIntExpr;
import ilog.concert.IloIntVar;
......@@ -41,6 +42,7 @@ public class MinII {
int recMII = -1;
try {
IloCplex cp = new IloCplex();
cp.setOut(SchedulingUtils.out);
Map<N, IloIntVar> startTimes = new LinkedHashMap<>();
for (N i : nodes) {
......
......@@ -17,6 +17,7 @@
package modsched;
import graphgen.util.SchedulingUtils;
import ilog.concert.IloException;
import ilog.concert.IloIntExpr;
import ilog.concert.IloIntVar;
......@@ -60,6 +61,7 @@ public final class MoovacFormulation<O, R> extends IterativeFormulation<O, R, Mo
long constructionBegin = System.nanoTime();
IloCplex cp = new IloCplex();
cp.setOut(SchedulingUtils.out);
// construct some constants
IloIntExpr _0 = cp.constant(0);
......
......@@ -52,8 +52,10 @@ import graphgen.util.SchedulingUtils;
import graphgen.util.TestUtils;
import modsched.Edge;
import modsched.Schedule;
import org.junit.Before;
import org.junit.Test;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
......@@ -62,6 +64,16 @@ import static org.junit.Assert.fail;
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
public void fail_ResMinIITooBig() {
......@@ -943,7 +955,7 @@ public class FeasibleMinIIPropertyTest {
ModuloSchedulingFormulation formulation) {
try {
graphGenerator.setVerbose(System.out);
graphGenerator.setOut(System.out);
Graph<ResourceNode> graph = graphGenerator.createGraph(seed);
TestUtils.assertEquals(minII, SchedulingUtils.getMinII(graph), seed);
......
......@@ -49,8 +49,10 @@ import graphgen.util.SchedulingUtils;
import graphgen.util.TestUtils;
import ilog.cplex.IloCplex.Status;
import modsched.Schedule;
import org.junit.Before;
import org.junit.Test;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
......@@ -60,6 +62,16 @@ import static org.junit.Assert.fail;
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
public void fail_ResMinIITooBig() {
......@@ -1844,9 +1856,9 @@ public class InfeasibleMinIIPropertyTest {
private Graph<ResourceNode> assertInfeasibility(GraphGenerator graphGenerator, int minII, long seed,
ModuloSchedulingFormulation formulation) {
graphGenerator.setVerbose(System.out);
try {
graphGenerator.setOut(System.out);
Graph<ResourceNode> graph = graphGenerator.createGraph(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