public void testClear() {
   PriorityQueue pq = new IntegerQueue(3);
   pq.put(new Integer(2));
   pq.put(new Integer(3));
   pq.put(new Integer(1));
   assertEquals(3, pq.size());
   pq.clear();
   assertEquals(0, pq.size());
 }
Beispiel #2
0
 /**
  * Atomically removes all of the elements from this delay queue. The queue will be empty after
  * this call returns. Elements with an unexpired delay are not waited for; they are simply
  * discarded from the queue.
  */
 public void clear() {
   final ReentrantLock lock = this.lock;
   lock.lock();
   try {
     q.clear();
   } finally {
     lock.unlock();
   }
 }
 public void testClear() {
   PriorityQueue<Integer> pq = new IntegerQueue(3);
   pq.add(2);
   pq.add(3);
   pq.add(1);
   assertEquals(3, pq.size());
   pq.clear();
   assertEquals(0, pq.size());
 }
Beispiel #4
0
  public ArrayList<Edge> search(int begNode) {
    // build list of edges for the result
    ArrayList<Edge> result = new ArrayList<Edge>();

    // you have a list of nodes that have been visited
    ArrayList<Integer> done = new ArrayList<Integer>();

    // populate the todo
    ArrayList<Integer> todo = new ArrayList<Integer>();
    for (int i = 0; i < 18; i++) {
      todo.add(i);
    }

    // stick the start node into done, remove from todo
    done.add(begNode);
    todo.remove(begNode);

    // this will be used for the getting of options
    PriorityQueue<Edge> edges = new PriorityQueue<Edge>();

    // until all the nodes are in done
    while (done.size() != 18) {
      // System.out.println("todo:			"+todo);
      // System.out.println("done:			"+done);
      // System.out.println("current result: \t"+result);
      // System.out.println("");
      // get the options currently available, starting at done nodes
      // and ending on "todo" nodes, and load them into a priority queue
      for (int i = 0; i < done.size(); i++) {
        int start = done.get(i);
        for (int j = 0; j < todo.size(); j++) {
          int end = todo.get(j);
          // System.out.println(" edge we are adding is " + start + " to " + end);
          edges.add(new Edge(c, start, end));
        }
      }

      // take the one off the top, add it to result
      Edge winner = edges.poll();
      // System.out.println("The winner is: " + winner);
      result.add(winner);

      // set it's new node as visited
      done.add((Integer) winner.end());
      todo.remove((Integer) winner.end());

      // clear the edges at the end
      edges.clear();
    }

    return result;
  }
  public void getIndexInfo(String indexdir, int freqThreshold) {
    IndexReader reader = null;

    try {
      Directory dir = FSDirectory.open(new File(indexdir));
      System.out.println(dir);
      reader = IndexReader.open(dir);

      System.out.println("document num:" + reader.numDocs());
      System.out.println("======================");

      TermEnum terms = reader.terms();
      sortedTermQueue.clear();
      maxDocNum = reader.maxDoc();
      linkMap.clear();
      termList.clear();
      while (terms.next()) {
        // System.out.print(terms.term() + "\tDocFreq:" +
        TermDocs termDocs = reader.termDocs(terms.term());
        MyTerm temp = new MyTerm(terms.term(), termDocs, maxDocNum);
        if (temp.totalFreq < freqThreshold) {
          continue;
        } /*
           * if(temp.originTrem.text().length()==1){ continue; }
           */
        linkMap.put(temp.originTrem.text(), temp);
        sortedTermQueue.add(temp);
        termList.add(temp);
      }
      System.out.println("total Size:" + sortedTermQueue.size());
      System.out.println("mapsize:" + linkMap.keySet().size());
      // System.exit(0);
      int num = 0;
      this.maxFreq = sortedTermQueue.peek().totalFreq;
      while (!sortedTermQueue.isEmpty()) {
        num++;
        System.out.println(num + ":" + sortedTermQueue.poll());
      }
      System.out.println("read index info done");
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        reader.close();

      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
 void clear() {
   pending_entries.clear();
   output_set.clear();
   object_tasks.clear();
   active_threads.clear();
   time_marks.clear();
   thread_entries = null;
   next_time = 0;
   end_time = 0;
   current_thread = null;
   thread_map.clear();
   cpu_time = null;
   thread_counter = 0;
   task_counter = 0;
   max_delta = 1;
 }
 // 清除所有优先队列的数据,设置优先种子
 private static void SetSeeds(String filepath) throws Exception {
   pq.clear();
   BufferedReader br = new BufferedReader(new FileReader(filepath));
   String line = null;
   UrlValue cur = null;
   visitedPrint();
   while ((line = br.readLine()) != null) {
     line = line.trim();
     // System.out.println(line);
     if (!line.equals("")) {
       if (!visitedUrl.contains(line)) {
         cur = new UrlValue();
         cur.url = line;
         cur.value = 1;
         pq.offer(cur);
       } else {
         System.out.println("contain");
       }
     }
   }
   br.close();
 }
Beispiel #8
0
  // Pick a target to shoot
  // Parameters:
  //  prevRound - an array of previous shoots, prevRound[i] is the player that player i shot
  //              -1 if player i did not shoot
  //  alive - an array of player's status, true if the player is still alive in this round
  // Return:
  //  int - the player id to shoot, return -1 if do not shoot anyone
  //
  public int shoot(int[] prevRound, boolean[] alive) {

    if (prevRound == null) {
      return -1; // Make love, not war
    }

    System.out.println(Arrays.toString(friends));

    // Keep track of who got shot, how many times earlier
    boolean[] shotAt = new boolean[prevRound.length];
    int[] shotBy = new int[prevRound.length];
    Arrays.fill(shotBy, -1);

    for (int player = 0; player < prevRound.length; player++) {
      if (prevRound[player] == -1) continue;
      shotBy[prevRound[player]] = player;
      shotAt[prevRound[player]] = true;
    }

    // bingyi
    for (int player = 0; player < prevRound.length; player++)
      record.get(player).add(prevRound[player]);

    // yash
    // call prediction function here
    predictNextRound(next_round, record, alive);

    // summing up next_round stats
    double[] next_round_sum = new double[nplayers];

    // add the columns of prediction matrix to get player most likely to be shot at
    for (int i = 0; i < nplayers; i++) {
      for (int j = 0; j < nplayers; j++) {
        next_round_sum[i] += next_round[j][i];
      }
    }

    // d
    System.out.println("Typical " + Arrays.toString(next_round_sum));

    for (int player = 0; player < prevRound.length; player++) {
      if (prevRound[player] != -1) whoShotWhomCount[player][prevRound[player]]++;
      gaugeSeverity(player, prevRound[player], alive, shotAt, shotBy, prevRound, next_round_sum);
    }
    // you shoot; he's still alive
    if (prevRound[this.id] != -1 && alive[prevRound[this.id]]) {
      priorityList.add(new PriorityTuple(prevRound[this.id], CON));
    }

    // Printing the next_round_sum array returned
    for (int i = 0; i < next_round.length; i++) {
      for (int j = 0; j < next_round.length; j++) {
        System.out.print(next_round[i][j]);
      }
      System.out.println();
    }

    /*
       int popular_target[]=new int[prevRound.length];
       int players[]=new int[prevRound.length];

       for(int i=0;i<players.length;i++)
       {
       	players[i]=i;
       }



       //sort player and popular_target arrays to get sorted list of targets
       for(int i=0;i<popular_target.length;i++)
       {
       	for(int j=0;j<popular_target.length-1;j++)
       	{
       		if(popular_target[j]<popular_target[j+1])
       		{
       			int temp=popular_target[j];
       			popular_target[j]=popular_target[j+1];
       			popular_target[j+1]=temp;
       			temp=players[j];
       			players[j]=players[j+1];
       			players[j+1]=temp;
       		}
       	}
       }
       //We only need the most likely target, but I'm sorting the list just to get an idea of what our targets are like

       //printing players and their likeliness to be shot
       for(int j=0;j<prediction.length;j++)
    {
    	System.out.print("("+players[j]+","+popular_target[j]+") ");
    }
    System.out.println();

       */
    /*
          //shoot the most likely player if he is not a friend
          for(int i=0;i<popular_target.length;i++)
          {
          //	if((isEnemy(players[i]) || isNeutral(players[i])) && players[i]!=this.id && alive[players[i]])
          	if((isEnemy(players[i]) || Enemyus(players[i], record) || EnemyourAF(players[i], record, alive))&& players[i]!=this.id && alive[players[i]])
    {
          		return players[i];
          	}
          }
          */

    // Choose whom to shoot

    // if no enemies or neutrals are to be shot at
    if (priorityList.size() == 0) {
      priorityList.clear();
      return -1;
    }
    // yash

    // ArrayList<Integer> targets=new ArrayList<Integer>();
    int target;
    PriorityTuple firstTuple;
    double maxNextRoundSum;
    try {
      do {
        firstTuple = priorityList.remove();

        maxNextRoundSum = next_round_sum[firstTuple.playerId];
        target = firstTuple.playerId;
        // targets.add(firstTuple.playerId);
      } while (isFriend(target));
    } catch (NullPointerException e) {
      return -1;
    }

    while (priorityList.size() != 0 && firstTuple.priority == priorityList.peek().priority) {
      PriorityTuple anotherTuple = priorityList.remove();
      // targets.add(tupleToAdd.playerId);
      if (next_round_sum[anotherTuple.playerId] > maxNextRoundSum) {
        maxNextRoundSum = next_round_sum[anotherTuple.playerId];
        target = anotherTuple.playerId;
      }
    }

    priorityList.clear();
    return target;

    //        System.out.println("this is our hate most list\n");
    //        printListofArray(hate_most);
    //        if(priorityList.size()==0)
    //        	return -1;
    //
    //        attentionSeekingPrint(priorityList.toString());

    //        int myTarget=getMyTarget(shotAt);
    //        priorityList.clear();
    //    	 //bingyi
    //        printMatrix(record);
    //        //bingyi
    //        return myTarget;
  }
 public static void clear() {
   pq.clear();
 }