List of usage examples for java.util PriorityQueue PriorityQueue
public PriorityQueue()
From source file:exploration.rendezvous.MultiPointRendezvousStrategy.java
/** * This method finds a point among connectionsToBase (that is in comm range of Base Station) * that is closest to origPoint. That is, it's an estimate of the shortest distance we need to * travel from origPoint to get into comm range of the Base station * * @param origPoint//ww w .j a v a2s. com * @param connectionsToBase * @param ag * @return */ public static int findNearestPointInBaseCommRange(NearRVPoint origPoint, List<CommLink> connectionsToBase, RealAgent ag) { int pathsCalculated = 0; // only calculate nearest base point for connectedPoint if we haven't already. if (origPoint.distanceToParent == Double.MAX_VALUE) { PriorityQueue<NearRVPoint> lineOfSightBasePoints = new PriorityQueue<NearRVPoint>(); PriorityQueue<NearRVPoint> nonLOSBasePoints = new PriorityQueue<NearRVPoint>(); for (CommLink baseLink : connectionsToBase) { NearRVPoint basePoint = new NearRVPoint(baseLink.getRemotePoint().x, baseLink.getRemotePoint().y); double approxPathLen = basePoint.distance(origPoint); basePoint.setDistanceToFrontier(approxPathLen); if (baseLink.numObstacles == 0) { lineOfSightBasePoints.add(basePoint); } else { nonLOSBasePoints.add(basePoint); } } LinkedList<NearRVPoint> pointsConnectedToBase = new LinkedList<NearRVPoint>(); for (int j = 0; (j < 5) && !lineOfSightBasePoints.isEmpty(); j++) { pointsConnectedToBase.add(lineOfSightBasePoints.poll()); } for (int j = 0; (j < 20) && !nonLOSBasePoints.isEmpty(); j++) { pointsConnectedToBase.add(nonLOSBasePoints.poll()); } for (NearRVPoint basePoint : pointsConnectedToBase) { pathsCalculated++; Path pathToBase = ag.calculatePath(origPoint, basePoint, false, false); double pathLen = Double.MAX_VALUE; if (pathToBase.found) { pathLen = pathToBase.getLength(); } if (pathLen < origPoint.distanceToParent) { origPoint.distanceToParent = pathLen; origPoint.parentPoint = basePoint; } } } return pathsCalculated; }
From source file:org.jiemamy.utils.collection.CollectionsUtil.java
/** * {@link PriorityQueue}?????//from ww w .java 2s . com * * @param <E> {@link PriorityQueue}?? * @return {@link PriorityQueue}??? * @see PriorityQueue#PriorityQueue() */ public static <E> PriorityQueue<E> newPriorityQueue() { return new PriorityQueue<E>(); }
From source file:exploration.rendezvous.MultiPointRendezvousStrategy.java
private void calculateRendezvousRandomSampling(int timeElapsed) { RendezvousAgentData rvd = agent.getRendezvousAgentData(); // Only calculate rv every several time steps at most if (rvd.getTimeSinceLastRVCalc() < SimConstants.RV_REPLAN_INTERVAL) { return;/* w ww.j av a 2 s . c o m*/ } else { rvd.setTimeSinceLastRVCalc(0); } TeammateAgent relay = agent.getParentTeammate(); generatedPoints = SampleEnvironmentPoints(agent, settings.SamplePointDensity); connectionsToBase = FindCommLinks(generatedPoints, agent); PriorityQueue<NearRVPoint> pointsNearFrontier = GetPointsWithinDistOfFrontier(generatedPoints, 100); int pathsCalculated = 0; //Now for top K points, let's calculate p' distances to base, and find the nearest point connected to base PriorityQueue<NearRVPoint> pointsNearFrontierReal = new PriorityQueue<NearRVPoint>(); for (int k = 0; (k < 50) && !pointsNearFrontier.isEmpty(); k++) { NearRVPoint p = pointsNearFrontier.poll(); double minDistToBase = Double.MAX_VALUE; for (CommLink link : p.commLinks) { NearRVPoint connectedPoint = link.getRemotePoint(); pathsCalculated = findNearestPointInBaseCommRange(connectedPoint, connectionsToBase, agent); if (connectedPoint.distanceToParent < minDistToBase) { minDistToBase = connectedPoint.distanceToParent; p.commLinkClosestToBase = link; } } //At this point, for p, we know: // 1. Connected point p' that is nearest to comm range of Base // 2. Distance from p' to comm range of Base // 3. Nearest point from p' that is within comm range of Base //So we know how long each point p will have to wait for relay, and so can estimate //where explorer will be at the time, to calculate regret accurately. //For now, just calculate accurate distance to next frontier: Path pathToFrontier = agent.calculatePath(p, getExplorerFrontier(), false, false); double distToFrontier = Double.MAX_VALUE; if (pathToFrontier.found) { distToFrontier = pathToFrontier.getLength(); } pathsCalculated++; p.setDistanceToFrontier(distToFrontier); if (p.commLinkClosestToBase == null || p.commLinkClosestToBase.getRemotePoint() == null) { //something went wrong, set RV to our current location and return Rendezvous meetingLocation = new Rendezvous(agent.getLocation()); Point baseLocation = agent.getTeammate(agent.getParentTeammate().getParent()).getLocation(); meetingLocation.parentsRVLocation = new Rendezvous(baseLocation); rvd.setParentRendezvous(meetingLocation); calculateRVTimings(timeElapsed); return; } p.utility = NearRVPoint.getFullRVUtility(p.distanceToFrontier, p.commLinkClosestToBase.getRemotePoint().distanceToParent, p.commLinkClosestToBase.numObstacles); pointsNearFrontierReal.add(p); } //Now just need to retrieve the best point NearRVPoint childPoint = pointsNearFrontierReal.peek(); NearRVPoint parentPoint = childPoint.commLinkClosestToBase.getRemotePoint(); Rendezvous meetingLocation = new Rendezvous(childPoint); meetingLocation.setParentLocation(parentPoint); Rendezvous parentsMeetingLocation = new Rendezvous(parentPoint.parentPoint); Point baseLocation = agent.getTeammate(agent.getParentTeammate().getParent()).getLocation(); parentsMeetingLocation .setParentLocation(agent.getTeammate(agent.getParentTeammate().getParent()).getLocation()); meetingLocation.parentsRVLocation = parentsMeetingLocation; rvd.setParentRendezvous(meetingLocation); Rendezvous backupRV = new Rendezvous(childPoint); rvd.setParentBackupRendezvous(backupRV); calculateRVTimings(timeElapsed); displayData.setGeneratedPoints(generatedPoints); displayData.setPointsNearFrontier(pointsNearFrontier); }