Skip to content

Commit

Permalink
Added method to check if there is a deadlock or non-live situation
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoPecora committed Jan 15, 2020
1 parent 7dbfbe2 commit 6807e50
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public abstract class TrajectoryEnvelopeCoordinator extends AbstractTrajectoryEn
//True if waiting for deadlocks to happen.
protected boolean staticReplan = false;

protected boolean isDeadlocked = false;

/**
* Set whether the coordinator should try to break deadlocks by attempting to re-plan
* the path of one of the robots involved in an unsafe cycle.
Expand Down Expand Up @@ -315,6 +317,15 @@ private HashSet<Dependency> computeClosestDependencies(HashMap<Integer,HashSet<D
return closestDeps;
}

/**
* Check whether there is or will be a deadlock.
* @return <code>true</code> iff there is currently a deadlock, or the situation is
* such that a deadlock will occur (non-live state).
*/
public boolean isDeadlocked() {
return this.isDeadlocked;
}

private HashMap<Integer,HashSet<Dependency>> findCurrentCycles(HashMap<Integer,HashSet<Dependency>> currentDeps, HashMap<Integer,HashSet<Dependency>> artificialDeps, HashSet<Dependency> reversibleDeps, HashMap<Integer,RobotReport> currentReports, Set<Integer> robotIDs) {

HashMap<Integer,HashSet<Dependency>> allDeps = new HashMap<Integer, HashSet<Dependency>>();
Expand All @@ -338,6 +349,8 @@ private HashMap<Integer,HashSet<Dependency>> findCurrentCycles(HashMap<Integer,H
SimpleDirectedGraph<Integer,Dependency> g = depsToGraph(currentDependencies);
List<List<Integer>> unsafeCycles = findSimpleUnsafeCycles(g);

if (unsafeCycles.size() > 0) this.isDeadlocked = true;

// ... keep tracks of size and old cycles for statistics
List<List<Integer>> unsafeCyclesNew = new ArrayList<List<Integer>>();
unsafeCyclesNew.addAll(unsafeCycles);
Expand Down

0 comments on commit 6807e50

Please sign in to comment.