Skip to content

Commit 5b7be25

Browse files
committed
implementing 8-connected grid
Signed-off-by: Christian Henkel <[email protected]>
1 parent 6731cae commit 5b7be25

File tree

1 file changed

+110
-51
lines changed

1 file changed

+110
-51
lines changed

roadmaps/benchmark.py

Lines changed: 110 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
# 'simple'
5757
]
5858
PLOT_GSRM_ON_MAP = 'z'
59-
N_SEEDS = 1 # 6
59+
N_SEEDS = 5
6060

6161

6262
class RoadmapToTest:
@@ -562,6 +562,10 @@ def __init__(self,
562562
self.runtime_ms = (end_t - start_t) * 1000
563563
self._set_graph(g)
564564

565+
def _make_gridmap(self, _):
566+
raise NotImplementedError("Implement in subclass.")
567+
568+
class GridMap4(GridMap):
565569
def _make_gridmap(self, n_side):
566570
edge_length = 1 / (n_side + 1)
567571
g = nx.Graph()
@@ -594,6 +598,51 @@ def _make_gridmap(self, n_side):
594598
p[0]) for i, p in nx.get_node_attributes(
595599
g, POS).items()}, POS)
596600
return g
601+
602+
603+
class GridMap8(GridMap):
604+
def _make_gridmap(self, n_side):
605+
edge_length = 1 / (n_side + 1)
606+
g = nx.Graph()
607+
grid = np.full((n_side, n_side), -1)
608+
for x, y in product(range(n_side), range(n_side)):
609+
i_to_add = len(g)
610+
coords = (
611+
x * edge_length + edge_length / 2,
612+
y * edge_length + edge_length / 2,
613+
)
614+
if is_coord_free(self.map_img, coords):
615+
g.add_node(i_to_add, **{POS: coords})
616+
grid[x, y] = i_to_add
617+
deltas = [
618+
[0, -1], # left
619+
[-1, -1], # up left
620+
[-1, 0], # up
621+
[-1, 1], # up right
622+
]
623+
for dx, dy in deltas:
624+
other_x, other_y = x + dx, y + dy
625+
if (
626+
other_x < 0 or
627+
other_x >= n_side or
628+
other_y < 0 or
629+
other_y >= n_side):
630+
continue
631+
if grid[other_x, other_y] != -1 and self._check_line(
632+
coords,
633+
g.nodes[grid[other_x, other_y]][POS]):
634+
g.add_edge(i_to_add, grid[other_x, other_y], **{
635+
DISTANCE: np.linalg.norm(
636+
np.array([dx, dy])) * edge_length
637+
})
638+
# swap x and y
639+
nx.set_node_attributes(
640+
g,
641+
{i: (p[1],
642+
p[0]) for i, p in nx.get_node_attributes(
643+
g, POS).items()}, POS)
644+
return g
645+
597646

598647

599648
# class VisibilityGraph(RoadmapToTest):
@@ -677,64 +726,73 @@ def run():
677726
# 'epochs_optim': 25, # of optimization
678727
# 'lr_optim': 1e-3,
679728
# }),
680-
(SPARS2, {
681-
'target_n': ns[0],
682-
'dense_to_sparse_multiplier': 40,
683-
'stretchFactor': 3,
684-
'maxFailures': 500,
685-
'maxTime': 8., # ignored
686-
'maxIter': 50000,
687-
}),
688-
(SPARS2, {
689-
'target_n': ns[1],
690-
'dense_to_sparse_multiplier': 30,
691-
'stretchFactor': 3,
692-
'maxFailures': 500,
693-
'maxTime': 8., # ignored
694-
'maxIter': 50000,
695-
}),
696-
(SPARS2, {
697-
'target_n': ns[2],
698-
'dense_to_sparse_multiplier': 20,
699-
'stretchFactor': 3,
700-
'maxFailures': 500,
701-
'maxTime': 8., # ignored
702-
'maxIter': 50000,
703-
}),
704-
(ORM, {
705-
'n': ns[0],
706-
'lr': 1e-3,
707-
'epochs': 50,
708-
}),
709-
(ORM, {
710-
'n': ns[1],
711-
'lr': 1e-3,
712-
'epochs': 50,
713-
}),
714-
(ORM, {
715-
'n': ns[2],
716-
'lr': 1e-3,
717-
'epochs': 50,
718-
}),
719-
(PRM, {
729+
# (SPARS2, {
730+
# 'target_n': ns[0],
731+
# 'dense_to_sparse_multiplier': 40,
732+
# 'stretchFactor': 3,
733+
# 'maxFailures': 500,
734+
# 'maxTime': 8., # ignored
735+
# 'maxIter': 50000,
736+
# }),
737+
# (SPARS2, {
738+
# 'target_n': ns[1],
739+
# 'dense_to_sparse_multiplier': 30,
740+
# 'stretchFactor': 3,
741+
# 'maxFailures': 500,
742+
# 'maxTime': 8., # ignored
743+
# 'maxIter': 50000,
744+
# }),
745+
# (SPARS2, {
746+
# 'target_n': ns[2],
747+
# 'dense_to_sparse_multiplier': 20,
748+
# 'stretchFactor': 3,
749+
# 'maxFailures': 500,
750+
# 'maxTime': 8., # ignored
751+
# 'maxIter': 50000,
752+
# }),
753+
# (ORM, {
754+
# 'n': ns[0],
755+
# 'lr': 1e-3,
756+
# 'epochs': 50,
757+
# }),
758+
# (ORM, {
759+
# 'n': ns[1],
760+
# 'lr': 1e-3,
761+
# 'epochs': 50,
762+
# }),
763+
# (ORM, {
764+
# 'n': ns[2],
765+
# 'lr': 1e-3,
766+
# 'epochs': 50,
767+
# }),
768+
# (PRM, {
769+
# 'n': ns[0],
770+
# 'start_radius': 0.06,
771+
# }),
772+
# (PRM, {
773+
# 'n': ns[1],
774+
# 'start_radius': 0.035,
775+
# }),
776+
# (PRM, {
777+
# 'n': ns[2],
778+
# 'start_radius': 0.025,
779+
# }),
780+
(GridMap4, {
720781
'n': ns[0],
721-
'start_radius': 0.06,
722782
}),
723-
(PRM, {
783+
(GridMap4, {
724784
'n': ns[1],
725-
'start_radius': 0.035,
726785
}),
727-
(PRM, {
786+
(GridMap4, {
728787
'n': ns[2],
729-
'start_radius': 0.025,
730788
}),
731-
(GridMap, {
789+
(GridMap8, {
732790
'n': ns[0],
733791
}),
734-
(GridMap, {
792+
(GridMap8, {
735793
'n': ns[1],
736794
}),
737-
(GridMap, {
795+
(GridMap8, {
738796
'n': ns[2],
739797
})
740798
]
@@ -1016,7 +1074,8 @@ def plots_for_paper():
10161074
'dense34'
10171075
]
10181076
n_plots = len(interesting_maps)
1019-
n_n_nodes = len(df[df.roadmap == 'PRM'].n_nodes.unique())
1077+
a_roadmap = df['roadmap'][0]
1078+
n_n_nodes = len(df[df.roadmap == a_roadmap].n_nodes.unique())
10201079
print(f'{n_plots=}, {n_n_nodes=}')
10211080
df = _group_n_nodes(df, n_n_nodes)
10221081
legend_i = 1
@@ -1066,7 +1125,7 @@ def table_for_paper():
10661125
on different maps.
10671126
"""
10681127
import latextable
1069-
from collections import OrderedDict
1128+
from collections import OrderedDict
10701129
from texttable import Texttable
10711130
df = pd.read_csv(CSV_PATH)
10721131

0 commit comments

Comments
 (0)