Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
The container registry cleanup task is now completed and the registry can be used normally.
Open sidebar
vadere
vadere
Commits
7b5a4eb4
Commit
7b5a4eb4
authored
Apr 15, 2020
by
Maxim Dudin
Browse files
max distance attribute made changeable over json
parent
be5b5dad
Pipeline
#237313
passed with stages
in 133 minutes and 15 seconds
Changes
4
Pipelines
1
Show whitespace changes
Inline
Side-by-side
VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/datakey/PedestriansNearbyData.java
View file @
7b5a4eb4
...
...
@@ -6,49 +6,50 @@ public class PedestriansNearbyData {
public
static
final
PedestriansNearbyData
noOverLap
=
new
PedestriansNearbyData
();
private
final
int
ped1Id
;
private
final
int
ped2Id
;
private
final
int
durationTimesteps
;
private
final
int
pedId1
;
private
final
int
pedId2
;
private
int
durationTimesteps
;
private
int
startTimestep
;
private
PedestriansNearbyData
()
{
this
.
ped
1
Id
=
-
1
;
this
.
ped
2
Id
=
-
1
;
this
.
pedId
1
=
-
1
;
this
.
pedId
2
=
-
1
;
this
.
durationTimesteps
=
1
;
this
.
startTimestep
=
1
;
}
public
int
getStartTimestep
()
{
return
startTimestep
;
}
public
PedestriansNearbyData
(
f
in
al
DynamicElemen
t
ped1
,
f
in
al
DynamicElemen
t
ped2
,
final
int
durationTimesteps
){
this
.
ped
1
Id
=
ped1
.
getId
(
);
this
.
ped
2
Id
=
ped2
.
getId
(
);
public
PedestriansNearbyData
(
int
ped1
,
int
ped2
,
final
int
durationTimesteps
,
int
startTimestep
){
this
.
pedId
1
=
Math
.
min
(
ped1
,
ped2
);
this
.
pedId
2
=
Math
.
max
(
ped1
,
ped2
);
this
.
durationTimesteps
=
durationTimesteps
;
this
.
startTimestep
=
startTimestep
;
}
/*
public
boolean isOverlap
(){
return
overlap > 0
;
}
*/
public
int
getPedId1
()
{
return
pedId1
;
}
/*
public
boolean isNotSelfOverlap
(){
return
!(
ped
1
Id
== ped2Id)
;
}
*/
public
int
getPedId2
()
{
return
pedId
2
;
}
public
int
get
Ped1Id
()
{
return
ped1Id
;
public
int
get
DurationTimesteps
()
{
return
durationTimesteps
;
}
public
int
getPed2Id
()
{
return
p
ed
2
Id
;
public
PedestriansNearbyData
getDataWithIncrementedDuration
()
{
return
new
PedestriansNearbyData
(
getP
edId
1
(),
getPedId2
(),
getDurationTimesteps
()
+
1
,
getStartTimestep
())
;
}
/*public Double getOverlap() {
return overlap;
}*/
public
String
[]
toStrings
(){
return
new
String
[]{
Integer
.
toString
(
durationTimesteps
)};
}
/*public int maxDist(@NotNull PedestiansNearbyData o) {
return Double.compare(overlap, o.getOverlap());
}*/
}
VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/datakey/TimestepPedestriansNearbyIdKey.java
View file @
7b5a4eb4
...
...
@@ -13,18 +13,14 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
private
final
int
timeStep
;
private
final
int
pedId1
;
//smaller id
private
final
int
pedId2
;
//bigger id
private
final
int
durationTimesteps
;
public
TimestepPedestriansNearbyIdKey
(
int
timeStep
,
int
pedA
,
int
pedB
)
{
this
.
timeStep
=
timeStep
;
this
.
pedId1
=
Math
.
min
(
pedA
,
pedB
);
this
.
pedId2
=
Math
.
max
(
pedA
,
pedB
);
this
.
durationTimesteps
=
1
;
//todo simulation step length
}
public
double
getDuration
()
{
return
durationTimesteps
;
}
public
static
String
[]
getHeaders
(){
return
new
String
[]{
TimestepKey
.
getHeader
(),
PedestrianIdKey
.
getHeader
(),
"pedestrianNearbyId"
};
...
...
@@ -46,6 +42,19 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
return
new
String
[]{
Integer
.
toString
(
timeStep
),
Integer
.
toString
(
pedId1
),
Integer
.
toString
(
pedId2
)};
}
public
boolean
isContinuationOf
(
PedestriansNearbyData
other
)
{
return
other
.
getPedId1
()
==
getPedId1
()
&&
other
.
getPedId2
()
==
getPedId2
()
&&
(
other
.
getStartTimestep
()
+
other
.
getDurationTimesteps
()
==
getTimeStep
());
}
public
boolean
isAccountedForBy
(
PedestriansNearbyData
other
)
{
return
equals
(
other
)
||
(
other
.
getPedId1
()
==
getPedId1
()
&&
other
.
getPedId2
()
==
getPedId2
()
&&
getTimeStep
()
>=
other
.
getStartTimestep
()
&&
getTimeStep
()
<
other
.
getStartTimestep
()
+
other
.
getDurationTimesteps
());
}
@Override
public
int
compareTo
(
@NotNull
TimestepPedestriansNearbyIdKey
o
)
{
int
result
=
Integer
.
compare
(
this
.
timeStep
,
o
.
timeStep
);
...
...
@@ -53,9 +62,6 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
result
=
Integer
.
compare
(
this
.
pedId1
,
o
.
pedId1
);
if
(
result
==
0
){
result
=
Integer
.
compare
(
this
.
pedId2
,
o
.
pedId2
);
if
(
result
==
0
)
{
result
=
Integer
.
compare
(
this
.
durationTimesteps
,
o
.
durationTimesteps
);
}
}
}
return
result
;
...
...
@@ -67,15 +73,15 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
TimestepPedestriansNearbyIdKey
that
=
(
TimestepPedestriansNearbyIdKey
)
o
;
return
timeStep
==
that
.
timeStep
&&
pedId1
==
that
.
pedId1
&&
pedId2
==
that
.
pedId2
&&
durationTimesteps
==
that
.
durationTimesteps
;
((
pedId1
==
that
.
pedId1
&&
pedId2
==
that
.
pedId2
)
||
(
pedId2
==
that
.
pedId1
&&
pedId1
==
that
.
pedId2
))
;
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
timeStep
,
pedId1
,
pedId2
,
durationTimesteps
);
return
Objects
.
hash
(
timeStep
,
pedId1
,
pedId2
);
}
@Override
...
...
@@ -84,7 +90,8 @@ public class TimestepPedestriansNearbyIdKey implements DataKey<TimestepPedestria
"timeStep="
+
timeStep
+
", pedId1="
+
pedId1
+
", pedId2="
+
pedId2
+
", durationTimesteps="
+
durationTimesteps
+
'}'
;
}
}
VadereSimulator/src/org/vadere/simulator/projects/dataprocessing/processor/PedestriansNearbyProcessor.java
View file @
7b5a4eb4
...
...
@@ -4,8 +4,9 @@ import org.vadere.annotation.factories.dataprocessors.DataProcessorClass;
import
org.vadere.simulator.control.simulation.SimulationState
;
import
org.vadere.simulator.projects.dataprocessing.ProcessorManager
;
import
org.vadere.simulator.projects.dataprocessing.datakey.PedestriansNearbyData
;
import
org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestrianIdOverlapKey
;
import
org.vadere.simulator.projects.dataprocessing.datakey.TimestepPedestriansNearbyIdKey
;
import
org.vadere.state.attributes.processor.AttributesNumberOverlapsProcessor
;
import
org.vadere.state.attributes.processor.AttributesPedestrianNearbyProcessor
;
import
org.vadere.state.scenario.DynamicElement
;
import
org.vadere.state.scenario.Pedestrian
;
import
org.vadere.state.scenario.Topography
;
...
...
@@ -22,12 +23,12 @@ import java.util.stream.Collectors;
@DataProcessorClass
()
public
class
PedestriansNearbyProcessor
extends
DataProcessor
<
TimestepPedestriansNearbyIdKey
,
PedestriansNearbyData
>
{
private
double
minDist
;
private
double
maxDistance
=
1.5
;
private
double
maxDistance
;
// todo adjustable with json
public
PedestriansNearbyProcessor
()
{
super
(
"durationTimesteps"
);
setAttributes
(
new
AttributesPedestrianNearbyProcessor
());
}
@Override
...
...
@@ -42,43 +43,35 @@ public class PedestriansNearbyProcessor extends DataProcessor<TimestepPedestrian
List
<
PedestriansNearbyData
>
pedsNearby
=
dynElemNneighbours
.
parallelStream
()
.
filter
(
p
->
ped
.
getId
()
!=
p
.
getId
())
.
map
(
p
->
new
PedestriansNearbyData
(
ped
,
p
,
1
))
.
map
(
p
->
new
PedestriansNearbyData
(
ped
.
getId
(),
p
.
getId
(),
1
,
timeStep
))
.
collect
(
Collectors
.
toList
());
pedsNearby
.
forEach
(
o
->
this
.
putValue
(
new
TimestepPedestriansNearbyIdKey
(
timeStep
,
o
.
getPed
1
Id
(),
o
.
getPed
2
Id
()),
o
));
pedsNearby
.
forEach
(
o
->
this
.
putValue
(
new
TimestepPedestriansNearbyIdKey
(
timeStep
,
o
.
getPedId
1
(),
o
.
getPedId
2
()),
o
));
}
/*double pedRadius = state.getTopography().getAttributesPedestrian().getRadius();
Collection<Pedestrian> peds = state.getTopography().getElements(Pedestrian.class);
String mainModelstring =state.getScenarioStore().getMainModel();
if(mainModelstring != null && mainModelstring.equals(CellularAutomaton.class.getName())) {
minDist = pedRadius * 2 - SPAWN_BUFFER; // allow touching agents for Cellular Automaton
}else{
minDist = pedRadius * 2;
}
int timeStep = state.getStep();
for (Pedestrian ped : peds) {
// get all Pedestrians with at most pedRadius*2.5 distance away
// this reduces the amount of overlap tests
VPoint pedPos = ped.getPosition();
List<DynamicElement> neighbours = getDynElementsAtPosition(state.getTopography(), ped.getPosition(), pedRadius *2.5);
// collect pedIds and distance of all overlaps for the current ped in the current timestep
List<OverlapData> overlaps = neighbours
.parallelStream()
.map(p -> new OverlapData(ped, p, minDist))
.filter(OverlapData::isNotSelfOverlap)
.filter(OverlapData::isOverlap)
.collect(Collectors.toList());
overlaps.forEach(o -> this.putValue(new TimestepPedestrianIdOverlapKey(timeStep, o.getPed1Id(), o.getPed2Id()), o));
}*/
}
public
String
[]
toStrings
(
final
TimestepPedestriansNearbyIdKey
key
)
{
return
this
.
hasValue
(
key
)
?
this
.
getValue
(
key
).
toStrings
()
:
new
String
[]{
"N/A"
,
"N/A"
};
}
@Override
protected
void
putValue
(
final
TimestepPedestriansNearbyIdKey
key
,
final
PedestriansNearbyData
value
)
{
for
(
TimestepPedestriansNearbyIdKey
alreadyExisting
:
getKeys
())
{
PedestriansNearbyData
currentVal
=
getValue
(
alreadyExisting
);
if
(
key
.
isAccountedForBy
(
currentVal
))
{
return
;
}
else
if
(
key
.
isContinuationOf
(
currentVal
))
{
super
.
putValue
(
alreadyExisting
,
currentVal
.
getDataWithIncrementedDuration
());
return
;
}
}
super
.
putValue
(
key
,
value
);
}
@Override
public
void
init
(
final
ProcessorManager
manager
)
{
super
.
init
(
manager
);
AttributesPedestrianNearbyProcessor
att
=
(
AttributesPedestrianNearbyProcessor
)
this
.
getAttributes
();
maxDistance
=
att
.
getMaxDistanceForANearbyPedestrian
();
}
private
List
<
DynamicElement
>
getDynElementsAtPosition
(
final
Topography
topography
,
VPoint
sourcePosition
,
double
radius
)
{
...
...
VadereState/src/org/vadere/state/attributes/processor/AttributesPedestrianNearbyProcessor.java
0 → 100644
View file @
7b5a4eb4
package
org.vadere.state.attributes.processor
;
/**
* @author Maxim Dudin
*
*/
public
class
AttributesPedestrianNearbyProcessor
extends
AttributesProcessor
{
private
double
maxDistanceForANearbyPedestrian
=
1.5
;
public
double
getMaxDistanceForANearbyPedestrian
()
{
return
maxDistanceForANearbyPedestrian
;
}
}
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