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

org.chocosolver.solver.constraints.nary.binPacking.PropItemToLoad 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) 2019, IMT Atlantique. All rights reserved.
 *
 * Licensed under the BSD 4-clause license.
 *
 * See LICENSE file in the project root for full license information.
 */
package org.chocosolver.solver.constraints.nary.binPacking;

import org.chocosolver.memory.IStateInt;
import org.chocosolver.solver.constraints.Propagator;
import org.chocosolver.solver.constraints.PropagatorPriority;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.delta.IIntDeltaMonitor;
import org.chocosolver.solver.variables.events.IntEventType;
import org.chocosolver.util.ESat;
import org.chocosolver.util.procedure.UnaryIntProcedure;
import org.chocosolver.util.tools.ArrayUtils;

import static org.chocosolver.solver.variables.events.IEventType.ALL_EVENTS;

/**
 * Propagator for a Bin Packing constraint
 * Propagates item/bin allocations to bin loads
 * Reacts to item/bin allocation variables only
 *
 * Should be used together with PropLoadToItem
 *
 * @author Jean-Guillaume Fages
 */
public class PropItemToLoad extends Propagator {

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

	private int nbItems, nbAvailableBins, offset;
	private int[] itemSize;
	private IntVar[] binOfItem, binLoad;

	// backtrackable counters
	private IStateInt[] minLoad, maxLoad;

	// structure allowing iteration over removed values since last call
	private IIntDeltaMonitor[] monitors;

	// method to be called for each removed value
	private UnaryIntProcedure procedure = new UnaryIntProcedure() {
		int item;
		@Override
		public UnaryIntProcedure set(Integer itemIdx) {
			item = itemIdx;
			return this;
		}
		@Override
		public void execute(int bin) throws ContradictionException {
			bin -= offset;
			if(bin>=0 && bin =0 && val= offset && val=0 && bin =nbAvailableBins+offset){
					return ESat.FALSE;
				}
			}
		}
		for(int b=0; b binLoad[b].getUB() || max < binLoad[b].getLB()){
				return ESat.FALSE;
			}
		}
		if(isCompletelyInstantiated()){
			return ESat.TRUE;
		}
		return ESat.UNDEFINED;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy