-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Start and end of tasks are always enforced at root #1119
Comments
Hi, Yes, it is the expected behaviour for the Task objects. However, this is something we are questionning as it can lead to true faulty behaviour, such as the one described in #1114. We still have not decided how we will definitely handle such cases. For the case you have described, I would recommend to declare the propagators yourself : new Constraint(ConstraintsName.CUMULATIVE, new Propagator[]{
new PropGraphCumulative(start, duration, end, demand, capacity, false, Cumulative.Filter.DEFAULT.make(start.length)),
new PropGraphCumulative(start, duration, end, demand, capacity, true, Cumulative.Filter.DEFAULT.make(start.length))
}).impliedBy(bv); |
Hi, thanks for the quick answer!
I'm not really experienced with the Choco solver so not entirely sure how to continue with this. Kind regards, |
Hi, I will look at this in more details at the end of the week. I'll try to find a way to make it work |
Hi, import org.chocosolver.solver.Model;
import org.chocosolver.solver.constraints.Constraint;
import org.chocosolver.solver.constraints.ConstraintsName;
import org.chocosolver.solver.constraints.Propagator;
import org.chocosolver.solver.constraints.nary.cumulative.PropGraphCumulative;
import org.chocosolver.solver.variables.BoolVar;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.constraints.nary.cumulative.Cumulative;
import java.util.ArrayList;
public class Example {
public static void main(String[] args) {
int nJobs = 60;
int nMachines = 4;
int horizon = 329;
int [] capacities = {13,11,12,13};
int [] machines = {0,1,1,1,3,0,2,3,1,3,1,0,3,3,0,0,2,0,0,2,1,2,1,2,0,1,0,2,2,0,3,1,3,2,0,1,0,2,3,3,3,2,3,3,3,0,1,1,2,1,0,1,2,3,2,1,2,3,1,3};
int [] resources = {10,1,9,4,1,10,6,8,6,3,7,8,1,9,6,2,2,7,5,8,4,4,5,1,9,7,3,3,7,6,4,7,4,1,9,7,5,1,5,1,9,6,1,9,7,4,8,2,7,5,2,1,6,7,3,4,9,7,3,1};
int [] duration = {8,1,10,6,5,8,9,1,9,8,3,6,2,5,1,3,10,9,1,3,6,3,3,7,6,10,9,8,4,3,3,6,1,9,9,1,2,4,9,10,8,4,3,6,6,7,3,2,10,4,2,1,4,10,8,6,10,3,10,1,0};
Model model = new Model("RCPSP");
// Define start and end variables
IntVar[] start = new IntVar[nJobs];
IntVar[] end = new IntVar[nJobs];
for (int i = 0; i < nJobs; i++) {
start[i] = model.intVar("start_" + i,0,horizon);
end[i] = model.intVar("end_" + i,0,horizon);
}
for (int mId =0; mId < nMachines; mId++) {
// collect the tasks to run on this machine
ArrayList<IntVar> mStart = new ArrayList<IntVar>() ;
ArrayList<IntVar> mDur = new ArrayList<IntVar>() ;
ArrayList<IntVar> mEnd = new ArrayList<IntVar>() ;
ArrayList<IntVar> mRes = new ArrayList<IntVar>() ;
for (int idx = 0; idx < nJobs; idx++) {
if (machines[idx] == mId) {
mStart.add(start[idx]);
mDur.add(model.intVar(duration[idx]));
mEnd.add(end[idx]);
mRes.add(model.intVar(resources[idx]));
}
}
// cast to arr
BoolVar bv = model.boolVar("Machine"+mId);
IntVar[] arrStart = mStart.toArray(new IntVar[0]);
IntVar[] arrDur = mDur.toArray(new IntVar[0]);
IntVar[] arrEnd = mEnd.toArray(new IntVar[0]);
IntVar[] arrRes = mRes.toArray(new IntVar[0]);
new Constraint(ConstraintsName.CUMULATIVE,new Propagator[]{
new PropGraphCumulative(arrStart, arrDur, arrEnd, arrRes, model.intVar(capacities[mId]), false, Cumulative.Filter.DEFAULT.make(start.length)),
new PropGraphCumulative(arrStart, arrDur, arrEnd, arrRes, model.intVar(capacities[mId]),true,Cumulative.Filter.DEFAULT.make(start.length)),
}).impliedBy(bv);
model.arithm(bv, ">=", 1).post();
}
System.out.println(model.getSolver().findSolution());
}
} |
Il seems that adding the following code solves the problem you are having : for (int i = 0; i < arrStart.length; i++) {
model.arithm(arrStart[i], "+", arrDur[i], "=", arrEnd[i]).impliedBy(bv);
} Code on the branch of MR #1117 works fine on your code without adding the code above, which is a good news, despite this branch having other problems |
Hi,
I'm attempting to model a half-reified Cumulative constraint (see sample code below).
However, while the "non-overlapness" of the Cumulative constraints is correctly reified, the link between start and end variables in the tasks is not reified with it.
E.g., the model with constraints
[e == 1, bv -> Cumulative([s], [3], [e], [1],[1])]
should be satisfied when the Boolean variable is set to False.However, as the task is created at the toplevel of the constraint model, it will fail because of the
e == 1
assignment.Is this considered the expected behaviour of the tasks-constructor? And if so, how should I modify my model to properly reflect a truely half-reified Cumulative constraint?
I'm running on the latest release (v4.10.17)
Kind regards,
Ignace
The text was updated successfully, but these errors were encountered: