コード例 #1
0
  /**
   * Performs precomputation before actual state elimination. This handles cases in which all or
   * some states can or have to be treated differently, e.g. because there are no target states at
   * all, or some states do never reach a target state.
   *
   * @return true iff state elimination is necessary to obtain a result
   */
  private boolean precompute() {
    /* if there are no target states, the result is zero everywhere
     * for a reachability probability analysis, so all states can be
     * made absorbing. If we are performing analysis of accumulated
     * rewards, the value will be infinity everywhere. */
    if (!pmc.isUseTime() && !pmc.hasTargetStates()) {
      for (int state = 0; state < pmc.getNumStates(); state++) {
        pmc.makeAbsorbing(state);
        if (pmc.isUseRewards()) {
          pmc.setReward(state, pmc.getFunctionFactory().getInf());
        }
      }
      return false;
    }

    /* search for states which might never reach a target state and thus
     * have to be assigned a reward of infinity. */
    if (pmc.isUseRewards()) {
      int[] backStatesArr = collectStatesBackward();
      HashSet<Integer> reaching = new HashSet<Integer>();
      for (int stateNr = 0; stateNr < backStatesArr.length; stateNr++) {
        reaching.add(backStatesArr[stateNr]);
      }
      for (int state = 0; state < pmc.getNumStates(); state++) {
        if (!pmc.isUseTime() && !reaching.contains(state)) {
          pmc.setReward(state, pmc.getFunctionFactory().getInf());
        }
      }
    }
    return true;
  }