Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
navipy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
Olivier Bertrand
navipy
Commits
94b40f80
Commit
94b40f80
authored
6 years ago
by
Olivier Bertrand
Browse files
Options
Downloads
Patches
Plain Diff
Simply build graph by using velocities
parent
1b0d75cc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
navipy/moving/agent.py
+33
-50
33 additions, 50 deletions
navipy/moving/agent.py
with
33 additions
and
50 deletions
navipy/moving/agent.py
+
33
−
50
View file @
94b40f80
...
@@ -439,56 +439,39 @@ the agent motion, or
...
@@ -439,56 +439,39 @@ the agent motion, or
nline
+=
1
nline
+=
1
return
self
.
velocities
.
copy
()
return
self
.
velocities
.
copy
()
def
build_graph
(
self
,
def
build_graph
(
self
,
movemode
,
moveparam
):
ncpu
=
5
,
"""
timeout
=
1
,
Connect edges with a given velocity
filename
=
None
,
"""
blocksize
=
100
):
if
self
.
velocities
.
dropna
().
shape
[
0
]
==
0
:
# Build a list of nodes
raise
NameError
(
'
compute_velocities should be called first
'
)
results_edges
=
[]
edges
=
pd
.
Series
(
data
=
np
.
nan
,
index
=
self
.
velocities
.
index
)
posorients_queue
=
JoinableQueue
()
# Make sure that the velocity start at the correct location
results_queue
=
Queue
()
posorients
=
self
.
_brain
.
posorients
if
version
<
2
:
myvelocities
=
self
.
velocities
.
copy
()
graph_nodes
=
list
(
self
.
_graph
.
nodes
())
myvelocities
=
myvelocities
.
swaplevel
(
axis
=
1
)
else
:
myvelocities
.
x
=
posorients
.
x
graph_nodes
=
list
(
self
.
_graph
.
nodes
)
myvelocities
.
y
=
posorients
.
y
for
node
in
graph_nodes
:
myvelocities
.
z
=
posorients
.
z
posorients_queue
.
put
(
self
.
_graph
.
nodes
[
node
][
'
posorient
'
])
myvelocities
.
alpha_0
=
posorients
.
alpha_0
myvelocities
.
alpha_1
=
posorients
.
alpha_1
# Start ndatabase loader
myvelocities
.
alpha_2
=
posorients
.
alpha_2
num_agents
=
ncpu
myvelocities
=
myvelocities
.
swaplevel
(
axis
=
1
)
agents
=
[
GridAgent
(
copy
.
copy
(
self
.
_brain
),
for
ii
,
row
in
myvelocities
.
iterrows
():
posorients_queue
=
posorients_queue
,
if
np
.
any
(
np
.
isnan
(
row
)):
results_queue
=
results_queue
)
continue
for
_
in
range
(
num_agents
)]
# Move according to user mode of motion
for
w
in
agents
:
nposorient
=
navimomath
.
next_pos
(
row
,
movemode
,
moveparam
)
w
.
mode_of_motion
=
self
.
mode_of_motion
# Snap to the closest point
w
.
start
()
nextpos_index
=
navimomath
.
closest_pos
(
nposorient
,
myvelocities
)
# Add a poison pill for each agent
edges
[
ii
]
=
nextpos_index
.
name
for
_
in
range
(
num_agents
):
# Format for graph
posorients_queue
.
put
(
None
)
validedges
=
edges
.
dropna
()
results_edges
=
np
.
vstack
(
# Wait for all of the tasks to finish
[
validedges
.
index
,
# posorients_queue.join()
validedges
.
values
]).
transpose
()
nline
=
0
# Add to graph
prev_nline
=
nline
t_start
=
time
.
time
()
nbnodes
=
nx
.
number_of_nodes
(
self
.
_graph
)
for
_
in
range
(
nx
.
number_of_nodes
(
self
.
_graph
)):
result
=
results_queue
.
get
(
timeout
=
timeout
)
results_edges
.
append
((
result
[
0
].
name
,
result
[
1
].
name
))
if
(
nline
-
prev_nline
)
>
blocksize
:
t_elapse
=
time
.
time
()
-
t_start
t_peritem
=
t_elapse
/
nline
remain
=
nbnodes
-
nline
print
(
'
Computed {} in {}
'
.
format
(
nline
,
t_elapse
))
print
(
'
Remain {}, done in {}
'
.
format
(
remain
,
remain
*
t_peritem
))
if
filename
is
not
None
:
np
.
save
(
filename
,
np
.
array
(
results_edges
))
nline
+=
1
# print(results_edges[-1])
self
.
_graph
.
add_edges_from
(
results_edges
)
self
.
_graph
.
add_edges_from
(
results_edges
)
self
.
check_graph
()
self
.
check_graph
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment