Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
vadere
vadere
Commits
b39e6733
Commit
b39e6733
authored
Oct 02, 2017
by
Benedikt Zoennchen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix compatibility issues between output processors and PostVis.
parent
d609f8c4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
32 deletions
+98
-32
VadereSimulator/src/org/vadere/simulator/projects/io/TrajectoryReader.java
...rc/org/vadere/simulator/projects/io/TrajectoryReader.java
+98
-32
No files found.
VadereSimulator/src/org/vadere/simulator/projects/io/TrajectoryReader.java
View file @
b39e6733
package
org.vadere.simulator.projects.io
;
import
com.sun.xml.internal.ws.policy.privateutil.PolicyUtils
;
import
org.apache.commons.math3.util.Pair
;
import
org.apache.log4j.LogManager
;
import
org.apache.log4j.Logger
;
...
...
@@ -14,19 +15,11 @@ import org.vadere.util.geometry.shapes.VPoint;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Path
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Random
;
import
java.util.*
;
import
java.util.stream.Collectors
;
/**
* A TrajectoryReader is the counterpart of the
* {@link PedestrianPositionProcessor}.
*
*
* This reader trys to generate a {@link java.util.stream.Stream< scenario.Pedestrian >} by
* reading it from a file.
* A TrajectoryReader is the counterpart of the {@link PedestrianPositionProcessor}.
*/
public
class
TrajectoryReader
{
...
...
@@ -36,34 +29,107 @@ public class TrajectoryReader {
private
AttributesAgent
attributesPedestrian
;
private
static
final
String
SPLITTER
=
" "
;
private
Set
<
String
>
pedestrianIdKeys
;
private
Set
<
String
>
stepKeys
;
private
Set
<
String
>
xKeys
;
private
Set
<
String
>
yKeys
;
private
Set
<
String
>
targetIdKeys
;
private
int
pedIdIndex
;
private
int
stepIndex
;
private
int
xIndex
;
private
int
yIndex
;
private
int
targetIdIndex
;
public
TrajectoryReader
(
final
Path
trajectoryFilePath
,
final
Scenario
scenario
)
throws
IOException
{
this
.
trajectoryFilePath
=
trajectoryFilePath
;
this
.
attributesPedestrian
=
scenario
.
getAttributesPedestrian
();
this
(
trajectoryFilePath
,
scenario
.
getAttributesPedestrian
());
}
public
TrajectoryReader
(
final
Path
trajectoryFilePath
)
{
this
.
trajectoryFilePath
=
trajectoryFilePath
;
this
.
attributesPedestrian
=
new
AttributesAgent
();
this
(
trajectoryFilePath
,
new
AttributesAgent
());
}
private
TrajectoryReader
(
final
Path
trajectoryFilePath
,
final
AttributesAgent
attributesAgent
)
{
this
.
trajectoryFilePath
=
trajectoryFilePath
;
this
.
attributesPedestrian
=
attributesAgent
;
pedestrianIdKeys
=
new
HashSet
<>();
stepKeys
=
new
HashSet
<>();
xKeys
=
new
HashSet
<>();
yKeys
=
new
HashSet
<>();
targetIdKeys
=
new
HashSet
<>();
pedestrianIdKeys
.
add
(
"id"
);
pedestrianIdKeys
.
add
(
"pedestrianId"
);
stepKeys
.
add
(
"timeStep"
);
stepKeys
.
add
(
"step"
);
xKeys
.
add
(
"x"
);
yKeys
.
add
(
"y"
);
targetIdKeys
.
add
(
"targetId"
);
pedIdIndex
=
-
1
;
stepIndex
=
-
1
;
xIndex
=
-
1
;
yIndex
=
-
1
;
targetIdIndex
=
-
1
;
}
public
Map
<
Step
,
List
<
Agent
>>
readFile
()
throws
IOException
{
return
Files
.
lines
(
this
.
trajectoryFilePath
)
.
skip
(
1
)
// Skip header line
.
map
(
line
->
line
.
split
(
" "
))
.
map
(
cells
->
{
int
step
=
Integer
.
parseInt
(
cells
[
0
]);
int
pedestrianId
=
Integer
.
parseInt
(
cells
[
1
]);
VPoint
pos
=
new
VPoint
(
Double
.
parseDouble
(
cells
[
2
]),
Double
.
parseDouble
(
cells
[
3
]));
int
targetId
=
Integer
.
parseInt
(
cells
[
4
]);
Pedestrian
ped
=
new
Pedestrian
(
new
AttributesAgent
(
this
.
attributesPedestrian
,
pedestrianId
),
new
Random
());
ped
.
setPosition
(
pos
);
LinkedList
<
Integer
>
targets
=
new
LinkedList
<
Integer
>();
targets
.
addFirst
(
targetId
);
ped
.
setTargets
(
targets
);
return
Pair
.
create
(
new
Step
(
Integer
.
parseInt
(
cells
[
0
])),
ped
);
})
.
collect
(
Collectors
.
groupingBy
(
pair
->
pair
.
getKey
(),
Collectors
.
mapping
(
pair
->
pair
.
getValue
(),
Collectors
.
toList
())));
// 1. Get the correct column
String
header
=
Files
.
lines
(
this
.
trajectoryFilePath
).
findFirst
().
get
();
String
[]
columns
=
header
.
split
(
SPLITTER
);
for
(
int
index
=
0
;
index
<
columns
.
length
;
index
++)
{
if
(
pedestrianIdKeys
.
contains
(
columns
[
index
]))
{
pedIdIndex
=
index
;
}
else
if
(
stepKeys
.
contains
(
columns
[
index
]))
{
stepIndex
=
index
;
}
else
if
(
xKeys
.
contains
(
columns
[
index
]))
{
xIndex
=
index
;
}
else
if
(
yKeys
.
contains
(
columns
[
index
]))
{
yIndex
=
index
;
}
else
if
(
targetIdKeys
.
contains
(
columns
[
index
]))
{
targetIdIndex
=
index
;
}
}
try
{
if
(
pedIdIndex
!=
-
1
&&
xIndex
!=
-
1
&&
yIndex
!=
-
1
&&
stepIndex
!=
-
1
)
{
return
Files
.
lines
(
this
.
trajectoryFilePath
)
.
skip
(
1
)
// Skip header line
.
map
(
line
->
line
.
split
(
" "
))
.
map
(
cells
->
{
int
step
=
Integer
.
parseInt
(
cells
[
stepIndex
]);
int
pedestrianId
=
Integer
.
parseInt
(
cells
[
pedIdIndex
]);
VPoint
pos
=
new
VPoint
(
Double
.
parseDouble
(
cells
[
xIndex
]),
Double
.
parseDouble
(
cells
[
yIndex
]));
int
targetId
=
targetIdIndex
!=
-
1
?
Integer
.
parseInt
(
cells
[
targetIdIndex
])
:
-
1
;
Pedestrian
ped
=
new
Pedestrian
(
new
AttributesAgent
(
this
.
attributesPedestrian
,
pedestrianId
),
new
Random
());
ped
.
setPosition
(
pos
);
LinkedList
<
Integer
>
targets
=
new
LinkedList
<
Integer
>();
targets
.
addFirst
(
targetId
);
ped
.
setTargets
(
targets
);
return
Pair
.
create
(
new
Step
(
Integer
.
parseInt
(
cells
[
0
])),
ped
);
})
.
collect
(
Collectors
.
groupingBy
(
pair
->
pair
.
getKey
(),
Collectors
.
mapping
(
pair
->
pair
.
getValue
(),
Collectors
.
toList
())));
}
else
{
throw
new
IOException
(
"could not read trajectory file, some colums are missing."
);
}
}
catch
(
Exception
e
)
{
logger
.
warn
(
"could not read trajectory file. The file format might not be compatible or it is missing."
);
throw
e
;
}
}
}
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