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

Commit a733de64 authored by Stefan Schuhbaeck's avatar Stefan Schuhbaeck

refactor SourceTests

parent 3a6093c1
......@@ -6,7 +6,7 @@ import org.vadere.state.attributes.scenario.AttributesDynamicElement;
import org.vadere.state.scenario.Obstacle;
import org.vadere.state.scenario.Source;
import org.vadere.state.scenario.Topography;
import org.vadere.state.util.SingleSourceSpawnArray;
import org.vadere.state.util.SpawnArray;
import org.vadere.util.geometry.PointPositioned;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
......@@ -27,14 +27,14 @@ public class SingleSourceController extends SourceController {
private static final int NUMBER_OF_REPOSITION_TRIES = 10;
private static final int NUMBER_OF_POINT_SEARCH = 1_000; // todo based on shape and position of source
private SingleSourceSpawnArray spawnArray;
private SpawnArray spawnArray;
public SingleSourceController(Topography scenario, Source source,
DynamicElementFactory dynamicElementFactory,
AttributesDynamicElement attributesDynamicElement,
Random random) {
super(scenario, source, dynamicElementFactory, attributesDynamicElement, random);
VRectangle elementBound = new VRectangle(dynamicElementFactory.getDynamicElementRequiredPlace(new VPoint(0,0)).getBounds2D());
this.spawnArray = new SingleSourceSpawnArray(source.getShape(),
this.spawnArray = new SpawnArray(source.getShape(),
new VRectangle(0, 0,elementBound.getWidth(), elementBound.getHeight()),
dynamicElementFactory::getDynamicElementRequiredPlace);
}
......
package org.vadere.state.util;
import com.oracle.jrockit.jfr.Producer;
import org.jetbrains.annotations.NotNull;
import org.vadere.state.scenario.DynamicElement;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape;
......@@ -15,11 +12,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Random;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
/**
* <h1>Groups</h1>
......@@ -54,7 +47,7 @@ import java.util.stream.IntStream;
* same as above but it will use a Randomize groupNumber Iterator.
*
*/
public class GroupSpawnArray extends AbstractSpawnArray {
public class GroupSpawnArray extends SpawnArray {
// not an index put a way to calculate the index 1..n where n is the number of possible ways to place a given group
// key: groupSize
......
package org.vadere.state.util;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VRectangle;
import org.vadere.util.geometry.shapes.VShape;
import java.util.List;
import java.util.function.Function;
/**
* <h1>Single Pedestrians</h1>
*
* The single spawn algorithm divides the source in a grid based on the width of the pedestrians.
* This grid is used to place newly spawn pedestrians. These points are called allowedSpawnPoints and
* are saved as an 1D-array. Based on the Source Attribute values one of the four functions will
* be used to select the next allowedSpawnPoints.
*
* use the next free spawn point in order (0..n) to place the next pedestrian. This function will
* try to place up to maxPoints pedestrian an will wrap around to spawnPoint 0 if needed. Also this
* function will allow overlapping pedestrians a complete overlap is not allowed due to numerical
* problems in OE-solvers.
*/
public class SingleSourceSpawnArray extends AbstractSpawnArray{
private static Logger logger = LogManager.getLogger(SingleSourceSpawnArray.class);
public static final double D = 0.01;
public SingleSourceSpawnArray(final VShape boundShape, final VRectangle spawnElementBound, Function<VPoint, VShape> shapeProducer) {
super(boundShape, spawnElementBound, shapeProducer);
}
}
......@@ -11,8 +11,8 @@ import java.util.HashMap;
import java.util.List;
import java.util.function.Function;
public abstract class AbstractSpawnArray {
private static Logger logger = LogManager.getLogger(AbstractSpawnArray.class);
public class SpawnArray {
private static Logger logger = LogManager.getLogger(SpawnArray.class);
protected final VRectangle spawnElementBound;
protected final VRectangle bound;
......@@ -28,8 +28,8 @@ public abstract class AbstractSpawnArray {
protected HashMap<Integer,Integer> validSpawnPointMapInBoundShape;
protected Function<VPoint, VShape> shapeProducer;
public AbstractSpawnArray(final VShape boundShape, final VRectangle spawnElementBound,
Function<VPoint, VShape> shapeProducer) {
public SpawnArray(final VShape boundShape, final VRectangle spawnElementBound,
Function<VPoint, VShape> shapeProducer) {
this.spawnElementBound = spawnElementBound;
this.bound = new VRectangle(boundShape.getBounds2D());
this.shapeProducer = shapeProducer;
......
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