コード例 #1
0
 @Override
 public void findDeadlocks(boolean fix) throws PrismException {
   for (int i = 0; i < numStates; i++) {
     // Note that no distributions is a deadlock, not an empty distribution
     if (trans.get(i).isEmpty()) {
       addDeadlockState(i);
       if (fix) {
         DistributionSet distrs = newDistributionSet(null);
         Distribution distr = new Distribution();
         distr.add(i, 1.0);
         distrs.add(distr);
         addDistributionSet(i, distrs);
       }
     }
   }
 }
コード例 #2
0
  @Override
  public void buildFromPrismExplicit(String filename) throws PrismException {
    BufferedReader in;
    Distribution distr;
    DistributionSet distrs;
    String s, ss[];
    int i, j, k1, k2, iLast, k1Last, k2Last, n, lineNum = 0;
    double prob;

    try {
      // Open file
      in = new BufferedReader(new FileReader(new File(filename)));
      // Parse first line to get num states
      s = in.readLine();
      lineNum = 1;
      if (s == null) {
        in.close();
        throw new PrismException("Missing first line of .tra file");
      }
      ss = s.split(" ");
      n = Integer.parseInt(ss[0]);
      // Initialise
      initialise(n);
      // Go though list of transitions in file
      iLast = -1;
      k1Last = -1;
      k2Last = -1;
      distrs = null;
      distr = null;
      s = in.readLine();
      lineNum++;
      while (s != null) {
        s = s.trim();
        if (s.length() > 0) {
          ss = s.split(" ");
          i = Integer.parseInt(ss[0]);
          k1 = Integer.parseInt(ss[1]);
          k2 = Integer.parseInt(ss[2]);
          j = Integer.parseInt(ss[3]);
          prob = Double.parseDouble(ss[4]);
          // For a new state or distribution set or distribution
          if (i != iLast || k1 != k1Last || k2 != k2Last) {
            // Add any previous distribution to the last set, create new one
            if (distrs != null) {
              distrs.add(distr);
            }
            distr = new Distribution();
            // Only for a new state or distribution set...
            if (i != iLast || k1 != k1Last) {
              // Add any previous distribution set to the last state, create new one
              if (distrs != null) {
                addDistributionSet(iLast, distrs);
              }
              distrs = newDistributionSet(null);
            }
          }
          // Add transition to the current distribution
          distr.add(j, prob);
          // Prepare for next iter
          iLast = i;
          k1Last = k1;
          k2Last = k2;
        }
        s = in.readLine();
        lineNum++;
      }
      // Add previous distribution to the last set
      distrs.add(distr);
      // Add previous distribution set to the last state
      addDistributionSet(iLast, distrs);
      // Close file
      in.close();
    } catch (IOException e) {
      System.out.println(e);
      System.exit(1);
    } catch (NumberFormatException e) {
      throw new PrismException("Problem in .tra file (line " + lineNum + ") for " + getModelType());
    }
    // Set initial state (assume 0)
    initialStates.add(0);
  }