Beispiel #1
0
		/**
		 * Add a new element to the 'best candidate set' - if it qualifies. 
		 * I.e., the distance is lower than the current worst candidate
		 * NOTE: Currently, this is hardcoded to distance, i.e., to be used with NNS
		 * @param v Vertex to be inserted if the distance parameter is lower than the current worst element in the BCS.
		 * @param distance The (NNS) distance of the vertex which determines whether v will be inserted in the BCS. 
		 */
		public bool add(Vertex v, double distance)
		{
			if (locations.Count >= maxSize && distance > locations.Keys.Last())
			{
				return false; //is not better than the worst element
			}
			else //insert order: From best (lowest NNS distance) to worst (highest NNS distance). 
			{
				//'hack' in case of duplicate values
				while (locations.ContainsKey(distance))
					distance += 0.0001;

				//Impl. note: Check for emptiness first as lastKey() will throw NoSuchElement if empty.
				//if (locations.isEmpty() || distance < locations.lastKey())
				locations.Add(distance, v);

				if (locations.Count > maxSize)
					locations.Remove(locations.Last().Key);

			}
			return true;
		}
 public void setVertex(Vertex v)
 {
     this.mVertex = v;
 }
        public EstimateResult getEstimate(SnifferWifiMeasurement currentMeasurement)
        {
            //Check ready state
            if (mCurrentBuilding == null)
                return null;

            //Maintain primary and secondary search space
            //Cf OfflineClientPocketPCUF
            if (secondarySearchSpace == null)
            {
                secondarySearchSpace = mCurrentBuilding.Vertices; // mGraph.getVertices();
            }
            EstimateResult primaryEstimate = new EstimateResult(null, Double.MaxValue);
            EstimateResult secondaryEstimate = new EstimateResult(null, Double.MaxValue);

            BestCandidateSet = new BCS(5); //candidates are added in the compare methods below

            //measurement is compared with primary search space (adjacent vertices to previous estimated vertex)
            //and secondary search space (non-connected nodes or the full graph)
            if (prevBestEstimateVertex != null)
            {
                primaryEstimate = mPosAlgorithm.compare(prevBestEstimateVertex.adjacentVertices(), currentMeasurement);
            }
            secondaryEstimate = mPosAlgorithm.compare(secondarySearchSpace, currentMeasurement);

            //Changed to accomodate hyper, where we return null if online meas only has one mac
            //Vertex best = null;
            EstimateResult bestEstimate = null;
            if (primaryEstimate != null)
                bestEstimate = primaryEstimate;
            if (secondaryEstimate != null)
            {
                //The primary estimate may be overriden by a secondary if it is better for the second time in a row
                if (secondaryEstimate.getDistance() < primaryEstimate.getDistance())
                {
                    numSecondaryBest++;
                    if (numSecondaryBest >= 2 || prevBestEstimateVertex == null)
                    {
                        numSecondaryBest = 0;
                        bestEstimate = secondaryEstimate; //.getVertex();
                    }
                }
                else
                {
                    numSecondaryBest = 0;
                }
            }
            prevBestEstimateVertex = bestEstimate.getVertex();

            //Currently, the error estimate is also calculated in the compare methods, 
            //but we override that logic here since this implementation considers the global 
            //candidates - not just the local primary- or secondary candidates. 
            //We throw in an extra 5 meters to account for movement
            double error = Math.Ceiling(BestCandidateSet.getMaxDistance()); //  + 5;
            bestEstimate.setErrorEstimate(error);

            return bestEstimate;
        }
 public EstimateResult(Vertex v, double distance)
 {
     this.mVertex = v;
     this.mDistance = distance;
 }