Esempio n. 1
0
  public static DeltaDisjunct mat2modRels(
      DBM dbm, MyEnum keep, LinearTerm[] substitution, boolean isOctagon, IntegerInf maxK) {

    Matrix m = dbm.mat();

    LinearRel lcs = new LinearRel();

    int size = m.size();

    boolean onlyZeroK = true; // coefficients of K always 0

    for (int i = 0; i < size; ++i) {

      for (int j = 0; j < size; ++j) {

        if (i == j) continue;

        Field f = m.get(i, j);

        if (!f.isFinite()) continue;

        // skip $0-$0'<=0 and $0'-$0<=0
        if (!isOctagon && ((i == size / 2 && j == 0) || (j == size / 2 && i == 0))) continue;

        LinearConstr lc = new LinearConstr();

        lc.addLinTerm(substitution[i].times(1));
        lc.addLinTerm(substitution[j].times(-1));

        boolean zeroK = f.fillLinTerms(lc, DeltaClosure.v_k);
        onlyZeroK &= zeroK;

        lcs.add(lc);
      }
    }
    if (!onlyZeroK) {
      if (m.fs() instanceof FieldStatic.ParametricFS) lcs.addConstraint(DeltaClosure.lc_k);

      if (maxK.isFinite()) {
        lcs.add(DeltaClosure.maxKconstr(maxK.toInt()));
      }
    }

    if (DeltaClosure.DEBUG_LEVEL >= DeltaClosure.DEBUG_LOW)
      System.out.println(lcs.toSBClever(Variable.ePRINT_prime));

    if (onlyZeroK) {
      Relation r = Relation.toMinType(lcs);

      Relation[] l;
      if (!r.contradictory()) l = new Relation[] {r};
      else l = new Relation[0];
      return new DeltaDisjunct(l, lcs, onlyZeroK);
    } else {
      Relation[] tmp = null;
      tmp = lcs.existElim1(DeltaClosure.v_k);
      // else keep null
      return new DeltaDisjunct(tmp, lcs, onlyZeroK);
    }
  }
Esempio n. 2
0
  public static DBM mat2matParam(DBM m, DBM paramCoef, Variable paramK) {

    Matrix mat = m.mat();

    Matrix paramCoefMat = (paramCoef == null) ? null : paramCoef.mat();

    if (paramCoefMat != null)
      if (mat.size() != paramCoefMat.size())
        throw new RuntimeException("Operation on matrices of incompatible sizes");

    int size = mat.size();

    FieldStaticInf fs = DeltaClosure.deltaFS();

    Matrix retMat = DBM.newMatrix(size, fs);
    retMat.init();

    for (int i = 0; i < size; ++i) {

      for (int j = 0; j < size; ++j) {

        Field f1 = mat.get(i, j);

        if (!f1.isFinite()) continue;

        int i_f1 = f1.toInt();
        int i_f2 = 0;
        {
          if (paramCoefMat != null) {
            Field f2 = paramCoefMat.get(i, j);
            i_f2 = f2.toInt();
          }
        }

        Field f = DeltaClosure.deltaBound(i_f1, i_f2);
        retMat.set(i, j, f);
      }
    }

    return new DBM(DBM.Encoding.DBC, retMat, fs);
  }