List of usage examples for java.util Queue remove
boolean remove(Object o);
From source file:bwem.Graph.java
private int[] computeDistances(final ChokePoint start, final List<ChokePoint> targets) { final int[] distances = new int[targets.size()]; TileImpl.getStaticMarkable().unmarkAll(); final Queue<Pair<Integer, ChokePoint>> toVisit = new PriorityQueue<>(Comparator.comparingInt(a -> a.first)); toVisit.offer(new Pair<>(0, start)); int remainingTargets = targets.size(); while (!toVisit.isEmpty()) { final Pair<Integer, ChokePoint> distanceAndChokePoint = toVisit.poll(); final int currentDist = distanceAndChokePoint.first; final ChokePoint current = distanceAndChokePoint.second; final Tile currentTile = getMap().getData().getTile(current.getCenter().toTilePosition(), CheckMode.NO_CHECK);//from w w w. j av a2 s .c o m // bwem_assert(currentTile.InternalData() == currentDist); if (!(((TileImpl) currentTile).getInternalData() == currentDist)) { throw new IllegalStateException(); } ((TileImpl) currentTile).setInternalData(0); // resets Tile::m_internalData for future usage ((TileImpl) currentTile).getMarkable().setMarked(); for (int i = 0; i < targets.size(); ++i) { if (current == targets.get(i)) { distances[i] = currentDist; --remainingTargets; } } if (remainingTargets == 0) { break; } if (current.isBlocked() && (!current.equals(start))) { continue; } for (final Area pArea : new Area[] { current.getAreas().getFirst(), current.getAreas().getSecond() }) { for (final ChokePoint next : pArea.getChokePoints()) { if (!next.equals(current)) { final int newNextDist = currentDist + distance(current, next); final Tile nextTile = getMap().getData().getTile(next.getCenter().toTilePosition(), CheckMode.NO_CHECK); if (!((TileImpl) nextTile).getMarkable().isMarked()) { if (((TileImpl) nextTile).getInternalData() != 0) { // next already in toVisit if (newNextDist < ((TileImpl) nextTile).getInternalData()) { // nextNewDist < nextOldDist // To update next's distance, we need to remove-insert it from toVisit: // bwem_assert(iNext != range.second); final boolean removed = toVisit .remove(new Pair<>(((TileImpl) nextTile).getInternalData(), next)); if (!removed) { throw new IllegalStateException(); } ((TileImpl) nextTile).setInternalData(newNextDist); ((ChokePointImpl) next).setPathBackTrace(current); toVisit.offer(new Pair<>(newNextDist, next)); } } else { ((TileImpl) nextTile).setInternalData(newNextDist); ((ChokePointImpl) next).setPathBackTrace(current); toVisit.offer(new Pair<>(newNextDist, next)); } } } } } } // // bwem_assert(!remainingTargets); // if (!(remainingTargets == 0)) { // throw new IllegalStateException(); // } // reset Tile::m_internalData for future usage for (Pair<Integer, ChokePoint> distanceToChokePoint : toVisit) { ((TileImpl) getMap().getData().getTile(distanceToChokePoint.second.getCenter().toTilePosition(), CheckMode.NO_CHECK)).setInternalData(0); } return distances; }
From source file:de.uni_koblenz.jgralab.utilities.rsa.Rsa2Tg.java
/** * @param containingGEC/*from w ww . ja v a 2s. c o m*/ * @param containedGEC * @param workingList * {@link Queue} which contains all elements which are nesting * some element but are not nested in any element */ private void insertContainingGECIntoWorkingList(GraphElementClass containingGEC, GraphElementClass containedGEC, Queue<GraphElementClass> workingList) { if (workingList.contains(containedGEC)) { workingList.remove(containedGEC); } if (!workingList.contains(containingGEC)) { workingList.add(containingGEC); } }
From source file:de.uni_koblenz.jgralab.utilities.rsa.Rsa2Tg.java
/** * /*from w ww . j av a 2 s . c om*/ */ private void createMayBeNestedIn() { System.out.println("Create MayBeNestedIn relations ..."); updateNestedElements(); // stores the GraphElementClass which have nested elements but are not // nested in another GraphElementClass Queue<GraphElementClass> workingList = new LinkedList<GraphElementClass>(); Queue<GraphElementClass> topLevelNestingElements = new LinkedList<GraphElementClass>(); // all edges have to be treated for (EdgeClass ec : sg.getEdgeClassVertices()) { workingList.add(ec); topLevelNestingElements.add(ec); } // create the explicitly modeled MayBeNestedIn edges for (GraphElement<?, ?, ?, ?> ge : nestedElements.getMarkedElements()) { GraphElementClass containingGEC = (GraphElementClass) ge; assert nestedElements.getMark(containingGEC) != null; assert !nestedElements.getMark(containingGEC).isEmpty(); for (GraphElementClass containedGEC : nestedElements.getMark(containingGEC)) { sg.createMayBeNestedIn(containedGEC, containingGEC); insertContainingGECIntoWorkingList(containingGEC, containedGEC, topLevelNestingElements); } } checkAcyclicityOfMayBeNestedIn(topLevelNestingElements); // check correctness of explicit modeled MayBeNestedIn edges and create // implicit MayBeNestedIn edges during a breadth first search over the // GraphElementClasses participating in the MayBeNestedIn tree LocalBooleanGraphMarker isImplicitlyNested = new LocalBooleanGraphMarker(sg); while (!workingList.isEmpty()) { GraphElementClass current = workingList.poll(); assert current != null; if (EdgeClass.class.isInstance(current)) { EdgeClass containedEC = (EdgeClass) current; // check constraints for explicitly nested EdgeClasses for (MayBeNestedIn_nestedElement i : containedEC.getIncidences(MayBeNestedIn_nestedElement.class)) { if (!isImplicitlyNested.isMarked(i.getEdge())) { GraphElementClass containingGEC = (GraphElementClass) i.getThat(); checkNestingConstraints(containedEC, containingGEC); } } // create implicit MayBeNestedIn edges for (GraphElementClass containingGEC : getAllNestingElements(containedEC)) { isImplicitlyNested.mark(sg.createMayBeNestedIn(containedEC, containingGEC)); if (topLevelNestingElements.contains(containedEC)) { topLevelNestingElements.remove(containedEC); } } } // insert all nested GraphElementClasses into workingList for (MayBeNestedIn_nestingElement i : current.getIncidences(MayBeNestedIn_nestingElement.class)) { if (!workingList.contains(i.getThat()) && !isImplicitlyNested.isMarked(i.getEdge())) { workingList.add((GraphElementClass) i.getThat()); } } } deleteDuplicateMayBeNestedIn(); checkAcyclicityOfMayBeNestedIn(topLevelNestingElements); }