Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ttc18
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
stgroup
ttc18
Commits
b6e62b7c
Commit
b6e62b7c
authored
6 years ago
by
IevgSvet
Browse files
Options
Downloads
Patches
Plain Diff
Merge develop; Add Main, gradle run for Genetic solver
parent
3ac3a7e8
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
jastadd-mquat-solver-genetic/build.gradle
+20
-0
20 additions, 0 deletions
jastadd-mquat-solver-genetic/build.gradle
jastadd-mquat-solver-genetic/src/main/java/de/tudresden/inf/st/mquat/solving/genetic/GeneticMain.java
+123
-0
123 additions, 0 deletions
...e/tudresden/inf/st/mquat/solving/genetic/GeneticMain.java
with
143 additions
and
0 deletions
jastadd-mquat-solver-genetic/build.gradle
+
20
−
0
View file @
b6e62b7c
apply
plugin:
'java'
apply
plugin:
'java'
apply
plugin:
'application'
sourceCompatibility
=
1.8
sourceCompatibility
=
1.8
...
@@ -7,6 +8,16 @@ repositories {
...
@@ -7,6 +8,16 @@ repositories {
mavenCentral
()
mavenCentral
()
}
}
jar
{
manifest
{
attributes
"Main-Class"
:
'de.tudresden.inf.st.mquat.solving.genetic.GeneticMain'
}
from
{
configurations
.
compile
.
collect
{
it
.
isDirectory
()
?
it
:
zipTree
(
it
)
}
}
}
dependencies
{
dependencies
{
compile
group:
'org.apache.logging.log4j'
,
name:
'log4j-api'
,
version:
'2.10.0'
compile
group:
'org.apache.logging.log4j'
,
name:
'log4j-api'
,
version:
'2.10.0'
compile
group:
'org.apache.logging.log4j'
,
name:
'log4j-core'
,
version:
'2.10.0'
compile
group:
'org.apache.logging.log4j'
,
name:
'log4j-core'
,
version:
'2.10.0'
...
@@ -22,3 +33,12 @@ dependencies {
...
@@ -22,3 +33,12 @@ dependencies {
compile
group:
'org.opt4j'
,
name:
'opt4j-viewer'
,
version:
'3.1.4'
compile
group:
'org.opt4j'
,
name:
'opt4j-viewer'
,
version:
'3.1.4'
compile
group:
'org.opt4j'
,
name:
'opt4j-benchmarks'
,
version:
'3.1.4'
compile
group:
'org.opt4j'
,
name:
'opt4j-benchmarks'
,
version:
'3.1.4'
}
}
run
{
mainClassName
=
'de.tudresden.inf.st.mquat.solving.genetic.GeneticMain'
standardInput
=
System
.
in
if
(
project
.
hasProperty
(
"appArgs"
))
{
args
Eval
.
me
(
appArgs
)
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
jastadd-mquat-solver-genetic/src/main/java/de/tudresden/inf/st/mquat/solving/genetic/GeneticMain.java
0 → 100644
+
123
−
0
View file @
b6e62b7c
package
de.tudresden.inf.st.mquat.solving.genetic
;
import
de.tudresden.inf.st.mquat.generator.ScenarioDescription
;
import
de.tudresden.inf.st.mquat.generator.ScenarioGenerator
;
import
de.tudresden.inf.st.mquat.jastadd.model.MquatWriteSettings
;
import
de.tudresden.inf.st.mquat.jastadd.model.Root
;
import
de.tudresden.inf.st.mquat.solving.BenchmarkableSolver
;
import
org.apache.logging.log4j.LogManager
;
import
org.apache.logging.log4j.Logger
;
import
de.tudresden.inf.st.mquat.jastadd.model.Solution
;
import
de.tudresden.inf.st.mquat.solving.SolvingException
;
import
java.io.BufferedWriter
;
import
java.nio.file.StandardOpenOption
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.concurrent.TimeUnit
;
import
static
java
.
nio
.
file
.
Files
.
exists
;
public
class
GeneticMain
{
protected
static
final
char
SEPARATOR
=
','
;
protected
static
void
writeHeader
(
BufferedWriter
writer
)
throws
IOException
{
writer
.
append
(
"name"
).
append
(
SEPARATOR
)
.
append
(
"Solved"
).
append
(
SEPARATOR
)
.
append
(
"Obj"
).
append
(
SEPARATOR
)
.
append
(
"Valid"
).
append
(
SEPARATOR
)
.
append
(
"TimeOut"
).
append
(
"\n"
);
}
private
static
void
createDirIfNecessary
(
Path
directory
)
throws
IOException
{
if
(!
exists
(
directory
))
{
Files
.
createDirectories
(
directory
);
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Logger
logger
=
LogManager
.
getLogger
(
GeneticMain
.
class
);
String
scenario_name
=
"size_v2_q1_d1_r15"
;
int
numTopLevelComponents
=
1
;
int
avgNumImplSubComponents
=
0
;
int
implSubComponentStdDerivation
=
0
;
int
avgNumCompSubComponents
=
2
;
int
compSubComponentStdDerivation
=
0
;
int
componentDepth
=
2
;
//from scenario - depth
int
numImplementations
=
2
;
//from scenario - variants
double
excessComputeResourceRatio
=
1.5
;
//from scenario - resources
int
numRequests
=
1
;
//from scenario - requests
int
numCpus
=
1
;
long
seed
=
0
;
//settings - seed
long
timeoutValue
=
20
;
//from scenarios.json
String
timeoutUnit
=
"SECONDS"
;
//from scenarios.json, possible values - "SECONDS", "MINUTES"
int
generations
=
200000
;
int
populationSize
=
1000
;
if
(
args
.
length
==
2
)
{
System
.
out
.
println
(
"============ Args: "
+
args
[
0
]
+
" and "
+
args
[
1
]);
generations
=
Integer
.
parseInt
(
args
[
0
]);
populationSize
=
Integer
.
parseInt
(
args
[
1
]);
System
.
out
.
println
(
"============ generations = "
+
generations
+
", populationSize = "
+
populationSize
);
}
ScenarioGenerator
generator
=
new
ScenarioGenerator
(
new
ScenarioDescription
(
numTopLevelComponents
,
avgNumImplSubComponents
,
implSubComponentStdDerivation
,
avgNumCompSubComponents
,
compSubComponentStdDerivation
,
componentDepth
,
numImplementations
,
excessComputeResourceRatio
,
numRequests
,
numCpus
,
seed
));
Root
model
=
generator
.
generate
();
logger
.
info
(
model
.
print
(
new
MquatWriteSettings
(
" "
)));
BenchmarkableSolver
solver
=
new
GeneticSolver
(
GeneticSolver
.
SelectorType
.
NSGA2
,
generations
,
populationSize
);
solver
.
setTimeout
(
timeoutValue
,
TimeUnit
.
valueOf
(
timeoutUnit
));
Path
path_for_results
=
Paths
.
get
(
"results/scenarios"
);
createDirIfNecessary
(
path_for_results
);
Path
results_file
=
Paths
.
get
(
path_for_results
.
toString
()
+
"/"
+
scenario_name
+
".csv"
);
BufferedWriter
bw
=
null
;
if
(!
Files
.
exists
(
results_file
))
{
bw
=
Files
.
newBufferedWriter
(
results_file
);
writeHeader
(
bw
);
}
if
(
bw
==
null
)
bw
=
Files
.
newBufferedWriter
(
results_file
,
StandardOpenOption
.
APPEND
,
StandardOpenOption
.
CREATE
);
StringBuilder
sb
=
new
StringBuilder
(
"genetic_NSGA2"
).
append
(
SEPARATOR
);
// name
Solution
solution
=
null
;
try
{
solution
=
solver
.
solve
(
model
);
if
(
solution
==
null
)
{
solution
=
Solution
.
emptySolutionOf
(
model
);
}
else
{
solution
.
explain
();
}
sb
.
append
(
solver
.
getLastSolvingTime
()).
append
(
SEPARATOR
)
// solution time
.
append
(
solution
.
computeObjective
()).
append
(
SEPARATOR
)
// objective
.
append
(
solution
.
isValid
());
// valid
}
catch
(
SolvingException
e
)
{
logger
.
catching
(
e
);
sb
.
append
(-
1
).
append
(
SEPARATOR
)
// solution time
.
append
(-
1
).
append
(
SEPARATOR
)
// objective
.
append
(
false
);
// valid
}
sb
.
append
(
SEPARATOR
).
append
(
solver
.
hadTimeout
())
// timeout
.
append
(
"\n"
);
bw
.
append
(
sb
.
toString
());
bw
.
close
();
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment