Commit 92ad3bb1 authored by TLauster's avatar TLauster
Browse files

Dreiecksverteilung mit normierung

parent 5acec227
package org.vadere.simulator.scripts;
import java.util.*;
import java.lang.*;
import org.vadere.simulator.control.SourceController;
import org.vadere.simulator.entrypoints.ScenarioBuilder;
import org.vadere.simulator.projects.Scenario;
import org.vadere.simulator.projects.ScenarioRun;
import org.vadere.simulator.projects.SingleScenarioFinishedListener;
import org.vadere.simulator.projects.VadereProject;
import org.vadere.simulator.projects.io.IOVadere;
import org.vadere.state.scenario.Source;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.BlockingQueue;
import java.util.Random;
import java.util.concurrent.BlockingQueue;
/* Works only for three targets */
......@@ -22,13 +19,13 @@ public class VadereAutomation {
//public static final String SCENARIO_NAME = "Kreuzung3_Unit";
//public static final String SCENARIO_PATH = "D:/repo_checkout/PersMarionGoedel/material/canwelearn/data/";
public static final String SCENARIO_NAME = "Kreuzung_softShell_overlapping_source";
public static final String SCENARIO_PATH = "C:/Studium/BA/vadereProjects/";
public static final int N_SIMULATIONS = 100;
public static final int N_CONCURENT_SIMULATIONS = 20; //if this is choosen too high, out of memory errors may occur
public static Scenario final_scenario;
private static ArrayList<Thread> arrThreads = new ArrayList<Thread>();
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 = 200;
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<>();
// ThreadPoolExecuter !
......@@ -72,8 +69,9 @@ public class VadereAutomation {
int nSimulationsLeft = Math.min(N_CONCURENT_SIMULATIONS, amount);
for (int i = 0; i < nSimulationsLeft; i++) {
System.out.println("Start of " + (i + iteration * N_CONCURENT_SIMULATIONS));
startAutomatic(final_scenario);
int id = (i + iteration * N_CONCURENT_SIMULATIONS);
System.out.println("Start of " + id);
startAutomatic(final_scenario, id);
amount--;
}
......@@ -93,24 +91,23 @@ public class VadereAutomation {
public static int randomCalc(int min, int max) {
Random rand = new Random();
int randomNumber = rand.nextInt(max-min)+min;
return randomNumber;
return rand.nextInt(max-min)+min;
}
public static void startAutomatic(Scenario scenario) { // Scenario als final übergeben
private static void startAutomatic(Scenario scenario, int id) { // Scenario als final übergeben
try {
ScenarioBuilder builder = new ScenarioBuilder(scenario);
Random rand = new Random();
/*
int spawnNumber = 0;
for (int i = 0; i < 3; i++) {
spawnNumber += scenario.getTopography().getSources().get(i).getAttributes().getSpawnNumber();
}
int []spawnValues = new int[3];
Random rand = new Random();
int randomStart = rand.nextInt()%3;
if(randomStart < 0){
......@@ -128,6 +125,10 @@ public class VadereAutomation {
Integer.toString((int) ((float) spawnValues[1] / (float) spawnNumber * 100)) + "-" +
Integer.toString((int) ((float) spawnValues[2] / (float) spawnNumber * 100));
System.out.println("Distribution of pedestrians on the targets: " + target_distribution);
*/
/*
int spawnNumberLeft = randomCalc(0, spawnNumber);
int spawnNumberStraight = randomCalc(0, spawnNumber - spawnNumberLeft);
......@@ -143,12 +144,46 @@ public class VadereAutomation {
Integer.toString((int) ((float) spawnNumberStraight / (float) spawnNumber * 100)) + "-" +
Integer.toString((int) ((float) spawnNumberRight / (float) spawnNumber * 100));
System.out.println("Distribution of pedestrians on the targets: " + target_distribution);
*/
scenario = builder.build();
List<Source> sources = scenario.getScenarioStore().topography.getSources();
for (Source source : sources) {
List<List<Integer>> targetIds = new ArrayList<>();
List<Double> probabilities = new ArrayList<>();
int targetSize = scenario.getScenarioStore().topography.getTargets().size();
//scenario.getScenarioStore().topography.getTargets().forEach(target -> targetIds.add(new ArrayList<>(target.getId())));
double probabilitiesSum = 0.;
//iterate over all available targets
for(int i = 0; i < targetSize; i++){
targetIds.add(Collections.singletonList(scenario.getScenarioStore().topography.getTargets().get(i).getId()));
//targetIds.add(new ArrayList<Integer>().add(scenario.getScenarioStore().topography.getTargets().get(i).getId()));
//get a probability for each one
//double randomDouble = rand.nextDouble();
double randomDouble = nextTriangularDouble();
probabilities.add(randomDouble);
probabilitiesSum += randomDouble;
}
//norm the probabilities to 1
for(int i = 0; i < probabilities.size();i++){
probabilities.set(i,probabilities.get(i)/probabilitiesSum);
}
//set the appropriate variables in the Scenario
source.getAttributes().setTargetDistributionIds(targetIds);
source.getAttributes().setTargetDistributionProbabilities(probabilities);
}
scenario.saveChanges();
scenario.setName(target_distribution + "_Distribution");
//scenario.setName("x_Distribution");
//scenario.setName(target_distribution + "_Distribution");
scenario.setName(id + "_Distribution");
......@@ -162,5 +197,10 @@ public class VadereAutomation {
System.out.println("error" + e.getMessage());
}
}
private static double nextTriangularDouble() {
Random rand = new Random();
return 1 - Math.sqrt(1 - rand.nextDouble());
}
}
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