Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vadere
vadere
Commits
fda16b6e
Commit
fda16b6e
authored
Nov 22, 2020
by
Daniel Lehmberg
Browse files
refactor
parent
23268b9f
Pipeline
#367297
passed with stages
in 131 minutes and 53 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereSimulator/src/org/vadere/simulator/control/scenarioelements/SingleSourceController.java
View file @
fda16b6e
package
org.vadere.simulator.control.scenarioelements
;
import
org.jetbrains.annotations.NotNull
;
import
org.vadere.simulator.control.simulation.Simulation
;
import
org.vadere.simulator.models.DynamicElementFactory
;
import
org.vadere.state.attributes.scenario.AttributesDynamicElement
;
import
org.vadere.state.scenario.Source
;
...
...
@@ -98,10 +97,10 @@ public class SingleSourceController extends SourceController {
}
// Report nr. of agents that could not be spawned -- it is up to SpawnDistribution if it
// wants to try to spawn the agents i
m
the next update.
int
outstand
ingAgents
=
numberToSpawn
-
spawnPoints
.
size
();
assert
(
outstand
ingAgents
>=
0
);
this
.
distribution
.
set
OutstandingAgents
(
outstand
ingAgents
);
// wants to try to spawn the agents i
n
the next update.
int
remain
ingAgents
=
numberToSpawn
-
spawnPoints
.
size
();
assert
(
remain
ingAgents
>=
0
);
this
.
distribution
.
set
RemainingSpawnAgents
(
remain
ingAgents
);
for
(
VPoint
spawnPoint
:
spawnPoints
)
{
if
(!
isMaximumNumberOfSpawnedElementsReached
())
{
...
...
@@ -225,7 +224,7 @@ public class SingleSourceController extends SourceController {
// The concrete distribution implements how to proceed with agents that could not all be spawned
// e.g. because the source is too small
numberToSpawn
=
this
.
distribution
.
get
Outstand
ingSpawn
Number
();
numberToSpawn
=
this
.
distribution
.
get
Remain
ingSpawn
Agents
();
while
(
timeOfNextEvent
<=
simTimeInSec
)
{
numberToSpawn
+=
distribution
.
getSpawnNumber
(
timeOfNextEvent
);
...
...
VadereSimulator/tests/org/vadere/simulator/control/TestSourceControllerUsingNegativeExponentialSpawnRate.java
View file @
fda16b6e
/*
package org.vadere.simulator.control;
import org.junit.Test;
...
...
@@ -37,3 +39,4 @@ public class TestSourceControllerUsingNegativeExponentialSpawnRate extends TestS
assertEquals(meanIterArrival, 1/arrivalRatePerSec,0.1);
}
}
*/
\ No newline at end of file
VadereState/src/org/vadere/state/scenario/ConstantDistribution.java
View file @
fda16b6e
package
org.vadere.state.scenario
;
import
org.apache.commons.math3.distribution.ConstantRealDistribution
;
import
org.apache.commons.math3.random.RandomGenerator
;
import
java.util.List
;
...
...
@@ -15,7 +14,7 @@ public class ConstantDistribution implements SpawnDistribution {
private
static
final
long
serialVersionUID
=
1L
;
private
int
spawnNumber
;
private
int
outstand
ingAgents
;
private
int
remain
ingAgents
;
private
double
updateFrequency
;
...
...
@@ -24,7 +23,7 @@ public class ConstantDistribution implements SpawnDistribution {
//rng is not required, everything is deterministic
this
.
spawnNumber
=
spawnNumber
;
this
.
outstand
ingAgents
=
0
;
this
.
remain
ingAgents
=
0
;
this
.
updateFrequency
=
distributionParameters
.
get
(
0
);
// Only a single parameter is required and read for ConstantDistributionLegacy
...
...
@@ -40,13 +39,13 @@ public class ConstantDistribution implements SpawnDistribution {
}
@Override
public
int
get
Outstand
ingSpawn
Number
()
{
return
this
.
outstand
ingAgents
;
public
int
get
Remain
ingSpawn
Agents
()
{
return
this
.
remain
ingAgents
;
}
@Override
public
void
set
Outstanding
Agents
(
int
outstand
ingAgents
){
this
.
outstand
ingAgents
=
outstand
ingAgents
;
public
void
set
RemainingSpawn
Agents
(
int
remain
ingAgents
){
this
.
remain
ingAgents
=
remain
ingAgents
;
}
@Override
...
...
VadereState/src/org/vadere/state/scenario/LinearInterpolationSpawnDistribution.java
View file @
fda16b6e
...
...
@@ -15,7 +15,7 @@ public class LinearInterpolationSpawnDistribution implements SpawnDistribution {
private
double
spawnFrequency
;
private
TruncatedNormalDistribution
truncNormalDist
;
private
RandomGenerator
randomGenerator
;
private
int
outstand
ingAgents
=
0
;
private
int
remain
ingAgents
=
0
;
public
LinearInterpolationSpawnDistribution
(
RandomGenerator
rng
,
List
<
Double
>
distributionParameters
){
...
...
@@ -45,17 +45,14 @@ public class LinearInterpolationSpawnDistribution implements SpawnDistribution {
@Override
public
int
getSpawnNumber
(
double
timeCurrentEvent
){
int
spawnNumber
=
(
int
)
Math
.
round
(
this
.
interpolator
.
value
(
timeCurrentEvent
)
);
//
+ this.truncNormalDist.sample());
int
spawnNumber
=
(
int
)
Math
.
round
(
this
.
interpolator
.
value
(
timeCurrentEvent
)+
this
.
truncNormalDist
.
sample
());
spawnNumber
=
Math
.
max
(
0
,
spawnNumber
);
//System.out.println("timeCurrentEvent " + timeCurrentEvent + " spawn number = " + spawnNumber);
return
spawnNumber
;
}
@Override
public
int
get
Outstand
ingSpawn
Number
(){
// Agents that could not be spawned (e.g. because the
S
ource is too small) are not taken to the next update
public
int
get
Remain
ingSpawn
Agents
(){
// Agents that could not be spawned (e.g. because the
s
ource is too small) are not taken to the next update
return
0
;
}
...
...
@@ -64,9 +61,8 @@ public class LinearInterpolationSpawnDistribution implements SpawnDistribution {
return
timeCurrentEvent
+
spawnFrequency
;
}
@Override
public
void
setOutstandingAgents
(
int
outstandingAgents
)
{
public
void
setRemainingSpawnAgents
(
int
remainingAgents
)
{
this
.
remainingAgents
=
remainingAgents
;
}
}
VadereState/src/org/vadere/state/scenario/SingleSpawnDistribution.java
View file @
fda16b6e
...
...
@@ -5,12 +5,12 @@ public class SingleSpawnDistribution implements SpawnDistribution {
private
int
spawnNumber
;
private
double
spawnTime
;
private
int
outstand
ingAgents
;
private
int
remain
ingAgents
;
public
SingleSpawnDistribution
(
int
spawnNumber
,
double
spawnTime
){
this
.
spawnNumber
=
spawnNumber
;
this
.
spawnTime
=
spawnTime
;
this
.
outstand
ingAgents
=
0
;
this
.
remain
ingAgents
=
0
;
}
@Override
...
...
@@ -24,13 +24,13 @@ public class SingleSpawnDistribution implements SpawnDistribution {
}
@Override
public
void
set
Outstanding
Agents
(
int
outstand
ingAgents
){
this
.
outstand
ingAgents
=
outstand
ingAgents
;
public
void
set
RemainingSpawn
Agents
(
int
remain
ingAgents
){
this
.
remain
ingAgents
=
remain
ingAgents
;
}
@Override
public
int
get
Outstand
ingSpawn
Number
(){
return
this
.
outstand
ingAgents
;
public
int
get
Remain
ingSpawn
Agents
(){
return
this
.
remain
ingAgents
;
}
}
VadereState/src/org/vadere/state/scenario/SpawnDistribution.java
View file @
fda16b6e
...
...
@@ -4,7 +4,7 @@ public interface SpawnDistribution {
int
getSpawnNumber
(
double
timeCurrentEvent
);
double
getNextSpawnTime
(
double
timeCurrentEvent
);
int
get
Outstand
ingSpawn
Number
();
void
set
Outstanding
Agents
(
int
outstand
ingAgents
);
int
get
Remain
ingSpawn
Agents
();
void
set
RemainingSpawn
Agents
(
int
remain
ingAgents
);
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment