List of usage examples for java.util PriorityQueue peek
public E peek()
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;/* ww w . j a va2 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); }