The name of the initial branch for new projects is now "main" instead of "master". Existing projects remain unchanged. More information: https://doku.lrz.de/display/PUBLIC/GitLab

Commit a50c7956 authored by Benedikt Zoennchen's avatar Benedikt Zoennchen
Browse files

add a faster exp-implementation approximating exp, and a benchmark library...

add a faster exp-implementation approximating exp, and a benchmark library called Java Microbenchmark Harness.
parent 6214738c
......@@ -15,6 +15,7 @@ import org.vadere.state.scenario.Pedestrian;
import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.Vector2D;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.math.MathUtil;
public class PotentialFieldObstacleCompactSoftshell implements PotentialFieldObstacle {
......@@ -50,10 +51,10 @@ public class PotentialFieldObstacleCompactSoftshell implements PotentialFieldObs
double currentPotential = 0;
if (distance < this.width) {
currentPotential = this.height * Math.exp(2 / (Math.pow(distance / (this.width), 2) - 1));
currentPotential = this.height * MathUtil.expAp(2 / (Math.pow(distance / (this.width), 2) - 1));
}
if (distance < radius) {
currentPotential += 100000 * Math.exp(1 / (Math.pow(distance / radius, 2) - 1));
currentPotential += 100000 * MathUtil.expAp(1 / (Math.pow(distance / radius, 2) - 1));
}
if (potential < currentPotential)
......
......@@ -15,6 +15,7 @@ import org.vadere.state.scenario.Topography;
import org.vadere.util.geometry.Vector2D;
import org.vadere.util.geometry.shapes.VCircle;
import org.vadere.util.geometry.shapes.VPoint;
import org.vadere.util.math.MathUtil;
public class PotentialFieldPedestrianCompactSoftshell implements PotentialFieldAgent {
......@@ -61,14 +62,14 @@ public class PotentialFieldPedestrianCompactSoftshell implements PotentialFieldA
double factor = this.attributes.getIntimateSpaceFactor();
if (distance < personalWidth + radii) {
potential += this.height * Math.exp(4 / (Math.pow(distance / (personalWidth + radii), (2 * perPower)) - 1));
potential += this.height * MathUtil.expAp(4 / (Math.pow(distance / (personalWidth + radii), (2 * perPower)) - 1));
}
if (distance < this.intimateWidth + radii) {
potential += this.height / factor
* Math.exp(4 / (Math.pow(distance / (this.intimateWidth + radii), (2 * intPower)) - 1));
* MathUtil.expAp(4 / (Math.pow(distance / (this.intimateWidth + radii), (2 * intPower)) - 1));
}
if (distance < radii) {
potential += 1000 * Math.exp(1 / (Math.pow(distance / radii, 4) - 1));
potential += 1000 * MathUtil.expAp(1 / (Math.pow(distance / radii, 4) - 1));
}
}
return potential;
......
......@@ -42,6 +42,13 @@ public class MathUtil {
return result;
}
public static double expAp(final double y) {
double x = 1d + y / 256d;
x *= x; x *= x; x *= x; x *= x;
x *= x; x *= x; x *= x; x *= x;
return x;
}
/**
* The value of the gradient of the 2D smooth function with compact support
* given by exp(1/((x/cut)^2-1)).
......
package org.vadere.util.math;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Level;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import java.util.concurrent.TimeUnit;
/**
* Created by bzoennchen on 26.04.18.
*/
public class TestExp {
@State(Scope.Thread)
public static class RandomDouble {
public double value;
@Setup(Level.Invocation)
public void doSetup() {
value = Math.random();
//System.out.println("Do Setup");
}
}
@Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS)
public void testExp(RandomDouble randomDouble) {
double exp = Math.exp(randomDouble.value);
}
@Benchmark @BenchmarkMode(Mode.Throughput) @OutputTimeUnit(TimeUnit.MILLISECONDS)
public void testExpAp(RandomDouble randomDouble) {
double exp = MathUtil.expAp(randomDouble.value);
}
}
......@@ -41,6 +41,19 @@
<artifactId>commons-math</artifactId>
<version>2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh/jmh-core -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
<version>1.20</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.openjdk.jmh/jmh-generator-annprocess -->
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-generator-annprocess</artifactId>
<version>1.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
......
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