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


Java PriorityQueue.size方法代码示例

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


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

示例1: 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

示例2: getTopN

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Get top N elements
 *
 * @param vec the vec to extract the top elements from
 * @param N the number of elements to extract
 * @return the indices and the sorted top N elements
 */
private List<Double> getTopN(INDArray vec, int N) {
  BasicModelUtils.ArrayComparator comparator = new BasicModelUtils.ArrayComparator();
  PriorityQueue<Double[]> queue = new PriorityQueue<>(vec.rows(), comparator);

  for (int j = 0; j < vec.length(); j++) {
    final Double[] pair = new Double[] {vec.getDouble(j), (double) j};
    if (queue.size() < N) {
      queue.add(pair);
    } else {
      Double[] head = queue.peek();
      if (comparator.compare(pair, head) > 0) {
        queue.poll();
        queue.add(pair);
      }
    }
  }

  List<Double> lowToHighSimLst = new ArrayList<>();

  while (!queue.isEmpty()) {
    double ind = queue.poll()[1];
    lowToHighSimLst.add(ind);
  }
  return Lists.reverse(lowToHighSimLst);
}
 
开发者ID:tteofili,项目名称:par2hier,代码行数:33,代码来源:Par2Hier.java

示例3: test1

import java.util.PriorityQueue; //导入方法依赖的package包/类
@Test public void test1() {
  int[] a = new int[]{1000,900,8,7,3,2,1,90000};
  int n=5;
  PriorityQueue<Integer> q = new PriorityQueue<>(n, new Comparator<Integer>() {
    @Override public int compare(Integer o1, Integer o2) {
      return o2-o1;
    }
  });

  for(int i: a) {
    if( q.size() < n ) q.add(i);
    else {
      if( i < q.peek() ) {
        q.poll();
        q.add(i);
      }
    }
  }

  while(!q.isEmpty()) {
    System.out.println(q.poll());
  }
}
 
开发者ID:spennihana,项目名称:FasterWordEmbeddings,代码行数:24,代码来源:TopNTest.java

示例4: CalculateBaseLine

import java.util.PriorityQueue; //导入方法依赖的package包/类
private void CalculateBaseLine() {
    _baseLine = 0f;
    PriorityQueue<Float> IntensityQueue = new PriorityQueue<>();
    for (XYData point : SmoothData.Data) {
        IntensityQueue.add(point.getY());
    }

    if (IntensityQueue.size() > 10) {
        for (int i = 0; i < IntensityQueue.size() / 10; i++) {
            _baseLine += IntensityQueue.poll();
        }
        _baseLine /= (IntensityQueue.size() / 10);
    } else {
        _baseLine = IntensityQueue.poll();
    }
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:17,代码来源:PeakCurve.java

示例5: doLogistics

import java.util.PriorityQueue; //导入方法依赖的package包/类
private boolean doLogistics() {
    ItemStack item = drone.getInv().getStackInSlot(0);
    FluidStack fluid = drone.getTank().getFluid();
    PriorityQueue<LogisticsTask> tasks = manager.getTasks(item.isEmpty() ? fluid : item);
    if (tasks.size() > 0) {
        curTask = tasks.poll();
        return execute(curTask);
    }
    return false;
}
 
开发者ID:TeamPneumatic,项目名称:pnc-repressurized,代码行数:11,代码来源:DroneAILogistics.java

示例6: 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

示例7: 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

示例8: onTimer

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

  AisMessage head = queue.peek();
  boolean emitAll = queue.size() > MAX_NUMBER_OF_QUEUED_ELEMENTS;

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

示例9: toIntArrayListReversed

import java.util.PriorityQueue; //导入方法依赖的package包/类
/**
 * Used in cases where a priority queue has been used to keep top K elements, and then its results are needed in descending order, 
 * in the form of an IntArrayList. The size of the results is equal to the size of the input.
 * @param <T> any subclass of ComparableIntFloatPair
 * @param pq
 * @return 
 */
public static <T extends ComparableIntFloatPair> IntArrayList toIntArrayListReversed(PriorityQueue<T> pq) {
    int i = pq.size();   
    int[] candidates = new int[i]; 
    while (!pq.isEmpty()) {
        T cand = pq.poll();
        candidates[--i] = cand.getEntityId(); //get pq elements in reverse order
    }
    return new IntArrayList(candidates);
}
 
开发者ID:vefthym,项目名称:MinoanER,代码行数:17,代码来源:Utils.java

示例10: main

import java.util.PriorityQueue; //导入方法依赖的package包/类
@SuppressWarnings("Duplicates")
public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    PriorityQueue<Integer> minHeap = new PriorityQueue<>(10, Collections.reverseOrder());
    PriorityQueue<Integer> maxHeap = new PriorityQueue<>(10);

    int n = scanner.nextInt();

    for (int i = 0; i < n; i++) {
        int num = scanner.nextInt();

        if (minHeap.size() <= maxHeap.size()) {
            minHeap.add(num);
        } else {
            maxHeap.add(num);
        }

        while (!minHeap.isEmpty() && !maxHeap.isEmpty() && minHeap.peek() > maxHeap.peek()) {
            int min = minHeap.poll();
            int max = maxHeap.poll();

            minHeap.add(max);
            maxHeap.add(min);
        }

        double median = (minHeap.size() == maxHeap.size() ? ((minHeap.peek() + maxHeap.peek()) / 2.0) : minHeap.peek());

        System.out.println(median);
    }
}
 
开发者ID:viatsko,项目名称:hack,代码行数:32,代码来源:HeapsFindTheRunningMedian.java

示例11: flatten

import java.util.PriorityQueue; //导入方法依赖的package包/类
public ClusterModel flatten(HierarchicalClusterModel model, ExampleSet exampleSet) throws OperatorException {
	HierarchicalClusterNode root = model.getRootNode();
	int numberOfClusters = getParameterAsInt(PARAMETER_NUMBER_OF_CLUSTER);

	// creating priorityQueue using reversing comparator
	PriorityQueue<HierarchicalClusterNode> queue = new PriorityQueue<HierarchicalClusterNode>(numberOfClusters,
			new Comparator<HierarchicalClusterNode>() {

		@Override
		public int compare(HierarchicalClusterNode o1, HierarchicalClusterNode o2) {
			int value = -1 * Double.compare(o1.getDistance(), o2.getDistance());
			if (value != 0) {
				return value;
			} else {
				return -1 * Double.compare(o1.getNumberOfExamplesInSubtree(), o2.getNumberOfExamplesInSubtree());
			}
		}
	});

	// Iteratively descend within graph by splitting at greatest node until queue is full or
	// enough leafs are collected
	LinkedList<HierarchicalClusterNode> leafs = new LinkedList<HierarchicalClusterNode>();
	queue.add(root);
	while (queue.size() < numberOfClusters - leafs.size()) {
		HierarchicalClusterNode topNode = queue.poll();
		if (topNode.getSubNodes().size() > 0) {
			queue.addAll(topNode.getSubNodes());
		} else {
			leafs.add(topNode);
		}
	}
	queue.addAll(leafs);

	// construct flat cluster model from nodes
	ClusterModel flatModel = new ClusterModel(exampleSet, numberOfClusters,
			getParameterAsBoolean(PARAMETER_ADD_AS_LABEL), getParameterAsBoolean(PARAMETER_REMOVE_UNLABELED));
	int i = 0;
	for (HierarchicalClusterNode node : queue) {
		Cluster flatCluster = flatModel.getCluster(i);
		for (Object exampleId : node.getExampleIdsInSubtree()) {
			flatCluster.assignExample(exampleId);
		}
		i++;
	}

	// delivering adapted example set
	if (exampleSetOutput.isConnected()) {
		exampleSetOutput.deliver(flatModel.apply((ExampleSet) exampleSet.clone()));
	}
	return flatModel;
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:52,代码来源:FlattenClusterModel.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.size方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。