Commit 809ee00a authored by Johannes Mey's avatar Johannes Mey
Browse files

revert some timing changes, cleanup

parent 5424f837
......@@ -71,6 +71,9 @@ public abstract class ILPExternalSolver extends AbstractILPSolver {
}
protected double solve0(Root model, StopWatch watch, List<IlpVariable> variablesSetToOne) throws SolvingException {
long startOfWriteOutInMillis = watch.time(TimeUnit.MILLISECONDS);
// Create temporary files
try {
lp = Files.createTempFile("ilp", ".lp");
......@@ -81,12 +84,8 @@ public abstract class ILPExternalSolver extends AbstractILPSolver {
logger.info("Writing ILP to {}, solving now", lp.toAbsolutePath());
}
long startOfWriteOutInMillis = watch.time(TimeUnit.MILLISECONDS);
// write out lp file
IlpString output = model.getILP().printIlp();
try (BufferedWriter writer = Files.newBufferedWriter(
lp, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
writer.write(output.toString());
......@@ -96,7 +95,7 @@ public abstract class ILPExternalSolver extends AbstractILPSolver {
this.lastGeneration = watch.time(TimeUnit.MILLISECONDS);
long millisecondsNeededToWriteOut = watch.time(TimeUnit.MILLISECONDS) - startOfWriteOutInMillis;
long remainingTimeInMillis = this.timeoutUnit.toMillis(this.timeoutValue) - lastGeneration;
long remainingTimeForSolvingInMillis = Math.max(0, remainingTimeInMillis - millisecondsNeededToWriteOut);
long remainingTimeForSolvingInMillis = Math.max(0, remainingTimeInMillis - 2*millisecondsNeededToWriteOut);
// take twice the time to have buffer to write out solution afterwards
......
......@@ -3,13 +3,10 @@ package de.tudresden.inf.st.mquat.solving.ilp;
import de.tudresden.inf.st.mquat.jastadd.model.ILP;
import de.tudresden.inf.st.mquat.jastadd.model.IlpVariable;
import de.tudresden.inf.st.mquat.solving.SolvingException;
import org.apache.logging.log4j.LogManager;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;
......@@ -20,9 +17,10 @@ public class SCIPSolver extends ILPExternalSolver {
* Create a new GLPK solver with default settings.
* Default is:
* <ul>
* <li>1 minute timeout</li>
* <li>delete temporary files on exit.</li>
* <li>1 minute timeout</li>
* <li>delete temporary files on exit.</li>
* </ul>
*
* @see SCIPSolver#setDeleteFilesOnExit(boolean)
*/
public SCIPSolver() {
......@@ -31,13 +29,13 @@ public class SCIPSolver extends ILPExternalSolver {
@Override
protected String[] getCommand(Path lp, Path solution, long remainingTimeForSolvingInMillis) {
String[] command = {"scip", "-c", "read " + lp.toAbsolutePath() + " set timing reading true set timing clocktype 2 set limit time " + remainingTimeForSolvingInMillis/1000 + " optimize write solution " + solution.toAbsolutePath() + " quit"};
String[] command = {"scip", "-c", "read " + lp.toAbsolutePath() + " set timing reading true set timing clocktype 2 set limit time " + remainingTimeForSolvingInMillis / 1000 + " optimize write solution " + solution.toAbsolutePath() + " quit"};
return command;
}
@Override
protected void readFromPlainTextSolution(ILP ilp, Path solution, ILPSolution result,
List<IlpVariable> variablesSetToOne) throws SolvingException {
List<IlpVariable> variablesSetToOne) throws SolvingException {
try (Stream<String> lines = Files.lines(solution)) {
for (String line : lines.collect(Collectors.toList())) {
if (line.startsWith("objective value:")) {
......@@ -53,7 +51,7 @@ public class SCIPSolver extends ILPExternalSolver {
if (tokens.length == 3) {
// tokens: name, value, objective
if (Math.round(Double.parseDouble(tokens[1])*1000000000)==1000000000) {
if (Math.round(Double.parseDouble(tokens[1]) * 1000000000) == 1000000000) {
logger.debug("found new variable {} with value {}", tokens[0], tokens[1]);
IlpVariable variable = ilp.resolve(tokens[0]);
if (variable == null) {
......
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