Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
stgroup
ttc18
Commits
df10f8bc
Commit
df10f8bc
authored
Sep 12, 2018
by
Johannes Mey
Browse files
add gurobi solver (untested so far)
parent
bffe7371
Changes
4
Hide whitespace changes
Inline
Side-by-side
jastadd-mquat-benchmark/src/main/java/de/tudresden/inf/st/mquat/benchmark/SolverFactory.java
View file @
df10f8bc
...
...
@@ -2,6 +2,7 @@ package de.tudresden.inf.st.mquat.benchmark;
import
de.tudresden.inf.st.mquat.solving.BenchmarkableSolver
;
import
de.tudresden.inf.st.mquat.solving.ilp.GLPKSolver
;
import
de.tudresden.inf.st.mquat.solving.ilp.GurobiSolver
;
import
de.tudresden.inf.st.mquat.solving.ilp.ILPDirectSolver
;
import
de.tudresden.inf.st.mquat.solving.genetic.GeneticSolver
;
import
de.tudresden.inf.st.mquat.solving.ilp.SCIPSolver
;
...
...
@@ -31,6 +32,7 @@ public class SolverFactory {
new
EMFeRSolver
(),
new
GLPKSolver
(),
new
SCIPSolver
(),
new
GurobiSolver
(),
new
ILPDirectSolver
(),
new
SimpleSolver
(),
new
RandomSolver
(
0
,
0
),
...
...
jastadd-mquat-solver-ilp/src/main/java/de/tudresden/inf/st/mquat/solving/ilp/GurobiSolver.java
0 → 100644
View file @
df10f8bc
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
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.Stream
;
public
class
GurobiSolver
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>
* </ul>
* @see GurobiSolver#setDeleteFilesOnExit(boolean)
*/
public
GurobiSolver
()
{
}
@Override
protected
String
[]
getCommand
(
Path
lp
,
Path
solution
,
long
remainingTimeForSolvingInMillis
)
{
String
[]
command
=
{
"gurobi_cl"
,
" ResultFile="
+
solution
.
toAbsolutePath
(),
"TimeLimit="
+
remainingTimeForSolvingInMillis
/
1000
,
String
.
valueOf
(
lp
.
toAbsolutePath
())};
return
command
;
}
@Override
protected
void
readFromPlainTextSolution
(
ILP
ilp
,
Path
solution
,
ILPSolution
result
,
List
<
IlpVariable
>
variablesSetToOne
)
throws
SolvingException
{
try
(
Stream
<
String
>
lines
=
Files
.
lines
(
solution
))
{
for
(
String
line
:
lines
.
collect
(
Collectors
.
toList
()))
{
if
(
line
.
startsWith
(
"#"
))
{
// comment line
if
(
line
.
startsWith
(
"# Objective Value ="
))
{
result
.
setObjective
(
Double
.
valueOf
(
line
.
substring
(
20
).
trim
()));
logger
.
debug
(
"read objective {}"
,
Double
.
valueOf
(
line
.
substring
(
20
).
trim
()));
}
}
else
{
String
[]
tokens
=
line
.
split
(
"\\s+"
);
if
(
tokens
.
length
==
2
)
{
// tokens: name, value
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
)
{
throw
new
SolvingException
(
"Could not find variable with name "
+
tokens
[
0
]);
}
variablesSetToOne
.
add
(
variable
);
}
}
}
}
}
catch
(
IOException
e
)
{
throw
new
SolvingException
(
"Could not open solution file"
,
e
);
}
catch
(
NumberFormatException
e
)
{
throw
new
SolvingException
(
"Could not parse solution file"
,
e
);
}
}
@Override
public
String
getName
()
{
return
"ilp-gurobi"
;
}
}
jastadd-mquat-solver-ilp/src/main/java/de/tudresden/inf/st/mquat/solving/ilp/ILPExternalSolver.java
View file @
df10f8bc
...
...
@@ -75,7 +75,7 @@ public abstract class ILPExternalSolver extends AbstractILPSolver {
try
{
lp
=
Files
.
createTempFile
(
"ilp"
,
".lp"
);
// solution = Files.createTempFile("solution", null);
solutionReadable
=
Files
.
createTempFile
(
"sol-read"
,
null
);
solutionReadable
=
Files
.
createTempFile
(
"sol-read"
,
".sol"
);
}
catch
(
IOException
e
)
{
throw
new
SolvingException
(
"Can not create lp or solution file"
,
e
);
}
if
(!
deleteFilesOnExit
)
{
logger
.
info
(
"Writing ILP to {}, solving now"
,
lp
.
toAbsolutePath
());
...
...
jastadd-mquat-solver-ilp/src/test/java/de/tudresden/inf/st/mquat/solving/GurobiHandwrittenTest.java
0 → 100644
View file @
df10f8bc
package
de.tudresden.inf.st.mquat.solving
;
import
de.tudresden.inf.st.mquat.solving.ilp.GurobiSolver
;
public
class
GurobiHandwrittenTest
extends
HandwrittenTestSuite
{
@Override
protected
Solver
getSolver
()
{
// set to false for debugging
return
new
GurobiSolver
().
setDeleteFilesOnExit
(
false
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment