Package gnu.trove.list.array

Examples of gnu.trove.list.array.TIntArrayList


    TIntArrayList sets;

    java.util.Random random;

    public Random(long seed) {
        sets = new TIntArrayList();
        random = new java.util.Random(seed);
    }
View Full Code Here


    Solver solver = new Solver();
    int n = matrix.length;
    // build model
    IntVar[] succ = new IntVar[n];
    int offset = -5;
    TIntArrayList l = new TIntArrayList();
    for (int i = 0; i < n-1; i++) {
      l.clear();
      for (int j = 0; j < n; j++) {
        if(matrix[i][j]){
          l.add(j+offset);
        }
      }
      if(l.isEmpty())throw new UnsupportedOperationException();
      if(enumerated){
        succ[i] = VF.enumerated("suc",l.toArray(),solver);
      }else{
        succ[i] = VF.bounded("suc",offset,n+offset,solver);
        solver.post(ICF.member(succ[i],l.toArray()));
      }
    }
    succ[n-1] = VF.fixed(n+offset,solver);
    solver.post(ICF.path(succ,VF.fixed(offset,solver),VF.fixed(n-1+offset,solver),offset));
    // configure solver
View Full Code Here

        this.variables = variables.clone();
        Solver solver = variables[0].getSolver();
        counter = new FailPerPropagator(solver.getCstrs(), solver);
        pid2ari = new TIntObjectHashMap<>();
        pid2arity = new TIntIntHashMap(10, 0.5F, -1, -1);
        bests = new TIntArrayList();
        this.valueSelector = valueSelector;
        decisionPool = new PoolManager<>();
        random = new java.util.Random(seed);
    }
View Full Code Here

 
  /**
   * Nearest
   */
  private TIntArrayList nearest(Point p, float furthestDistance) {
    TIntArrayList ret = new TIntArrayList();
    float nearestDistance = furthestDistance;
    TIntObjectIterator<Rectangle> i = m_map.iterator();
    while (i.hasNext()) {
      i.advance();
      int currentId = i.key();
      Rectangle currentRectangle = i.value();
      float distance = currentRectangle.distance(p);
      if (distance < nearestDistance) {
        nearestDistance = distance;
        ret.clear();        
      }
      if (distance <= nearestDistance) {
        ret.add(currentId)
      }
    }
    return ret;  
  }
View Full Code Here

 
  /**
   * @see net.sf.jsi.SpatialIndex#nearest(Point, gnu.trove.TIntProcedure, float)
   */
  public void nearest(Point p, final TIntProcedure v, float furthestDistance) {
    TIntArrayList nearestList = nearest(p, furthestDistance);
    nearestList.forEach(new TIntProcedure() {
      public boolean execute(int id) {
        v.execute(id)
        return true;
     
    });
View Full Code Here

     
    });
  }
 
  private TIntArrayList nearestN(Point p, int n, float furthestDistance) {
    TIntArrayList ids = new TIntArrayList();
    TFloatArrayList distances = new TFloatArrayList();
   
    TIntObjectIterator<Rectangle> iter = m_map.iterator();
    while (iter.hasNext()) {
      iter.advance();
      int currentId = iter.key();
      Rectangle currentRectangle = iter.value();
      float distance = currentRectangle.distance(p);
     
      if (distance <= furthestDistance) {
        int insertionIndex = 0;
        while (ids.size() > insertionIndex && distances.get(insertionIndex) <= distance) {
          insertionIndex++;
        }
       
        ids.insert(insertionIndex, currentId);
        distances.insert(insertionIndex, distance);
       
        // remove the entries with the greatest distance, if necessary.
        if (ids.size() > n) {
          // check that removing all entries with equal greatest distance
          // would leave at least N entries.
          int maxDistanceCount = 1;
          int currentIndex = distances.size() - 1;
          float maxDistance = distances.get(currentIndex);
          while (currentIndex - 1 >= 0 && distances.get(currentIndex - 1) == maxDistance) {
            currentIndex--;
            maxDistanceCount++;
          }
          if (ids.size() - maxDistanceCount >= n) {
            ids.remove(currentIndex, maxDistanceCount);
            distances.remove(currentIndex, maxDistanceCount);
          }
        }
      }
    }
View Full Code Here

 
  /**
   * @see net.sf.jsi.SpatialIndex#nearestN(Point, gnu.trove.TIntProcedure, int, float)
   */
  public void nearestN(Point p, final TIntProcedure v, int n, float furthestDistance) {
    TIntArrayList nearestList = nearestN(p, n, furthestDistance);
    nearestList.forEach(new TIntProcedure() {
      public boolean execute(int id) {
        v.execute(id)
        return true;
      }
    });
View Full Code Here

   */
  public void nearest(Point p, TIntProcedure v, float furthestDistance) {
    Node rootNode = getNode(rootNodeId);

    float furthestDistanceSq = furthestDistance * furthestDistance;
    TIntArrayList nearestIds = new TIntArrayList();
    nearest(p, rootNode, furthestDistanceSq, nearestIds);

    nearestIds.forEach(v);
    nearestIds.reset();
  }
View Full Code Here

    parents.push(rootNodeId);

    TIntStack parentsEntry = new TIntArrayStack();
    parentsEntry.push(-1);

    TIntArrayList savedValues = new TIntArrayList();
    float savedPriority = 0;

    // TODO: possible shortcut here - could test for intersection with the
    //       MBR of the root node. If no intersection, return immediately.

    float furthestDistanceSq = furthestDistance * furthestDistance;

    while (parents.size() > 0) {
      Node n = getNode(parents.peek());
      int startIndex = parentsEntry.peek() + 1;

      if (!n.isLeaf()) {
        // go through every entry in the index node to check
        // if it could contain an entry closer than the farthest entry
        // currently stored.
        boolean near = false;
        for (int i = startIndex; i < n.entryCount; i++) {
          if (Rectangle.distanceSq(n.entriesMinX[i], n.entriesMinY[i],
                                 n.entriesMaxX[i], n.entriesMaxY[i],
                                 p.x, p.y) <= furthestDistanceSq) {
            parents.push(n.ids[i]);
            parentsEntry.pop();
            parentsEntry.push(i); // this becomes the start index when the child has been searched
            parentsEntry.push(-1);
            near = true;
            break; // ie go to next iteration of while()
          }
        }
        if (near) {
          continue;
        }
      } else {
        // go through every entry in the leaf to check if
        // it is currently one of the nearest N entries.
        for (int i = 0; i < n.entryCount; i++) {
          float entryDistanceSq = Rectangle.distanceSq(n.entriesMinX[i], n.entriesMinY[i],
                                                   n.entriesMaxX[i], n.entriesMaxY[i],
                                                   p.x, p.y);
          int entryId = n.ids[i];

          if (entryDistanceSq <= furthestDistanceSq) {
            distanceQueue.insert(entryId, entryDistanceSq);

            while (distanceQueue.size() > count) {
              // normal case - we can simply remove the lowest priority (highest distance) entry
              int value = distanceQueue.getValue();
              float distanceSq = distanceQueue.getPriority();
              distanceQueue.pop();

              // rare case - multiple items of the same priority (distance)
              if (distanceSq == distanceQueue.getPriority()) {
                savedValues.add(value);
                savedPriority = distanceSq;
              } else {
                savedValues.reset();
              }
            }

            // if the saved values have the same distance as the
            // next one in the tree, add them back in.
            if (savedValues.size() > 0 && savedPriority == distanceQueue.getPriority()) {
              for (int svi = 0; svi < savedValues.size(); svi++) {
                distanceQueue.insert(savedValues.get(svi), savedPriority);
              }
              savedValues.reset();
            }

            // narrow the search, if we have already found N items
            if (distanceQueue.getPriority() < furthestDistanceSq && distanceQueue.size() >= count) {
              furthestDistanceSq = distanceQueue.getPriority();
View Full Code Here

    ids.reset();
    priorities.reset();
  }

  public SortedList() {
    ids = new TIntArrayList(DEFAULT_PREFERRED_MAXIMUM_SIZE);
    priorities = new TFloatArrayList(DEFAULT_PREFERRED_MAXIMUM_SIZE);
  }
View Full Code Here

TOP

Related Classes of gnu.trove.list.array.TIntArrayList

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.