Skip to content

[BUG] Start and end of tasks are always enforced at root #1119

@IgnaceBleukx

Description

@IgnaceBleukx

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?

import org.chocosolver.solver.Model;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.BoolVar;
import org.chocosolver.solver.variables.Task;

public class CumulativeModel {
    public static void main(String[] args) {
        // Create a Choco model
        Model model = new Model("Cumulative Scheduling Model");

        // Define variables
        IntVar[] start = new IntVar[3];
        IntVar[] end = new IntVar[3];
        int[] duration = {3, 3, 3};
        IntVar[] demand = new IntVar[3];
        IntVar capacity = model.intVar("cap", 1,1);

        for (int i = 0; i < 3; i++) {
            start[i] = model.intVar("start[" + i + "]", 0, 5);
            end[i] = model.intVar("end[" + i + "]", 0, 5);
            demand[i] = model.intVar("demand[" + i +"]", 1,1);
        }

        // Make the tasks
        Task[] tasks = new Task[3];
        for (int i = 0; i < 3; i++) {
            tasks[i] = new Task(start[i], duration[i], end[i]);
        }

        // Define the Boolean variable
        BoolVar bv = model.boolVar("bv");
        // Add cumulative constraint wrapped in implication
        model.cumulative(tasks, demand, capacity).impliedBy(bv);

        // Add the constraint end[0] == 1
        model.arithm(end[0], "=", 1).post(); // This makes the model UNSAT

        // Solve the model
        if (model.getSolver().solve()) {
            System.out.println("Solution found:");
            for (int i = 0; i < 3; i++) {
                System.out.println("start[" + i + "] = " + start[i].getValue());
                System.out.println("end[" + i + "] = " + end[i].getValue());
            }
        } else {
            System.out.println("No solution found.");
        }
    }
}

I'm running on the latest release (v4.10.17)

Kind regards,
Ignace

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions