Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid calling detect_collision twice needlessly #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 13 additions & 12 deletions code/cbs_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@ def detect_collision(path1, path2):

return None


def detect_collisions(paths):
##############################
# Task 3.1: Return a list of first collisions between all robot pairs.
# A collision can be represented as dictionary that contains the id of the two robots, the vertex or edge
# A collision can be represented as a dictionary that contains the id of the two robots, the vertex or edge
# causing the collision, and the timestep at which the collision occurred.
# You should use your detect_collision function to find a collision between two robots.
collisions =[]
for i in range(len(paths)-1):
for j in range(i+1,len(paths)):
if detect_collision(paths[i],paths[j]) !=None:
position,t = detect_collision(paths[i],paths[j])
collisions.append({'a1':i,
'a2':j,
'loc':position,
'timestep':t+1})
collisions = []
for i in range(len(paths) - 1):
for j in range(i + 1, len(paths)):
collision_result = detect_collision(paths[i], paths[j]) # Store result of the function call
if collision_result is not None:
position, t = collision_result # Use the stored result
collisions.append({
'a1': i,
'a2': j,
'loc': position,
'timestep': t + 1
})
return collisions


def standard_splitting(collision):
##############################
# Task 3.2: Return a list of (two) constraints to resolve the given collision
Expand Down