当前位置: 首页>>代码示例>>Java>>正文


Java PriorityQueue.remove方法代码示例

本文整理汇总了Java中java.util.PriorityQueue.remove方法的典型用法代码示例。如果您正苦于以下问题:Java PriorityQueue.remove方法的具体用法?Java PriorityQueue.remove怎么用?Java PriorityQueue.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.PriorityQueue的用法示例。


在下文中一共展示了PriorityQueue.remove方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: improve

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Replace a given path with that of this candidate move.
 *
 * @param openMap The list of available nodes.
 * @param openMapQueue The queue of available nodes.
 * @param f The heuristic values for A*.
 * @param sh An optional {@code SearchHeuristic} to apply.
 */
public void improve(HashMap<String, PathNode> openMap,
    PriorityQueue<PathNode> openMapQueue,
    HashMap<String, Integer> f,
    SearchHeuristic sh) {
    PathNode best = openMap.get(dst.getId());
    if (best != null) {
        openMap.remove(dst.getId());
        openMapQueue.remove(best);
    }
    int fcost = cost;
    if (sh != null && dst.getTile() != null) {
        fcost += sh.getValue(dst.getTile());
    }
    f.put(dst.getId(), fcost);
    openMap.put(dst.getId(), path);
    openMapQueue.offer(path);
}
 
开发者ID:wintertime,项目名称:FreeCol,代码行数:26,代码来源:Map.java

示例2: getMostUnderservedQueues

import java.util.PriorityQueue; //导入方法依赖的package包/类
protected Collection<TempQueue> getMostUnderservedQueues(
    PriorityQueue<TempQueue> orderedByNeed, TQComparator tqComparator) {
  ArrayList<TempQueue> underserved = new ArrayList<TempQueue>();
  while (!orderedByNeed.isEmpty()) {
    TempQueue q1 = orderedByNeed.remove();
    underserved.add(q1);
    TempQueue q2 = orderedByNeed.peek();
    // q1's pct of guaranteed won't be larger than q2's. If it's less, then
    // return what has already been collected. Otherwise, q1's pct of
    // guaranteed == that of q2, so add q2 to underserved list during the
    // next pass.
    if (q2 == null || tqComparator.compare(q1,q2) < 0) {
      return underserved;
    }
  }
  return underserved;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:ProportionalCapacityPreemptionPolicy.java

示例3: testRetainAll

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * retainAll(c) retains only those elements of c and reports true if changed
 */
public void testRetainAll() {
    PriorityQueue q = populatedQueue(SIZE);
    PriorityQueue p = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        boolean changed = q.retainAll(p);
        if (i == 0)
            assertFalse(changed);
        else
            assertTrue(changed);

        assertTrue(q.containsAll(p));
        assertEquals(SIZE - i, q.size());
        p.remove();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:19,代码来源:PriorityQueueTest.java

示例4: main

import java.util.PriorityQueue; //导入方法依赖的package包/类
public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    
    /* Create PriorityQueue and add/remove entries */
    PriorityQueue<Student> pq = new PriorityQueue<>(n, new StudentComparator());
    while (n-- > 0) {
        String event = scan.next();
        switch (event) {
            case "ENTER":
                String fname = scan.next();
                double cgpa  = scan.nextDouble();
                int    token = scan.nextInt();
                pq.add(new Student(fname, cgpa, token));
                break;
            case "SERVED":
                pq.poll();
                break;
            default:
                break;
        } 
    }
    scan.close();
    
    /* Print Student names */
    if (pq.isEmpty()) {
        System.out.println("EMPTY");
    } else {
        while (!pq.isEmpty()) {
            Student s = pq.remove();
            System.out.println(s.getFname());
        }
    }
}
 
开发者ID:rshaghoulian,项目名称:HackerRank_solutions,代码行数:35,代码来源:Solution.java

示例5: improve

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Replace a given path with that of this candidate move.
 *
 * @param openMap The list of available nodes.
 * @param openMapQueue The queue of available nodes.
 * @param f The heuristic values for A*.
 * @param sh A {@code SearchHeuristic} to apply.
 */
public void improve(HashMap<String, PathNode> openMap,
                    PriorityQueue<PathNode> openMapQueue,
                    HashMap<String, Integer> f,
                    SearchHeuristic sh) {
    PathNode best = openMap.get(dst.getId());
    if (best != null) {
        openMap.remove(dst.getId());
        openMapQueue.remove(best);
    }
    add(openMap, openMapQueue, f, sh);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:20,代码来源:Map.java

示例6: onTimer

import java.util.PriorityQueue; //导入方法依赖的package包/类
@Override
public void onTimer(long timestamp, OnTimerContext context,
    Collector<Tuple3<String, Long, String>> out) throws Exception {
  PriorityQueue<Tuple3<String, Long, String>> queue = queueState.value();
  Long watermark = context.timerService().currentWatermark();

  Tuple3<String, Long, String> head = queue.peek();
  boolean emitAll = queue.size() > MAX_NUMBER_OF_QUEUED_ELEMENTS;

  while (head != null && (head.f1 <= watermark || emitAll)) {
    out.collect(head);
    queue.remove(head);
    head = queue.peek();
  }
}
 
开发者ID:ehabqadah,项目名称:in-situ-processing-datAcron,代码行数:16,代码来源:RawMessagesSorter.java

示例7: removeSameNeighborWithLowerRank

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * At this point, pq contains x and maybe 1 more element y with the same key as x. If y exists, keep from those two the one with the better value. 
 * If y does not exist, keep x. 
 * @param pq
 * @param x
 * @return 
 */
private PriorityQueue<ComparableIntFloatPair> removeSameNeighborWithLowerRank(PriorityQueue<ComparableIntFloatPair> pq, ComparableIntFloatPair x) {
    int neighborIdToAdd = x.getEntityId();
    double newValue = x.getValue();
    ComparableIntFloatPair elementToDelete = null;
    boolean sameRankTwice = false;
    for (ComparableIntFloatPair qElement : pq) { //traverses the queue in random order
        if (qElement.getEntityId() == neighborIdToAdd) {
            if (qElement.getValue() > newValue) { //y is worse than x => delete y
                elementToDelete = qElement;
                break;
            } else if (qElement.getValue() < newValue) { //y is better than x => delete x
                elementToDelete = x;
                break;
            } else {  //qElement has the same value as x
                if (!sameRankTwice) { //first time meeting this element (it can be x or a y with the same rank)
                    sameRankTwice = true; 
                } else{               //second time meeting this element (x and y are equivalent => delete one of them)
                    elementToDelete = x;
                    break;
                }
            }
        }
    }
    if (elementToDelete != null) {
        pq.remove(elementToDelete);
    }
    return pq;
}
 
开发者ID:vefthym,项目名称:MinoanER,代码行数:36,代码来源:RelationsRank.java

示例8: removeSamePairWithLowerValue

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * At this point, pq contains x and maybe 1 more element y with the same key as x. If y exists, keep from those two the one with the better value. 
 * If y does not exist, keep x. 
 * @param pq
 * @param x
 * @return 
 */
private PriorityQueue<ComparableIntFloatPair> removeSamePairWithLowerValue(PriorityQueue<ComparableIntFloatPair> pq, ComparableIntFloatPair x) {
    int entityIdToAdd = x.getEntityId();
    float newValue = x.getValue();
    ComparableIntFloatPair elementToDelete = null;
    boolean sameValueTwice = false;
    for (ComparableIntFloatPair qElement : pq) { //traverses the queue in random order
        if (qElement.getEntityId() == entityIdToAdd) {
            if (qElement.getValue() < newValue) { //y is worse than x => delete y
                elementToDelete = qElement;
                break;
            } else if (qElement.getValue() > newValue) { //y is better than x => delete x
                elementToDelete = x;
                break;
            } else {  //qElement has the same value as x (or is x)
                if (!sameValueTwice) { //first time meeting this element (it can be x or a y with the same rank)
                    sameValueTwice = true; 
                } else{               //second time meeting this element (x and y are equivalent => delete one of them)
                    elementToDelete = x;
                    break;
                }
            }
        }
    }
    if (elementToDelete != null) {
        pq.remove(elementToDelete);
    }
    return pq;
}
 
开发者ID:vefthym,项目名称:MinoanER,代码行数:36,代码来源:CNPNeighbors.java

示例9: testEmpty

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * isEmpty is true before add, false after
 */
public void testEmpty() {
    PriorityQueue q = new PriorityQueue(2);
    assertTrue(q.isEmpty());
    q.add(new Integer(1));
    assertFalse(q.isEmpty());
    q.add(new Integer(2));
    q.remove();
    q.remove();
    assertTrue(q.isEmpty());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:PriorityQueueTest.java

示例10: testRemove

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * remove removes next element, or throws NSEE if empty
 */
public void testRemove() {
    PriorityQueue q = populatedQueue(SIZE);
    for (int i = 0; i < SIZE; ++i) {
        assertEquals(i, q.remove());
    }
    try {
        q.remove();
        shouldThrow();
    } catch (NoSuchElementException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:PriorityQueueTest.java

示例11: testRemoveAll

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * removeAll(c) removes only those elements of c and reports true if changed
 */
public void testRemoveAll() {
    for (int i = 1; i < SIZE; ++i) {
        PriorityQueue q = populatedQueue(SIZE);
        PriorityQueue p = populatedQueue(i);
        assertTrue(q.removeAll(p));
        assertEquals(SIZE - i, q.size());
        for (int j = 0; j < i; ++j) {
            Integer x = (Integer)(p.remove());
            assertFalse(q.contains(x));
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:PriorityQueueTest.java

示例12: computeCOF

import java.util.PriorityQueue; //导入方法依赖的package包/类
public void computeCOF(ArrayList<COFObject> cofobjectList, int k, DistanceMeasure measure) {

		// define a list of knn for each cof object
		PriorityQueue<COFKnn> knnList = new PriorityQueue<COFKnn>();

		// reset pcl, kDist, and deviation
		double pcl = 0.0;
		double kDist = 0.0;
		double deviation = 0.0;

		for (COFObject cofobject : cofobjectList) {// for all objects in the dataset
			double distance = Double.POSITIVE_INFINITY;
			// compute the distance to current object
			distance = measure.calculateDistance(this.getValues(), cofobject.getValues());
			COFKnn cOFKnn = new COFKnn(cofobject, distance);
			// determine if cofobject is on of the nearest neighbors to current object
			if (knnList.size() < k) {
				knnList.offer(cOFKnn);
			} else if (distance < knnList.peek().getDistance()) {
				knnList.remove();
				knnList.offer(cOFKnn);
			}
			// if the cofobject has the same class label, add its distance to deviation
			if (this.getLabel() == cofobject.getLabel()) {
				deviation += distance;
			}

		}
		this.setDeviation(deviation); // save deviation

		// compute pcl to current object
		for (COFKnn cofKnn : knnList) {
			kDist += measure.calculateDistance(getValues(), cofKnn.getCofobject().getValues());
			if (this.getLabel() == cofKnn.getCofobject().getLabel()) {
				pcl++;
			}
		}

		this.setPcl(pcl); // save pcl
		this.setCOF(pcl); // save the initial cof based on pcl
		this.setKDist(kDist); // save kDist

	}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:44,代码来源:COFObject.java

示例13: computePaths

import java.util.PriorityQueue; //导入方法依赖的package包/类
private ConditionVertex computePaths()
{
	System.out.println("  -----------------------");
	System.out.println("  COMPUTEPATHS IS INVOKED");
	
	//the nodes are stored in a Priorityqueue, so that the node with the least
	//distance is extracted everytime the poll function is called
	PriorityQueue<ConditionVertex> openSet = new PriorityQueue<ConditionVertex>();

	//adding the source node to the PriorityQueue
	this.source.distance = 0;
	openSet.add(this.source);
	System.out.println("  openset initialized with: " + openSet);
	System.out.println("  now entering operationsloop");

	int operations=0;
	while (!abort.get() && !openSet.isEmpty() && operations < OPERATIONCOUNT_THRESHOLD) 	//TODO: as long as this is not threaded... we will have a maximum search complexity.
	{
		System.out.println("    iteration " + operations);
		ConditionVertex u = openSet.poll();
		System.out.println("    poll returned: " + u);
		// if conditions are fulfilled return the respective node
		if (checkConditions(u.scene.getPlanningPlayer().getMapPosition(0), u.effects) && Math.exp(-u.distance) > 0.01)
		{
			System.out.println("    iterationloop terminates");
			System.out.println("  EXPANDNODE RETURNS: " + u);
			System.out.println("  --------------------");
			return u;
		}
		// if conditions are not fulfilled, the node is expanded
		System.out.println("    expanding u with: " + goal);
		System.out.println("    adjacencies before: " +u.adjacencies.size());
		u.expandNode(goal);
		System.out.println("    adjacenceis after: " + u.adjacencies.size());
		System.out.println("    now entering adjacencies loop");
		for (ProbabilityEdge e : u.adjacencies){
			operations++;
			
			ConditionVertex v = e.target;
			double eventDistance = e.weight;
			System.out.print("WEIGHT =" + e.weight);
			System.out.print(" V DISTANCE =" + v.distance);
			System.out.print(" U DISTANCE =" + u.distance);
			System.out.println(" ");
			double newDistanceToV = u.distance + eventDistance - DEPTH_COST_BIAS;		
			
			// check if new likelihood is greater
			if (newDistanceToV < v.distance)
			{						
				openSet.remove(v);
				v.distance = newDistanceToV;
				v.prev = u;
				openSet.add(v);
			}
		}			
	}
	
	System.out.println(operations + " EFFECT CHAINING OPERATIONS PERFORMED (NOT FOUND)!");

	// return null if no possible goal node is reachable
	return null;
}
 
开发者ID:CognitiveModeling,项目名称:BrainControl,代码行数:63,代码来源:EffectChaining.java

示例14: buildTree

import java.util.PriorityQueue; //导入方法依赖的package包/类
public Node buildTree() {
	// sort the triples before adding them
	//this.sortTriples();    	
	
	PriorityQueue<Node> nodesQueue = getNodesQueue();
	
	Node tree = nodesQueue.poll();
	
	// set the root node with the variables that need to be projected
	ArrayList<String> projectionList = new ArrayList<String>();
	for(int i = 0; i < variables.size(); i++)
		projectionList.add(variables.get(i).getVarName());
	tree.setProjectionList(projectionList);
	
	// visit the hypergraph to build the tree
	Node currentNode = tree;
	ArrayDeque<Node> visitableNodes = new ArrayDeque<Node>();
	while(!nodesQueue.isEmpty()){
		
		int limitWidth = 0;
		// if a limit not set, a heuristic decides the width 
		if(treeWidth == -1){
	    	treeWidth = heuristicWidth(currentNode); 
		}
		
		Node newNode =  findRelateNode(currentNode, nodesQueue);
		
		// there are nodes that are impossible to join with the current tree width
		if (newNode == null && visitableNodes.isEmpty()) {
			// set the limit to infinite and execute again
			treeWidth = Integer.MAX_VALUE;
			return buildTree();
		}
		
		// add every possible children (wide tree) or limit to a custom width
		// stop if a width limit exists and is reached
		while(newNode != null && !(treeWidth > 0 && limitWidth == treeWidth)){
			
			// append it to the current node and to the queue
			currentNode.addChildren(newNode);
			
			// visit again the new child
			visitableNodes.add(newNode);
			
			// remove consumed node and look for another one
			nodesQueue.remove(newNode);
			newNode = findRelateNode(currentNode, nodesQueue);
			
			limitWidth++;
		}
		
		// next Node is one of the children
		if(!visitableNodes.isEmpty() && !nodesQueue.isEmpty()){
			currentNode = visitableNodes.pop();
			
		}
	}
	
	return tree;
}
 
开发者ID:tf-dbis-uni-freiburg,项目名称:PRoST,代码行数:61,代码来源:Translator.java

示例15: searchPath

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * the algorithm used to search a path between initial point and goal point, it is based on A* algorithm
 * @return: true, if the path is found, otherwise false 
 */
private static boolean searchPath(Junction init1, Junction init2, Junction goal) {
    // comparator to order junction in the Priority Queue
    Comparator<Junction> junctionComparator = new Comparator<Junction>(){
        @Override
        public int compare(Junction junction1, Junction junction2){
            if (junction1.cost> junction2.cost){return 1;}
            else if (junction1.cost< junction2.cost){return -1;} 
            return 0;
        }       
    };
    PriorityQueue<Junction> queue = new PriorityQueue<Junction>(junctionComparator); // priority queue
    HashSet<Junction> found = new HashSet<Junction>(); // store all found junctions
    
    // add the two initial points
    queue.add(init1);
    queue.add(init2);
    found.add(init1);
    found.add(init2);
    while (!queue.isEmpty() && !queue.peek().equals(goal)) {
        // remove the first element in the priority queue
        Junction temp = queue.poll();
        // add all neighbors of the first element to the queue
        for (Junction j: temp.neighbor.keySet()) {
            float newCost = temp.cost + temp.neighbor.get(j).length;
            if (!found.contains(j)) {
                j.predecessor = temp;
                j.cost = newCost;
                found.add(j);
                queue.add(j);
            } else if (j.cost > newCost) {
                // set new predecessor and cost
                j.predecessor = temp;
                j.cost = newCost;
                if (queue.remove(j)) {
                    // if it is contained in the queue, update it
                    queue.add(j);
                }
            }
        }
    }
    // return whether the path is found
    if (queue.isEmpty()) {
        return false;
    } else {
        return true;
    }
}
 
开发者ID:moment-of-peace,项目名称:AI-uniform-cost-search,代码行数:52,代码来源:MyNavigator.java


注:本文中的java.util.PriorityQueue.remove方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。