@Override
  public Iterator<T> iterator() {
    pruneToDuration();
    try {
      @SuppressWarnings("unchecked")
      final List<TimeWrapped> dc = Arrays.asList(queue.toArray());
      Collections.sort(dc);
      return new Iterator<T>() {
        List<TimeWrapped> dataclone = dc;
        int index = 0;
        TimeWrapped last;

        @Override
        public boolean hasNext() {
          return index < dataclone.size();
        }

        @Override
        public T next() {
          return (last = dataclone.get(index++)).getWrapped();
        }

        @Override
        public void remove() {
          queue.remove(last);
          decrement(last.getWrapped());
        }
      };
    } catch (ClassCastException e) {
      System.out.print(queue.toString());
      e.printStackTrace();
      System.exit(1);
    }
    return null;
  }
  /* THIS SECTION IN STASIS. The plan is to use the WeightedDirectedGraph class with
   * an optimized exact solution to the MWIS. Not there yet though. **/
  public Iterable<Long> findBestNonOverlappingGraph(Long[] relIds) {

    boolean trivialTestCase = false;

    if (trivialTestCase) {
      return Arrays.asList(relIds);
    }

    // vertices in this graph represent candidate relationships
    // edges represent overlap in the mrca sets between pairs of candidate relationships
    WeightedUndirectedGraph G = new WeightedUndirectedGraph();

    for (long relId : relIds) {
      G.addNode(relId, getWeight(relId));
    }

    // attach this candidate rel to any others with overlapping descendant sets
    for (int i = 0; i < relIds.length; i++) {
      long a = getStartNodeId(relIds[i]);
      for (int j = i + 1; j < relIds.length; j++) {
        long b = getStartNodeId(relIds[j]);
        if (nodeMrcaTipsAndInternal.get(a).containsAny(nodeMrcaTipsAndInternal.get(b))) {
          G.getNode(a).attachTo(b);
        }
      }
    }

    // find a set S' of vertices such that the total weight of S' is maximized, and no two vertices
    // in S' share an edge
    // this corresponds to a set of non-overlapping candidate relationships with maximum weight
    //		return new LPWeightedIS(G);
    return null; // garbage...
  }
 @SuppressWarnings("unchecked")
 @RequestMapping(
     value = "timeAggregation",
     method = RequestMethod.GET,
     produces = "application/json")
 public @ResponseBody List<TimeAggregation> getTimeAggregation() {
   return Arrays.asList(TimeAggregation.values());
 }
Example #4
0
 @SuppressWarnings("unchecked")
 @Override
 public List<ItemStack> getDrops(
     IBlockAccess world, BlockPos pos, IBlockState state, int fortune) {
   return new ArrayList<ItemStack>(
       Arrays.asList(
           new ItemStack[] {
             new ItemStack(
                 UItems.infectedcrop, MathHelper.getRandomIntegerInRange(new Random(), 1, 4))
           }));
 }
 /** Export this snapshot to GTFS, using the validity range in the snapshot. */
 public ProcessGtfsSnapshotExport(Snapshot snapshot, File output) {
   this(Arrays.asList(new Tuple2[] {snapshot.id}), output, snapshot.validFrom, snapshot.validTo);
 }
  @Test
  public void testRegistryEntries() throws Exception {
    int startingPort = 9090;
    System.err.println(executeCommand("fabric:create -n root"));
    CuratorFramework curator = getCurator();
    // Wait for zookeeper service to become available.
    System.err.println(
        executeCommand("fabric:profile-create --parents feature-camel fabric-camel"));
    System.err.println(
        executeCommand("fabric:profile-create --parents fabric-camel fabric-camel-server"));
    System.err.println(
        executeCommand("fabric:profile-create --parents fabric-camel fabric-camel-client"));
    System.err.println(
        executeCommand(
            "fabric:profile-edit --repositories mvn:org.fusesource.examples.fabric-camel-cluster/features/"
                + System.getProperty("fabric.version")
                + "/xml/features fabric-camel"));

    System.err.println(
        executeCommand("fabric:profile-edit --features camel-server fabric-camel-server"));
    executeCommand("fabric:profile-edit --features camel-client fabric-camel-client");

    Set<Container> containers =
        ContainerBuilder.create(3)
            .withName("fabric-camel")
            .withProfiles("fabric-camel")
            .assertProvisioningResult()
            .build();

    // We will use the first container as a client and the rest as servers.
    Container camelClientContainer = containers.iterator().next();
    containers.remove(camelClientContainer);
    Set<Container> camelServerContainers = new LinkedHashSet<Container>(containers);

    int index = 1;
    for (Container c : camelServerContainers) {
      setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(c.getId()), "changing");
      executeCommand(
          "fabric:container-connect -u admin -p admin "
              + camelClientContainer.getId()
              + " log:set DEBUG");
      System.err.println(
          executeCommand(
              "fabric:profile-create --parents fabric-camel-server fabric-camel-server-" + index));
      System.err.println(
          executeCommand(
              "fabric:profile-edit --pid io.fabric8.examples.camel.loadbalancing.server/portNumber="
                  + (startingPort++)
                  + " fabric-camel-server-"
                  + index));
      System.err.println(executeCommand("fabric:profile-display fabric-camel-server-" + index));
      System.err.println(
          executeCommand(
              "fabric:container-change-profile "
                  + c.getId()
                  + " fabric-camel-server-"
                  + (index++)));
    }

    Provision.provisioningSuccess(camelServerContainers, PROVISION_TIMEOUT);
    setData(
        curator,
        ZkPath.CONTAINER_PROVISION_RESULT.getPath(camelClientContainer.getId()),
        "changing");
    System.err.println(
        executeCommand(
            "fabric:container-change-profile "
                + camelClientContainer.getId()
                + " fabric-camel-client"));
    Provision.provisioningSuccess(
        Arrays.asList(new Container[] {camelClientContainer}), PROVISION_TIMEOUT);

    System.err.println(executeCommand("fabric:container-list"));
    System.err.println(executeCommand("fabric:profile-display --overlay fabric-camel-server"));

    // Check that the entries have been properly propagated.
    Assert.assertNotNull(exists(curator, "/fabric/registry/camel/endpoints/"));
    Assert.assertEquals(1, getChildren(curator, "/fabric/registry/camel/endpoints/").size());
    Thread.sleep(5000);
    System.err.println(
        executeCommand(
            "fabric:container-connect -u admin -p admin "
                + camelClientContainer.getId()
                + " camel:route-list"));
    String response =
        new AnsiString(
                executeCommand(
                    "fabric:container-connect -u admin -p admin "
                        + camelClientContainer.getId()
                        + " camel:route-info fabric-client | grep Failed"))
            .getPlain()
            .toString();
    System.err.println(response);
    int failed = Integer.parseInt(response.replaceAll("[^0-9]", ""));
    Assert.assertEquals("Failed exchanges found on client", 0, failed);

    // We want to kill all but one server, so we take out the first and keep it to the end.
    Container lastActiveServerContainer = camelServerContainers.iterator().next();
    camelServerContainers.remove(lastActiveServerContainer);
    for (Container c : camelServerContainers) {
      c.destroy();
      Thread.sleep(25000);
      response =
          new AnsiString(
                  executeCommand(
                      "fabric:container-connect -u admin -p admin "
                          + camelClientContainer.getId()
                          + " camel:route-info fabric-client | grep Failed"))
              .getPlain()
              .toString();
      System.err.println(response);
      failed = Integer.parseInt(response.replaceAll("[^0-9]", ""));
      Assert.assertEquals(
          "Failed exchanges found after container:" + c.getId() + " shut down", 0, failed);
    }
  }
  private List<Long> findBestNonOverlapping(Collection<Relationship> rels) {

    if (rels.size() < 1) {
      if (VERBOSE) {
        System.out.println("(no non-singleton rels to select from)");
      }
      return new ArrayList<Long>();
    }

    TLongBitArraySet[] mrcaSetsForRels = new TLongBitArraySet[rels.size()];
    double[] weights = new double[rels.size()];
    Long[] relIds = new Long[rels.size()];

    // used to check if no overlap exists among any rels, if not don't bother with the mwis
    // really we could be smarter about this and find the rels that have no overlap and exclude them
    int taxSum = 0;

    HashSet<Long> uniqueTips = new HashSet<Long>();

    Iterator<Relationship> relsIter = rels.iterator();
    for (int i = 0; relsIter.hasNext(); i++) {
      Relationship rel = relsIter.next();

      TLongBitArraySet currDesc = mrcaTipsAndInternal(rel);

      // this represents a pathological case, so die horribly
      if (currDesc == null) {
        throw new IllegalStateException("Found a rel with no descendants: " + rel);
      }

      relIds[i] = rel.getId();
      mrcaSetsForRels[i] = currDesc;
      weights[i] = getScoreNodeCount(rel);

      //			long [] currTips = mrcaTips(rel);
      TLongBitArraySet currTips = mrcaTips(rel.getStartNode());
      taxSum += currTips.size();
      //			for (int j = 0; j < currTips.size(); j++) {
      //				uniqueTips.add(currTips.get(j));
      //			}
      for (long t : currTips) {
        uniqueTips.add(t);
      }

      if (VERBOSE) {
        System.out.println(
            rel.getId()
                + ": nodeMrca("
                + rel.getStartNode().getId()
                + ") = "
                + nodeMrcaTipsAndInternal.get(rel.getStartNode().getId())
                + ". score = "
                + weights[i]);
      }
    }

    System.out.println(
        "taxSum = "
            + taxSum
            + "; uniqueTips size = "
            + uniqueTips.size()
            + "; incoming rels = "
            + relIds.length);

    if (taxSum
        == uniqueTips
            .size()) { // if there is no conflict, skip the set comparisons and just add everything
                       // (saves major time)
      System.out.println("no conflict! saving all incoming rels.");
      return new ArrayList<Long>(Arrays.asList(relIds));

    } else if (relIds.length
        <= BruteWeightedIS
            .MAX_TRACTABLE_N) { // otherwise if the set is small enough find the exact MWIS solution
      return new BruteWeightedIS(relIds, weights, mrcaSetsForRels).best();

    } else { // otherwise we need to use the approximation method
      return new GreedyApproximateWeightedIS(relIds, weights, mrcaSetsForRels).best();
    }
  }