org.chocosolver.solver.constraints.nary.binPacking.PropItemToLoad Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of choco-solver Show documentation
Show all versions of choco-solver Show documentation
Open-source constraint solver.
/*
* 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;
}
}