Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
We have upgraded GitLab to 15.1. Due to major code changes GitLab was down for some time.
Open sidebar
vadere
vadere
Commits
66fe9454
Commit
66fe9454
authored
Apr 15, 2020
by
Christina
Browse files
extended probability list - TBD
parent
85f5d96d
Changes
3
Hide whitespace changes
Inline
Side-by-side
VadereSimulator/src/org/vadere/simulator/control/scenarioelements/TargetChangerController.java
View file @
66fe9454
...
...
@@ -50,9 +50,11 @@ public class TargetChangerController {
JDKRandomGenerator
randomGenerator
=
new
JDKRandomGenerator
();
randomGenerator
.
setSeed
(
seed
);
d
ouble
probabilityToChangeTarget
=
targetChanger
.
getAttributes
().
getProbabilityToChangeTarget
();
LinkedList
<
D
ouble
>
probabilityToChangeTarget
=
targetChanger
.
getAttributes
().
getProbabilityToChangeTarget
();
int
trials
=
BINOMIAL_DISTRIBUTION_SUCCESS_VALUE
;
// I.e., possible outcomes are 0 and 1 when calling "sample()".
binomialDistribution
=
new
BinomialDistribution
(
randomGenerator
,
trials
,
probabilityToChangeTarget
);
// 0.5 = probabilityToChangeTarget
binomialDistribution
=
new
BinomialDistribution
(
randomGenerator
,
trials
,
0.5
);
}
// Getters
...
...
@@ -75,6 +77,8 @@ public class TargetChangerController {
if
(
hasAgentReachedTargetChangerArea
(
agent
)
&&
processedAgents
.
containsKey
(
agent
.
getId
())
==
false
)
{
logEnteringTimeOfAgent
(
agent
,
simTimeInSec
);
int
nextTargetListIndex
=
agent
.
getNextTargetListIndex
();
int
binomialDistributionSample
=
binomialDistribution
.
sample
();
boolean
changeTarget
=
(
binomialDistributionSample
==
BINOMIAL_DISTRIBUTION_SUCCESS_VALUE
);
...
...
VadereSimulator/tests/org/vadere/simulator/control/TargetChangerControllerTest.java
View file @
66fe9454
...
...
@@ -159,10 +159,12 @@ public class TargetChangerControllerTest {
@Test
public
void
updateChangesTargetListOfAffectedPedestrianIfProbabilityIsOne
()
{
LinkedList
<
Integer
>
nextTarget
=
createIntegerList
(
2
);
double
probability
=
1.0
;
LinkedList
<
Double
>
probability
=
new
LinkedList
<
Double
>(
Arrays
.
asList
(
1.0
,
1.0
,
0.5
));
// must be 1
AttributesTargetChanger
attributesTargetChanger
=
createAttributesWithFixedRectangle
();
attributesTargetChanger
.
setNextTarget
(
nextTarget
);
attributesTargetChanger
.
setProbabilityToChangeTarget
(
probability
);
TargetChanger
targetChanger
=
new
TargetChanger
(
attributesTargetChanger
);
...
...
@@ -187,7 +189,7 @@ public class TargetChangerControllerTest {
pedestrians
.
get
(
1
).
setNextTargetListIndex
(
nextTargetIndex
);
LinkedList
<
Integer
>
nextTarget
=
createIntegerList
(
2
);
d
ouble
probability
=
1.0
;
LinkedList
<
D
ouble
>
probability
=
new
LinkedList
<
Double
>(
Arrays
.
asList
(
1.0
,
1.0
,
0.5
));
// must be 1
AttributesTargetChanger
attributesTargetChanger
=
createAttributesWithFixedRectangle
();
attributesTargetChanger
.
setNextTarget
(
nextTarget
);
...
...
@@ -207,7 +209,7 @@ public class TargetChangerControllerTest {
@Test
public
void
updateDoesNotChangeTargetListOfAffectedPedestrianIfProbabilityIsZero
()
{
LinkedList
<
Integer
>
nextTarget
=
createIntegerList
(
2
);
d
ouble
probability
=
0.0
;
LinkedList
<
D
ouble
>
probability
=
new
LinkedList
<
Double
>(
Arrays
.
asList
(
1.0
,
1.0
,
0.5
));
// must be 1
AttributesTargetChanger
attributesTargetChanger
=
createAttributesWithFixedRectangle
();
attributesTargetChanger
.
setNextTarget
(
nextTarget
);
...
...
@@ -229,7 +231,7 @@ public class TargetChangerControllerTest {
@Test
public
void
targetChangerWithListOfTargetsAndStaticTargets
()
{
LinkedList
<
Integer
>
nextTarget
=
createIntegerList
(
2
,
1
);
d
ouble
probability
=
1.0
;
LinkedList
<
D
ouble
>
probability
=
new
LinkedList
<
Double
>(
Arrays
.
asList
(
1.0
,
1.0
,
0.5
));
// must be 1
pedestrians
.
forEach
(
p
->
p
.
setTargets
(
createIntegerList
(
1
)));
AttributesTargetChanger
attributesTargetChanger
=
createAttributesWithFixedRectangle
();
...
...
@@ -251,7 +253,7 @@ public class TargetChangerControllerTest {
@Test
public
void
targetChangerWithListOfTargetsAndDynamicTargets
()
{
//must choose first element
LinkedList
<
Integer
>
nextTarget
=
createIntegerList
(
1
,
2
);
d
ouble
probability
=
1.0
;
LinkedList
<
D
ouble
>
probability
=
new
LinkedList
<
Double
>(
Arrays
.
asList
(
1.0
,
1.0
,
0.5
));
// must be 1
pedestrians
.
forEach
(
p
->
p
.
setTargets
(
createIntegerList
(
1
)));
AttributesTargetChanger
attributesTargetChanger
=
createAttributesWithFixedRectangle
();
...
...
@@ -274,7 +276,7 @@ public class TargetChangerControllerTest {
@Test
public
void
updateAddsTargetPedestrianToTopographyIfTargetIsDynamic
()
{
LinkedList
<
Integer
>
nextTarget
=
createIntegerList
(
1
);
d
ouble
probability
=
1.0
;
LinkedList
<
D
ouble
>
probability
=
new
LinkedList
<
Double
>(
Arrays
.
asList
(
1.0
,
1.0
,
0.5
));
// must be 1
AttributesTargetChanger
attributesTargetChanger
=
createAttributesWithFixedRectangle
();
attributesTargetChanger
.
setNextTarget
(
nextTarget
);
...
...
@@ -296,7 +298,7 @@ public class TargetChangerControllerTest {
@Test
public
void
updateChangesTargetListOfAffectedPedestrianIfTargetIsDynamic
()
{
LinkedList
<
Integer
>
nextTarget
=
createIntegerList
(
1
);
d
ouble
probability
=
1.0
;
LinkedList
<
D
ouble
>
probability
=
new
LinkedList
<
Double
>(
Arrays
.
asList
(
1.0
,
1.0
,
0.5
));
// must be 1
AttributesTargetChanger
attributesTargetChanger
=
createAttributesWithFixedRectangle
();
attributesTargetChanger
.
setNextTarget
(
nextTarget
);
...
...
@@ -320,7 +322,7 @@ public class TargetChangerControllerTest {
@Test
public
void
updateModifiesFollowersIfTargetIsDynamic
()
{
LinkedList
<
Integer
>
nextTarget
=
createIntegerList
(
1
);
d
ouble
probability
=
1.0
;
LinkedList
<
D
ouble
>
probability
=
new
LinkedList
<
Double
>(
Arrays
.
asList
(
1.0
,
1.0
,
0.5
));
// must be 1
AttributesTargetChanger
attributesTargetChanger
=
createAttributesWithFixedRectangle
();
attributesTargetChanger
.
setNextTarget
(
nextTarget
);
...
...
@@ -342,7 +344,8 @@ public class TargetChangerControllerTest {
@Test
public
void
updateModifiesPedestrianWithExistingFollwersIfTargetIsDynamic
()
{
LinkedList
<
Integer
>
nextTarget
=
createIntegerList
(
1
);
double
probability
=
1.0
;
LinkedList
<
Double
>
probability
=
new
LinkedList
<
Double
>(
Arrays
.
asList
(
1.0
,
1.0
,
0.5
));
// must be 1
// Add two new agents were one follows the other.
List
<
Pedestrian
>
newPedestrians
=
createTwoPedestrianWithTargetT1
(
3
);
...
...
@@ -377,7 +380,7 @@ public class TargetChangerControllerTest {
@Test
public
void
updateUseStaticTargetAsFallbackIfNoPedestrianIsFoundIfTargetIsDynamic
()
{
LinkedList
<
Integer
>
nextTarget
=
createIntegerList
(
3
);
d
ouble
probability
=
1.0
;
LinkedList
<
D
ouble
>
probability
=
new
LinkedList
<
Double
>(
Arrays
.
asList
(
1.0
,
1.0
,
0.5
));
// must be 1
AttributesTargetChanger
attributesTargetChanger
=
createAttributesWithFixedRectangle
();
attributesTargetChanger
.
setNextTarget
(
nextTarget
);
...
...
VadereState/src/org/vadere/state/attributes/scenario/AttributesTargetChanger.java
View file @
66fe9454
...
...
@@ -4,7 +4,6 @@ import org.vadere.state.attributes.AttributesEmbedShape;
import
org.vadere.util.geometry.shapes.VShape
;
import
java.util.LinkedList
;
import
java.util.List
;
/**
* Attributes of "TargetChanger" object, used by "TargetChangerController" during simulation.
...
...
@@ -36,7 +35,7 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
* Change target of a given pedestrian only with a certain probability between
* 0 and 1.
*/
private
d
ouble
probabilityToChangeTarget
=
0.0
;
private
LinkedList
<
D
ouble
>
probabilityToChangeTarget
=
new
LinkedList
<>()
;
// Constructors
public
AttributesTargetChanger
()
{
...
...
@@ -51,15 +50,18 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
this
.
id
=
id
;
}
public
AttributesTargetChanger
(
final
VShape
shape
,
final
int
id
,
double
reachDistance
,
LinkedList
<
Integer
>
nextTarget
,
d
ouble
probabilit
y
ToChangeTarget
)
{
public
AttributesTargetChanger
(
final
VShape
shape
,
final
int
id
,
double
reachDistance
,
LinkedList
<
Integer
>
nextTarget
,
LinkedList
<
D
ouble
>
probabilit
ies
ToChangeTarget
)
{
this
.
shape
=
shape
;
this
.
id
=
id
;
this
.
reachDistance
=
reachDistance
;
this
.
nextTarget
=
nextTarget
;
for
(
Double
probabilityToChangeTarget
:
probabilitiesToChangeTarget
){
if
(
probabilityToChangeTarget
<
0.0
||
probabilityToChangeTarget
>
1.0
)
{
throw
new
IllegalArgumentException
(
"Probability must be in range 0.0 to 1.0!"
);
if
(
probabilityToChangeTarget
<
0.0
||
probabilityToChangeTarget
>
1.0
)
{
throw
new
IllegalArgumentException
(
"Probability must be in range 0.0 to 1.0!"
);
}
}
this
.
probabilityToChangeTarget
=
probabilityToChangeTarget
;
}
...
...
@@ -85,7 +87,7 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
return
nextTarget
;
}
public
d
ouble
getProbabilityToChangeTarget
()
{
public
LinkedList
<
D
ouble
>
getProbabilityToChangeTarget
()
{
return
probabilityToChangeTarget
;
}
...
...
@@ -113,9 +115,13 @@ public class AttributesTargetChanger extends AttributesEmbedShape {
this
.
nextTarget
=
nextTarget
;
}
public
void
setProbabilityToChangeTarget
(
double
probabilityToChangeTarget
)
{
if
(
probabilityToChangeTarget
<
0.0
||
probabilityToChangeTarget
>
1.0
)
{
throw
new
IllegalArgumentException
(
"Probability must be in range 0.0 to 1.0!"
);
public
void
setProbabilityToChangeTarget
(
LinkedList
<
Double
>
probabilitiesToChangeTarget
)
{
for
(
Double
probabilityToChangeTarget
:
probabilitiesToChangeTarget
){
if
(
probabilityToChangeTarget
<
0.0
||
probabilityToChangeTarget
>
1.0
)
{
throw
new
IllegalArgumentException
(
"Probability must be in range 0.0 to 1.0!"
);
}
}
this
.
probabilityToChangeTarget
=
probabilityToChangeTarget
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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