Skip to content
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] IntVar.eq(...) creating new variables in the model. #743

Open
MathieuVavrille opened this issue Nov 12, 2020 · 2 comments
Open

[BUG] IntVar.eq(...) creating new variables in the model. #743

MathieuVavrille opened this issue Nov 12, 2020 · 2 comments
Assignees
Labels

Comments

@MathieuVavrille
Copy link
Collaborator

I found out that posting an equality constraint on IntVar can create new variables in the model. An example of code showing that variables are created is the following:

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

public class TestModel {

  public static Model generateModel() {
    Model model = new Model("TestModel");
    IntVar[] vars = model.intVarArray("x", 4, 1, 2);
      for (int j = 0; j < 3; j++) {
        vars[j].eq(j%2+1).post();
      }
    return model;
  }
}

On the first time executing the line when posting the constraint, two variables are created, on the second time, one variable is created, and on the third time no variable is created.
After testing a little, it seems that creation of variables depends on the lower bound of the variables, and on the constant in the equality (in this case, the constants are either 1 or 2, so only two different variables are created).

@cprudhom cprudhom self-assigned this Nov 12, 2020
@cprudhom cprudhom added the bug label Nov 12, 2020
@cprudhom cprudhom added this to the 4.10.6 milestone Nov 12, 2020
@cprudhom
Copy link
Member

It is related to scalar conversion. It turns the int into an IntVar to ease linear combination reduction.
I suppose this needs to be revamped.
I let you know.

@cprudhom
Copy link
Member

In fact, it is more related to BiReExpression which was initially designed to deal with 2 IntVars.
Here, one element of the binary relation is an int, so it is automatically turned into a IntVar.

@cprudhom cprudhom modified the milestones: 4.10.6, 4.10.7 Dec 9, 2020
@cprudhom cprudhom modified the milestones: 4.10.7, 4.10.8 Jul 21, 2021
@cprudhom cprudhom removed this from the 4.10.8 milestone Jan 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants