Search in sources :

Example 1 with PredicateNode

use of de.bmoth.parser.ast.nodes.PredicateNode in project bmoth by hhu-stups.

the class ExplicitStateModelChecker method labelStateSpace.

private void labelStateSpace() {
    Queue<State> statesToUpdate = new ArrayDeque<>();
    statesToUpdate.addAll(stateSpace.vertexSet());
    while (!statesToUpdate.isEmpty()) {
        State current = statesToUpdate.poll();
        final Set<BuechiAutomatonNode> buechiNodes = new HashSet<>();
        final Set<BuechiAutomatonNode> candidates = new HashSet<>();
        if (stateSpace.rootVertexSet().contains(current)) {
            candidates.addAll(buechiAutomaton.getInitialStates());
        } else {
            Set<DefaultEdge> incomingEdges = stateSpace.incomingEdgesOf(current);
            for (DefaultEdge incomingEdge : incomingEdges) {
                State predecessor = stateSpace.getEdgeSource(incomingEdge);
                predecessor.getBuechiNodes().forEach(n -> candidates.addAll(n.getSuccessors()));
            }
        }
        for (BuechiAutomatonNode node : candidates) {
            if (node.getLabels().isEmpty()) {
                buechiNodes.add(node);
            }
            // TODO use all labels?
            for (PredicateNode label : node.getLabels()) {
                labelSolver.reset();
                labelSolver.add(FormulaToZ3Translator.translatePredicate(label, getContext(), getMachineTranslator().getZ3TypeInference()));
                labelSolver.add(current.getStateConstraint(getContext()));
                Status status = labelSolver.check();
                switch(status) {
                    case UNSATISFIABLE:
                        break;
                    case UNKNOWN:
                        throw new UnsupportedOperationException("should not be undefined");
                    case SATISFIABLE:
                        buechiNodes.add(node);
                }
            }
        }
        buechiNodes.stream().filter(n -> !current.getBuechiNodes().contains(n)).forEach(newBuechiNode -> {
            // found a new node, need to update successors again
            current.addBuechiNode(newBuechiNode);
            Set<DefaultEdge> outgoingEdges = stateSpace.outgoingEdgesOf(current);
            for (DefaultEdge outgoingEdge : outgoingEdges) {
                State successor = stateSpace.getEdgeTarget(outgoingEdge);
                if (!statesToUpdate.contains(successor)) {
                    statesToUpdate.add(successor);
                }
            }
        });
    }
}
Also used : Status(com.microsoft.z3.Status) Z3SolverFactory(de.bmoth.backend.z3.Z3SolverFactory) de.bmoth.modelchecker(de.bmoth.modelchecker) java.util(java.util) FormulaToZ3Translator(de.bmoth.backend.z3.FormulaToZ3Translator) DefaultEdge(org.jgrapht.graph.DefaultEdge) Solver(com.microsoft.z3.Solver) MachineNode(de.bmoth.parser.ast.nodes.MachineNode) SolutionFinder(de.bmoth.backend.z3.SolutionFinder) ModelCheckingResult(de.bmoth.modelchecker.ModelCheckingResult) NOT(de.bmoth.parser.ast.nodes.ltl.LTLPrefixOperatorNode.Kind.NOT) TarjanSimpleCycles(org.jgrapht.alg.cycle.TarjanSimpleCycles) Model(com.microsoft.z3.Model) PredicateNode(de.bmoth.parser.ast.nodes.PredicateNode) de.bmoth.parser.ast.nodes.ltl(de.bmoth.parser.ast.nodes.ltl) BoolExpr(com.microsoft.z3.BoolExpr) LTLTransformations(de.bmoth.backend.ltl.LTLTransformations) Status(com.microsoft.z3.Status) TranslationOptions(de.bmoth.backend.TranslationOptions) BMothPreferences(de.bmoth.preferences.BMothPreferences) PredicateNode(de.bmoth.parser.ast.nodes.PredicateNode) DefaultEdge(org.jgrapht.graph.DefaultEdge)

Example 2 with PredicateNode

use of de.bmoth.parser.ast.nodes.PredicateNode in project bmoth by hhu-stups.

the class ConvertNotFormulaToNegatedBFormula method transformNode.

@Override
public Node transformNode(Node node) {
    LTLPrefixOperatorNode notOperator = (LTLPrefixOperatorNode) node;
    LTLNode argument = notOperator.getArgument();
    LTLBPredicateNode bPredicateNode = (LTLBPredicateNode) argument;
    PredicateNode negatedPredicate = bPredicateNode.getPredicate().getNegatedPredicateNode();
    return new LTLBPredicateNode(negatedPredicate);
}
Also used : LTLPrefixOperatorNode(de.bmoth.parser.ast.nodes.ltl.LTLPrefixOperatorNode) LTLNode(de.bmoth.parser.ast.nodes.ltl.LTLNode) LTLBPredicateNode(de.bmoth.parser.ast.nodes.ltl.LTLBPredicateNode) PredicateNode(de.bmoth.parser.ast.nodes.PredicateNode) LTLBPredicateNode(de.bmoth.parser.ast.nodes.ltl.LTLBPredicateNode)

Example 3 with PredicateNode

use of de.bmoth.parser.ast.nodes.PredicateNode in project bmoth by hhu-stups.

the class BuechiAutomatonNode method toString.

public String toString() {
    StringJoiner nodeString = new StringJoiner("\n", "", "");
    nodeString.add(this.name + ": ");
    StringJoiner incomingString = new StringJoiner(", ", "{", "}");
    for (BuechiAutomatonNode incomingNode : this.incoming) {
        incomingString.add(incomingNode.name);
    }
    nodeString.add("Incoming: " + incomingString.toString());
    StringJoiner successorString = new StringJoiner(", ", "{", "}");
    for (BuechiAutomatonNode successorNode : this.successors) {
        successorString.add(successorNode.name);
    }
    nodeString.add("Successors: " + successorString.toString());
    StringJoiner unprocessedString = new StringJoiner("; ", "(", ")");
    for (LTLNode subNode : this.unprocessed) {
        unprocessedString.add(subNode.toString());
    }
    nodeString.add("Unprocessed: " + unprocessedString.toString());
    StringJoiner processedString = new StringJoiner("; ", "(", ")");
    for (LTLNode subNode : this.processed) {
        processedString.add(subNode.toString());
    }
    nodeString.add("Processed: " + processedString.toString());
    StringJoiner nextString = new StringJoiner("; ", "(", ")");
    for (LTLNode subNode : this.next) {
        nextString.add(subNode.toString());
    }
    nodeString.add("Next: " + nextString.toString());
    StringJoiner labelString = new StringJoiner("; ", "(", ")");
    for (PredicateNode predicate : labels) {
        labelString.add(predicate.toString());
    }
    nodeString.add("Labels: " + labelString.toString());
    nodeString.add("Initial state? " + isInitialState);
    nodeString.add("Accepting state? " + isAcceptingState);
    return nodeString.toString();
}
Also used : PredicateNode(de.bmoth.parser.ast.nodes.PredicateNode)

Aggregations

PredicateNode (de.bmoth.parser.ast.nodes.PredicateNode)3 BoolExpr (com.microsoft.z3.BoolExpr)1 Model (com.microsoft.z3.Model)1 Solver (com.microsoft.z3.Solver)1 Status (com.microsoft.z3.Status)1 TranslationOptions (de.bmoth.backend.TranslationOptions)1 LTLTransformations (de.bmoth.backend.ltl.LTLTransformations)1 FormulaToZ3Translator (de.bmoth.backend.z3.FormulaToZ3Translator)1 SolutionFinder (de.bmoth.backend.z3.SolutionFinder)1 Z3SolverFactory (de.bmoth.backend.z3.Z3SolverFactory)1 de.bmoth.modelchecker (de.bmoth.modelchecker)1 ModelCheckingResult (de.bmoth.modelchecker.ModelCheckingResult)1 MachineNode (de.bmoth.parser.ast.nodes.MachineNode)1 de.bmoth.parser.ast.nodes.ltl (de.bmoth.parser.ast.nodes.ltl)1 LTLBPredicateNode (de.bmoth.parser.ast.nodes.ltl.LTLBPredicateNode)1 LTLNode (de.bmoth.parser.ast.nodes.ltl.LTLNode)1 LTLPrefixOperatorNode (de.bmoth.parser.ast.nodes.ltl.LTLPrefixOperatorNode)1 NOT (de.bmoth.parser.ast.nodes.ltl.LTLPrefixOperatorNode.Kind.NOT)1 BMothPreferences (de.bmoth.preferences.BMothPreferences)1 java.util (java.util)1