Topic
IC4NOTICE: developerWorks Community will be offline May 29-30, 2015 while we upgrade to the latest version of IBM Connections. For more information, read our upgrade FAQ.
1 reply Latest Post - ‏2013-02-07T14:06:26Z by SystemAdmin
SystemAdmin
SystemAdmin
623 Posts
ACCEPTED ANSWER

Pinned topic Problem to show all solutions

‏2013-02-06T22:43:15Z |
Hi,

I would like to find all possible solution in my example (the color map problem) but it gives me an error in the main block with the variables, maybe someone can give me a hand with the syntaxis? This is my exemple:

code

using CP;

range r = 0..2;
string Names[r] = ;

dvar int AO in r;
dvar int TN in r;
dvar int AS in r;
dvar int Q in r;
dvar int NG in r;
dvar int V in r;

execute {
cp.param.SearchType = "DepthFirst";
}

subject to {
AO != TN;
AO != AS;
TN != AS;
TN != Q;
AS != Q;
AS != NG;
AS != V;
Q != NG;
NG != V;
}

main {
thisOplModel.generate();
cp.startNewSearch();
var n=0;
while (cp.next()) {
n=n+1;
writeln("Solution:", n," -> AO:", thisOplModel.NombresAO ,
"TN:" ,thisOplModel.NombresTN ,
"AS:" ,thisOplModel.NombresAS ,
"Q:" ,thisOplModel.Nombres[Q] ,
"NG:" ,thisOplModel.NombresNG ,
"V:" ,thisOplModel.Nombres[V]);
}
cp.endSearch();
}
[/code]
Updated on 2013-02-07T14:06:26Z at 2013-02-07T14:06:26Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    623 Posts
    ACCEPTED ANSWER

    Re: Problem to show all solutions

    ‏2013-02-07T14:06:26Z  in response to SystemAdmin
    Hello,
    What is the error message?
    When I run your model I first get:

    
    syntax error, unexpected 
    ';'    5:19-20 model.mod
    


    Which seems to suggest that array Names is not initialized at line 5:

    
    string Names[r] = ;
    


    And if I comment the above line (Names is not used anywhere else), I get another error:

    
    Execution of 
    "main" failed: 
    "model.mod", line 36: Element 
    "NombresAO" does not exist in OPL model
    


    That seems to suggest that NombresAO does not exist in the model, which is indeed true again.

    Now if I use the right variable names as follows:

    
    using CP;   range r = 0..2; 
    //string Names[r] = ;   dvar 
    
    int AO in r; dvar 
    
    int TN in r; dvar 
    
    int AS in r; dvar 
    
    int Q  in r; dvar 
    
    int NG in r; dvar 
    
    int V  in r;   execute 
    { cp.param.SearchType = 
    "DepthFirst"; 
    }   subject to 
    { AO != TN; AO != AS; TN != AS; TN != Q; AS != Q; AS != NG; AS != V; Q  != NG; NG != V; 
    }   main 
    { thisOplModel.generate(); cp.startNewSearch(); var n=0; 
    
    while (cp.next()) 
    { n=n+1; writeln(
    "Solution:", n,
    " -> AO:", thisOplModel.AO , 
    " TN:", thisOplModel.TN , 
    " AS:", thisOplModel.AS , 
    " Q:", thisOplModel.Q , 
    " NG:", thisOplModel.NG , 
    " V:", thisOplModel.V); 
    } cp.endSearch(); 
    }
    


    I get :

    
    Solution:1 -> AO:0 TN:2 AS:1 Q:0 NG:2 V:0 Solution:2 -> AO:2 TN:1 AS:0 Q:2 NG:1 V:2 Solution:3 -> AO:0 TN:1 AS:2 Q:0 NG:1 V:0 Solution:4 -> AO:1 TN:2 AS:0 Q:1 NG:2 V:1 Solution:5 -> AO:1 TN:2 AS:0 Q:1 NG:2 V:1 Solution:6 -> AO:2 TN:0 AS:1 Q:2 NG:0 V:2 Solution:7 -> AO:1 TN:0 AS:2 Q:1 NG:0 V:1 Solution:8 -> AO:0 TN:2 AS:1 Q:0 NG:2 V:0 Solution:9 -> AO:2 TN:1 AS:0 Q:2 NG:1 V:2 Solution:10 -> AO:1 TN:0 AS:2 Q:1 NG:0 V:1 Solution:11 -> AO:2 TN:0 AS:1 Q:2 NG:0 V:2
    


    Is it what you expect?

    Philippe