Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
language: python
python:
- "2.7"
- "3.5"
- "3.6"
install:
Expand Down
9 changes: 6 additions & 3 deletions socialforce/simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +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):
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
Expand All @@ -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 = ped_ped or PedPedPotential(self.delta_t)
self.U = ped_space

# field of view
self.w = FieldOfView()
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

similarly here self.w = field_of_view or FieldOfView()

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add or FieldOfView() so that default behavior is restored?
Similarly for ped_ped above.

self.w = field_of_view or FieldOfView()

def f_ab(self):
"""Compute f_ab."""
Expand All @@ -59,6 +61,7 @@ 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[desired_speeds == 0] = 0.0
return desired_velocity * np.expand_dims(factor, -1)

def step(self):
Expand Down
4 changes: 3 additions & 1 deletion socialforce/stateutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
directions = destination_vectors / np.expand_dims(norm_factors, -1)
directions[norm_factors == 0] = [0, 0]
return directions


def speeds(state):
Expand Down