public Trans findTrans(Set<Trans> s, UniverseCell c) {
    double a = c.getAvg();
    Trans last = null;

    for (Trans t : s) {
      if (a < t.getLimit()) {
        return t;
      }
      last = t;
    }

    return last;
  }
		return new STM<stm.Void>({Trans t =>
			TResult r = null;
			boolean mark[] = {false};
			Long version = valueFieldInfo.wlock.get(mark);
		    if(mark[0] && t.transId.equals(version)){
		    	assert(valueFieldInfo.wlock.isMarked() && valueFieldInfo.wlock.getReference().equals(t.transId));
				t.writeSet.put(valueFieldInfo, n);
				r = new TResult(new stm.Void(), t, Trans.Status.ACTIVE);
			}else{
				if(valueFieldInfo.wlock.compareAndSet(null, t.transId, false, true)){
					t.writeSet.put(valueFieldInfo, n);
					if (valueFieldInfo.rlock.getReference() > t.validationStamp && !t.extend()){
						r = new TResult(null, t, Trans.Status.ABORTED);
					}else
						r = new TResult(new stm.Void(), t, Trans.Status.ACTIVE);
					}
				else{
					r = new TResult(null, t, Trans.Status.ABORTED);
				}
			}		
			r
		});
Exemple #3
0
  public void treatmentDotAutomate() {
    try {
      PrintWriter file = new PrintWriter(new FileWriter(destination));

      file.println("digraph G {");
      for (int i = 0; i < auto.vTrans.size(); i++) {
        Trans trans = (Trans) auto.vTrans.get(i);

        for (int j = 0; j < auto.vEntity.size(); j++) {
          Entity etape = (Entity) auto.vEntity.get(j);
          if (etape.getNum() == trans.getNumInitialEnt()) {
            file.print(etape.getLabel());
          }
        }
        file.print("->");
        for (int j = 0; j < auto.vEntity.size(); j++) {
          Entity etape = (Entity) auto.vEntity.get(j);
          if (etape.getNum() == trans.getNumFinalEnt()) {
            file.print(etape.getLabel());
          }
        }
        file.print(" [label=\"");
        file.print(trans.getThreshold());

        // recuperation du signe
        if (trans.getSign() == 1) {
          file.print("+");
        } else {
          file.print("-");
        }
        file.println("\"];");
      }
      file.println("}");
      file.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public void processCell(int row, int col) {
    Movement[] movements = getMovements();

    UniverseCell acc = this.sourceUniverse.getCellFactory().factor();
    UniverseCell thisCell = this.sourceUniverse.get(row, col);
    UniverseCell targetCell = this.targetUniverse.get(row, col);
    Trans trans = findTrans(stepTrans, thisCell);

    for (Movement movement : movements) {
      int otherRow = row + movement.getRowMovement();
      int otherCol = col + movement.getColumnmMovement();
      if (this.sourceUniverse.isValid(otherRow, otherCol)) {
        UniverseCell otherCell = this.sourceUniverse.get(otherRow, otherCol);
        UniverseCell tp = trans.calculate(otherCell);
        ((ContinuousCell) acc).add(tp);
      }
    }

    Trans trans2 = findTrans(finalTrans, acc);
    acc = trans2.calculate(acc);
    ((ContinuousCell) acc).clamp(0, 1);
    targetCell.copy(acc);
  }
Exemple #5
0
  /**
   * Begins a new transaction for this environment and associates it with the current thread. If a
   * transaction is already active for this environment and thread, a nested transaction will be
   * created.
   *
   * @param config the transaction configuration used for calling {@link
   *     Environment#beginTransaction}, or null to use the default configuration.
   * @return the new transaction.
   * @throws DatabaseException if the transaction cannot be started, in which case any existing
   *     transaction is not affected.
   * @throws IllegalStateException if a transaction is already active and nested transactions are
   *     not supported by the environment.
   */
  public final Transaction beginTransaction(TransactionConfig config) throws DatabaseException {

    Trans trans = (Trans) localTrans.get();
    if (trans != null) {
      if (trans.txn != null) {
        if (!DbCompat.NESTED_TRANSACTIONS) {
          throw new IllegalStateException("Nested transactions are not supported");
        }
        Transaction parentTxn = trans.txn;
        trans = new Trans(trans, config);
        trans.txn = env.beginTransaction(parentTxn, config);
        localTrans.set(trans);
      } else {
        trans.txn = env.beginTransaction(null, config);
        trans.config = config;
      }
    } else {
      trans = new Trans(null, config);
      trans.txn = env.beginTransaction(null, config);
      localTrans.set(trans);
    }
    return trans.txn;
  }