Search in sources :

Example 1 with RelationGraph

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph 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 RelationGraph

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph 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 RelationGraph

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph in project Dat3M by hernanponcedeleon.

the class ExecutionGraph method getOrCreateGraphFromRelation.

private RelationGraph getOrCreateGraphFromRelation(Relation rel) {
    if (relationGraphMap.containsKey(rel)) {
        return relationGraphMap.get(rel);
    }
    RelationGraph graph;
    Class<?> relClass = rel.getClass();
    // ===== Filter special relations ======
    if (SPECIAL_RELS.contains(rel.getName())) {
        switch(rel.getName()) {
            case CTRL:
                graph = new CtrlDepGraph();
                break;
            case DATA:
                graph = new DataDepGraph();
                break;
            case ADDR:
                graph = new AddrDepGraph();
                break;
            case CRIT:
                graph = new RcuGraph();
                break;
            default:
                throw new UnsupportedOperationException(rel.getName() + " is marked as special relation but has associated graph.");
        }
    } else if (relClass == RelRf.class) {
        graph = new ReadFromGraph();
    } else if (relClass == RelLoc.class) {
        graph = new LocationGraph();
    } else if (relClass == RelPo.class) {
        graph = new ProgramOrderGraph();
    } else if (relClass == RelCo.class) {
        graph = new CoherenceGraph();
    } else if (rel.isRecursiveRelation()) {
        RecursiveGraph recGraph = new RecursiveGraph();
        recGraph.setName(rel.getName() + "_rec");
        relationGraphMap.put(rel, recGraph);
        recGraph.setConcreteGraph(getOrCreateGraphFromRelation(rel.getInner()));
        return recGraph;
    } else if (rel.isUnaryRelation()) {
        Relation innerRelation = rel.getInner();
        RelationGraph innerGraph = getOrCreateGraphFromRelation(innerRelation);
        // A safety check because recursion might have computed this RelationGraph already
        if (relationGraphMap.containsKey(rel)) {
            return relationGraphMap.get(rel);
        }
        if (relClass == RelInverse.class) {
            graph = new InverseGraph(innerGraph);
        } else if (relClass == RelTrans.class) {
            graph = new TransitiveGraph(innerGraph);
        } else if (relClass == RelRangeIdentity.class) {
            graph = new RangeIdentityGraph(innerGraph);
        } else if (relClass == RelTransRef.class) {
            // FIXME: This is very, very sketchy and instead of doing this
            // a WmmProcessor should run that transforms the wmm accordingly.
            RelTrans relTrans = new RelTrans(innerRelation);
            RelationGraph transGraph = getOrCreateGraphFromRelation(relTrans);
            graph = new ReflexiveClosureGraph(transGraph);
        } else {
            throw new UnsupportedOperationException(relClass.toString() + " has no associated graph yet.");
        }
    } else if (rel.isBinaryRelation()) {
        RelationGraph first = getOrCreateGraphFromRelation(rel.getFirst());
        RelationGraph second = getOrCreateGraphFromRelation(rel.getSecond());
        // A safety check because recursion might have computed this RelationGraph already
        if (relationGraphMap.containsKey(rel)) {
            return relationGraphMap.get(rel);
        }
        if (relClass == RelUnion.class) {
            graph = new UnionGraph(first, second);
        } else if (relClass == RelIntersection.class) {
            graph = new IntersectionGraph(first, second);
        } else if (relClass == RelComposition.class) {
            graph = new CompositionGraph(first, second);
        } else if (relClass == RelMinus.class) {
            graph = new DifferenceGraph(first, second);
        } else {
            throw new UnsupportedOperationException(relClass.toString() + " has no associated graph yet.");
        }
    } else if (rel.isStaticRelation()) {
        if (relClass == RelCartesian.class) {
            RelCartesian cartRel = (RelCartesian) rel;
            SetPredicate lhs = getOrCreateSetFromFilter(cartRel.getFirstFilter());
            SetPredicate rhs = getOrCreateSetFromFilter(cartRel.getSecondFilter());
            graph = new CartesianGraph(lhs, rhs);
        } else if (relClass == RelRMW.class) {
            graph = new RMWGraph();
        } else if (relClass == RelExt.class) {
            graph = new ExternalGraph();
        } else if (relClass == RelInt.class) {
            graph = new InternalGraph();
        } else if (relClass == RelFencerel.class) {
            graph = new FenceGraph(((RelFencerel) rel).getFenceName());
        } else if (relClass == RelSetIdentity.class) {
            SetPredicate set = getOrCreateSetFromFilter(((RelSetIdentity) rel).getFilter());
            graph = new SetIdentityGraph(set);
        } else if (relClass == RelId.class) {
            graph = new IdentityGraph();
        } else if (relClass == RelEmpty.class) {
            graph = new EmptyGraph();
        } else {
            // This is a fallback for all unimplemented static graphs
            graph = new StaticDefaultWMMGraph(rel);
        }
    } else {
        throw new UnsupportedOperationException(relClass.toString() + " has no associated graph yet.");
    }
    graph.setName(rel.getName());
    relationGraphMap.put(rel, graph);
    return graph;
}
Also used : IdentityGraph(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.base.IdentityGraph) RelRMW(com.dat3m.dartagnan.wmm.relation.base.RelRMW) Relation(com.dat3m.dartagnan.wmm.relation.Relation) SetPredicate(com.dat3m.dartagnan.solver.caat.predicates.sets.SetPredicate) RelComposition(com.dat3m.dartagnan.wmm.relation.binary.RelComposition) RelTransRef(com.dat3m.dartagnan.wmm.relation.unary.RelTransRef) RelationGraph(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph) RelUnion(com.dat3m.dartagnan.wmm.relation.binary.RelUnion) RelTrans(com.dat3m.dartagnan.wmm.relation.unary.RelTrans) EmptyGraph(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.base.EmptyGraph) RelRf(com.dat3m.dartagnan.wmm.relation.base.memory.RelRf)

Example 4 with RelationGraph

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph in project Dat3M by hernanponcedeleon.

the class IntersectionGraph method forwardPropagate.

@Override
@SuppressWarnings("unchecked")
public Collection<Edge> forwardPropagate(CAATPredicate changedSource, Collection<? extends Derivable> added) {
    if (changedSource == first || changedSource == second) {
        RelationGraph other = (changedSource == first) ? second : first;
        Collection<Edge> addedEdges = (Collection<Edge>) added;
        List<Edge> newlyAdded = new ArrayList<>();
        for (Edge e1 : addedEdges) {
            Edge e2 = other.get(e1);
            if (e2 != null) {
                Edge e = derive(e1, e2);
                simpleGraph.add(e);
                newlyAdded.add(e);
            }
        }
        return newlyAdded;
    } else {
        return Collections.emptyList();
    }
}
Also used : RelationGraph(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph) Edge(com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)

Example 5 with RelationGraph

use of com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph 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

RelationGraph (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.RelationGraph)5 AcyclicityConstraint (com.dat3m.dartagnan.solver.caat.constraints.AcyclicityConstraint)3 Constraint (com.dat3m.dartagnan.solver.caat.constraints.Constraint)3 EmptinessConstraint (com.dat3m.dartagnan.solver.caat.constraints.EmptinessConstraint)2 IrreflexivityConstraint (com.dat3m.dartagnan.solver.caat.constraints.IrreflexivityConstraint)2 Edge (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.Edge)2 SetPredicate (com.dat3m.dartagnan.solver.caat.predicates.sets.SetPredicate)2 Relation (com.dat3m.dartagnan.wmm.relation.Relation)2 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 EmptyGraph (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.base.EmptyGraph)1 IdentityGraph (com.dat3m.dartagnan.solver.caat.predicates.relationGraphs.base.IdentityGraph)1 Element (com.dat3m.dartagnan.solver.caat.predicates.sets.Element)1 Conjunction (com.dat3m.dartagnan.utils.logic.Conjunction)1 DNF (com.dat3m.dartagnan.utils.logic.DNF)1 Axiom (com.dat3m.dartagnan.wmm.axiom.Axiom)1 RelRMW (com.dat3m.dartagnan.wmm.relation.base.RelRMW)1