Ejemplo n.º 1
0
  @Override
  public void eyePtChanged() {

    Point3d eyePt = getViewPosInLocal(frontRoot);

    // System.out.println("eye pt = " + eyePt)
    if (eyePt != null) {

      for (int i = 0; i < 6; i++) {
        // if (perspectiveAttr.getValue() == true)
        // {
        // eyeVec.sub(eyePt, faceCenter[i]);
        // } else
        {
          eyeVec.sub(eyePt, volCenter);
        }
        frontFaceBits.set(i);
        backFaceBits.clear(i);
        if (eyeVec.dot(faceNormal[i]) < 0) {
          backFaceBits.set(i);
          frontFaceBits.clear(i);
        } else {
          frontFaceBits.set(i);
          backFaceBits.clear(i);
        }
      }
      frontAnnotations.setChildMask(frontFaceBits);
      backAnnotations.setChildMask(backFaceBits);
    }
  }
Ejemplo n.º 2
0
 private IdentifierInfo clear() {
   requiredScripts.clear();
   scriptSetSet.clear();
   numerics.clear();
   commonAmongAlternates.clear();
   return this;
 }
  /**
   * Updates the interal bitset from <code>iterator</code>. This will set <code>validMask</code> to
   * true if <code>iterator</code> is non-null.
   */
  private void updateMask(AttributedCharacterIterator iterator) {
    if (iterator != null) {
      validMask = true;
      this.iterator = iterator;

      // Update the literal mask
      if (literalMask == null) {
        literalMask = new BitSet();
      } else {
        for (int counter = literalMask.length() - 1; counter >= 0; counter--) {
          literalMask.clear(counter);
        }
      }

      iterator.first();
      while (iterator.current() != CharacterIterator.DONE) {
        Map attributes = iterator.getAttributes();
        boolean set = isLiteral(attributes);
        int start = iterator.getIndex();
        int end = iterator.getRunLimit();

        while (start < end) {
          if (set) {
            literalMask.set(start);
          } else {
            literalMask.clear(start);
          }
          start++;
        }
        iterator.setIndex(start);
      }
    }
  }
  private void changeServiceDependencies(final double addFactor, final double removeFactor) {
    BitSet servicesInNeighbourhood[] = new BitSet[numNeighbourhoods];
    for (int s = 0; s < servicesInNeighbourhood.length; ++s) {
      servicesInNeighbourhood[s] = new BitSet();
    }

    IntAVLTreeSet serviceToNeighbourhoods[] = new IntAVLTreeSet[services.length];
    for (int s = 0; s < services.length; ++s) serviceToNeighbourhoods[s] = new IntAVLTreeSet();

    for (Process p : processes) {
      int n = machines[assignment[p.id]].neighborhood;
      int s = p.service;

      servicesInNeighbourhood[n].set(s);

      serviceToNeighbourhoods[s].add(n);
    }

    for (int sid = 0; sid < services.length; sid++) {
      IntAVLTreeSet neighbourhoods = serviceToNeighbourhoods[sid];

      BitSet intersection = null;
      for (int n : neighbourhoods) {
        if (intersection == null) {
          intersection = new BitSet();
          intersection.or(servicesInNeighbourhood[n]);
        } else intersection.and(servicesInNeighbourhood[n]);
      }

      // intersection - all possible services I can depend on

      for (int d : services[sid].dependencies) intersection.clear(d);

      intersection.clear(sid); // exclude itself
      // services we can add as new dependencies

      int[] list = new int[intersection.cardinality()];
      int i = 0;
      for (int q = intersection.nextSetBit(0); q >= 0; q = intersection.nextSetBit(q + 1)) {
        list[i++] = q;
      }
      MyArrayUtils.shuffle(list, random);

      int addCount = nextInt(0, 1 + (int) (addFactor * services[sid].dependencies.length));
      // addCount = 0;
      int removeCount = nextInt(0, 1 + (int) (addFactor * services[sid].dependencies.length));

      int[] newdependencies =
          org.apache.commons.lang.ArrayUtils.addAll(
              services[sid].dependencies,
              Arrays.copyOfRange(list, 0, Math.min(list.length, addCount)));
      MyArrayUtils.shuffle(newdependencies, random);

      services[sid].dependencies =
          Arrays.copyOfRange(newdependencies, 0, Math.max(0, newdependencies.length - removeCount));
    }
  }
Ejemplo n.º 5
0
 /** Hydra task to execution ops, then stop scheduling. */
 public static void HydraTask_doOps() {
   BitSet availableOps = new BitSet(operations.length);
   availableOps.flip(FIRST_OP, LAST_OP + 1);
   // don't do local ops in bridge configuration
   availableOps.clear(LOCAL_INVALIDATE);
   availableOps.clear(LOCAL_DESTROY);
   testInstance.doOps(availableOps);
   if (availableOps.cardinality() == 0) {
     CQUtilBB.getBB().getSharedCounters().increment(CQUtilBB.TimeToStop);
     throw new StopSchedulingTaskOnClientOrder("Finished with ops");
   }
 }
Ejemplo n.º 6
0
  /**
   * Sets the game state from a string: the inverse of getGameState(). It reconstructs all the
   * game's variables from the string.
   *
   * @param gameState The game state represented as a string
   */
  public void setGameState(String gameState) {
    String[] values = gameState.split(",");

    int index = 0;

    indiceDeLaberinto = Integer.parseInt(values[index++]);
    tiempoTotal = Integer.parseInt(values[index++]);
    score = Integer.parseInt(values[index++]);
    tiempoLvlActual = Integer.parseInt(values[index++]);
    cuentaElLvl = Integer.parseInt(values[index++]);

    pacman =
        new PacMan(
            Integer.parseInt(values[index++]),
            MOVE.valueOf(values[index++]),
            Integer.parseInt(values[index++]),
            Boolean.parseBoolean(values[index++]));

    fantasmas = new EnumMap<GHOST, Ghost>(GHOST.class);

    for (GHOST ghostType : GHOST.values())
      fantasmas.put(
          ghostType,
          new Ghost(
              ghostType,
              Integer.parseInt(values[index++]),
              Integer.parseInt(values[index++]),
              Integer.parseInt(values[index++]),
              MOVE.valueOf(values[index++])));

    _setPills(laberintoActua = laberintos[indiceDeLaberinto]);

    for (int i = 0; i < values[index].length(); i++)
      if (values[index].charAt(i) == '1') pills.set(i);
      else pills.clear(i);

    index++;

    for (int i = 0; i < values[index].length(); i++)
      if (values[index].charAt(i) == '1') powerPills.set(i);
      else powerPills.clear(i);

    timeOfLastGlobalReversal = Integer.parseInt(values[++index]);
    pacmanFueComido = Boolean.parseBoolean(values[++index]);

    fantasmaComido = new EnumMap<GHOST, Boolean>(GHOST.class);

    for (GHOST ghost : GHOST.values())
      fantasmaComido.put(ghost, Boolean.parseBoolean(values[++index]));

    pastillaFueComida = Boolean.parseBoolean(values[++index]);
    pildoraPoderFueComida = Boolean.parseBoolean(values[++index]);
  }
Ejemplo n.º 7
0
 private void tryToMatch(int i) throws ContradictionException {
   int mate = augmentPath_BFS(i);
   if (mate != -1) {
     free.clear(mate);
     free.clear(i);
     int tmp = mate;
     while (tmp != i) {
       digraph.removeArc(father[tmp], tmp);
       digraph.addArc(tmp, father[tmp]);
       tmp = father[tmp];
     }
   }
 }
Ejemplo n.º 8
0
 public void set(int bitIndex, boolean value) {
   if (value == true) {
     set(bitIndex);
   } else {
     clear(bitIndex);
   }
 }
Ejemplo n.º 9
0
 public void set(int fromIndex, int toIndex, boolean value) {
   if (value == true) {
     set(fromIndex, toIndex);
   } else {
     clear(fromIndex, toIndex);
   }
 }
Ejemplo n.º 10
0
 public final void flushAll() {
   assert currentState == ISequencer.State.SLEEPING : "wrong state: " + currentState;
   for (int i = toPropagate.nextSetBit(0); i >= 0; i = toPropagate.nextSetBit(i + 1)) {
     master.requests[i].deque();
     toPropagate.clear(i);
   }
 }
Ejemplo n.º 11
0
  public void andNot(BitSet set) {
    // a & !a is false
    if (this == set) {
      // all falses result in an empty BitSet
      clear();
      return;
    }

    // trim the second set to avoid extra work
    trimToSize(array);
    int length = array.length();

    // truth table
    //
    // case | a | b | !b | a & !b | change?
    // 1 | false | false | true | false | a is already false
    // 2 | false | true | false | false | a is already false
    // 3 | true | false | true | true | a is already true
    // 4 | true | true | false | false | set a to false
    //
    // we only need to change something in case 4
    // whenever b is true, a should be false, so iterate over set b
    int index = 0;
    while ((index = nextSetWord(set.array, index)) != -1) {
      setWord(array, index, getWord(array, index) & ~set.array.get(index));
      if (++index >= length) {
        // nothing further will affect anything
        break;
      }
    }
  }
Ejemplo n.º 12
0
 /** Performs a deep copy on <i>other</i>. */
 public Appl(Appl other) {
   __isset_bit_vector.clear();
   __isset_bit_vector.or(other.__isset_bit_vector);
   if (other.isSetId()) {
     this.id = other.id;
   }
   if (other.isSetType()) {
     this.type = other.type;
   }
   this.excuteAction = other.excuteAction;
   if (other.isSetExcuteDescribe()) {
     this.excuteDescribe = other.excuteDescribe;
   }
   if (other.isSetPkgName()) {
     this.pkgName = other.pkgName;
   }
   if (other.isSetLevel()) {
     this.level = other.level;
   }
   if (other.isSetCategory()) {
     this.category = other.category;
   }
   if (other.isSetName()) {
     this.name = other.name;
   }
 }
Ejemplo n.º 13
0
 /** Performs a deep copy on <i>other</i>. */
 public ChosenMenuItem(ChosenMenuItem other) {
   __isset_bit_vector.clear();
   __isset_bit_vector.or(other.__isset_bit_vector);
   this.menuItemId = other.menuItemId;
   if (other.isSetSingleChoiceOptions()) {
     List<org.pocketcampus.platform.sdk.shared.common.ChosenSingleChoiceOption>
         __this__singleChoiceOptions =
             new ArrayList<org.pocketcampus.platform.sdk.shared.common.ChosenSingleChoiceOption>();
     for (org.pocketcampus.platform.sdk.shared.common.ChosenSingleChoiceOption other_element :
         other.singleChoiceOptions) {
       __this__singleChoiceOptions.add(
           new org.pocketcampus.platform.sdk.shared.common.ChosenSingleChoiceOption(
               other_element));
     }
     this.singleChoiceOptions = __this__singleChoiceOptions;
   }
   if (other.isSetMultiChoiceOptions()) {
     List<org.pocketcampus.platform.sdk.shared.common.ChosenMultiChoiceOption>
         __this__multiChoiceOptions =
             new ArrayList<org.pocketcampus.platform.sdk.shared.common.ChosenMultiChoiceOption>();
     for (org.pocketcampus.platform.sdk.shared.common.ChosenMultiChoiceOption other_element :
         other.multiChoiceOptions) {
       __this__multiChoiceOptions.add(
           new org.pocketcampus.platform.sdk.shared.common.ChosenMultiChoiceOption(other_element));
     }
     this.multiChoiceOptions = __this__multiChoiceOptions;
   }
   if (other.isSetComments()) {
     this.comments = other.comments;
   }
 }
 /** The longest dep set of the sub-sequence s[0..idx]. */
 public static BitSet longestDepSet(Sequence s, int idx) {
   if (s.size() == 0) throw new IllegalArgumentException("size must be greater than 0.");
   if (idx < 0 || idx >= s.size()) throw new IllegalArgumentException();
   assert s.size() <= maxlength;
   int max = -1;
   int maxidx = -1;
   for (int i = 0; i <= idx; i++) {
     BitSet set = sets[i];
     set.clear();
     set.set(i);
     lastuse[i] = i;
     for (Variable invar : s.getInputs(i)) {
       set.or(sets[lastuse[invar.index]]);
       lastuse[invar.index] = i;
     }
     int size = set.cardinality();
     if (size > max) {
       max = size;
       maxidx = i;
     }
   }
   for (int i = 0; i < s.size(); i++) {
     // System.out.println("@ " + sets[i]);
   }
   return sets[maxidx];
 }
Ejemplo n.º 15
0
  // Eats a power pill - turns ghosts edible (blue)
  protected boolean eatPowerPill() {
    boolean reverse = false;
    int powerPillIndex = getPowerPillIndex(curPacManLoc);

    if (powerPillIndex >= 0 && powerPills.get(powerPillIndex)) {
      score += G.POWER_PILL;
      ghostEatMultiplier = 1;
      powerPills.clear(powerPillIndex);

      // This ensures that only ghosts outside the lair (i.e., inside the maze) turn edible
      int newEdibleTime = (int) (G.EDIBLE_TIME * (Math.pow(G.EDIBLE_TIME_REDUCTION, totLevel)));

      for (int i = 0; i < NUM_GHOSTS; i++)
        if (lairTimes[i] == 0) edibleTimes[i] = newEdibleTime;
        else edibleTimes[i] = 0;

      // This turns all ghosts edible, independent on whether they are in the lair or not
      //
      //	Arrays.fill(edibleTimes,(int)(G.EDIBLE_TIME*(Math.pow(G.EDIBLE_TIME_REDUCTION,totLevel))));

      reverse = true;
    } else if (levelTime > 1 && Math.random() < G.GHOST_REVERSAL) // random ghost reversal
    reverse = true;

    return reverse;
  }
Ejemplo n.º 16
0
  /**
   * Prob0 precomputation algorithm. i.e. determine the states of an STPG which, with min/max
   * probability 0, reach a state in {@code target}, while remaining in those in @{code remain}.
   * {@code min}=true gives Prob0E, {@code min}=false gives Prob0A.
   *
   * @param stpg The STPG
   * @param remain Remain in these states (optional: null means "all")
   * @param target Target states
   * @param min1 Min or max probabilities for player 1 (true=lower bound, false=upper bound)
   * @param min2 Min or max probabilities for player 2 (true=min, false=max)
   */
  public BitSet prob0(STPG stpg, BitSet remain, BitSet target, boolean min1, boolean min2) {
    int n, iters;
    BitSet u, soln, unknown;
    boolean u_done;
    long timer;

    // Start precomputation
    timer = System.currentTimeMillis();
    if (verbosity >= 1)
      mainLog.println(
          "Starting Prob0 (" + (min1 ? "min" : "max") + (min2 ? "min" : "max") + ")...");

    // Special case: no target states
    if (target.cardinality() == 0) {
      soln = new BitSet(stpg.getNumStates());
      soln.set(0, stpg.getNumStates());
      return soln;
    }

    // Initialise vectors
    n = stpg.getNumStates();
    u = new BitSet(n);
    soln = new BitSet(n);

    // Determine set of states actually need to perform computation for
    unknown = new BitSet();
    unknown.set(0, n);
    unknown.andNot(target);
    if (remain != null) unknown.and(remain);

    // Fixed point loop
    iters = 0;
    u_done = false;
    // Least fixed point - should start from 0 but we optimise by
    // starting from 'target', thus bypassing first iteration
    u.or(target);
    soln.or(target);
    while (!u_done) {
      iters++;
      // Single step of Prob0
      stpg.prob0step(unknown, u, min1, min2, soln);
      // Check termination
      u_done = soln.equals(u);
      // u = soln
      u.clear();
      u.or(soln);
    }

    // Negate
    u.flip(0, n);

    // Finished precomputation
    timer = System.currentTimeMillis() - timer;
    if (verbosity >= 1) {
      mainLog.print("Prob0 (" + (min1 ? "min" : "max") + (min2 ? "min" : "max") + ")");
      mainLog.println(" took " + iters + " iterations and " + timer / 1000.0 + " seconds.");
    }

    return u;
  }
  protected void setImageDescriptor(ImageDescriptor descriptor) {
    if (Util.equals(imageDescriptor, descriptor)) {
      return;
    }

    Image oldImage = image;
    ImageDescriptor oldDescriptor = imageDescriptor;
    image = null;
    imageDescriptor = descriptor;

    // Don't queue events triggered by image changes. We'll dispose the image
    // immediately after firing the event, so we need to fire it right away.
    immediateFirePropertyChange(IWorkbenchPartConstants.PROP_TITLE);
    if (queueEvents) {
      // If there's a PROP_TITLE event queued, remove it from the queue because
      // we've just fired it.
      queuedEvents.clear(IWorkbenchPartConstants.PROP_TITLE);
    }

    // If we had allocated the old image, deallocate it now (AFTER we fire the property change
    // -- listeners may need to clean up references to the old image)
    if (oldImage != null) {
      JFaceResources.getResources().destroy(oldDescriptor);
    }
  }
 void initializeState(String name) {
   assert !myBusy;
   myBusy = true;
   myNameLength = name.length();
   isAsciiName = IOUtil.isAscii(name);
   myTable.clear();
 }
 synchronized boolean remove(long hash, K key) {
   int h = smallMap.startSearch(hash);
   boolean found = false;
   while (true) {
     int pos = smallMap.nextPos();
     if (pos < 0) {
       break;
     }
     bytes.storePositionAndSize(store, pos * smallEntrySize, smallEntrySize);
     K key2 = getKey();
     if (equals(key, key2)) {
       usedSet.clear(pos);
       smallMap.remove(h, pos);
       found = true;
       this.size--;
       break;
     }
   }
   K key2 = key instanceof CharSequence ? (K) key.toString() : key;
   DirectStore remove = map.remove(key2);
   if (remove == null) return found;
   offHeapUsed -= remove.size();
   remove.free();
   this.size--;
   return true;
 }
Ejemplo n.º 20
0
 public Transformer(FiniteStateTable dfa) {
   this.dfa = dfa;
   flatFST = new FlatFST();
   used = new BitSet(dfa.getTransitionTable().size());
   used.clear();
   statePosition = new int[dfa.getDFA().size()];
 }
Ejemplo n.º 21
0
  /**
   * Replaces an old successor with a new successor. This will throw RuntimeException if {@code
   * oldIndex} was not a successor.
   *
   * @param oldIndex index of old successor block
   * @param newIndex index of new successor block
   */
  public void replaceSuccessor(int oldIndex, int newIndex) {
    if (oldIndex == newIndex) {
      return;
    }

    // Update us.
    successors.set(newIndex);

    if (primarySuccessor == oldIndex) {
      primarySuccessor = newIndex;
    }

    for (int i = successorList.size() - 1; i >= 0; i--) {
      if (successorList.get(i) == oldIndex) {
        successorList.set(i, newIndex);
      }
    }

    successors.clear(oldIndex);

    // Update new successor.
    parent.getBlocks().get(newIndex).predecessors.set(index);

    // Update old successor.
    parent.getBlocks().get(oldIndex).predecessors.clear(index);
  }
Ejemplo n.º 22
0
  /**
   * Constructs and inserts a new empty GOTO block {@code Z} between this block ({@code A}) and a
   * current successor block ({@code B}). The new block will replace B as A's successor and A as B's
   * predecessor. A and B will no longer be directly connected. If B is listed as a successor
   * multiple times, all references are replaced.
   *
   * @param other current successor (B)
   * @return {@code non-null;} an appropriately-constructed instance
   */
  public SsaBasicBlock insertNewSuccessor(SsaBasicBlock other) {
    SsaBasicBlock newSucc = parent.makeNewGotoBlock();

    if (!successors.get(other.index)) {
      throw new RuntimeException(
          "Block " + other.getRopLabelString() + " not successor of " + getRopLabelString());
    }

    // Update the new block.
    newSucc.predecessors.set(this.index);
    newSucc.successors.set(other.index);
    newSucc.successorList.add(other.index);
    newSucc.primarySuccessor = other.index;

    // Update us.
    for (int i = successorList.size() - 1; i >= 0; i--) {
      if (successorList.get(i) == other.index) {
        successorList.set(i, newSucc.index);
      }
    }

    if (primarySuccessor == other.index) {
      primarySuccessor = newSucc.index;
    }
    successors.clear(other.index);
    successors.set(newSucc.index);

    // Update "other".
    other.predecessors.set(newSucc.index);
    other.predecessors.set(index, successors.get(other.index));

    return newSucc;
  }
Ejemplo n.º 23
0
  @Override
  public void visitCode(Code obj) {
    Method m = getMethod();
    if (m.getReturnType() == Type.VOID) {
      return;
    }

    stack.resetForMethodEntry(this);
    ifBlocks.clear();
    activeUnconditional = null;

    CodeException[] ces = obj.getExceptionTable();
    if (CollectionUtils.isEmpty(ces)) {
      catchPCs = null;
    } else {
      catchPCs = new BitSet();
      for (CodeException ce : ces) {
        catchPCs.set(ce.getHandlerPC());
      }
    }
    gotoBranchPCs.clear();
    casePositions.clear();
    lookingForResetOp = false;

    try {
      super.visitCode(obj);
    } catch (StopOpcodeParsingException e) {
      // reported an issue, so get out
    }
  }
 /** Performs a deep copy on <i>other</i>. */
 public OrderPlacedByClient(OrderPlacedByClient other) {
   __isset_bit_vector.clear();
   __isset_bit_vector.or(other.__isset_bit_vector);
   if (other.isSetChosenItems()) {
     List<ChosenMenuItem> __this__chosenItems = new ArrayList<ChosenMenuItem>();
     for (ChosenMenuItem other_element : other.chosenItems) {
       __this__chosenItems.add(new ChosenMenuItem(other_element));
     }
     this.chosenItems = __this__chosenItems;
   }
   this.expectedPrice = other.expectedPrice;
   this.userId = other.userId;
   if (other.isSetHowWillPay()) {
     this.howWillPay = other.howWillPay;
   }
   this.pickUp = other.pickUp;
   if (other.isSetAddress()) {
     this.address = other.address;
   }
   if (other.isSetPhoneNumber()) {
     this.phoneNumber = other.phoneNumber;
   }
   this.timestamp = other.timestamp;
   this.tableId = other.tableId;
   if (other.isSetPhoneId()) {
     this.phoneId = other.phoneId;
   }
   this.orderId = other.orderId;
   if (other.isSetUsername()) {
     this.username = other.username;
   }
 }
Ejemplo n.º 25
0
 /**
  * Faster removal of components from a entity.
  *
  * @param type the type of component to remove from this entity
  * @return this EntityEdit for chaining
  */
 public EntityEdit remove(ComponentType type) {
   if (componentBits.get(type.getIndex())) {
     world.getComponentManager().removeComponent(entity, type);
     componentBits.clear(type.getIndex());
   }
   return this;
 }
Ejemplo n.º 26
0
 private int augmentPath_BFS(int root) {
   in.clear();
   int indexFirst = 0, indexLast = 0;
   fifo[indexLast++] = root;
   in.set(root); // TODO CORRECTION JG 15/11/12 to test on minizinc instance
   int x, y;
   ISet succs;
   while (indexFirst != indexLast) {
     x = fifo[indexFirst++];
     succs = digraph.getSuccessorsOf(x);
     for (y = succs.getFirstElement(); y >= 0; y = succs.getNextElement()) {
       if (!in.get(y)) {
         father[y] = x;
         fifo[indexLast++] = y;
         in.set(y);
         if (flow[y] < this.ub[y]) {
           if (y < n) {
             throw new UnsupportedOperationException();
           }
           return y;
         }
       }
     }
   }
   return -1;
 }
Ejemplo n.º 27
0
 /**
  * Transition to the next generation by applying the Conway's Game Of Life rule.
  *
  * <ol>
  *   <li>Any live cell with fewer than two live neighbours dies, as if caused by under-population.
  *   <li>Any live cell with two or three live neighbours lives on to the next generation.
  *   <li>Any live cell with more than three live neighbours dies, as if by overcrowding.
  *   <li>Any dead cell with exactly three live neighbours becomes a live cell, as if by
  *       reproduction.
  * </ol>
  */
 public void nextGeneration() {
   // At each step time, looping all cells in the current generation to apply the rules
   for (int i = 0; i < vertical; i++) {
     for (int j = 0; j < horizontal; j++) {
       byte liveCellNeighbours = countLiveNeighbourCells(i, j);
       // If the cell is dead and have exactly 3 live cells neighbours becomes a live cell
       if (!currentGeneration.get(getIndex(i, j))) {
         if (liveCellNeighbours == 3) {
           tempGeneration.set(getIndex(i, j));
         }
       } else { // If the cell is live cell
         // If live cell with fewer than two live neighbours dies
         // If live cell with more than three live neighbours dies, as if by overcrowding.
         if (liveCellNeighbours < 2 || liveCellNeighbours > 3) {
           tempGeneration.clear(getIndex(i, j));
         } else { // Otherwise, keep the current state of the cell
           tempGeneration.set(getIndex(i, j), currentGeneration.get(getIndex(i, j)));
         }
       }
     }
   }
   // Swap the next generation to the current generation for the next step time
   BitSet bs = currentGeneration;
   currentGeneration = tempGeneration;
   tempGeneration = bs;
 }
Ejemplo n.º 28
0
  /**
   * Do operations on the REGION_NAME's keys using keyIntervals to specify which keys get which
   * operations. This will return when all operations in all intervals have completed.
   *
   * @param availableOps - Bits which are true correspond to the operations that should be executed.
   */
  public void doOps(BitSet availableOps) {

    boolean useTransactions = getInitialImage.InitImagePrms.useTransactions();

    while (availableOps.cardinality() != 0) {
      int whichOp = getOp(availableOps, operations.length);
      boolean doneWithOps = false;

      if (useTransactions) {
        TxHelper.begin();
      }

      switch (whichOp) {
        case ADD_NEW_KEY:
          doneWithOps = addNewKey();
          break;
        case INVALIDATE:
          doneWithOps = invalidate();
          break;
        case DESTROY:
          doneWithOps = destroy();
          break;
        case UPDATE_EXISTING_KEY:
          doneWithOps = updateExistingKey();
          break;
        case GET:
          doneWithOps = get();
          break;
        case LOCAL_INVALIDATE:
          doneWithOps = localInvalidate();
          break;
        case LOCAL_DESTROY:
          doneWithOps = localDestroy();
          break;
        default:
          {
            throw new TestException("Unknown operation " + whichOp);
          }
      }

      if (useTransactions) {
        try {
          TxHelper.commit();
        } catch (CommitConflictException e) {
          // currently not expecting any conflicts ...
          throw new TestException(
              "Unexpected CommitConflictException " + TestHelper.getStackTrace(e));
        }
      }

      if (doneWithOps) {
        Log.getLogWriter().info("Done with operation " + whichOp);
        availableOps.clear(whichOp);
      }
      if (sleepBetweenOps) {
        Log.getLogWriter().info("Sleeping between ops for " + SLEEP_BETWEEN_OPS_MILLIS + " millis");
        MasterController.sleepForMs(SLEEP_BETWEEN_OPS_MILLIS);
      }
    }
  }
Ejemplo n.º 29
0
 @Override
 public void propagate(int evtmask) throws ContradictionException {
   if (PropagatorEventType.isFullPropagation(evtmask)) {
     if (n2 < n + vars[n].getLB()) {
       fails(); // TODO: could be more precise, for explanation purpose
     }
     buildDigraph();
   }
   digraph.removeNode(n2);
   digraph.removeNode(n2 + 1);
   free.clear();
   for (int i = 0; i < n; i++) {
     if (digraph.getPredOf(i).size() == 0) {
       free.set(i);
     }
   }
   for (int i = n; i < n2; i++) {
     if (digraph.getSuccOf(i).size() == 0) {
       free.set(i);
     }
   }
   int card = repairMatching();
   vars[n].updateUpperBound(card, this);
   if (vars[n].getLB() == card) {
     filter();
   }
   for (int i = 0; i < idms.length; i++) {
     idms[i].unfreeze();
   }
 }
Ejemplo n.º 30
0
  /**
   * Converse of addRule. Since we know all the rules ever stored in this flowmap we simply retrieve
   * the rule using the id provided and remove each of its fields from the underlying structures.
   *
   * @param id - the id of the rule to remove
   * @throws FlowEntryNotFound - if this id is unknown. Could indicate that rule has already been
   *     removed.
   * @return
   */
  public void removeRule(int id) throws FlowEntryNotFound {
    ruleCount--;

    if (!rules.containsKey(id)) throw new FlowEntryNotFound(id);

    FlowEntry rule = rules.get(id);

    BitSet flowRuleSet = getFlowRuleSet(rule);

    remove(port, rule.getRuleMatch().getInputPort(), flowRuleSet);
    remove(dpids, rule.dpid, flowRuleSet);
    remove(vlan, (int) rule.getRuleMatch().getDataLayerVirtualLan(), flowRuleSet);
    remove(vlan, rule.getRuleMatch().getDataLayerVirtualLanPriorityCodePoint() << 16, flowRuleSet);
    remove(dl_type, rule.getRuleMatch().getDataLayerType(), flowRuleSet);

    remove(nw, (short) rule.getRuleMatch().getNetworkProtocol(), flowRuleSet);
    remove(nw, (short) (rule.getRuleMatch().getNetworkTypeOfService() << 8), flowRuleSet);

    remove(tp, (int) rule.getRuleMatch().getTransportSource(), flowRuleSet);
    remove(tp, rule.getRuleMatch().getTransportDestination() << 16, flowRuleSet);

    remove(dl_src, FVMatch.toLong(rule.getRuleMatch().getDataLayerSource()), flowRuleSet);
    remove(dl_dst, FVMatch.toLong(rule.getRuleMatch().getDataLayerDestination()), flowRuleSet);

    remove(prioSet, rule.getPriority(), flowRuleSet);

    vlan_ignore.clear(rule.getId());
    rules.remove(rule.getId());
    allRules.andNot(flowRuleSet);
  }