Commit 24a4cffd authored by TLauster's avatar TLauster
Browse files

create File for Generated Distributions

parent fc7ae36a
Pipeline #64264 failed with stage
in 25 seconds
...@@ -6,6 +6,11 @@ import org.vadere.simulator.projects.VadereProject; ...@@ -6,6 +6,11 @@ import org.vadere.simulator.projects.VadereProject;
import org.vadere.simulator.projects.io.IOVadere; import org.vadere.simulator.projects.io.IOVadere;
import org.vadere.state.scenario.Source; 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.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
...@@ -22,7 +27,7 @@ public class VadereAutomation { ...@@ -22,7 +27,7 @@ public class VadereAutomation {
private static final String SCENARIO_NAME = "Kreuzung_softShell_one_source"; private static final String SCENARIO_NAME = "Kreuzung_softShell_one_source";
private static final String SCENARIO_PATH = "C:/Studium/BA/vadereProjects/"; private static final String SCENARIO_PATH = "C:/Studium/BA/vadereProjects/";
private static final int N_SIMULATIONS = 200; private static final int N_SIMULATIONS = 10;
private static final int N_CONCURENT_SIMULATIONS = 20; //if this is choosen too high, out of memory errors may occur 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 Scenario final_scenario;
private static ArrayList<Thread> arrThreads = new ArrayList<>(); private static ArrayList<Thread> arrThreads = new ArrayList<>();
...@@ -33,6 +38,7 @@ public class VadereAutomation { ...@@ -33,6 +38,7 @@ public class VadereAutomation {
public static void main(String[] args) { public static void main(String[] args) {
long start_time = System.currentTimeMillis(); long start_time = System.currentTimeMillis();
// load project and choose the scenario // load project and choose the scenario
...@@ -75,6 +81,8 @@ public class VadereAutomation { ...@@ -75,6 +81,8 @@ public class VadereAutomation {
amount--; amount--;
} }
// wait for all threads to finish // wait for all threads to finish
try { try {
for (int i = 0; i < arrThreads.size(); i++) { for (int i = 0; i < arrThreads.size(); i++) {
...@@ -84,6 +92,7 @@ public class VadereAutomation { ...@@ -84,6 +92,7 @@ public class VadereAutomation {
System.out.println(ie); System.out.println(ie);
} }
} }
GeneratedDistributionWriter.getInstance().writeToFile();
// time // time
long stop_time = (System.currentTimeMillis() - start_time ) / 1000; // seconds long stop_time = (System.currentTimeMillis() - start_time ) / 1000; // seconds
System.out.println("*** Simulations took " + stop_time + " seconds ****"); System.out.println("*** Simulations took " + stop_time + " seconds ****");
...@@ -165,7 +174,7 @@ public class VadereAutomation { ...@@ -165,7 +174,7 @@ public class VadereAutomation {
//get a probability for each one //get a probability for each one
//double randomDouble = rand.nextDouble(); //double randomDouble = rand.nextDouble();
double randomDouble = nextTriangularDouble(); double randomDouble = nextExponentialDouble();
probabilities.add(randomDouble); probabilities.add(randomDouble);
probabilitiesSum += randomDouble; probabilitiesSum += randomDouble;
} }
...@@ -178,6 +187,7 @@ public class VadereAutomation { ...@@ -178,6 +187,7 @@ public class VadereAutomation {
//set the appropriate variables in the Scenario //set the appropriate variables in the Scenario
source.getAttributes().setTargetDistributionIds(targetIds); source.getAttributes().setTargetDistributionIds(targetIds);
source.getAttributes().setTargetDistributionProbabilities(probabilities); source.getAttributes().setTargetDistributionProbabilities(probabilities);
GeneratedDistributionWriter.getInstance().addLineToFile(probabilities.toString().substring(1,probabilities.toString().length()-1));
} }
...@@ -202,5 +212,41 @@ public class VadereAutomation { ...@@ -202,5 +212,41 @@ public class VadereAutomation {
Random rand = new Random(); Random rand = new Random();
return 1 - Math.sqrt(1 - rand.nextDouble()); 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;
}
}
Supports Markdown
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