Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vadere
vadere
Commits
24a4cffd
Commit
24a4cffd
authored
Aug 02, 2018
by
TLauster
Browse files
create File for Generated Distributions
parent
fc7ae36a
Pipeline
#64264
failed with stage
in 25 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereSimulator/src/org/vadere/simulator/scripts/VadereAutomation.java
View file @
24a4cffd
...
...
@@ -6,6 +6,11 @@ import org.vadere.simulator.projects.VadereProject;
import
org.vadere.simulator.projects.io.IOVadere
;
import
org.vadere.state.scenario.Source
;
import
java.io.IOException
;
import
java.nio.charset.Charset
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.List
;
...
...
@@ -22,7 +27,7 @@ public class VadereAutomation {
private
static
final
String
SCENARIO_NAME
=
"Kreuzung_softShell_one_source"
;
private
static
final
String
SCENARIO_PATH
=
"C:/Studium/BA/vadereProjects/"
;
private
static
final
int
N_SIMULATIONS
=
20
0
;
private
static
final
int
N_SIMULATIONS
=
1
0
;
private
static
final
int
N_CONCURENT_SIMULATIONS
=
20
;
//if this is choosen too high, out of memory errors may occur
private
static
Scenario
final_scenario
;
private
static
ArrayList
<
Thread
>
arrThreads
=
new
ArrayList
<>();
...
...
@@ -33,6 +38,7 @@ public class VadereAutomation {
public
static
void
main
(
String
[]
args
)
{
long
start_time
=
System
.
currentTimeMillis
();
// load project and choose the scenario
...
...
@@ -75,6 +81,8 @@ public class VadereAutomation {
amount
--;
}
// wait for all threads to finish
try
{
for
(
int
i
=
0
;
i
<
arrThreads
.
size
();
i
++)
{
...
...
@@ -84,6 +92,7 @@ public class VadereAutomation {
System
.
out
.
println
(
ie
);
}
}
GeneratedDistributionWriter
.
getInstance
().
writeToFile
();
// time
long
stop_time
=
(
System
.
currentTimeMillis
()
-
start_time
)
/
1000
;
// seconds
System
.
out
.
println
(
"*** Simulations took "
+
stop_time
+
" seconds ****"
);
...
...
@@ -165,7 +174,7 @@ public class VadereAutomation {
//get a probability for each one
//double randomDouble = rand.nextDouble();
double
randomDouble
=
next
Triangular
Double
();
double
randomDouble
=
next
Exponential
Double
();
probabilities
.
add
(
randomDouble
);
probabilitiesSum
+=
randomDouble
;
}
...
...
@@ -178,6 +187,7 @@ public class VadereAutomation {
//set the appropriate variables in the Scenario
source
.
getAttributes
().
setTargetDistributionIds
(
targetIds
);
source
.
getAttributes
().
setTargetDistributionProbabilities
(
probabilities
);
GeneratedDistributionWriter
.
getInstance
().
addLineToFile
(
probabilities
.
toString
().
substring
(
1
,
probabilities
.
toString
().
length
()-
1
));
}
...
...
@@ -202,5 +212,41 @@ public class VadereAutomation {
Random
rand
=
new
Random
();
return
1
-
Math
.
sqrt
(
1
-
rand
.
nextDouble
());
}
private
static
double
nextExponentialDouble
()
{
Random
rand
=
new
Random
();
return
Math
.
log
(
rand
.
nextDouble
())
*
-
1
;
}
}
class
GeneratedDistributionWriter
{
private
static
final
GeneratedDistributionWriter
inst
=
new
GeneratedDistributionWriter
();
private
List
<
String
>
lines
=
new
ArrayList
<>();
private
GeneratedDistributionWriter
()
{
super
();
}
synchronized
void
addLineToFile
(
String
str
)
{
lines
.
add
(
str
);
}
void
writeToFile
()
{
Path
file
=
Paths
.
get
(
"C:/Studium/BA/Vadere/vadere/output/"
+
"generatedDistribution.txt"
);
try
{
Files
.
write
(
file
,
lines
,
Charset
.
forName
(
"UTF-8"
));
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
static
GeneratedDistributionWriter
getInstance
()
{
return
inst
;
}
}
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