/**
  * Constructor: build an STPG from an MDP. Data is copied directly from the MDP so take a copy
  * first if you plan to keep/modify the MDP.
  */
 public STPGAbstrSimple(MDPSimple m) {
   DistributionSet set;
   int i;
   // TODO: actions?
   initialise(m.getNumStates());
   copyFrom(m);
   for (i = 0; i < numStates; i++) {
     set = newDistributionSet(null);
     set.addAll(m.getChoices(i));
     addDistributionSet(i, set);
   }
 }
 /** Constructor: empty STPG. */
 public STPGAbstrSimple() {
   initialise(0);
 }
 /** Constructor: new STPG with fixed number of states. */
 public STPGAbstrSimple(int numStates) {
   initialise(numStates);
 }
  @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);
  }