Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
vadere
vadere
Commits
75c979c8
Commit
75c979c8
authored
Jun 30, 2021
by
Christina
Browse files
added further tests to corridorchoice
parent
4948af69
Pipeline
#575778
passed with stages
in 200 minutes and 12 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
VadereSimulator/src/org/vadere/simulator/control/external/models/ControlModel.java
View file @
75c979c8
...
...
@@ -35,6 +35,11 @@ public abstract class ControlModel implements IControlModel {
processedAgents
=
new
HashMap
<>();
}
public
abstract
boolean
isPedReact
();
protected
abstract
void
triggerRedRaction
(
Pedestrian
ped
);
public
void
setProcessedAgents
(
Pedestrian
ped
,
LinkedList
<
Integer
>
ids
){
if
(
processedAgents
.
containsKey
(
ped
)){
...
...
@@ -64,7 +69,6 @@ public abstract class ControlModel implements IControlModel {
public
abstract
void
getControlAction
(
Pedestrian
ped
,
JSONObject
command
);
public
void
update
(
Topography
topo
,
Double
time
,
String
commandStr
,
Integer
pedId
)
{
topography
=
topo
;
simTime
=
time
;
...
...
@@ -79,9 +83,7 @@ public abstract class ControlModel implements IControlModel {
this
.
setProcessedAgents
(
ped
,
getCommandId
());
}
}
}
}
public
void
update
(
Topography
topography
,
Double
time
,
String
command
)
{
...
...
@@ -119,18 +121,12 @@ public abstract class ControlModel implements IControlModel {
}
public
abstract
boolean
isPedReact
();
public
void
setAction
(
Pedestrian
ped
){
if
(
isPedReact
()){
triggerRedRaction
(
ped
);
}
}
protected
abstract
void
triggerRedRaction
(
Pedestrian
ped
);
public
void
setReactionModel
(
ReactionModel
reactionModel
){
this
.
reactionModel
=
reactionModel
;
}
...
...
@@ -142,7 +138,6 @@ public abstract class ControlModel implements IControlModel {
return
isFirstInformation
(
ped
);
}
// 2. handle recurring information that is received multiple times.
if
(
isIdInList
(
ped
,
commandId
)){
return
reactionModel
.
isReactingToRecurringInformation
();
...
...
VadereSimulator/src/org/vadere/simulator/control/external/models/CtlCommand.java
View file @
75c979c8
...
...
@@ -3,6 +3,7 @@ package org.vadere.simulator.control.external.models;
import
org.json.JSONException
;
import
org.json.JSONObject
;
import
org.vadere.util.geometry.shapes.VCircle
;
import
org.vadere.util.geometry.shapes.VRectangle
;
import
org.vadere.util.geometry.shapes.VShape
;
import
java.time.temporal.ValueRange
;
...
...
@@ -12,7 +13,7 @@ public class CtlCommand {
private
int
commandId
=
0
;
JSONObject
rawCommand
;
V
Circl
e
space
;
V
Shap
e
space
;
Double
time
;
JSONObject
pedCommand
;
...
...
@@ -42,26 +43,42 @@ public class CtlCommand {
return
time
;
}
public
V
Circl
e
getSpace
(){
public
V
Shap
e
getSpace
(){
// only radius
VShape
shape
;
double
x
=
0
;
double
y
=
0
;
double
radius
=
0
;
double
height
=
0
;
double
width
=
0
;
try
{
JSONObject
space
=
rawCommand
.
getJSONObject
(
"space"
);
x
=
space
.
getDouble
(
"x"
);
y
=
space
.
getDouble
(
"y"
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
try
{
JSONObject
space
=
rawCommand
.
getJSONObject
(
"space"
);
radius
=
space
.
getDouble
(
"radius"
);
if
(
radius
>=
0
)
{
if
(
radius
>
0
)
{
this
.
space
=
new
VCircle
(
x
,
y
,
radius
);
}
}
catch
(
JSONException
ignored
)
{}
try
{
JSONObject
space
=
rawCommand
.
getJSONObject
(
"space"
);
height
=
space
.
getDouble
(
"height"
);
width
=
space
.
getDouble
(
"width"
);
if
((
height
>
0
)
&&
(
width
>
0
))
{
this
.
space
=
new
VRectangle
(
x
,
y
,
width
,
height
);
}
}
catch
(
JSONException
ignored
)
{}
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
return
this
.
space
;
}
...
...
@@ -72,7 +89,6 @@ public class CtlCommand {
public
JSONObject
getPedCommand
(){
try
{
pedCommand
=
rawCommand
.
getJSONObject
(
"command"
);
...
...
@@ -86,17 +102,8 @@ public class CtlCommand {
public
int
getCommandId
()
{
try
{
commandId
=
rawCommand
.
getInt
(
"commandId"
);
}
catch
(
JSONException
e
)
{
e
.
printStackTrace
();
}
}
catch
(
JSONException
ignored
)
{
}
return
commandId
;
}
public
boolean
hasCommandId
(){
return
getCommandId
()
>=
0
;
}
}
VadereSimulator/src/org/vadere/simulator/control/external/models/RouteChoice.java
View file @
75c979c8
...
...
@@ -34,15 +34,6 @@ public class RouteChoice extends ControlModel {
newTargetList
=
getTargetFromNavigationApp
();
}
public
boolean
isProcessedCommand
(
Pedestrian
ped
,
int
commandId
){
if
(
processedAgents
.
containsKey
(
ped
))
{
LinkedList
<
Integer
>
ids
=
processedAgents
.
get
(
ped
);
return
ids
.
contains
(
commandId
);
}
return
true
;
}
@Override
public
boolean
isPedReact
()
{
...
...
VadereSimulator/testResources/control/external/CorridorChoiceData3.json
View file @
75c979c8
...
...
@@ -3,11 +3,12 @@
"space"
:
{
"x"
:
0.0
,
"y"
:
0.0
,
"radius"
:
100
"height"
:
100
,
"width"
:
100
},
"command"
:
{
"targetIds"
:
[
1
,
2
,
3
,
4
]
,
"probability"
:
[
1
,
0
,
0
,
0
]
"probability"
:
[
0
,
1
,
0
,
0
]
},
"commandId"
:
1
}
\ No newline at end of file
VadereSimulator/tests/org/vadere/simulator/control/external/models/RouteChoiceTest.java
View file @
75c979c8
...
...
@@ -212,6 +212,26 @@ public class RouteChoiceTest {
assertEquals
(
target
,
4
);
}
@Test
public
void
pedInRectangle
()
{
// Create a single pedestrian with initial target nr. 5
Topography
topo
=
createTopography
(
createPedestrians
(
1
));
Pedestrian
ped
=
topo
.
getPedestrianDynamicElements
().
getElement
(
0
);
ped
.
setPosition
(
new
VPoint
(
5
.,
5
.));
String
msg
=
readInputFile3
();
RouteChoice
routeChoice
=
new
RouteChoice
();
// keep old target nr.5 because timeout reached
routeChoice
.
update
(
topo
,
-
1
.,
msg
);
int
target
=
ped
.
getNextTargetId
();
assertEquals
(
target
,
2
);
}
public
void
commandIdMissing
()
{
// the route choice app requires a unique command id.
...
...
@@ -229,7 +249,6 @@ public class RouteChoiceTest {
try
{
commandIdMissing
();
}
catch
(
final
IllegalArgumentException
e
)
{
e
.
printStackTrace
();
assertTrue
(
e
.
getMessage
().
equals
(
"Please provide a unique commandId != 0 for each command. Otherwise, information might not be processed."
));
}
}
...
...
@@ -247,7 +266,7 @@ public class RouteChoiceTest {
routeChoice
.
update
(
topo
,
-
1
.,
readInputFile
());
assertEquals
(
ped
.
getNextTargetId
(),
4
);
// readInputFile3() provides target
1
. it is skipped because the command id is the same.
// readInputFile3() provides target
2
. it is skipped because the command id is the same.
routeChoice
.
update
(
topo
,
-
1
.,
readInputFile3
());
assertEquals
(
ped
.
getNextTargetId
(),
4
);
...
...
Write
Preview
Markdown
is supported
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