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


Java PriorityQueue.offer方法代码示例

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


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

示例1: computeRelaxation

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * 
 * @param arc
 * @param paths
 * @param distances
 * @param queue
 */
private void computeRelaxation(Arc arc, Map<Node, ResidualArc> paths,
        Map<Node, Integer> distances, PriorityQueue<Node> queue) {
    Node srcNode = arc.getSourceNode();
    Node destNode = arc.getDestinationNode();
    int sd = distances.get(srcNode);
    int dd = distances.get(destNode);
    int cost = arc.getCost();

    if (dd > sd + cost) {
        distances.put(destNode, sd + cost);
        paths.put(destNode, (ResidualArc) arc);

        // There can be multiple instance of the same node in the queue.
        // This is the only way to update the queue.
        queue.offer(destNode);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:MinimumBendOrthogonalizer.java

示例2: main

import java.util.PriorityQueue; //导入方法依赖的package包/类
public static void main(String[] args) 
{
   // queue of capacity 11
   PriorityQueue<Double> queue = new PriorityQueue<>();

   // insert elements to queue
   queue.offer(3.2);
   queue.offer(9.8);
   queue.offer(5.4);

   System.out.print("Polling from queue: ");

   // display elements in queue
   while (queue.size() > 0)
   {
      System.out.printf("%.1f ", queue.peek()); // view top element
      queue.poll(); // remove top element
   } 
}
 
开发者ID:cleitonferreira,项目名称:LivroJavaComoProgramar10Edicao,代码行数:20,代码来源:PriorityQueueTest.java

示例3: testInQueue

import java.util.PriorityQueue; //导入方法依赖的package包/类
@Test
public void testInQueue() {
    PriorityQueue<ExponentialBackoff> queue = new PriorityQueue<>();
    ExponentialBackoff backoff1 = new ExponentialBackoff(params);
    backoff.trackFailure();
    backoff.trackFailure();
    backoff1.trackFailure();
    backoff1.trackFailure();
    backoff1.trackFailure();
    queue.offer(backoff);
    queue.offer(backoff1);

    assertEquals(queue.poll(), backoff); // The one with soonest retry time
    assertEquals(queue.peek(), backoff1);

    queue.offer(backoff);
    assertEquals(queue.poll(), backoff); // Still the same one
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:19,代码来源:ExponentialBackoffTest.java

示例4: main

import java.util.PriorityQueue; //导入方法依赖的package包/类
public static void main(String[] args) {
    
    PriorityQueue<Integer> pq = new PriorityQueue<>();
    
    // offer (add) some element
    pq.offer(3);
    pq.offer(2);
    pq.offer(4);
    System.out.println("Offer Some Element, autosort. Content: " + pq.toString());
            
    // add
    pq.add(1);        
    pq.add(5);
    pq.add(2);
    System.out.println("Add some element, autosort. Content: "+pq.toString());
    
    // peek head element
    System.out.println("Peek is " + pq.peek());
    
    // poll head element
    System.out.println("Poll is " + pq.poll()+", content: " + pq.toString());                        
}
 
开发者ID:mkdika,项目名称:learnjava8,代码行数:23,代码来源:TestPriorityQueue.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 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

示例6: updateProxyPool

import java.util.PriorityQueue; //导入方法依赖的package包/类
public void updateProxyPool() {
    PriorityQueue<HttpProxy> temp = new PriorityQueue<>(poolSize);
    addressSet.clear();
    while (proxies.size() > updateThreshold) {
        addressSet.add(proxies.peek().address);
        temp.offer(proxies.poll());
    }
    proxies.clear();
    proxies = temp;
    this.fill(HttpProxyCollector.getProxyIps(strategy, (poolSize - temp.size()) * 2));
}
 
开发者ID:ZhangJiupeng,项目名称:Gospy,代码行数:12,代码来源:HttpProxyManager.java

示例7: getSortedTimestamps

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Gets the sorted timestamps of any buffered events.
 *
 * @return a sorted list of timestamps that have at least one buffered event.
 */
private PriorityQueue<Long> getSortedTimestamps() throws Exception {
    PriorityQueue<Long> sortedTimestamps = new PriorityQueue<>();
    for (Long timestamp : elementQueueState.keys()) {
        sortedTimestamps.offer(timestamp);
    }
    return sortedTimestamps;
}
 
开发者ID:pravega,项目名称:flink-connectors,代码行数:13,代码来源:EventTimeOrderingOperator.java

示例8: add

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Add this candidate to the open map+queue.
 *
 * @param openMap The list of available nodes.
 * @param openMapQueue The queue of available nodes.
 * @param cost The provisional cost for the path.
 * @param sh A {@code SearchHeuristic} to apply.
 */
public void add(HashMap<String, PathNode> openMap,
                PriorityQueue<PathNode> openMapQueue,
                HashMap<String, Integer> f,
                SearchHeuristic sh) {
    int fcost = this.cost;
    if (this.dst.getTile() != null) {
        fcost += sh.getValue(this.dst.getTile());
    }
    f.put(this.dst.getId(), fcost);
    PathNode path = new PathNode(this.dst, this.movesLeft, this.turns,
        this.onCarrier, this.current, null);
    openMap.put(this.dst.getId(), path);
    openMapQueue.offer(path);
}
 
开发者ID:FreeCol,项目名称:freecol,代码行数:23,代码来源:Map.java

示例9: nextGeneration

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Advances the current population to the next generation. All objects are cloned during
 * the process.
 */
@SuppressWarnings("unchecked")
public void nextGeneration() {
	PriorityQueue<T> newPopulation = new PriorityQueue<T>(getPopulationSize(), new FitnessComparator());

	//Take best n and copy into new population
	newPopulation.addAll(getTopN(config.getNumElite()));

	int fitnessSum = getFitnessSum();
	
	while (newPopulation.size() < config.getPopulationSize()) {
		T mommy = getWeightedOrganism(fitnessSum);
		T daddy = getWeightedOrganism(fitnessSum);
		
		T offspring = mommy;
		if (shouldCrossover()) {
			offspring = (T) mommy.breed(daddy);
		}
		
		if (shouldMutate()) {
			offspring = (T) offspring.mutate();
		}
		newPopulation.offer(offspring);
	}
	
	generation++;
	population = newPopulation;
}
 
开发者ID:ryantate314,项目名称:genetic-one-tough-puzzle-solver,代码行数:32,代码来源:Ecosystem.java

示例10: testOfferNull

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * offer(null) throws NPE
 */
public void testOfferNull() {
    PriorityQueue q = new PriorityQueue(1);
    try {
        q.offer(null);
        shouldThrow();
    } catch (NullPointerException success) {}
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:PriorityQueueTest.java

示例11: testOfferNonComparable

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Offer of non-Comparable throws CCE
 */
public void testOfferNonComparable() {
    PriorityQueue q = new PriorityQueue(1);
    try {
        q.offer(new Object());
        shouldThrow();
    } catch (ClassCastException success) {
        assertTrue(q.isEmpty());
        assertEquals(0, q.size());
        assertNull(q.poll());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源: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


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