<commit_before>/*
 * Copyright (c) 1999-2012, Ecole des Mines de Nantes
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the Ecole des Mines de Nantes nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package solver.objective;

import solver.ResolutionPolicy;
import solver.Solver;
import solver.exception.ContradictionException;
import solver.explanations.Deduction;
import solver.explanations.Explanation;
import solver.explanations.VariableState;
import solver.variables.IntVar;

/**
 * Class that monitors the objective function and avoid exploring "worse" solutions
 *
 * @author <NAME>
 * @since Oct. 2012
 */
public class IntObjectiveManager extends ObjectiveManager {

    final IntVar objective;
	final boolean strict;
    int bestKnownUpperBound;
    int bestKnownLowerBound;

    /**
     * Creates an optimization manager
     * Enables to cut "worse" solutions
     *
     * @param objective variable (represent the value of a solution)
     * @param policy    SATISFACTION / MINIMIZATION / MAXIMIZATION
     * @param solver
     * @param strict enables to find same value solutions when set to false
     */
    public IntObjectiveManager(final IntVar objective, ResolutionPolicy policy, Solver solver, boolean strict) {
        super(policy,solver.getMeasures());
        this.objective = objective;
        if (policy != ResolutionPolicy.SATISFACTION) {
            this.bestKnownLowerBound = objective.getLB();
            this.bestKnownUpperBound = objective.getUB();
        }
        this.strict = strict;
    }

    /**
     * Creates an optimization manager
     * Enables to cut "worse" solutions
     *
     * @param objective variable (represent the value of a solution)
     * @param policy    SATISFACTION / MINIMIZATION / MAXIMIZATION
     * @param solver
     */
    public IntObjectiveManager(final IntVar objective, ResolutionPolicy policy, Solver solver) {
        this(objective, policy, solver, true);
    }

    public Integer getBestSolutionValue() {
        if (policy == ResolutionPolicy.MINIMIZE) {
            return bestKnownUpperBound;
        }
        if (policy == ResolutionPolicy.MAXIMIZE) {
            return bestKnownLowerBound;
        }
        throw new UnsupportedOperationException("There is no objective variable in satisfaction problems");
    }

    public IntVar getObjective() {
        return objective;
    }

    /**
     * @return the best lower bound computed so far
     */
    public int getBestLB() {
        return bestKnownLowerBound;
    }

    /**
     * @return the best upper bound computed so far
     */
    public int getBestUB() {
        return bestKnownUpperBound;
    }
<commit_msg>enable to overwrite obj bounds<commit_after>/*
 * Copyright (c) 1999-2012, <NAME>
 * All rights reserved.
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the Ecole des Mines de Nantes nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

package solver.objective;

import solver.ResolutionPolicy;
import solver.Solver;
import solver.exception.ContradictionException;
import solver.explanations.Deduction;
import solver.explanations.Explanation;
import solver.explanations.VariableState;
import solver.variables.IntVar;

/**
 * Class that monitors the objective function and avoid exploring "worse" solutions
 *
 * @author <NAME>
 * @since Oct. 2012
 */
public class IntObjectiveManager extends ObjectiveManager {

    final IntVar objective;
	final boolean strict;
    int bestKnownUpperBound;
    int bestKnownLowerBound;

    /**
     * Creates an optimization manager
     * Enables to cut "worse" solutions
     *
     * @param objective variable (represent the value of a solution)
     * @param policy    SATISFACTION / MINIMIZATION / MAXIMIZATION
     * @param solver
     * @param strict enables to find same value solutions when set to false
     */
    public IntObjectiveManager(final IntVar objective, ResolutionPolicy policy, Solver solver, boolean strict) {
        super(policy,solver.getMeasures());
        this.objective = objective;
        if (policy != ResolutionPolicy.SATISFACTION) {
            this.bestKnownLowerBound = objective.getLB();
            this.bestKnownUpperBound = objective.getUB();
        }
        this.strict = strict;
    }

    /**
     * Creates an optimization manager
     * Enables to cut "worse" solutions
     *
     * @param objective variable (represent the value of a solution)
     * @param policy    SATISFACTION / MINIMIZATION / MAXIMIZATION
     * @param solver
     */
    public IntObjectiveManager(final IntVar objective, ResolutionPolicy policy, Solver solver) {
        this(objective, policy, solver, true);
    }

    public Integer getBestSolutionValue() {
        if (policy == ResolutionPolicy.MINIMIZE) {
            return bestKnownUpperBound;
        }
        if (policy == ResolutionPolicy.MAXIMIZE) {
            return bestKnownLowerBound;
        }
        throw new UnsupportedOperationException("There is no objective variable in satisfaction problems");
    }

    public IntVar getObjective() {
        return objective;
    }

    /**
     * @return the best lower bound computed so far
     */
    public int getBestLB() {
        return bestKnownLowerBound;
    }

	/**
	 * States that lb is a global lower bound on the problem
	 * @param lb lower bound
	 */
	public void updateBestLB(int lb) {
		bestKnownLowerBound = Math.max(bestKnownLowerBound,lb);
	}

	/**
	 * States that ub is a global upper bound on the problem
	 * @param ub upper bound
	 */
	public void updateBestUB(int ub) {
		bestKnownUpperBound = Math.min(bestKnownUpperBound,ub);
	}

    /**
     * @return the best upper bound computed so far
     */
    public int getBestUB() {
        return bestKnownUpperBound;
    }

{'fraction_non_alphanumeric': 0.06641721234798878, 'fraction_numerical': 0.002806361085126286, 'mean_word_length': 3.186490455212922, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '4627710', 'n_tokens_mistral': 2318, 'n_tokens_neox': 2095, 'n_words': 888}