Starting from 2021-07-01, all LRZ GitLab users will be required to explicitly accept the GitLab Terms of Service. Please see the detailed information at https://doku.lrz.de/display/PUBLIC/GitLab and make sure that your projects conform to the requirements.

Commit 6a8873dd authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

add some usful comments and remove unnecessary logging.

parent 1064f70c
......@@ -143,13 +143,11 @@ public class OnlineVisualization implements PassiveCallback {
selectedAgent = (Agent)model.getSelectedElement();
}
/*if(model.config.isShowPotentialField() && selectedAgent != null && potentialField != null) {
if(model.config.isShowPotentialField() && selectedAgent != null && potentialField != null) {
pedPotentialField = IPotentialField.copyAgentField(potentialField, selectedAgent, new VRectangle(model.getTopographyBound()), 0.1);
}*/
//ObservationAreaSnapshotData data = new ObservationAreaSnapshotData(simTimeInSec, domain.clone(), pft, pedPotentialField, selectedAgent, discretizations);
ObservationAreaSnapshotData data = new ObservationAreaSnapshotData(simTimeInSec, domain, pft, pedPotentialField, selectedAgent, discretizations);
}
ObservationAreaSnapshotData data = new ObservationAreaSnapshotData(simTimeInSec, domain.clone(), pft, pedPotentialField, selectedAgent, discretizations);
model.pushObservationAreaSnapshot(data);
}
}
......
package org.vadere.gui.onlinevisualization.view;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Random;
import java.util.stream.Stream;
import org.jetbrains.annotations.NotNull;
......@@ -16,7 +14,6 @@ import org.vadere.gui.renderer.agent.AgentRender;
import org.vadere.state.scenario.Agent;
import org.vadere.state.scenario.Pedestrian;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.visualization.ColorHelper;
public class OnlinevisualizationRenderer extends SimulationRenderer {
......@@ -25,7 +22,6 @@ public class OnlinevisualizationRenderer extends SimulationRenderer {
private final Map<Integer, VPoint> lastPedestrianPositions;
private final Map<Integer, VPoint> pedestrianDirections;
private final Map<Integer, LinkedList<VPoint>> pedestrianPositions;
private final ArrayList<Color> randomColors = new ArrayList<>();
public OnlinevisualizationRenderer(final OnlineVisualizationModel model) {
super(model);
......@@ -58,35 +54,10 @@ public class OnlinevisualizationRenderer extends SimulationRenderer {
}
}
private Color getNextRandomColor() {
Random random = new Random(1);
Color color = new Color(random.nextInt(150), random.nextInt(150), random.nextInt(150));
while (randomColors.contains(color)) {
color = new Color(random.nextInt(150), random.nextInt(150), random.nextInt(150));
}
randomColors.add(color);
return color;
}
private Color getRandomColor(final int index) {
if(randomColors.size() <= index) {
while (randomColors.size() <= index) {
randomColors.add(getNextRandomColor());
}
}
return randomColors.get(index);
}
private void renderPedestrians(final Graphics2D g) {
AgentRender agentRender = getAgentRender();
for (Pedestrian ped : model.getPedestrians()) {
Color agentColor = getPedestrianColor(ped);
if(ped.updateCount != -1) {
agentColor = getRandomColor(ped.updateCount);
}
g.setColor(agentColor);
VPoint position = ped.getPosition();
agentRender.render(ped, agentColor, g);
......
......@@ -15,7 +15,6 @@ import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.geometry.shapes.VTriangle;
import org.vadere.util.logging.Logger;
import org.vadere.util.math.IDistanceFunction;
import org.vadere.util.math.InterpolationUtil;
import java.util.ArrayList;
import java.util.HashSet;
......
......@@ -121,7 +121,7 @@ public class GenEikMesh<V extends IVertex, E extends IHalfEdge, F extends IFace>
private static final Logger log = Logger.getLogger(GenEikMesh.class);
static {
log.setDebug();
//log.setDebug();
}
......
......@@ -65,19 +65,11 @@ public class MeshConstructor {
IDistanceFunction distanceFunction = IDistanceFunction.create(segmentBound, holes);
logger.info("construct distance function");
IDistanceFunction distanceFunctionApproximation = new DistanceFunctionApproxBF(pslg, distanceFunction, () -> new PMesh());
((DistanceFunctionApproxBF) distanceFunctionApproximation).printPython();
IEdgeLengthFunction edgeLengthFunction = p -> hmin + smoothness * Math.abs((distanceFunctionApproximation).apply(p));
EdgeLengthFunctionApprox edgeLengthFunctionApprox = new EdgeLengthFunctionApprox(pslg, edgeLengthFunction, p -> hmax);
edgeLengthFunctionApprox.smooth(smoothness);
logger.info("construct element size function");
edgeLengthFunctionApprox.printPython();
//((DistanceFunctionApproxBF) distanceFunctionApproximation).printPython();
//edgeLengthFunctionApprox.printPython();
//edgeLengthFunctionApprox.printPython();
Collection<VPolygon> polygons = pslg.getAllPolygons();
//polygons.add(targetShape);
......@@ -107,14 +99,6 @@ public class MeshConstructor {
var meshPanel = new PMeshPanel(meshRenderer, 500, 500);
meshPanel.display("EikMesh h0 = " + h0);
/*try {
MovRecorder<PVertex, PHalfEdge, PFace> movRecorder = new MovRecorder<>(meshImprover, meshRenderer, 500, 500);
movRecorder.record();
movRecorder.finish();
} catch (IOException e) {
e.printStackTrace();
}*/
while (!meshImprover.isFinished()) {
synchronized (meshImprover.getMesh()) {
meshImprover.improve();
......@@ -123,35 +107,6 @@ public class MeshConstructor {
meshPanel.repaint();
}
logger.info("generation completed.");
/*BufferedWriter meshWriter = null;
try {
File dir = new File("/Users/bzoennchen/Development/workspaces/hmRepo/PersZoennchen/PhD/trash/generated/eikmesh/");
BufferedWriter bufferedWriterQualities1 = IOUtils.getWriter("qualities1_eik.csv", dir);
bufferedWriterQualities1.write("iteration quality\n");
BufferedWriter bufferedWriterQualities2 = IOUtils.getWriter("qualities2_eik.csv", dir);
bufferedWriterQualities2.write("iteration quality\n");
BufferedWriter bufferedWriterAngles = IOUtils.getWriter("angles_eik.csv", dir);
bufferedWriterAngles.write("iteration angle\n");
bufferedWriterQualities1.write(printQualities(200, meshImprover.getMesh(), f -> meshImprover.getTriangulation().faceToQuality(f)));
bufferedWriterQualities1.close();
bufferedWriterQualities2.write(printQualities(200, meshImprover.getMesh(), f -> meshImprover.getTriangulation().faceToLongestEdgeQuality(f)));
bufferedWriterQualities2.close();
bufferedWriterAngles.write(printAngles(200, meshImprover.getMesh()));
bufferedWriterAngles.close();
meshWriter = IOUtils.getWriter("kaiserslautern_mittel.tex", dir);
meshWriter.write(TexGraphGenerator.toTikz(meshImprover.getMesh(), f -> Colors.YELLOW, e -> Color.BLACK, vertexColorFunction, 1.0f, true));
meshWriter.close();
} catch (IOException e) {
e.printStackTrace();
}*/
} else {
meshImprover.generate();
......@@ -159,59 +114,6 @@ public class MeshConstructor {
return meshImprover.getMesh();
}
/*public IMesh<PVertex, PHalfEdge, PFace> pslgToUniformPMesh(@NotNull final PSLG pslg, final double hmin, final double hmax, final boolean viszalize) {
EdgeLengthFunctionApprox edgeLengthFunctionApprox = new EdgeLengthFunctionApprox(pslg, p -> Double.POSITIVE_INFINITY, p -> hmax);
edgeLengthFunctionApprox.smooth(0.4);
logger.info("construct element size function");
//edgeLengthFunctionApprox.printPython();
Collection<VPolygon> holes = pslg.getHoles();
VPolygon segmentBound = pslg.getSegmentBound();
IDistanceFunction distanceFunction = IDistanceFunction.create(segmentBound, holes);
logger.info("construct distance function");
IDistanceFunction distanceFunctionApproximation = new DistanceFunctionApproxBF(pslg, distanceFunction, () -> new PMesh());
Collection<VPolygon> polygons = pslg.getAllPolygons();
//polygons.add(targetShape);
// (3) use EikMesh to improve the mesh
double h0 = hmin;
var meshImprover = new PEikMesh(
distanceFunctionApproximation,
p -> edgeLengthFunctionApprox.apply(p),
h0,
pslg.getBoundingBox(),
polygons
);
if(viszalize) {
Function<PVertex, Color> vertexColorFunction = v -> {
if(meshImprover.isSlidePoint(v)){
return Colors.BLUE;
} else if(meshImprover.isFixPoint(v)) {
return Colors.RED;
} else {
return Color.BLACK;
}
};
var meshRenderer = new MeshRenderer<>(meshImprover.getMesh(), f -> false, f -> Colors.YELLOW, e -> Color.BLACK, vertexColorFunction);
var meshPanel = new PMeshPanel(meshRenderer, 500, 500);
meshPanel.display("EikMesh uniform h0 = " + h0);
while (!meshImprover.isFinished()) {
synchronized (meshImprover.getMesh()) {
meshImprover.improve();
}
meshPanel.repaint();
}
} else {
meshImprover.generate();
}
return meshImprover.getMesh();
}*/
public IMesh<PVertex, PHalfEdge, PFace> pslgToUniformPMesh(@NotNull final PSLG pslg, final double h0, final boolean viszalize) {
Collection<VPolygon> holes = pslg.getHoles();
VPolygon segmentBound = pslg.getSegmentBound();
......@@ -274,12 +176,6 @@ public class MeshConstructor {
logger.info("construct element size function");
edgeLengthFunctionApprox.printPython();
//((DistanceFunctionApproxBF) distanceFunctionApproximation).printPython();
//edgeLengthFunctionApprox.printPython();
//edgeLengthFunctionApprox.printPython();
Collection<VPolygon> polygons = pslg.getAllPolygons();
//polygons.add(targetShape);
......@@ -307,14 +203,6 @@ public class MeshConstructor {
var meshPanel = new PMeshPanel(meshRenderer, 500, 500);
meshPanel.display("EikMesh h0 = " + h0);
/*try {
MovRecorder<PVertex, PHalfEdge, PFace> movRecorder = new MovRecorder<>(meshImprover, meshRenderer, 500, 500);
movRecorder.record();
movRecorder.finish();
} catch (IOException e) {
e.printStackTrace();
}*/
while (!meshImprover.isFinished()) {
synchronized (meshImprover.getMesh()) {
meshImprover.improve();
......@@ -323,35 +211,6 @@ public class MeshConstructor {
meshPanel.repaint();
}
logger.info("generation completed.");
/*BufferedWriter meshWriter = null;
try {
File dir = new File("/Users/bzoennchen/Development/workspaces/hmRepo/PersZoennchen/PhD/trash/generated/eikmesh/");
BufferedWriter bufferedWriterQualities1 = IOUtils.getWriter("qualities1_eik.csv", dir);
bufferedWriterQualities1.write("iteration quality\n");
BufferedWriter bufferedWriterQualities2 = IOUtils.getWriter("qualities2_eik.csv", dir);
bufferedWriterQualities2.write("iteration quality\n");
BufferedWriter bufferedWriterAngles = IOUtils.getWriter("angles_eik.csv", dir);
bufferedWriterAngles.write("iteration angle\n");
bufferedWriterQualities1.write(printQualities(200, meshImprover.getMesh(), f -> meshImprover.getTriangulation().faceToQuality(f)));
bufferedWriterQualities1.close();
bufferedWriterQualities2.write(printQualities(200, meshImprover.getMesh(), f -> meshImprover.getTriangulation().faceToLongestEdgeQuality(f)));
bufferedWriterQualities2.close();
bufferedWriterAngles.write(printAngles(200, meshImprover.getMesh()));
bufferedWriterAngles.close();
meshWriter = IOUtils.getWriter("kaiserslautern_mittel.tex", dir);
meshWriter.write(TexGraphGenerator.toTikz(meshImprover.getMesh(), f -> Colors.YELLOW, e -> Color.BLACK, vertexColorFunction, 1.0f, true));
meshWriter.close();
} catch (IOException e) {
e.printStackTrace();
}*/
} else {
meshImprover.generate();
......
package org.vadere.simulator.examples;
package org.vadere.simulator.examples.Meshing;
import org.vadere.meshing.mesh.gen.MeshPanel;
import org.vadere.meshing.mesh.gen.PFace;
......
package org.vadere.simulator.examples;
package org.vadere.simulator.examples.Meshing;
import org.vadere.meshing.WeilerAtherton;
import org.vadere.meshing.mesh.gen.IncrementalTriangulation;
......
package org.vadere.simulator.examples;
package org.vadere.simulator.examples.Meshing;
import org.vadere.meshing.examples.ElementSizeFunction;
import org.vadere.meshing.mesh.gen.PMesh;
......
package org.vadere.simulator.examples;
package org.vadere.simulator.examples.Meshing;
import org.jetbrains.annotations.NotNull;
import org.vadere.meshing.mesh.gen.PFace;
......
package org.vadere.simulator.examples;
package org.vadere.simulator.examples.Meshing;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.time.StopWatch;
......
......@@ -49,38 +49,22 @@ public class UpdateSchemeEventDrivenParallel extends UpdateSchemeEventDriven {
super(topography);
this.topography = topography;
this.pedestrianPotentialWidth = pedestrianPotentialWidth;
File dir = new File("/Users/bzoennchen/Development/workspaces/hmRepo/PersZoennchen/PhD/trash/generated/parallelOSM/");
try {
bufferedWriter = IOUtils.getWriter("histogram.csv", dir);
bufferedWriter.write("iteration round\n");
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public void update(final double timeStepInSec, final double currentTimeInSec) {
ArrayList<Integer> histUpdateable = new ArrayList<>();
topography.getElements(PedestrianOSM.class).parallelStream().forEach(pedestrianOSM -> pedestrianOSM.clearStrides());
if(sideLength <= 0) {
double maxStepSize = topography.getElements(PedestrianOSM.class).parallelStream().mapToDouble(ped -> ped.getDesiredStepSize()).max().orElse(0);
double maxDesiredSpeed = topography.getElements(PedestrianOSM.class).parallelStream().mapToDouble(ped -> ped.getDesiredSpeed()).max().orElse(0);
//double stepSize = Math.max(maxStepSize, maxDesiredSpeed * timeStepInSec);
//double sideLength = (stepSize+pedestrianPotentialWidth) * 2.0;
double stepSize = maxStepSize;
sideLength = (2.0*stepSize+pedestrianPotentialWidth); ;
double stepSize = Math.max(maxStepSize, maxDesiredSpeed * timeStepInSec);
// this formula is slightly different than the formula in the PhD of B. Zoennchen (p. 63, eq. 5.3)
// bit it is a good approximation
double sideLength = (2.0 * stepSize + pedestrianPotentialWidth);
//logger.debug("initial grid with a grid edge length equal to " + sideLength);
}
for(PedestrianOSM ped : pedestrianEventsQueue) {
ped.updateCount = -1;
}
int nCells = 0;
int counter = 1;
// event driven update ignores time credits
do {
......@@ -97,10 +81,10 @@ public class UpdateSchemeEventDrivenParallel extends UpdateSchemeEventDriven {
// lock cell of the agent
if(!locked[gridPos[0]][gridPos[1]]) {
updateAbleAgents.add(ped);
ped.updateCount = counter;
//ped.updateCount = counter;
} else {
notUpdateAbleAgents.add(ped);
ped.updateCount = -1;
//ped.updateCount = -1;
}
// lock neighbours
......@@ -113,8 +97,6 @@ public class UpdateSchemeEventDrivenParallel extends UpdateSchemeEventDriven {
}
}
histUpdateable.add(updateAbleAgents.size());
//logger.debug("not updated " + notUpdateAbleAgents.size() + " " + counter + ".");
updateAbleAgents.parallelStream().forEach(ped -> {
//logger.info(ped.getTimeOfNextStep());
......@@ -128,20 +110,5 @@ public class UpdateSchemeEventDrivenParallel extends UpdateSchemeEventDriven {
} while (!pedestrianEventsQueue.isEmpty() && pedestrianEventsQueue.peek().getTimeOfNextStep() < currentTimeInSec);
iteration++;
logger.debug("rounds: " + counter + ", #peds: " + topography.getPedestrianDynamicElements().getElements().size() + ", cells: " + nCells + ", sideLen:" + sideLength);
try {
StringBuilder builder = new StringBuilder();
for(int round = 1; round <= histUpdateable.size(); round++) {
for(int i = 0; i < histUpdateable.get(round-1); i++) {
builder.append(iteration);
builder.append(" ");
builder.append(round);
builder.append("\n");
}
}
bufferedWriter.write(builder.toString());
bufferedWriter.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
}
......@@ -130,7 +130,7 @@ public class EikonalSolverFIM extends AGridEikonalSolver {
activeList.addAll(newActiveList);
}
System.out.println("#update / #vertices: " + nUpdates + " / " + cellGrid.pointStream().filter(p -> cellGrid.getValue(p).tag == PathFindingTag.Reached).count());
logger.debug("#update / #vertices: " + nUpdates + " / " + cellGrid.pointStream().filter(p -> cellGrid.getValue(p).tag == PathFindingTag.Reached).count());
nUpdates = 0;
}
......
......@@ -81,7 +81,6 @@ public class EikonalSolverFMM extends AGridEikonalSolver {
}
long runTime = System.currentTimeMillis() - ms;
logger.debug("fmm on the gird run time = " + runTime + ", #updates = " + updates);
System.out.println("fmm on the gird run time = " + runTime + ", #updates = " + updates);
}
/**
......
......@@ -16,7 +16,11 @@ import java.util.List;
import java.util.ListIterator;
import java.util.stream.Collectors;
/**
* The Informed Fast Iterative Method on a Cartesian Grid, compare PhD thesis B. Zoennchen Section 9.5
*
* @author Benedikt Zoennchen
*/
public class EikonalSolverIFIM extends AGridEikonalSolver {
private final IDistanceFunction distFunc;
......
......@@ -40,6 +40,8 @@ import java.util.stream.Collectors;
* Abstract class that solves the eikonal equation on a Mesh i.e. 2-D triangular mesh.
* It is the basis for the implementation of the FMM, FIM, FSM and IFIM on triangular meshes.
*
* @author Benedikt Zoennchen
*
* @param <V> the type of the vertices of the triangulation
* @param <E> the type of the half-edges of the triangulation
* @param <F> the type of the faces of the triangulation
......
......@@ -10,6 +10,10 @@ import org.vadere.simulator.models.potential.solver.timecost.ITimeCostFunction;
import java.util.Comparator;
import java.util.PriorityQueue;
/**
* @author Benedikt Zoennchen
*
*/
public abstract class AMeshEikonalSolverFMM<V extends IVertex, E extends IHalfEdge, F extends IFace> extends AMeshEikonalSolver<V, E, F> {
protected PriorityQueue<V> narrowBand;
......
......@@ -10,6 +10,10 @@ import org.vadere.simulator.models.potential.solver.timecost.ITimeCostFunction;
import org.vadere.util.geometry.GeometryUtils;
import org.vadere.util.geometry.shapes.VPoint;
/**
* @author Benedikt Zoennchen
*
*/
public interface MeshEikonalSolver<V extends IVertex, E extends IHalfEdge, F extends IFace> extends EikonalSolver {
/**
......
......@@ -30,6 +30,8 @@ import java.util.List;
* @param <V> the type of the vertices of the triangulation
* @param <E> the type of the half-edges of the triangulation
* @param <F> the type of the faces of the triangulation
*
* @author Benedikt Zoennchen
*/
public class MeshEikonalSolverDFMM<V extends IVertex, E extends IHalfEdge, F extends IFace> extends AMeshEikonalSolverFMM<V, E, F> {
......@@ -41,10 +43,6 @@ public class MeshEikonalSolverDFMM<V extends IVertex, E extends IHalfEdge, F ext
final String identifier;
static {
logger.setDebug();
}
/**
* The time cost function defined on the geometry.
*/
......
......@@ -5,31 +5,28 @@ import org.vadere.meshing.mesh.inter.IFace;
import org.vadere.meshing.mesh.inter.IHalfEdge;
import org.vadere.meshing.mesh.inter.IIncrementalTriangulation;
import org.vadere.meshing.mesh.inter.IVertex;
import org.vadere.meshing.utils.io.IOUtils;
import org.vadere.simulator.models.potential.solver.timecost.ITimeCostFunction;
import org.vadere.util.geometry.shapes.VShape;
import org.vadere.util.logging.Logger;
import org.vadere.util.math.IDistanceFunction;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.concurrent.ForkJoinPool;
/**
* This class computes the traveling time T using the fast iterative method for arbitrary triangulated meshes.
* This class computes the traveling time T using the (single threaded) Fast Iterative Method for arbitrary triangulated meshes.
* The quality of the result depends on the quality of the triangulation. For a high accuracy the triangulation
* should not contain too many non-acute triangles.
*
* @param <V> the type of the vertices of the triangulation
* @param <E> the type of the half-edges of the triangulation
* @param <F> the type of the faces of the triangulation
*
* @author Benedikt Zoennchen
*/
public class MeshEikonalSolverFIM<V extends IVertex, E extends IHalfEdge, F extends IFace> extends AMeshEikonalSolver<V, E, F> {
......@@ -57,12 +54,6 @@ public class MeshEikonalSolverFIM<V extends IVertex, E extends IHalfEdge, F exte
private int nUpdates = 0;
private final double epsilon = 0;
// delete this, its only for logging
private BufferedWriter bufferedWriter;
private ArrayList<Integer> updates = new ArrayList<>();
private ArrayList<ArrayList<Integer>> narrowBandSizes = new ArrayList<>();
// Note: The updateOrder of arguments in the constructors are exactly as they are since the generic type of a collection is only known at run-time!
/**
......@@ -83,13 +74,6 @@ public class MeshEikonalSolverFIM<V extends IVertex, E extends IHalfEdge, F exte
this.identifier = identifier;
this.activeList = new LinkedList<>();
/*File dir = new File("/Users/bzoennchen/Development/workspaces/hmRepo/PersZoennchen/PhD/trash/generated/floorFieldPlot/");
try {
bufferedWriter = IOUtils.getWriter("updates_fim.csv", dir);
} catch (IOException e) {
e.printStackTrace();
}*/
//TODO a more clever init!
List<V> initialVertices = new ArrayList<>();
for(VShape shape : targetShapes) {
......@@ -113,7 +97,6 @@ public class MeshEikonalSolverFIM<V extends IVertex, E extends IHalfEdge, F exte
double ms = System.currentTimeMillis();
getTriangulation().enableCache();
nUpdates = 0;
//narrowBandSizes.add(new ArrayList<>());
if(!solved || needsUpdate()) {
if(!solved) {
......@@ -129,31 +112,13 @@ public class MeshEikonalSolverFIM<V extends IVertex, E extends IHalfEdge, F exte
}
solved = true;
//updates.add(nUpdates);
double runTime = (System.currentTimeMillis() - ms);