Skip to content

Commit

Permalink
small fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Henkel <[email protected]>
  • Loading branch information
ct2034 committed Nov 3, 2024
1 parent 0acd34d commit aec5fee
Show file tree
Hide file tree
Showing 14 changed files with 42 additions and 41 deletions.
23 changes: 12 additions & 11 deletions planner/cbs-ta_vs_tcbs/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
from planner.mapf_implementations.plan_cbs_ta import plan as cbs_ta_plan
from planner.tcbs.plan import generate_config
from planner.tcbs.plan import plan as tcbs_plan
from scenarios.generators import tracing_pathes_in_the_dark
from scenarios.generators import tracing_paths_in_the_dark


def tcbs_with_single_goals(gridmap, starts, goals, timeout):
def tcbs_with_single_goals(grid, starts, goals, timeout):
"""
Adapter to call TCBS with single goals.
(Normally, TCBS defines jobs as transport tasks,
Expand All @@ -24,8 +24,8 @@ def tcbs_with_single_goals(gridmap, starts, goals, timeout):
for g in goals:
jobs.append((tuple(g), tuple(g), 0)) # start = goal = g, time = 0
# map must be time-expanded
t_max = gridmap.shape[0] * gridmap.shape[1] * 2
_map = np.repeat(gridmap[:, :, np.newaxis], t_max, axis=2)
t_max = grid.shape[0] * grid.shape[1] * 2
_map = np.repeat(grid[:, :, np.newaxis], t_max, axis=2)
config = generate_config()
config["time_extended"] = False
return tcbs_plan(
Expand All @@ -38,11 +38,12 @@ def tcbs_with_single_goals(gridmap, starts, goals, timeout):
)


def execute_both_planners(gridmap, starts, goals, timeout):
def execute_both_planners(grid, starts, goals, timeout):
"""Execute both planners and return the results."""
if isinstance(goals, np.ndarray):
goals = [list(g) for g in goals]
cbs_ta_res = cbs_ta_plan(gridmap, starts, goals, timeout)
tcbs_res = tcbs_with_single_goals(gridmap, starts, goals, timeout)
cbs_ta_res = cbs_ta_plan(grid, starts, goals, timeout)
tcbs_res = tcbs_with_single_goals(grid, starts, goals, timeout)
return cbs_ta_res, tcbs_res


Expand Down Expand Up @@ -89,6 +90,7 @@ def get_paths_from_cbs_ta_res(cbs_ta_res):


def demo():
"""Demonstrate the comparison of CBS-TA and TCBS."""
gridmap = np.array([[FREE] * 3] * 3)
gridmap[1, 1] = OBSTACLE
starts = [[0, 0], [0, 1], [0, 2]]
Expand Down Expand Up @@ -160,7 +162,7 @@ def eval_same_cost_for_random_scenarios():
res_success_tcbs = 0

for _ in tqdm.tqdm(range(n_runs)):
gridmap, starts, goals = tracing_pathes_in_the_dark(
gridmap, starts, goals = tracing_paths_in_the_dark(
size=size,
fill=0.2,
n_agents=n_agents,
Expand All @@ -184,9 +186,8 @@ def eval_same_cost_for_random_scenarios():
if cost_cbs_ta == cost_tcbs:
res_same_cost += 1

print(
f"Same cost: {res_same_cost}/{n_runs} = " + f"{res_same_cost/n_runs*100:.2f}%"
)
percentage_same_cost = res_same_cost / n_runs * 100
print(f"Same cost: {res_same_cost}/{n_runs} = {percentage_same_cost:.2f}%")
print(f"Success CBS-TA: {res_success_cbs_ta/n_runs*100:.2f}%")
print(f"Success TCBS: {res_success_tcbs/n_runs*100:.2f}%")

Expand Down
4 changes: 2 additions & 2 deletions planner/dhc/dhc_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from definitions import INVALID
from planner.dhc.eval import eval
from scenarios.generators import tracing_pathes_in_the_dark
from scenarios.generators import tracing_paths_in_the_dark


class DhcTest(unittest.TestCase):
Expand All @@ -14,7 +14,7 @@ def test_eval(self):
size = 10
fill = 0.5
n_agents = 5
env, starts, goals = tracing_pathes_in_the_dark(size, fill, n_agents, rng)
env, starts, goals = tracing_paths_in_the_dark(size, fill, n_agents, rng)
res = eval(env, starts, goals)
success, steps, paths = res
self.assertTrue(success)
Expand Down
4 changes: 2 additions & 2 deletions planner/dhc/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from definitions import INVALID
from planner.dhc import generate_scenarios
from planner.dhc.DHC import test
from scenarios.generators import tracing_pathes_in_the_dark
from scenarios.generators import tracing_paths_in_the_dark


def eval(env, starts, goals):
Expand All @@ -27,7 +27,7 @@ def eval(env, starts, goals):
size = 10
fill = 0.5
n_agents = 5
env, starts, goals = tracing_pathes_in_the_dark(size, fill, n_agents, rng)
env, starts, goals = tracing_paths_in_the_dark(size, fill, n_agents, rng)
print(f"{starts=}")
print(f"{goals=}")

Expand Down
4 changes: 2 additions & 2 deletions planner/dhc/generate_scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tqdm import tqdm

from definitions import SCENARIO_TYPE
from scenarios.generators import tracing_pathes_in_the_dark
from scenarios.generators import tracing_paths_in_the_dark
from tools import hasher


Expand All @@ -31,7 +31,7 @@ def generate_file(scen: SCENARIO_TYPE):
n_agents = 5

for _ in tqdm(range(n_scenarios)):
env, starts, goals = tracing_pathes_in_the_dark(size, fill, n_agents, rng)
env, starts, goals = tracing_paths_in_the_dark(size, fill, n_agents, rng)
tests.append((env, starts, goals))

path = f"./DHC/test_set/tracing_pathes_in_the_dark_{size}_{fill}_{n_agents}.pth"
Expand Down
6 changes: 3 additions & 3 deletions planner/policylearn/generate_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from planner.policylearn.generate_fovs import *
from planner.policylearn.generate_graph import *
from scenarios.evaluators import cached_ecbs
from scenarios.generators import building_walls, random_fill, tracing_pathes_in_the_dark
from scenarios.generators import building_walls, random_fill, tracing_paths_in_the_dark
from scenarios.main_eval import GENERATOR
from sim.decentralized.runner import will_scenario_collide_and_get_paths
from tools import ProgressBar
Expand All @@ -44,7 +44,7 @@
CLASSIFICATION_FOV_RADIUS = 3 # self plus x in all 4 directions
DTYPE_SAMPLES = np.int8

GENERATORS = [building_walls, random_fill, tracing_pathes_in_the_dark]
GENERATORS = [building_walls, random_fill, tracing_paths_in_the_dark]


def show_map(x):
Expand Down Expand Up @@ -588,7 +588,7 @@ def simulate_one_data(width, fill, n_agents, base_seed, pb, i):
while len(all_data) < n_data_to_gen:
do_collide = False
while not do_collide:
gridmap, starts, goals = tracing_pathes_in_the_dark(
gridmap, starts, goals = tracing_paths_in_the_dark(
width, fill, n_agents, random.Random(seed)
)
seed += 1
Expand Down
4 changes: 2 additions & 2 deletions planner/primal2/eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from definitions import SCENARIO_TYPE
from scenarios.evaluators import cost_ecbs
from scenarios.generators import tracing_pathes_in_the_dark
from scenarios.generators import tracing_paths_in_the_dark
from tools import hasher


Expand Down Expand Up @@ -78,7 +78,7 @@ def eval_primal2(workdir):
rng = Random(0)
scens = []
for _ in range(n_eval):
scen = tracing_pathes_in_the_dark(size=8, fill=0.5, n_agents=4, rng=rng)
scen = tracing_paths_in_the_dark(size=8, fill=0.5, n_agents=4, rng=rng)
scens.append(scen)
convert_scenario_to_primal(scen, get_fnames(workdir, scen)[0])

Expand Down
2 changes: 1 addition & 1 deletion scenarios/generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_random_next_to_free_pose_or_any_if_full(env: np.ndarray, rng: random.Ran
return step_pos


def tracing_pathes_in_the_dark(
def tracing_paths_in_the_dark(
size: int, fill: float, n_agents: int, rng: random.Random
):
"""Starting with a black map, clearing straight lines through it, making
Expand Down
4 changes: 2 additions & 2 deletions scenarios/generators_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from matplotlib import pyplot as plt
from visualization import plot_env_with_arrows

from scenarios.generators import building_walls, movingai, tracing_pathes_in_the_dark
from scenarios.generators import building_walls, movingai, tracing_paths_in_the_dark


def demo_movingai():
Expand All @@ -13,7 +13,7 @@ def demo_movingai():

def demo_tracing_pathes_in_the_dark():
n_agents = 3
env, starts, goals = tracing_pathes_in_the_dark(50, 0.5, n_agents, 0)
env, starts, goals = tracing_paths_in_the_dark(50, 0.5, n_agents, 0)
plot_env_with_arrows(env, starts, goals)


Expand Down
14 changes: 7 additions & 7 deletions scenarios/generators_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,21 +121,21 @@ def test_get_random_next_to_free_pose_or_any_if_full_next(self):
self.assertIn(tuple(pos_next), [(1, 0), (2, 1), (1, 2), (0, 1)])

def test_tracing_pathes_in_the_dark_determinism(self):
(base_env, base_starts, base_goals) = tracing_pathes_in_the_dark(
(base_env, base_starts, base_goals) = tracing_paths_in_the_dark(
10, 0.5, 10, random.Random(0)
)
# --------

# everything the same
(same_env, same_starts, same_goals) = tracing_pathes_in_the_dark(
(same_env, same_starts, same_goals) = tracing_paths_in_the_dark(
10, 0.5, 10, random.Random(0)
)
self.assertTrue(np.all(base_env == same_env))
self.assertTrue(np.all(base_starts == same_starts))
self.assertTrue(np.all(base_goals == same_goals))

# everything different
(other_env, other_starts, other_goals) = tracing_pathes_in_the_dark(
(other_env, other_starts, other_goals) = tracing_paths_in_the_dark(
10, 0.5, 10, random.Random(1)
)
self.assertFalse(np.all(base_env == other_env))
Expand All @@ -144,7 +144,7 @@ def test_tracing_pathes_in_the_dark_determinism(self):
# --------

# only env different -> all different
(other_env, other_starts, other_goals) = tracing_pathes_in_the_dark(
(other_env, other_starts, other_goals) = tracing_paths_in_the_dark(
10, 0.4, 10, random.Random(0)
)
self.assertFalse(np.all(base_env == other_env))
Expand All @@ -153,15 +153,15 @@ def test_tracing_pathes_in_the_dark_determinism(self):

def test_tracing_pathes_in_the_dark_gen_low_fills(self):
"""tests if generator handles low fill numbers correctly"""
(env, starts, goals) = tracing_pathes_in_the_dark(10, 0.1, 10, random.Random(0))
(env, starts, goals) = tracing_paths_in_the_dark(10, 0.1, 10, random.Random(0))
self.assertEqual(np.count_nonzero(env), 10) # 10% of 10*10

(env, starts, goals) = tracing_pathes_in_the_dark(10, 0, 10, random.Random(0))
(env, starts, goals) = tracing_paths_in_the_dark(10, 0, 10, random.Random(0))
self.assertEqual(np.count_nonzero(env), 0) # 0% of 10*10

def test_tracing_pathes_in_the_dark_radomism(self):
"""tests if generator makes actually random changes between agents"""
(env, starts, goals) = tracing_pathes_in_the_dark(10, 0, 10, random.Random(0))
(env, starts, goals) = tracing_paths_in_the_dark(10, 0, 10, random.Random(0))
problematic = np.array(starts)[1:, :]
self.assertFalse(all(problematic[:, 1] == np.arange(9)))
self.assertFalse(all(problematic[:, 0] == 5))
Expand Down
2 changes: 1 addition & 1 deletion scenarios/main_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def make_full_df():
# low_agents, high_agents) = init_values_focus()

# parameters to evaluate against
generators = [random_fill, tracing_pathes_in_the_dark, building_walls]
generators = [random_fill, tracing_paths_in_the_dark, building_walls]

fills = np.around(np.linspace(0, max_fill, n_fills), 2) # list of fills we want

Expand Down
6 changes: 3 additions & 3 deletions scenarios/storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@


class TestStorage(unittest.TestCase):
scenario1 = generators.tracing_pathes_in_the_dark(2, 0.5, 1, rng=random.Random(1))
scenario2 = generators.tracing_pathes_in_the_dark(2, 0.5, 1, rng=random.Random(2))
scenario1 = generators.tracing_paths_in_the_dark(2, 0.5, 1, rng=random.Random(1))
scenario2 = generators.tracing_paths_in_the_dark(2, 0.5, 1, rng=random.Random(2))
to_store = 42
to_store2 = 42.5
to_store3 = 42.6
Expand All @@ -36,7 +36,7 @@ def test_storage(self):
# same paths for same scenarios
path1 = storage.get_filepath(self.scenario1)
self.assertTrue(path1.startswith(TestStorage.data_path))
scenario1_2 = generators.tracing_pathes_in_the_dark(
scenario1_2 = generators.tracing_paths_in_the_dark(
2, 0.5, 1, rng=random.Random(1)
)
path1_2 = storage.get_filepath(scenario1_2)
Expand Down
2 changes: 1 addition & 1 deletion scenarios/visualization_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


# %%
env, starts, goals = scenarios.generators.tracing_pathes_in_the_dark(
env, starts, goals = scenarios.generators.tracing_paths_in_the_dark(
50, 0.6, 8, random.Random(0)
)

Expand Down
4 changes: 2 additions & 2 deletions sim/decentralized/demo_policylearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from matplotlib import pyplot as plt

from scenarios import visualization
from scenarios.generators import tracing_pathes_in_the_dark
from scenarios.generators import tracing_paths_in_the_dark
from sim.decentralized.agent import Agent
from sim.decentralized.policy import PolicyType
from sim.decentralized.runner import run_a_scenario
Expand All @@ -17,7 +17,7 @@ def make_scenario():
n_agents = 100
fill = 0.4
seed = 2034
gridmap, starts, goals = tracing_pathes_in_the_dark(width, fill, n_agents, seed)
gridmap, starts, goals = tracing_paths_in_the_dark(width, fill, n_agents, seed)
return (gridmap, starts, goals)


Expand Down
4 changes: 2 additions & 2 deletions sim/decentralized/runner_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
arena_with_crossing,
corridor_with_passing,
random_fill,
tracing_pathes_in_the_dark,
tracing_paths_in_the_dark,
)
from scenarios.solvers import ecbs
from scenarios.visualization import plot_env_with_arrows, plot_with_paths
Expand Down Expand Up @@ -138,7 +138,7 @@ def find_and_run_interesting_scenario():
seed = 0

while not interesting:
env, starts, goals = tracing_pathes_in_the_dark(
env, starts, goals = tracing_paths_in_the_dark(
size, 0.5, n_agents, random.Random(seed)
)
agents = to_agent_objects(env, starts, goals, policy)
Expand Down

0 comments on commit aec5fee

Please sign in to comment.