Combine Assignment and Element

  • Graeme

    I have and array of objects I'd like to place in a larger space, i.e. object 1-5 go into spaces 1-10, with some rules. To apply the rules I need to access the properites of each x. To do this I have tried to combine the Assingment and Element constraints, but it fails for reasons which are not clear to me. Here is some example code:-

    int xl=5;
    int dl=7;
    int f = {2,7,4,9,1};
    Store store=new Store();
    IntVar xs=new IntVar;
    IntVar ys=new IntVar;
    IntVar ds=new IntVar;
    for(int i=0;i<xl;i++) {
    xs_=new IntVar(store,"x_"+i,0,dl);

    for(int i=0;i<dl;i++) {
    ds=new IntVar(store,"d_"+i,0,xl);
    ys=new IntVar(store,"y_"+i,0,10);
    store.impose(new Assignment(xs,ds));
    for(int i=0;i<dl;i++) {
    store.impose(new Element(ds,f,ys));
    if(store.consistency()) {
    } else {

    This will always print out bad, but it is not clear to me why this wouldn't work._

  • kris

    I am sorry but we do not have resources to analyze your problem and constraints. A good method to get more insight for you is to run your program with some constraints and see what are domains of variables after consistency.


  • Hi,

    Your description is not clear.

    You need to expand on your description. You need to provide an example with a proposal of a good solution that should be found by JaCoP solver but it is not found. I may be able to have better clue what is your problem. 

    If you were aiming for 1D space and you have objects of length 1 then you should use one of the versions of Alldifferent (e.g. Alldiff). Assignment seems rather bad choice for your problem.

    Did you consult guide to make sure that you did not misunderstood the semantic of the Assignment constraint?