2.12.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 3da97584 authored by Benedikt Kleinmeier's avatar Benedikt Kleinmeier
Browse files

Merge branch 'develop' of gitlab.lrz.de:vadere/vadere into develop

parents e52611ce dbb6b563
Pipeline #61292 failed with stage
in 21 seconds
......@@ -300,7 +300,7 @@ public class PostvisualizationModel extends SimulationModel<PostvisualizationCon
private double getSimTimeInSec(final Step step) {
return step.getSimTimeInSec()
.orElse(step.getStepNumber() * vadere.getScenarioStore().attributesSimulation.getSimTimeStepLength());
.orElse(step.getStepNumber() * vadere.getScenarioStore().getAttributesSimulation().getSimTimeStepLength());
}
public synchronized void setPotentialFieldContainer(final PotentialFieldContainer container) {
......
......@@ -173,7 +173,7 @@ public class TextView extends JPanel implements IJsonView {
switch (attributeType) {
case MODEL:
ModelDefinition modelDefinition = JsonConverter.deserializeModelDefinition(json);
currentScenario.getScenarioStore().mainModel = modelDefinition.getMainModel();
currentScenario.getScenarioStore().setMainModel(modelDefinition.getMainModel());
currentScenario.setAttributesModel(modelDefinition.getAttributesList());
break;
case SIMULATION:
......@@ -220,7 +220,7 @@ public class TextView extends JPanel implements IJsonView {
switch (attributeType) {
case MODEL:
txtrTextfiletextarea.setText(StateJsonConverter.serializeMainModelAttributesModelBundle(
scenario.getModelAttributes(), scenario.getScenarioStore().mainModel));
scenario.getModelAttributes(), scenario.getScenarioStore().getMainModel()));
break;
case SIMULATION:
txtrTextfiletextarea
......
......@@ -67,7 +67,7 @@ public class Simulation {
this.name = name;
this.mainModel = mainModel;
this.scenarioStore = scenarioStore;
this.attributesSimulation = scenarioStore.attributesSimulation;
this.attributesSimulation = scenarioStore.getAttributesSimulation();
this.attributesAgent = scenarioStore.getTopography().getAttributesPedestrian();
this.sourceControllers = new LinkedList<>();
this.targetControllers = new LinkedList<>();
......
......@@ -61,9 +61,9 @@ public class ScenarioBuilder {
// TODO: duplicated code
if(AttributesSimulation.class == clazz){
builder = new AttributesBuilder<>((E)store.attributesSimulation);
builder = new AttributesBuilder<>((E)store.getAttributesSimulation());
builder.setField(fieldName, value);
store.attributesSimulation = (AttributesSimulation) builder.build();
store.setAttributesSimulation((AttributesSimulation) builder.build());
}
else if(AttributesAgent.class == clazz){
builder = new AttributesBuilder<>((E)store.getTopography().getAttributesPedestrian());
......@@ -84,8 +84,8 @@ public class ScenarioBuilder {
else {
builder = new AttributesBuilder<>(store.getAttributes(clazz));
builder.setField(fieldName, value);
store.attributesList.removeIf(attributes -> attributes.getClass() == clazz);
store.attributesList.add(builder.build());
store.removeAttributesIf(attributes -> attributes.getClass() == clazz);
store.addAttributes(builder.build());
}
}
......
......@@ -25,7 +25,7 @@ public class MainModelBuilder {
public void createModelAndRandom()
throws ClassNotFoundException, InstantiationException, IllegalAccessException {
final AttributesSimulation attributesSimulation = scenarioStore.attributesSimulation;
final AttributesSimulation attributesSimulation = scenarioStore.getAttributesSimulation();
if (attributesSimulation.isUseRandomSeed()) {
random = new Random(attributesSimulation.getRandomSeed());
} else {
......@@ -45,10 +45,10 @@ public class MainModelBuilder {
}
private MainModel instantiateMainModel(Random random) {
String mainModelName = scenarioStore.mainModel;
String mainModelName = scenarioStore.getMainModel();
DynamicClassInstantiator<MainModel> instantiator = new DynamicClassInstantiator<>();
MainModel mainModel = instantiator.createObject(mainModelName);
mainModel.initialize(scenarioStore.attributesList, scenarioStore.getTopography(),
mainModel.initialize(scenarioStore.getAttributesList(), scenarioStore.getTopography(),
scenarioStore.getTopography().getAttributesPedestrian(), random);
return mainModel;
}
......
......@@ -11,6 +11,7 @@ import java.util.List;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.jetbrains.annotations.NotNull;
import org.vadere.simulator.projects.dataprocessing.DataProcessingJsonManager;
import org.vadere.simulator.projects.io.JsonConverter;
import org.vadere.state.attributes.Attributes;
......@@ -32,24 +33,17 @@ import difflib.DiffUtils;
public class Scenario {
private static Logger logger = LogManager.getLogger(Scenario.class);
private ScenarioStore scenarioStore;
private DataProcessingJsonManager dataProcessingJsonManager;
private String savedStateSerialized;
private String currentStateSerialized;
public Scenario(final String name) {
this(name, new ScenarioStore(name));
}
public Scenario(final ScenarioStore store) {
this(store.name, store);
this(new ScenarioStore(name));
}
public Scenario(final String name, final ScenarioStore store) {
public Scenario(@NotNull final ScenarioStore store) {
this.scenarioStore = store;
this.dataProcessingJsonManager = new DataProcessingJsonManager();
......@@ -88,7 +82,7 @@ public class Scenario {
}
public String getName() {
return scenarioStore.name;
return scenarioStore.getName();
}
public ScenarioStore getScenarioStore() {
......@@ -96,7 +90,7 @@ public class Scenario {
}
public List<Attributes> getModelAttributes() {
return scenarioStore.attributesList;
return scenarioStore.getAttributesList();
}
public AttributesAgent getAttributesPedestrian() {
......@@ -104,26 +98,26 @@ public class Scenario {
}
public AttributesSimulation getAttributesSimulation() {
return scenarioStore.attributesSimulation;
return scenarioStore.getAttributesSimulation();
}
public Topography getTopography() {
return scenarioStore.getTopography();
}
public void setName(String name) {
this.scenarioStore.name = name;
public void setName(@NotNull final String name) {
this.scenarioStore.setName(name);
}
public void setAttributesModel(List<Attributes> attributesList) {
scenarioStore.attributesList = attributesList;
public void setAttributesModel(@NotNull final List<Attributes> attributesList) {
scenarioStore.setAttributesList(attributesList);
}
public void setAttributesSimulation(AttributesSimulation attributesSimulation) {
this.scenarioStore.attributesSimulation = attributesSimulation;
public void setAttributesSimulation(@NotNull final AttributesSimulation attributesSimulation) {
this.scenarioStore.setAttributesSimulation(attributesSimulation);
}
public void setTopography(final Topography topography) {
public void setTopography(@NotNull final Topography topography) {
scenarioStore.setTopography(topography);
}
......@@ -142,7 +136,7 @@ public class Scenario {
}
public String getDisplayName() {
return scenarioStore.name + (hasUnsavedChanges() ? "*" : "");
return scenarioStore.getName() + (hasUnsavedChanges() ? "*" : "");
}
public void discardChanges() {
......@@ -157,16 +151,16 @@ public class Scenario {
}
public String getDescription() {
return scenarioStore.description;
return scenarioStore.getDescription();
}
public void setDescription(String description) {
scenarioStore.description = description;
scenarioStore.setDescription(description);
}
public String readyToRunResponse() { // TODO [priority=medium] [task=check] add more conditions
if (scenarioStore.mainModel == null) {
return scenarioStore.name + ": no mainModel is set";
if (scenarioStore.getMainModel() == null) {
return scenarioStore.getName() + ": no mainModel is set";
}
return null;
}
......@@ -175,11 +169,11 @@ public class Scenario {
return dataProcessingJsonManager;
}
public void setDataProcessingJsonManager(final DataProcessingJsonManager manager) {
public void setDataProcessingJsonManager(@NotNull final DataProcessingJsonManager manager) {
this.dataProcessingJsonManager = manager;
}
public void saveToOutputPath(final Path outputPath) {
public void saveToOutputPath(@NotNull final Path outputPath) {
try (PrintWriter out = new PrintWriter(Paths.get(outputPath.toString(), getName() + IOUtils.SCENARIO_FILE_EXTENSION).toString())) {
out.println(JsonConverter.serializeScenarioRunManager(this, true));
} catch (IOException e) {
......
......@@ -84,7 +84,7 @@ public class ScenarioRun implements Runnable {
final Random random = modelBuilder.getRandom();
// prepare processors and simulation data writer
if(scenarioStore.attributesSimulation.isWriteSimulationData()) {
if(scenarioStore.getAttributesSimulation().isWriteSimulationData()) {
processorManager = dataProcessingJsonManager.createProcessorManager(mainModel);
}
......@@ -97,7 +97,7 @@ public class ScenarioRun implements Runnable {
sealAllAttributes();
// Run simulation main loop from start time = 0 seconds
simulation = new Simulation(mainModel, 0, scenarioStore.name, scenarioStore, passiveCallbacks, random, processorManager);
simulation = new Simulation(mainModel, 0, scenarioStore.getName(), scenarioStore, passiveCallbacks, random, processorManager);
}
simulation.run();
......@@ -165,8 +165,8 @@ public class ScenarioRun implements Runnable {
}
public String readyToRunResponse() { // TODO [priority=medium] [task=check] add more conditions
if (scenarioStore.mainModel == null) {
return scenarioStore.name + ": no mainModel is set";
if (scenarioStore.getMainModel() == null) {
return scenarioStore.getName() + ": no mainModel is set";
}
return null;
}
......
......@@ -3,6 +3,7 @@ package org.vadere.simulator.projects;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.log4j.LogManager;
......@@ -28,11 +29,11 @@ import com.fasterxml.jackson.core.JsonProcessingException;
public class ScenarioStore {
private static Logger logger = LogManager.getLogger(ScenarioStore.class);
public String name;
public String description;
public String mainModel;
public List<Attributes> attributesList;
public AttributesSimulation attributesSimulation;
private String name;
private String description;
private String mainModel;
private List<Attributes> attributesList;
private AttributesSimulation attributesSimulation;
private Topography topography;
public ScenarioStore(final String name, final String description, final String mainModel, final List<Attributes> attributesModel,
......@@ -85,4 +86,52 @@ public class ScenarioStore {
public <T extends Attributes> T getAttributes(@NotNull final Class<T> clazz) {
return FindByClass.findSingleObjectOfClass(attributesList, clazz);
}
public void setAttributesList(final List<Attributes> attributesList) {
this.attributesList = attributesList;
}
public void setAttributesSimulation(final AttributesSimulation attributesSimulation) {
this.attributesSimulation = attributesSimulation;
}
public void removeAttributesIf(@NotNull final Predicate<Attributes> predicate) {
attributesList.removeIf(predicate);
}
public void addAttributes(@NotNull final Attributes attributes) {
attributesList.add(attributes);
}
public void setDescription(final String description) {
this.description = description;
}
public void setMainModel(final String mainModel) {
this.mainModel = mainModel;
}
public void setName(final String name) {
this.name = name;
}
public AttributesSimulation getAttributesSimulation() {
return attributesSimulation;
}
public List<Attributes> getAttributesList() {
return attributesList;
}
public String getDescription() {
return description;
}
public String getMainModel() {
return mainModel;
}
public String getName() {
return name;
}
}
......@@ -87,8 +87,8 @@ public class JsonConverter {
}
private static void serializeMeta(ObjectNode node, boolean commitHashIncluded, ScenarioStore scenarioStore) {
node.put("name", scenarioStore.name);
node.put("description", scenarioStore.description);
node.put("name", scenarioStore.getName());
node.put("description", scenarioStore.getDescription());
node.put("release", HashGenerator.releaseNumber());
if (commitHashIncluded)
node.put("commithash", HashGenerator.commitHash());
......@@ -97,14 +97,14 @@ public class JsonConverter {
private static ObjectNode serializeVadereNode(ScenarioStore scenarioStore) {
ObjectNode vadereNode = StateJsonConverter.createObjectNode();
vadereNode.put(StateJsonConverter.MAIN_MODEL_KEY, scenarioStore.mainModel);
vadereNode.put(StateJsonConverter.MAIN_MODEL_KEY, scenarioStore.getMainModel());
// vadere > attributesModel
ObjectNode attributesModelNode = StateJsonConverter.serializeAttributesModelToNode(scenarioStore.attributesList);
ObjectNode attributesModelNode = StateJsonConverter.serializeAttributesModelToNode(scenarioStore.getAttributesList());
vadereNode.set("attributesModel", attributesModelNode);
// vadere > attributesSimulation
vadereNode.set("attributesSimulation", StateJsonConverter.convertValue(scenarioStore.attributesSimulation, JsonNode.class));
vadereNode.set("attributesSimulation", StateJsonConverter.convertValue(scenarioStore.getAttributesSimulation(), JsonNode.class));
// vadere > topography
ObjectNode topographyNode = StateJsonConverter.serializeTopographyToNode(scenarioStore.getTopography());
......@@ -119,10 +119,10 @@ public class JsonConverter {
}
public static ScenarioStore cloneScenarioStore(ScenarioStore scenarioStore) throws IOException {
JsonNode attributesSimulationNode = StateJsonConverter.convertValue(scenarioStore.attributesSimulation, JsonNode.class);
ObjectNode attributesModelNode = StateJsonConverter.serializeAttributesModelToNode(scenarioStore.attributesList);
JsonNode attributesSimulationNode = StateJsonConverter.convertValue(scenarioStore.getAttributesSimulation(), JsonNode.class);
ObjectNode attributesModelNode = StateJsonConverter.serializeAttributesModelToNode(scenarioStore.getAttributesList());
ObjectNode topographyNode = StateJsonConverter.serializeTopographyToNode(scenarioStore.getTopography());
return new ScenarioStore(scenarioStore.name, scenarioStore.description, scenarioStore.mainModel,
return new ScenarioStore(scenarioStore.getName(), scenarioStore.getDescription(), scenarioStore.getMainModel(),
StateJsonConverter.deserializeAttributesListFromNode(attributesModelNode),
StateJsonConverter.deserializeAttributesSimulationFromNode(attributesSimulationNode),
StateJsonConverter.deserializeTopographyFromNode(topographyNode));
......
/*
* Copyright 1993-2010 NVIDIA Corporation. All rights reserved.
*
* Please refer to the NVIDIA end user license agreement (EULA) associated
* with this source code for terms and conditions that govern your use of
* this software. Any use, reproduction, disclosure, or distribution of
* this software and related documentation outside the terms of the EULA
* is strictly prohibited.
*
*/
#define LOCAL_SIZE_LIMIT 16U
inline void ComparatorPrivate(
uint *keyA,
uint *valA,
uint *keyB,
uint *valB,
uint dir
){
if( (*keyA > *keyB) == dir ){
uint t;
t = *keyA; *keyA = *keyB; *keyB = t;
t = *valA; *valA = *valB; *valB = t;
}
}
inline void ComparatorLocal(
__local uint *keyA,
__local uint *valA,
__local uint *keyB,
__local uint *valB,
uint dir
){
if( (*keyA > *keyB) == dir ){
uint t;
t = *keyA; *keyA = *keyB; *keyB = t;
t = *valA; *valA = *valB; *valB = t;
}
}
////////////////////////////////////////////////////////////////////////////////
// Monolithic bitonic sort kernel for short arrays fitting into local memory
////////////////////////////////////////////////////////////////////////////////
__kernel void bitonicSortLocal(
__global uint *d_DstKey,
__global uint *d_DstVal,
__global uint *d_SrcKey,
__global uint *d_SrcVal,
uint arrayLength,
uint dir
){
__local uint l_key[LOCAL_SIZE_LIMIT];
__local uint l_val[LOCAL_SIZE_LIMIT];
//Offset to the beginning of subbatch and load data
d_SrcKey += get_group_id(0) * LOCAL_SIZE_LIMIT + get_local_id(0);
d_SrcVal += get_group_id(0) * LOCAL_SIZE_LIMIT + get_local_id(0);
d_DstKey += get_group_id(0) * LOCAL_SIZE_LIMIT + get_local_id(0);
d_DstVal += get_group_id(0) * LOCAL_SIZE_LIMIT + get_local_id(0);
l_key[get_local_id(0) + 0] = d_SrcKey[ 0];
l_val[get_local_id(0) + 0] = d_SrcVal[ 0];
l_key[get_local_id(0) + (LOCAL_SIZE_LIMIT / 2)] = d_SrcKey[(LOCAL_SIZE_LIMIT / 2)];
l_val[get_local_id(0) + (LOCAL_SIZE_LIMIT / 2)] = d_SrcVal[(LOCAL_SIZE_LIMIT / 2)];
for(uint size = 2; size < arrayLength; size <<= 1){
//Bitonic merge
uint ddd = dir ^ ( (get_local_id(0) & (size / 2)) != 0 );
for(uint stride = size / 2; stride > 0; stride >>= 1){
barrier(CLK_LOCAL_MEM_FENCE);
uint pos = 2 * get_local_id(0) - (get_local_id(0) & (stride - 1));
ComparatorLocal(
&l_key[pos + 0], &l_val[pos + 0],
&l_key[pos + stride], &l_val[pos + stride],
ddd
);
}
}
//ddd == dir for the last bitonic merge step
{
for(uint stride = arrayLength / 2; stride > 0; stride >>= 1){
barrier(CLK_LOCAL_MEM_FENCE);
uint pos = 2 * get_local_id(0) - (get_local_id(0) & (stride - 1));
ComparatorLocal(
&l_key[pos + 0], &l_val[pos + 0],
&l_key[pos + stride], &l_val[pos + stride],
dir
);
}
}
barrier(CLK_LOCAL_MEM_FENCE);
d_DstKey[ 0] = l_key[get_local_id(0) + 0];
d_DstVal[ 0] = l_val[get_local_id(0) + 0];
d_DstKey[(LOCAL_SIZE_LIMIT / 2)] = l_key[get_local_id(0) + (LOCAL_SIZE_LIMIT / 2)];
d_DstVal[(LOCAL_SIZE_LIMIT / 2)] = l_val[get_local_id(0) + (LOCAL_SIZE_LIMIT / 2)];
}
////////////////////////////////////////////////////////////////////////////////
// Bitonic sort kernel for large arrays (not fitting into local memory)
////////////////////////////////////////////////////////////////////////////////
//Bottom-level bitonic sort
//Almost the same as bitonicSortLocal with the only exception
//of even / odd subarrays (of LOCAL_SIZE_LIMIT points) being
//sorted in opposite directions
__kernel void bitonicSortLocal1(
__global uint *d_DstKey,
__global uint *d_DstVal,
__global uint *d_SrcKey,
__global uint *d_SrcVal
){
__local uint l_key[LOCAL_SIZE_LIMIT];
__local uint l_val[LOCAL_SIZE_LIMIT];
//Offset to the beginning of subarray and load data
d_SrcKey += get_group_id(0) * LOCAL_SIZE_LIMIT + get_local_id(0);
d_SrcVal += get_group_id(0) * LOCAL_SIZE_LIMIT + get_local_id(0);
d_DstKey += get_group_id(0) * LOCAL_SIZE_LIMIT + get_local_id(0);
d_DstVal += get_group_id(0) * LOCAL_SIZE_LIMIT + get_local_id(0);
l_key[get_local_id(0) + 0] = d_SrcKey[ 0];
l_val[get_local_id(0) + 0] = d_SrcVal[ 0];
l_key[get_local_id(0) + (LOCAL_SIZE_LIMIT / 2)] = d_SrcKey[(LOCAL_SIZE_LIMIT / 2)];
l_val[get_local_id(0) + (LOCAL_SIZE_LIMIT / 2)] = d_SrcVal[(LOCAL_SIZE_LIMIT / 2)];
uint comparatorI = get_global_id(0) & ((LOCAL_SIZE_LIMIT / 2) - 1);
for(uint size = 2; size < LOCAL_SIZE_LIMIT; size <<= 1){
//Bitonic merge
uint ddd = (comparatorI & (size / 2)) != 0;
for(uint stride = size / 2; stride > 0; stride >>= 1){
barrier(CLK_LOCAL_MEM_FENCE);
uint pos = 2 * get_local_id(0) - (get_local_id(0) & (stride - 1));
ComparatorLocal(
&l_key[pos + 0], &l_val[pos + 0],
&l_key[pos + stride], &l_val[pos + stride],
ddd
);
}
}
//Odd / even arrays of LOCAL_SIZE_LIMIT elements
//sorted in opposite directions
{
uint ddd = (get_group_id(0) & 1);
for(uint stride = LOCAL_SIZE_LIMIT / 2; stride > 0; stride >>= 1){
barrier(CLK_LOCAL_MEM_FENCE);
uint pos = 2 * get_local_id(0) - (get_local_id(0) & (stride - 1));
ComparatorLocal(
&l_key[pos + 0], &l_val[pos + 0],
&l_key[pos + stride], &l_val[pos + stride],
ddd
);
}
}
barrier(CLK_LOCAL_MEM_FENCE);
d_DstKey[ 0] = l_key[get_local_id(0) + 0];
d_DstVal[ 0] = l_val[get_local_id(0) + 0];
d_DstKey[(LOCAL_SIZE_LIMIT / 2)] = l_key[get_local_id(0) + (LOCAL_SIZE_LIMIT / 2)];
d_DstVal[(LOCAL_SIZE_LIMIT / 2)] = l_val[get_local_id(0) + (LOCAL_SIZE_LIMIT / 2)];
}
//Bitonic merge iteration for 'stride' >= LOCAL_SIZE_LIMIT
__kernel void bitonicMergeGlobal(
__global uint *d_DstKey,
__global uint *d_DstVal,
__global uint *d_SrcKey,
__global uint *d_SrcVal,
uint arrayLength,
uint size,
uint stride,
uint dir
){
uint global_comparatorI = get_global_id(0);
uint comparatorI = global_comparatorI & (arrayLength / 2 - 1);
//Bitonic merge
uint ddd = dir ^ ( (comparatorI & (size / 2)) != 0 );
uint pos = 2 * global_comparatorI - (global_comparatorI & (stride - 1));
uint keyA = d_SrcKey[pos + 0];
uint valA = d_SrcVal[pos + 0];
uint keyB = d_SrcKey[pos + stride];
uint valB = d_SrcVal[pos + stride];
ComparatorPrivate(
&keyA, &valA,
&keyB, &valB,
ddd
);
d_DstKey[pos + 0] = keyA;
d_DstVal[pos + 0] = valA;
d_DstKey[pos + stride] = keyB;
d_DstVal[pos + stride] = valB;
}
//Combined bitonic merge steps for
//'size' > LOCAL_SIZE_LIMIT and 'stride' = [1 .. LOCAL_SIZE_LIMIT / 2]
__kernel void bitonicMergeLocal(
__global uint *d_DstKey,
__global uint *d_DstVal,
__global uint *d_SrcKey,
__global uint *d_SrcVal,
uint arrayLength,
uint stride,
uint size,
uint dir
){
__local uint l_key[LOCAL_SIZE_LIMIT];
__local uint l_val[LOCAL_SIZE_LIMIT];
d_SrcKey += get_group_id(0) * LOCAL_SIZE_LIMIT + get_local_id(0);
d_SrcVal += get_group_id(0) * LOCAL_SIZE_LIMIT + get_local_id(0);
d_DstKey += get_group_id(0) * LOCAL_SIZE_LIMIT + get_local_id(0);
d_DstVal += get_group_id(0) * LOCAL_SIZE_LIMIT + get_local_id(0);