Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

Golomb Rulers

  • 1.  Golomb Rulers

    Posted Thu February 19, 2009 04:46 PM

    Originally posted by: SystemAdmin


    [polochon said:]

    Hi,
    I try to implemente the Golomb Rulers problem, I try it with a simple exemple (m=4) but I have an erroneous result (x=(0, 1, 2, 3))
    to express  the inequality, we have the " !=" operator no?!
    this is my code :

    int m=...;

    dvar int x[1..m] in 0..m*m;

    minimize x[m];
    subject to {
        forall (i in 1..m-1)
            x[i] < x&#91;i+1&#93;;<br />    forall (i in 1..m, j in 1..m,
               k in 1..m, l in 1..m: (i < j, k < l))<br />       x[j] - x[i] != x[l] - x[k];
    }

    #DecisionOptimization
    #OPLusingCPOptimizer


  • 2.  Re: Golomb Rulers

    Posted Thu February 19, 2009 05:07 PM

    Originally posted by: SystemAdmin


    [alain.chabrier said:]

    Hi,
    missing parenthesis ?

      (x[j] - x[i]) != (x[l] - x[k]);

    operators precedence are given somewhere in the documentation.

    Alain
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 3.  Re: Golomb Rulers

    Posted Thu February 19, 2009 05:09 PM

    Originally posted by: SystemAdmin


    [polochon said:]

    I try also with parenthesis but no way...
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 4.  Re: Golomb Rulers

    Posted Sun February 22, 2009 05:39 PM

    Originally posted by: SystemAdmin


    [polochon said:]

    is there someone to execute this program and tell me the result?
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 5.  Re: Golomb Rulers

    Posted Wed March 18, 2009 01:27 AM

    Originally posted by: SystemAdmin


    [shaw said:]

    Hello,

    It seems that you have an error in your model because
    there are values of i,j,k,l for which j-i = l-k and so your
    difference constraint is necessarily violated.

    Perhaps you mean:

    forall (i,j,k,l in 1..m : i < j && k < l && i < k && j < l)<br />  x[j] - x[i] != x[l] - x[k]


    Paul

    #DecisionOptimization
    #OPLusingCPOptimizer


  • 6.  Re: Golomb Rulers

    Posted Wed March 18, 2009 11:24 AM

    Originally posted by: SystemAdmin


    [polochon said:]

    Hello,

    thanks Paul, I think that I see the problem, I must have :

    forall (i,j,k,l in 1..m : i < j && k < l && (i != k || j != l))<br />   x[j] - x[i] != x[l] - x[k]

    we can also have for example : x[3]-x[5] != x[2]-x[5]

    so, i != k  or j != l
    [b]

    I try it and it works fine :)
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 7.  Re: Golomb Rulers

    Posted Wed March 18, 2009 11:38 AM

    Originally posted by: SystemAdmin


    [shaw said:]

    Thanks for decoding my reply.  A typo seems to have corrupted
    the last expression and its font.  I just wanted to follow up to say
    that your filtering expression on the forall can be stronger than the
    one you use.  For example, adding the difference constraint on

    x[5] - x[2] != x[6] - x[2]

    is pointless.  In addition, you don't break symmetries with your rule
    and so you will add each difference constraint twice.  i.e. you would also add:

    x[6] - x[2] != x[5] - x[2]


    Paul
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 8.  Re: Golomb Rulers

    Posted Wed March 18, 2009 11:47 AM

    Originally posted by: SystemAdmin


    [polochon said:]

    That's true, my goal is to shift from a model to another more performed, I reformulate the last constraint by:


    forall (i in 1..m, j in 1..m: i < j)<br />d[i,j]=x[j]-x[i];

    alldifferent(all(i in 1..m, j in 1..m: i < j) d&#91;i,j&#93;);<br />

    thanks Paul,
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 9.  Re: Golomb Rulers

    Posted Wed March 18, 2009 12:13 PM

    Originally posted by: SystemAdmin


    [polochon said:]

    Hello,

    does the alldiff constraint (ex. alldifferent(all(i in 1..m, j in 1..m: i < j) d[i,j]) ) exist in CP Optimizer?
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 10.  Re: Golomb Rulers

    Posted Wed March 18, 2009 10:37 PM

    Originally posted by: SystemAdmin


    [Didier Vidal said:]

    does the alldiff constraint (ex. alldifferent(all(i in 1..m, j in 1..m: i < j) d&#91;i,j&#93;) ) exist in CP Optimizer?<br />
    Yes it does. Search the keyword 'allDifferent' (with capitalized D) in the OPL documentation.

    Didier.
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 11.  Re: Golomb Rulers

    Posted Thu March 19, 2009 11:55 AM

    Originally posted by: SystemAdmin


    [polochon said:]

    Thanks Didier, it works fine with allDifferent.

    I have another question :) , I'd like to define a matrix d[i,j] that will be initialised to x[j]-x[i] :


    ...
    int d[1..m,1..m]=...;
    ...
    subject to{
    ...
    forall (i in 1..m, j in 1..m : i < j)<br /> d[i,j] == x[j]-x[i];
    ...
    }


    how to do that?
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 12.  Re: Golomb Rulers

    Posted Fri March 20, 2009 05:42 PM

    Originally posted by: SystemAdmin


    [shaw said:]

    Hello,

    Perhaps you want this?

    dexpr int d[i in 1..m][j in 1..m] = x[j]-x[i];



    Paul
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 13.  Re: Golomb Rulers

    Posted Fri March 27, 2009 02:36 PM

    Originally posted by: SystemAdmin


    [polochon said:]

    Thanks Paul,
    I have now another problem :


    dexpr int d[i in 1..m][j in 1..m] = x[j]-x[i];
    .
    .
    .

    allDifferent(all(i in 1..m, j in 1..m : i < j) d&#91;i,j&#93;);<br />

    I have an error on the allDifferent, the message is :


    Argument type mismatch calling function operatorALL (float):[range] with arguments range, dexpr int.

    #DecisionOptimization
    #OPLusingCPOptimizer


  • 14.  Re: Golomb Rulers

    Posted Thu April 02, 2009 05:52 PM

    Originally posted by: SystemAdmin


    [Didier Vidal said:]

    The allDifferent constraint works only on decision variables, not on decision expression. So You have to change a bit your model. See below an example that uses a tuple set to define only the variables you need.


    using CP;

    int m = 10;
    dvar int x[1..m] in 0..1000;

    tuple indexerTuple {
    int i;
    int j;
    }
    {indexerTuple} indexes = {<i, j> | i,j in 1..m : i < j};<br />// No longer define d as a dexpr
    dvar int d[indexes];

    constraints {
    // Then force values of d by a constraint
    forall(ind in indexes)
      d[ind] == x[ind.j]-x[ind.i];


    // allDifferent statement applies on the array of decision variables
    allDifferent(d);

    }



    Didier.
    #DecisionOptimization
    #OPLusingCPOptimizer


  • 15.  Re: Golomb Rulers

    Posted Thu April 02, 2009 06:25 PM

    Originally posted by: SystemAdmin


    [polochon said:]

    Thanks Didier, it works fine :)

    Nadjib.
    #DecisionOptimization
    #OPLusingCPOptimizer