コード例 #1
0
  /** Model check a P operator. */
  private Result checkExpressionProb(ExpressionProb expr) throws PrismException {
    boolean min;
    ExpressionTemporal exprTemp;
    Expression exprTarget;
    BitSet targetLocs;
    int timeBound;
    boolean timeBoundStrict;
    double prob;

    // Check whether Pmin=? or Pmax=? (only two cases allowed)
    if (expr.getProb() != null) {
      throw new PrismException(
          "PTA model checking currently only supports Pmin=? and Pmax=? properties (try the digital clocks engine instead)");
    }
    min = expr.getRelOp().equals("min=");

    // Check this is a F path property (only case allowed at the moment)
    if (!(expr.getExpression() instanceof ExpressionTemporal))
      throw new PrismException(
          "PTA model checking currently only supports the F path operator (try the digital clocks engine instead)");
    exprTemp = (ExpressionTemporal) expr.getExpression();
    if (exprTemp.getOperator() != ExpressionTemporal.P_F || !exprTemp.isSimplePathFormula())
      throw new PrismException(
          "PTA model checking currently only supports the F path operator (try the digital clocks engine instead)");

    // Determine locations satisfying target
    exprTarget = exprTemp.getOperand2();
    targetLocs = checkLocationExpression(exprTarget);
    mainLog.println(
        "Target (" + exprTarget + ") satisfied by " + targetLocs.cardinality() + " locations.");
    // mainLog.println(targetLocs);

    // If there is a time bound, add a clock and encode this into target
    if (exprTemp.hasBounds()) {
      mainLog.println("Modifying PTA to encode time bound from property...");
      // Get time bound info (is always of form <=T or <T)
      timeBound = exprTemp.getUpperBound().evaluateInt(constantValues);
      timeBoundStrict = exprTemp.upperBoundIsStrict();
      // Modify PTA to include time bound; get new target
      targetLocs = buildTimeBoundIntoPta(pta, targetLocs, timeBound, timeBoundStrict);
      mainLog.println("New PTA: " + pta.infoString());
    }

    // Compute probability of reaching the set of target locations
    prob = computeProbabilisticReachability(targetLocs, min);

    // Return result
    return new Result(new Double(prob));
  }
コード例 #2
0
  /** Model check a property. */
  public Result check(Expression expr) throws PrismException {
    Modules2PTA m2pta;
    Result res;
    String resultString;
    long timer;

    // Starting model checking
    timer = System.currentTimeMillis();

    // Check for system...endsystem - not supported yet
    if (modulesFile.getSystemDefn() != null) {
      throw new PrismException(
          "The system...endsystem construct is not supported yet (try the digital clocks engine instead)");
    }

    // Translate ModulesFile object into a PTA object
    mainLog.println("\nBuilding PTA...");
    m2pta = new Modules2PTA(prism, modulesFile);
    pta = m2pta.translate();
    mainLog.println("\nPTA: " + pta.infoString());

    // Check for references to clocks - not allowed (yet)
    // (do this before modifications below for better error reporting)
    expr.accept(
        new ASTTraverseModify() {
          public Object visit(ExpressionVar e) throws PrismLangException {
            if (e.getType() instanceof TypeClock) {
              throw new PrismLangException(
                  "Properties cannot contain references to clocks (try the digital clocks engine instead)",
                  e);
            } else {
              return e;
            }
          }
        });

    // Take a copy of property, since will modify
    expr = expr.deepCopy();
    // Remove property refs ands labels from property
    expr = (Expression) expr.expandPropRefsAndLabels(propertiesFile, labelList);
    // Evaluate constants in property (easier to do now)
    expr = (Expression) expr.replaceConstants(constantValues);
    // Also simplify expression to optimise model checking
    expr = (Expression) expr.simplify();

    // Do model checking
    res = checkExpression(expr);

    // Model checking complete
    timer = System.currentTimeMillis() - timer;
    mainLog.println("\nModel checking completed in " + (timer / 1000.0) + " secs.");

    // Print result to log
    resultString = "Result";
    if (!("Result".equals(expr.getResultName())))
      resultString += " (" + expr.getResultName().toLowerCase() + ")";
    resultString += ": " + res;
    mainLog.print("\n" + resultString + "\n");

    // Return result
    return res;
  }