package edg.slicing;

import edg.graph.EDG;

/**
 * Constraind tabular algorithm with subsumption.
 * It uses stack ordering to disallow insertion into pathEdge and workList if a subsuming
 * stack is included in them already.
 * @see ConstrainedTabularAlgorithm
 */
public class ConstrainedSubsumedTabularAlgorithm extends ConstrainedTabularAlgorithm {
    public ConstrainedSubsumedTabularAlgorithm(EDG edg) {
        super(edg);
    }

    @Override
    protected void propagate(Work work) {
        if (!pathEdge.contains(work)) {
            if (work.current().stack().isEdgeConstraintsEmpty() || pathEdge.stream().noneMatch(work::isSubsumedBy)) {
                workList.removeIf(w -> w.isSubsumedBy(work));
                pathEdge.add(work);
                workList.add(work);
            }
        }
    }
}