From fbfaf8ad11a3220598975e097c78e5843b8cc46b Mon Sep 17 00:00:00 2001 From: theDebugger811 Date: Wed, 29 Jan 2020 12:20:53 +0100 Subject: [PATCH 1/5] Works with stationary agents --- socialforce/simulator.py | 10 ++++++---- socialforce/stateutils.py | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/socialforce/simulator.py b/socialforce/simulator.py index f116c8b..b28b35f 100644 --- a/socialforce/simulator.py +++ b/socialforce/simulator.py @@ -26,7 +26,9 @@ class Simulator(object): delta_t in seconds. tau in seconds: either float or numpy array of shape[n_ped]. """ - def __init__(self, initial_state, ped_space=None, delta_t=0.4, tau=0.5): + def __init__(self, initial_state, ped_space=None, delta_t=0.4, tau=0.5, + v0=2.1, sigma=0.3, + twophi=200.0, out_of_view_factor=0.5): self.state = initial_state self.initial_speeds = stateutils.speeds(initial_state) self.max_speeds = MAX_SPEED_MULTIPLIER * self.initial_speeds @@ -39,11 +41,11 @@ def __init__(self, initial_state, ped_space=None, delta_t=0.4, tau=0.5): self.state = np.concatenate((self.state, np.expand_dims(tau, -1)), axis=-1) # potentials - self.V = PedPedPotential(self.delta_t) + self.V = PedPedPotential(self.delta_t, v0, sigma) self.U = ped_space # field of view - self.w = FieldOfView() + self.w = FieldOfView(twophi, out_of_view_factor) def f_ab(self): """Compute f_ab.""" @@ -58,7 +60,7 @@ def f_aB(self): def capped_velocity(self, desired_velocity): """Scale down a desired velocity to its capped speed.""" desired_speeds = np.linalg.norm(desired_velocity, axis=-1) - factor = np.minimum(1.0, self.max_speeds / desired_speeds) + factor = np.minimum(1.0, np.nan_to_num(self.max_speeds / desired_speeds)) return desired_velocity * np.expand_dims(factor, -1) def step(self): diff --git a/socialforce/stateutils.py b/socialforce/stateutils.py index cb74b52..b29eaba 100644 --- a/socialforce/stateutils.py +++ b/socialforce/stateutils.py @@ -7,7 +7,9 @@ def desired_directions(state): """Given the current state and destination, compute desired direction.""" destination_vectors = state[:, 4:6] - state[:, 0:2] norm_factors = np.linalg.norm(destination_vectors, axis=-1) - return destination_vectors / np.expand_dims(norm_factors, -1) + desired_directions = destination_vectors / np.expand_dims(norm_factors, -1) + desired_directions[norm_factors == 0] = [0, 0] + return desired_directions def speeds(state): From 4175fef14dd80af426b22f2e5a4c4793b4a646a1 Mon Sep 17 00:00:00 2001 From: theDebugger811 Date: Fri, 31 Jan 2020 19:34:19 +0100 Subject: [PATCH 2/5] Initializer updated --- socialforce/simulator.py | 10 +++++----- socialforce/stateutils.py | 6 +++--- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/socialforce/simulator.py b/socialforce/simulator.py index b28b35f..a1012c7 100644 --- a/socialforce/simulator.py +++ b/socialforce/simulator.py @@ -22,13 +22,13 @@ class Simulator(object): tau is optional in this vector. ped_space is an instance of PedSpacePotential. + ped_ped is an instance of PedPedPotential. delta_t in seconds. tau in seconds: either float or numpy array of shape[n_ped]. """ - def __init__(self, initial_state, ped_space=None, delta_t=0.4, tau=0.5, - v0=2.1, sigma=0.3, - twophi=200.0, out_of_view_factor=0.5): + def __init__(self, initial_state, ped_space=None, ped_ped=None, + field_of_view=None, delta_t=0.4, tau=0.5): self.state = initial_state self.initial_speeds = stateutils.speeds(initial_state) self.max_speeds = MAX_SPEED_MULTIPLIER * self.initial_speeds @@ -41,11 +41,11 @@ def __init__(self, initial_state, ped_space=None, delta_t=0.4, tau=0.5, self.state = np.concatenate((self.state, np.expand_dims(tau, -1)), axis=-1) # potentials - self.V = PedPedPotential(self.delta_t, v0, sigma) + self.V = ped_ped self.U = ped_space # field of view - self.w = FieldOfView(twophi, out_of_view_factor) + self.w = field_of_view def f_ab(self): """Compute f_ab.""" diff --git a/socialforce/stateutils.py b/socialforce/stateutils.py index b29eaba..5d2635a 100644 --- a/socialforce/stateutils.py +++ b/socialforce/stateutils.py @@ -7,9 +7,9 @@ def desired_directions(state): """Given the current state and destination, compute desired direction.""" destination_vectors = state[:, 4:6] - state[:, 0:2] norm_factors = np.linalg.norm(destination_vectors, axis=-1) - desired_directions = destination_vectors / np.expand_dims(norm_factors, -1) - desired_directions[norm_factors == 0] = [0, 0] - return desired_directions + directions = destination_vectors / np.expand_dims(norm_factors, -1) + directions[norm_factors == 0] = [0, 0] + return directions def speeds(state): From 32a1c9c3c0508836bce9e1192373c8d24a82fc4e Mon Sep 17 00:00:00 2001 From: theDebugger811 Date: Fri, 7 Feb 2020 19:33:42 +0100 Subject: [PATCH 3/5] Default behavior added --- socialforce/simulator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/socialforce/simulator.py b/socialforce/simulator.py index a1012c7..a70c684 100644 --- a/socialforce/simulator.py +++ b/socialforce/simulator.py @@ -41,11 +41,11 @@ def __init__(self, initial_state, ped_space=None, ped_ped=None, self.state = np.concatenate((self.state, np.expand_dims(tau, -1)), axis=-1) # potentials - self.V = ped_ped + self.V = ped_ped or PedPedPotential(self.delta_t) self.U = ped_space # field of view - self.w = field_of_view + self.w = field_of_view or FieldOfView() def f_ab(self): """Compute f_ab.""" From d14afcdaf15d5a168b4d2cbd733d2ccee9b59956 Mon Sep 17 00:00:00 2001 From: theDebugger811 Date: Fri, 7 Feb 2020 19:46:29 +0100 Subject: [PATCH 4/5] Capped velocity fixed --- socialforce/simulator.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/socialforce/simulator.py b/socialforce/simulator.py index a70c684..47b90e3 100644 --- a/socialforce/simulator.py +++ b/socialforce/simulator.py @@ -60,7 +60,8 @@ def f_aB(self): def capped_velocity(self, desired_velocity): """Scale down a desired velocity to its capped speed.""" desired_speeds = np.linalg.norm(desired_velocity, axis=-1) - factor = np.minimum(1.0, np.nan_to_num(self.max_speeds / desired_speeds)) + factor = np.minimum(1.0, self.max_speeds / desired_speeds) + factor[desired_speeds == 0] = 0.0 return desired_velocity * np.expand_dims(factor, -1) def step(self): From 58a36883b5ac4cc1520a8a68575da9b5492df691 Mon Sep 17 00:00:00 2001 From: theDebugger811 Date: Sun, 9 Feb 2020 17:17:16 +0100 Subject: [PATCH 5/5] Python2.7 test removed --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 227f7ae..ad3d59b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: python python: - - "2.7" - "3.5" - "3.6" install: