All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.chocosolver.solver.constraints.set.PropIntCstMemberSet Maven / Gradle / Ivy

There is a newer version: 4.10.17
Show newest version
/*
 * This file is part of choco-solver, http://choco-solver.org/
 *
 * Copyright (c) 2023, IMT Atlantique. All rights reserved.
 *
 * Licensed under the BSD 4-clause license.
 *
 * See LICENSE file in the project root for full license information.
 */
/**
 * Created by IntelliJ IDEA.
 * User: Jean-Guillaume Fages
 * Date: 14/01/13
 * Time: 16:36
 */

package org.chocosolver.solver.constraints.set;

import org.chocosolver.solver.constraints.Propagator;
import org.chocosolver.solver.constraints.PropagatorPriority;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.variables.SetVar;
import org.chocosolver.util.ESat;

/**
 * Propagator for Member constraint: int cst is in set
 *
 * @author Jean-Guillaume Fages
 */
public class PropIntCstMemberSet extends Propagator {

    //***********************************************************************************
    // VARIABLES
    //***********************************************************************************

    private final int cst;

    //***********************************************************************************
    // CONSTRUCTORS
    //***********************************************************************************

    /**
     * Propagator for Member constraint: cst is in setVar
     *
     * @param setVar a set variable
     * @param cst a constant (int)
     */
    public PropIntCstMemberSet(SetVar setVar, int cst) {
        super(new SetVar[]{setVar}, PropagatorPriority.UNARY, false);
        this.cst = cst;
    }

    //***********************************************************************************
    // METHODS
    //***********************************************************************************

    @Override
    public void propagate(int evtmask) throws ContradictionException {
		vars[0].force(cst,this);
		setPassive();
    }

    @Override
    public ESat isEntailed() {
		if(vars[0].getLB().contains(cst)){
			return ESat.TRUE;
		}else if(vars[0].getUB().contains(cst)){
			return ESat.UNDEFINED;
		}else{
			return ESat.FALSE;
		}
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy