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
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
nline
+=
1
return
self
.
velocities
.
copy
()
def
build_graph
(
self
,
ncpu
=
5
,
timeout
=
1
,
filename
=
None
,
blocksize
=
100
):
# Build a list of nodes
results_edges
=
[]
posorients_queue
=
JoinableQueue
()
results_queue
=
Queue
()
if
version
<
2
:
graph_nodes
=
list
(
self
.
_graph
.
nodes
())
else
:
graph_nodes
=
list
(
self
.
_graph
.
nodes
)
for
node
in
graph_nodes
:
posorients_queue
.
put
(
self
.
_graph
.
nodes
[
node
][
'
posorient
'
])
# Start ndatabase loader
num_agents
=
ncpu
agents
=
[
GridAgent
(
copy
.
copy
(
self
.
_brain
),
posorients_queue
=
posorients_queue
,
results_queue
=
results_queue
)
for
_
in
range
(
num_agents
)]
for
w
in
agents
:
w
.
mode_of_motion
=
self
.
mode_of_motion
w
.
start
()
# Add a poison pill for each agent
for
_
in
range
(
num_agents
):
posorients_queue
.
put
(
None
)
# Wait for all of the tasks to finish
# posorients_queue.join()
nline
=
0
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])
def
build_graph
(
self
,
movemode
,
moveparam
):
"""
Connect edges with a given velocity
"""
if
self
.
velocities
.
dropna
().
shape
[
0
]
==
0
:
raise
NameError
(
'
compute_velocities should be called first
'
)
edges
=
pd
.
Series
(
data
=
np
.
nan
,
index
=
self
.
velocities
.
index
)
# Make sure that the velocity start at the correct location
posorients
=
self
.
_brain
.
posorients
myvelocities
=
self
.
velocities
.
copy
()
myvelocities
=
myvelocities
.
swaplevel
(
axis
=
1
)
myvelocities
.
x
=
posorients
.
x
myvelocities
.
y
=
posorients
.
y
myvelocities
.
z
=
posorients
.
z
myvelocities
.
alpha_0
=
posorients
.
alpha_0
myvelocities
.
alpha_1
=
posorients
.
alpha_1
myvelocities
.
alpha_2
=
posorients
.
alpha_2
myvelocities
=
myvelocities
.
swaplevel
(
axis
=
1
)
for
ii
,
row
in
myvelocities
.
iterrows
():
if
np
.
any
(
np
.
isnan
(
row
)):
continue
# Move according to user mode of motion
nposorient
=
navimomath
.
next_pos
(
row
,
movemode
,
moveparam
)
# Snap to the closest point
nextpos_index
=
navimomath
.
closest_pos
(
nposorient
,
myvelocities
)
edges
[
ii
]
=
nextpos_index
.
name
# Format for graph
validedges
=
edges
.
dropna
()
results_edges
=
np
.
vstack
(
[
validedges
.
index
,
validedges
.
values
]).
transpose
()
# Add to graph
self
.
_graph
.
add_edges_from
(
results_edges
)
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