Search in sources :

Example 1 with Conjunction

use of com.dat3m.dartagnan.utils.logic.Conjunction 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 Conjunction

use of com.dat3m.dartagnan.utils.logic.Conjunction 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 3 with Conjunction

use of com.dat3m.dartagnan.utils.logic.Conjunction in project Dat3M by hernanponcedeleon.

the class Refiner method refine.

// This method computes a refinement clause from a set of violations.
// Furthermore, it computes symmetric violations if symmetry learning is enabled.
public BooleanFormula refine(DNF<CoreLiteral> coreReasons, SolverContext context) {
    // TODO: A specialized algorithm that computes the orbit under permutation may be better,
    // since most violations involve only few threads and hence the orbit is far smaller than the full
    // set of permutations.
    BooleanFormulaManager bmgr = context.getFormulaManager().getBooleanFormulaManager();
    BooleanFormula refinement = bmgr.makeTrue();
    // For each symmetry permutation, we will create refinement clauses
    for (Function<Event, Event> perm : symmPermutations) {
        for (Conjunction<CoreLiteral> reason : coreReasons.getCubes()) {
            BooleanFormula permutedClause = reason.getLiterals().stream().map(lit -> bmgr.not(permuteAndConvert(lit, perm, context))).reduce(bmgr.makeFalse(), bmgr::or);
            refinement = bmgr.and(refinement, permutedClause);
        }
    }
    return refinement;
}
Also used : EquivalenceClass(com.dat3m.dartagnan.utils.equivalence.EquivalenceClass) ThreadSymmetry(com.dat3m.dartagnan.program.analysis.ThreadSymmetry) CoreLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.CoreLiteral) ExecLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.ExecLiteral) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula) Set(java.util.Set) DNF(com.dat3m.dartagnan.utils.logic.DNF) Relation(com.dat3m.dartagnan.wmm.relation.Relation) Thread(com.dat3m.dartagnan.program.Thread) Function(java.util.function.Function) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) RelLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.RelLiteral) ArrayList(java.util.ArrayList) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) AddressLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.AddressLiteral) List(java.util.List) Conjunction(com.dat3m.dartagnan.utils.logic.Conjunction) REFINEMENT_SYMMETRY_LEARNING(com.dat3m.dartagnan.GlobalSettings.REFINEMENT_SYMMETRY_LEARNING) SolverContext(org.sosy_lab.java_smt.api.SolverContext) Event(com.dat3m.dartagnan.program.event.core.Event) RefinementTask(com.dat3m.dartagnan.verification.RefinementTask) Comparator(java.util.Comparator) Utils.generalEqual(com.dat3m.dartagnan.expression.utils.Utils.generalEqual) BooleanFormulaManager(org.sosy_lab.java_smt.api.BooleanFormulaManager) MemEvent(com.dat3m.dartagnan.program.event.core.MemEvent) Event(com.dat3m.dartagnan.program.event.core.Event) CoreLiteral(com.dat3m.dartagnan.solver.caat4wmm.coreReasoning.CoreLiteral) BooleanFormula(org.sosy_lab.java_smt.api.BooleanFormula)

Example 4 with Conjunction

use of com.dat3m.dartagnan.utils.logic.Conjunction in project Dat3M by hernanponcedeleon.

the class CoreReasoner method toCoreReason.

public Conjunction<CoreLiteral> toCoreReason(Conjunction<CAATLiteral> baseReason) {
    RelationRepository repo = memoryModel.getRelationRepository();
    EventDomain domain = executionGraph.getDomain();
    List<CoreLiteral> coreReason = new ArrayList<>(baseReason.getSize());
    for (CAATLiteral lit : baseReason.getLiterals()) {
        if (lit instanceof ElementLiteral) {
            Event e = domain.getObjectById(((ElementLiteral) lit).getElement().getId()).getEvent();
            // We only have static tags, so all of them reduce to execution literals
            coreReason.add(new ExecLiteral(e, lit.isNegative()));
        } else {
            EdgeLiteral edgeLit = (EdgeLiteral) lit;
            Edge edge = edgeLit.getEdge();
            Event e1 = domain.getObjectById(edge.getFirst()).getEvent();
            Event e2 = domain.getObjectById(edge.getSecond()).getEvent();
            Tuple tuple = new Tuple(e1, e2);
            Relation rel = repo.getRelation(lit.getName());
            if (lit.isPositive() && rel.getMinTupleSet().contains(tuple)) {
                // Statically present edges
                addExecReason(tuple, coreReason);
            } else if (lit.isNegative() && !rel.getMaxTupleSet().contains(tuple)) {
            // Statically absent edges
            } else {
                if (rel instanceof RelFencerel) {
                    // We should do this transformation directly on the Wmm to avoid this special reasoning
                    if (lit.isNegative()) {
                        throw new UnsupportedOperationException(String.format("FenceRel %s is not allowed on the rhs of differences.", rel));
                    }
                    addFenceReason(rel, edge, coreReason);
                } else if (rel.getName().equals(LOC)) {
                    coreReason.add(new AddressLiteral(tuple, lit.isNegative()));
                } else if (rel.getName().equals(RF) || rel.getName().equals(CO)) {
                    coreReason.add(new RelLiteral(rel.getName(), tuple, lit.isNegative()));
                } else {
                    // TODO: Right now, we assume many relations like Data, Ctrl and Addr to be
                    // static.
                    addExecReason(tuple, coreReason);
                }
            }
        }
    }
    minimize(coreReason);
    return new Conjunction<>(coreReason);
}
Also used : CAATLiteral(com.dat3m.dartagnan.solver.caat.reasoning.CAATLiteral) ArrayList(java.util.ArrayList) RelationRepository(com.dat3m.dartagnan.wmm.utils.RelationRepository) Relation(com.dat3m.dartagnan.wmm.relation.Relation) EventDomain(com.dat3m.dartagnan.solver.caat4wmm.EventDomain) ElementLiteral(com.dat3m.dartagnan.solver.caat.reasoning.ElementLiteral) RelFencerel(com.dat3m.dartagnan.wmm.relation.base.stat.RelFencerel) Conjunction(com.dat3m.dartagnan.utils.logic.Conjunction) Event(com.dat3m.dartagnan.program.event.core.Event) Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge) EdgeLiteral(com.dat3m.dartagnan.solver.caat.reasoning.EdgeLiteral) Tuple(com.dat3m.dartagnan.wmm.utils.Tuple)

Aggregations

Conjunction (com.dat3m.dartagnan.utils.logic.Conjunction)4 DNF (com.dat3m.dartagnan.utils.logic.DNF)3 ArrayList (java.util.ArrayList)3 Event (com.dat3m.dartagnan.program.event.core.Event)2 Constraint (com.dat3m.dartagnan.solver.caat.constraints.Constraint)2 Edge (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)2 CAATLiteral (com.dat3m.dartagnan.solver.caat.reasoning.CAATLiteral)2 Relation (com.dat3m.dartagnan.wmm.relation.Relation)2 REFINEMENT_SYMMETRY_LEARNING (com.dat3m.dartagnan.GlobalSettings.REFINEMENT_SYMMETRY_LEARNING)1 Utils.generalEqual (com.dat3m.dartagnan.expression.utils.Utils.generalEqual)1 Thread (com.dat3m.dartagnan.program.Thread)1 ThreadSymmetry (com.dat3m.dartagnan.program.analysis.ThreadSymmetry)1 MemEvent (com.dat3m.dartagnan.program.event.core.MemEvent)1 AcyclicityConstraint (com.dat3m.dartagnan.solver.caat.constraints.AcyclicityConstraint)1 EdgeDirection (com.dat3m.dartagnan.solver.caat.misc.EdgeDirection)1 PathAlgorithm.findShortestPath (com.dat3m.dartagnan.solver.caat.misc.PathAlgorithm.findShortestPath)1 CAATPredicate (com.dat3m.dartagnan.solver.caat.predicates.CAATPredicate)1 Derivable (com.dat3m.dartagnan.solver.caat.predicates.Derivable)1 PredicateVisitor (com.dat3m.dartagnan.solver.caat.predicates.misc.PredicateVisitor)1 RelationGraph (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph)1