<commit_before>package org.chocosolver.graphsolver.cstrs.connectivity;


import org.chocosolver.graphsolver.util.ConnectivityFinder;
import org.chocosolver.graphsolver.variables.GraphEventType;
import org.chocosolver.graphsolver.variables.UndirectedGraphVar;
import org.chocosolver.solver.constraints.Propagator;
import org.chocosolver.solver.constraints.PropagatorPriority;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.variables.Variable;
import org.chocosolver.util.ESat;

import java.util.*;

/**
 * Propagator ensuring that the size of all the connected components (CC) of a graph variable g is bounded by
 * minNCC (c.f. http://www.emn.fr/x-info/sdemasse/gccat/sec2.2.2.4.html#uid940) and
 * maxNCC (c.f. http://www.emn.fr/x-info/sdemasse/gccat/sec2.2.2.4.html#uid922).
 */
public class PropSizeCC extends Propagator<Variable> {

    /* Variables */

    private UndirectedGraphVar g;
    private int minNCC, maxNCC;
    private ConnectivityFinder GlbCCFinder, GubCCFinder;

    /* Constructor */

    public PropSizeCC(UndirectedGraphVar graph, int minNCC, int maxNCC) {
        super(new Variable[] {graph}, PropagatorPriority.LINEAR, false);
        this.g = graph;
        this.minNCC = minNCC;
        this.maxNCC = maxNCC;
        this.GlbCCFinder = new ConnectivityFinder(g.getLB());
        this.GubCCFinder = new ConnectivityFinder(g.getUB());
    }

    /* Methods */

    @Override
    public int getPropagationConditions(int vIdx) {
        return GraphEventType.ALL_EVENTS;
    }

    @Override
    public void propagate(int evtmask) throws ContradictionException {
        // Trivial case: empty GUB => there will be no CC.
        if (g.getPotentialNodes().size() == 0) {
            return;
        }

        // Trivial case: minNCC > NbMaxNodes and |GLB| > 0 => fails.
        if (g.getNbMaxNodes() < minNCC && g.getMandatoryNodes().size() > 0) {
            this.fails();
        }

        // Find all GLB CC
        GlbCCFinder.findAllCC();
        int nbGlbCC = GlbCCFinder.getNBCC();<commit_msg>Assert that minNCC <= maxNCC in ProgSizeCC propagator<commit_after>package org.chocosolver.graphsolver.cstrs.connectivity;


import org.chocosolver.graphsolver.util.ConnectivityFinder;
import org.chocosolver.graphsolver.variables.GraphEventType;
import org.chocosolver.graphsolver.variables.UndirectedGraphVar;
import org.chocosolver.solver.constraints.Propagator;
import org.chocosolver.solver.constraints.PropagatorPriority;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.variables.Variable;
import org.chocosolver.util.ESat;

import java.util.*;

/**
 * Propagator ensuring that the size of all the connected components (CC) of a graph variable g is bounded by
 * minNCC (c.f. http://www.emn.fr/x-info/sdemasse/gccat/sec2.2.2.4.html#uid940) and
 * maxNCC (c.f. http://www.emn.fr/x-info/sdemasse/gccat/sec2.2.2.4.html#uid922).
 */
public class PropSizeCC extends Propagator<Variable> {

    /* Variables */

    private UndirectedGraphVar g;
    private int minNCC, maxNCC;
    private ConnectivityFinder GlbCCFinder, GubCCFinder;

    /* Constructor */

    public PropSizeCC(UndirectedGraphVar graph, int minNCC, int maxNCC) {
        super(new Variable[] {graph}, PropagatorPriority.LINEAR, false);
        assert minNCC <= maxNCC;
        this.g = graph;
        this.minNCC = minNCC;
        this.maxNCC = maxNCC;
        this.GlbCCFinder = new ConnectivityFinder(g.getLB());
        this.GubCCFinder = new ConnectivityFinder(g.getUB());
    }

    /* Methods */

    @Override
    public int getPropagationConditions(int vIdx) {
        return GraphEventType.ALL_EVENTS;
    }

    @Override
    public void propagate(int evtmask) throws ContradictionException {
        // Trivial case: empty GUB => there will be no CC.
        if (g.getPotentialNodes().size() == 0) {
            return;
        }

        // Trivial case: minNCC > NbMaxNodes and |GLB| > 0 => fails.
        if (g.getNbMaxNodes() < minNCC && g.getMandatoryNodes().size() > 0) {
            this.fails();
        }

        // Find all GLB CC
        GlbCCFinder.findAllCC();
        int nbGlbCC = GlbCCFinder.getNBCC();
{'fraction_non_alphanumeric': 0.11169077543277212, 'fraction_numerical': 0.008062603746739389, 'mean_word_length': 3.1597633136094676, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5014774', 'n_tokens_mistral': 1453, 'n_tokens_neox': 1403, 'n_words': 284}