Search in sources :

Example 1 with Constraint

use of com.dat3m.dartagnan.solver.caat.constraints.Constraint in project Dat3M by hernanponcedeleon.

the class Reasoner method computeViolationReasons.

// ========================== Reason computation ==========================
public DNF<CAATLiteral> computeViolationReasons(Constraint constraint) {
    if (!constraint.checkForViolations()) {
        return DNF.FALSE();
    }
    CAATPredicate pred = constraint.getConstrainedPredicate();
    Collection<? extends Collection<? extends Derivable>> violations = constraint.getViolations();
    List<Conjunction<CAATLiteral>> reasonList = new ArrayList<>(violations.size());
    if (constraint instanceof AcyclicityConstraint) {
        // For acyclicity constraints, it is likely that we encounter the same
        // edge multiple times (as it can be part of different cycles)
        // so we memoize the computed reasons and reuse them if possible.
        final RelationGraph constrainedGraph = (RelationGraph) pred;
        final int mapSize = violations.stream().mapToInt(Collection::size).sum() * 4 / 3;
        final Map<Edge, Conjunction<CAATLiteral>> reasonMap = new HashMap<>(mapSize);
        for (Collection<Edge> violation : (Collection<Collection<Edge>>) violations) {
            Conjunction<CAATLiteral> reason = violation.stream().map(edge -> reasonMap.computeIfAbsent(edge, key -> computeReason(constrainedGraph, key))).reduce(Conjunction.TRUE(), Conjunction::and);
            reasonList.add(reason);
        }
    } else {
        for (Collection<? extends Derivable> violation : violations) {
            Conjunction<CAATLiteral> reason = violation.stream().map(edge -> computeReason(pred, edge)).reduce(Conjunction.TRUE(), Conjunction::and);
            reasonList.add(reason);
        }
    }
    return new DNF<>(reasonList);
}
Also used : PredicateVisitor(com.dat3m.dartagnan.solver.caat.predicates.misc.PredicateVisitor) java.util(java.util) Element(com.dat3m.dartagnan.solver.caat.predicates.sets.Element) AcyclicityConstraint(com.dat3m.dartagnan.solver.caat.constraints.AcyclicityConstraint) DNF(com.dat3m.dartagnan.utils.logic.DNF) CAATPredicate(com.dat3m.dartagnan.solver.caat.predicates.CAATPredicate) Conjunction(com.dat3m.dartagnan.utils.logic.Conjunction) Derivable(com.dat3m.dartagnan.solver.caat.predicates.Derivable) Constraint(com.dat3m.dartagnan.solver.caat.constraints.Constraint) PathAlgorithm.findShortestPath(com.dat3m.dartagnan.solver.caat.misc.PathAlgorithm.findShortestPath) RelationGraph(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph) Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge) EdgeDirection(com.dat3m.dartagnan.solver.caat.misc.EdgeDirection) SetPredicate(com.dat3m.dartagnan.solver.caat.predicates.sets.SetPredicate) AcyclicityConstraint(com.dat3m.dartagnan.solver.caat.constraints.AcyclicityConstraint) CAATPredicate(com.dat3m.dartagnan.solver.caat.predicates.CAATPredicate) AcyclicityConstraint(com.dat3m.dartagnan.solver.caat.constraints.AcyclicityConstraint) Constraint(com.dat3m.dartagnan.solver.caat.constraints.Constraint) RelationGraph(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph) Conjunction(com.dat3m.dartagnan.utils.logic.Conjunction) Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge) DNF(com.dat3m.dartagnan.utils.logic.DNF)

Example 2 with Constraint

use of com.dat3m.dartagnan.solver.caat.constraints.Constraint in project Dat3M by hernanponcedeleon.

the class ExecutionGraph method getOrCreateConstraintFromAxiom.

// =======================================================
// =================== Reading the WMM ====================
private Constraint getOrCreateConstraintFromAxiom(Axiom axiom) {
    if (constraintMap.containsKey(axiom)) {
        return constraintMap.get(axiom);
    }
    Constraint constraint;
    RelationGraph innerGraph = getOrCreateGraphFromRelation(axiom.getRelation());
    if (axiom.isAcyclicity()) {
        constraint = new AcyclicityConstraint(innerGraph);
    } else if (axiom.isEmptiness()) {
        constraint = new EmptinessConstraint(innerGraph);
    } else if (axiom.isIrreflexivity()) {
        constraint = new IrreflexivityConstraint(innerGraph);
    } else {
        throw new UnsupportedOperationException("The axiom " + axiom + " is not recognized.");
    }
    constraintMap.put(axiom, constraint);
    return constraint;
}
Also used : RelationGraph(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph) EmptinessConstraint(com.dat3m.dartagnan.solver.caat.constraints.EmptinessConstraint) AcyclicityConstraint(com.dat3m.dartagnan.solver.caat.constraints.AcyclicityConstraint) IrreflexivityConstraint(com.dat3m.dartagnan.solver.caat.constraints.IrreflexivityConstraint) EmptinessConstraint(com.dat3m.dartagnan.solver.caat.constraints.EmptinessConstraint) Constraint(com.dat3m.dartagnan.solver.caat.constraints.Constraint) AcyclicityConstraint(com.dat3m.dartagnan.solver.caat.constraints.AcyclicityConstraint) IrreflexivityConstraint(com.dat3m.dartagnan.solver.caat.constraints.IrreflexivityConstraint)

Example 3 with Constraint

use of com.dat3m.dartagnan.solver.caat.constraints.Constraint in project Dat3M by hernanponcedeleon.

the class CAATModel method from.

public static CAATModel from(Collection<? extends CAATPredicate> predicates, Collection<? extends Constraint> constraints) {
    Set<Constraint> consts = new HashSet<>(constraints);
    Set<CAATPredicate> preds = new HashSet<>(predicates);
    consts.forEach(c -> preds.add(c.getConstrainedPredicate()));
    PredicateHierarchy hierarchy = new PredicateHierarchy(preds);
    return new CAATModel(hierarchy, consts);
}
Also used : PredicateHierarchy(com.dat3m.dartagnan.solver.caat.predicates.PredicateHierarchy) Constraint(com.dat3m.dartagnan.solver.caat.constraints.Constraint) CAATPredicate(com.dat3m.dartagnan.solver.caat.predicates.CAATPredicate)

Example 4 with Constraint

use of com.dat3m.dartagnan.solver.caat.constraints.Constraint in project Dat3M by hernanponcedeleon.

the class CAATSolver method computeInconsistencyReasons.

// ======================================== Reason computation ==============================================
private DNF<CAATLiteral> computeInconsistencyReasons(List<Constraint> violatedConstraints) {
    List<Conjunction<CAATLiteral>> reasons = new ArrayList<>();
    for (Constraint constraint : violatedConstraints) {
        reasons.addAll(reasoner.computeViolationReasons(constraint).getCubes());
    }
    stats.numComputedReasons += reasons.size();
    // The conversion to DNF removes duplicates and dominated clauses
    DNF<CAATLiteral> result = new DNF<>(reasons);
    stats.numComputedReducedReasons += result.getNumberOfCubes();
    return result;
}
Also used : CAATLiteral(com.dat3m.dartagnan.solver.caat.reasoning.CAATLiteral) Constraint(com.dat3m.dartagnan.solver.caat.constraints.Constraint) Conjunction(com.dat3m.dartagnan.utils.logic.Conjunction) ArrayList(java.util.ArrayList) DNF(com.dat3m.dartagnan.utils.logic.DNF)

Example 5 with Constraint

use of com.dat3m.dartagnan.solver.caat.constraints.Constraint in project Dat3M by hernanponcedeleon.

the class ExecutionGraph method constructMappings.

// --------------------------------------------------
private void constructMappings(boolean createOnlyAxiomRelevantGraphs) {
    Set<RelationGraph> graphs = new HashSet<>();
    Set<Constraint> constraints = new HashSet<>();
    for (Axiom axiom : verificationTask.getAxioms()) {
        Constraint constraint = getOrCreateConstraintFromAxiom(axiom);
        constraints.add(constraint);
    }
    if (!createOnlyAxiomRelevantGraphs) {
        for (Relation rel : verificationTask.getRelationDependencyGraph().getNodeContents()) {
            if (!EXCLUDED_RELS.contains(rel.getName())) {
                RelationGraph graph = getOrCreateGraphFromRelation(rel);
                graphs.add(graph);
            }
        }
    }
    caatModel = CAATModel.from(graphs, constraints);
}
Also used : Relation(com.dat3m.dartagnan.wmm.relation.Relation) RelationGraph(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph) AcyclicityConstraint(com.dat3m.dartagnan.solver.caat.constraints.AcyclicityConstraint) IrreflexivityConstraint(com.dat3m.dartagnan.solver.caat.constraints.IrreflexivityConstraint) EmptinessConstraint(com.dat3m.dartagnan.solver.caat.constraints.EmptinessConstraint) Constraint(com.dat3m.dartagnan.solver.caat.constraints.Constraint) Axiom(com.dat3m.dartagnan.wmm.axiom.Axiom) HashSet(java.util.HashSet)

Aggregations

Constraint (com.dat3m.dartagnan.solver.caat.constraints.Constraint)5 AcyclicityConstraint (com.dat3m.dartagnan.solver.caat.constraints.AcyclicityConstraint)3 RelationGraph (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph)3 EmptinessConstraint (com.dat3m.dartagnan.solver.caat.constraints.EmptinessConstraint)2 IrreflexivityConstraint (com.dat3m.dartagnan.solver.caat.constraints.IrreflexivityConstraint)2 CAATPredicate (com.dat3m.dartagnan.solver.caat.predicates.CAATPredicate)2 Conjunction (com.dat3m.dartagnan.utils.logic.Conjunction)2 DNF (com.dat3m.dartagnan.utils.logic.DNF)2 EdgeDirection (com.dat3m.dartagnan.solver.caat.misc.EdgeDirection)1 PathAlgorithm.findShortestPath (com.dat3m.dartagnan.solver.caat.misc.PathAlgorithm.findShortestPath)1 Derivable (com.dat3m.dartagnan.solver.caat.predicates.Derivable)1 PredicateHierarchy (com.dat3m.dartagnan.solver.caat.predicates.PredicateHierarchy)1 PredicateVisitor (com.dat3m.dartagnan.solver.caat.predicates.misc.PredicateVisitor)1 Edge (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)1 Element (com.dat3m.dartagnan.solver.caat.predicates.sets.Element)1 SetPredicate (com.dat3m.dartagnan.solver.caat.predicates.sets.SetPredicate)1 CAATLiteral (com.dat3m.dartagnan.solver.caat.reasoning.CAATLiteral)1 Axiom (com.dat3m.dartagnan.wmm.axiom.Axiom)1 Relation (com.dat3m.dartagnan.wmm.relation.Relation)1 java.util (java.util)1