Hi, thanks for your great work about this social force simulator. I've tried this simulator and find it very useful.
I have a suggestion to improve the computation efficiency about the force calculation, that is the ObstacleForce class.
the _get_force() func will calculate the distance first for all the points in obstacle lines, then it add masks. When there are lots of obstacles this function will greatly slow-down the process.
To speed up this process, now I add a simple judgement to pre-select nearby obstacles. This improvement will speed up the process from 14sec/step to 0.05sec/step in our case. Note that the solution here is not very elegant. You can try to improve by this thought.
class ObstacleForce(Force):
def _get_force(self):
sigma = self.config("sigma", 0.2)
threshold = self.config("threshold", 0.2) + self.peds.agent_radius
force = np.zeros((self.peds.size(), 2))
if len(self.scene.get_obstacles()) == 0:
return force
obstacles = np.vstack(self.scene.get_obstacles())
pos = self.peds.pos()
for i, p in enumerate(pos):
diff = p - obstacles
diff_select = diff[np.logical_and(np.logical_and(diff[:,0]<10,diff[:,0]>-10),np.logical_and(diff[:,1]<10,diff[:,1]>-10))]
if diff_select.shape[0] == 0:
continue
else:
directions, dist = stateutils.normalize(diff_select)
dist = dist - self.peds.agent_radius
if np.all(dist >= threshold):
continue
dist_mask = dist < threshold
directions[dist_mask] *= np.exp(-dist[dist_mask].reshape(-1, 1) / sigma)
force[i] = np.sum(directions[dist_mask], axis=0)
return force * self.factor
Hi, thanks for your great work about this social force simulator. I've tried this simulator and find it very useful.
I have a suggestion to improve the computation efficiency about the force calculation, that is the
ObstacleForceclass.the _get_force() func will calculate the distance first for all the points in obstacle lines, then it add masks. When there are lots of obstacles this function will greatly slow-down the process.
To speed up this process, now I add a simple judgement to pre-select nearby obstacles. This improvement will speed up the process from 14sec/step to 0.05sec/step in our case. Note that the solution here is not very elegant. You can try to improve by this thought.