Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  CP- Cplex hybrdization

    Posted 03/06/18 06:52 AM

    Originally posted by: AMM1


    hello,

    I am trying to hybridize CP with Cplex for vehicle routing problem

    actually i  have an error 

    (Execution of "main" failed: "C:\Users\Dell\opl\hybridizing VRPTW\hybrid (3).mod", line 53: not of type 'IloTuple': 0. )

    for this (  sol.setValue(opl2.x[i],opl1.x[i]);) 

    how can i fix this error?


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 2.  Re: CP- Cplex hybrdization

    Posted 03/06/18 12:24 PM

    Hi,

    you should use loops with the right indexes.

    For instance line 51 of hybrid .mod you should replace

    for(var i=0;i<=(n+2)*(n+2)-1;i++)

    by

    for(var e in opl1.Edges) for(t=1;t<opl1.m;t++)
      sol.setValue(opl2.x[e][t],opl1.x[e][t]);

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 3.  Re: CP- Cplex hybrdization

    Posted 03/07/18 03:11 AM

    Let me fix your entire flow control because your second warm start from cpo to cplex does not work either.

    regards

     

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 4.  Re: CP- Cplex hybrdization

    Posted 03/07/18 05:13 AM

    Originally posted by: AMM1


    THANK YOU, Mr. Alex, for your help, I really appreciate it :))

    but when I run the code, new error appeared :

    Scripting runtime error: Array argument expected.

    on this line: (cplex.addMIPStart(opl1.x,opl2.results) ;   

     

    the output is :

    iter 1
    cplex objective = 2161
    cplex objective = 2161
    cp objective = 1609
    cpo objective =1609
    // Script execution failed with status -1.

    Regards

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 5.  Re: CP- Cplex hybrdization

    Posted 03/07/18 05:34 AM

    Hi,

    can you move to cplex latest version ? (12.8)

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 6.  Re: CP- Cplex hybrdization

    Posted 03/08/18 02:12 AM

    Originally posted by: AMM1


    good morning Mr, Alex

    I am trying to download version 12.8 since yesterday but this appears to me all the time,

     

    (Your eligibility to order the following items is under review. You will be notified of your eligibility by email. Please retry your order at that time.

    • IBM ILOG CPLEX Optimization Studio v12.8 - Student (CJ2IKML) - Download

    I didn't receive any emails.

     when I try to update it, this error appears to me 

    how can i get this version?

    Regards

     


    #DecisionOptimization


  • 7.  Re: CP- Cplex hybrdization

    Posted 03/08/18 12:02 PM

    Originally posted by: AMM1


    HELLO Mr Alex,

    i tried version 12.8

    i got :iter 1
    cplex objective = 1813
    cp objective = 1714
    cpo objective =1714
    iter 2
    cplex objective = 1813
    cp objective = 1714
    cpo objective =1714
    iter 3
    cplex objective = 1813
    cp objective = 1714
    cpo objective =1714

     and when i run CP alone 

    i got 1506 

    i didnt get it why is it worse when we hybrid them?

     


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 8.  Re: CP- Cplex hybrdization

    Posted 03/08/18 01:01 PM

    Hi,

    in the log do you see anything like

    Warning:  No solution found from 6 MIP starts.

    ?

    This means than when you warmstart in cplex the solution is not accepted by cplex.

    And by the way this hybrid approach works in somes cases and for some other problems this could be less efficient.

    But what I would do first is to change

    cplex.addMIPStart(opl1.x,opl2.results) ; 

    into

    cplex.addMIPStart(opl1.x,opl2.results,3) ; 

    to increase the effort for mipstart

     

    Then on my machine I get

    cplex objective = 1813
    cplex objective = 1813
    cp objective = 1499
    cpo objective =1499
    iter 2
    cplex objective = 1499
    cplex objective = 1499
    cp objective = 1445
    cpo objective =1445

    regards

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 9.  Re: CP- Cplex hybrdization

    Posted 03/22/18 07:56 AM

    Originally posted by: AMM1


    hello Mr. Alex ,

    i have a problem in my cp model 

    i need to add a fixed cost to reduce the number of used vehicles 

    how can i add the fixed cost of the vehicle?

     

     

    my CP model:

     

    using CP;
    tuple Position {
       key int id;
       int x;
       int y;
     };
     
    {Position} Positions = ...;
     
    tuple Demand {
       key int id;
       int q;
       int s;
     };
      {Demand} Demands = ...;
     
    int n = ...;
    int m =...; // Number of trucks
    int K = ...;  
    //tuple distance { int c1; int c2; int dista; };
     
     
    tuple timewin {
    key int l1;  
    key int l2; 
    key int l3;
    }
    timewin lowerbound[d in Demands]=...;
    tuple timewin2 {
    key int u1;  
    key int u2;
    key int u3;

    }

    timewin2 upperbound[d in Demands]=...;
    int ld=...;
    int ud=...;
     
    {int} Customers = { p.id | p in Positions };
    dvar interval visit [d in Demands] size d.s;
    dvar interval tvisit[d in Demands][t in 1..m] optional (101>d.id>=1) size d.s;
    dvar sequence truck[t in 1..m] in all(d in Demands) tvisit[d][t] types all(d in Demands) d.id;
     
    tuple triplet { int c1; int c2; int d; };
    {triplet} Dist = {
    <p1.id,p2.id,ftoi(round(sqrt(pow(p2.x-p1.x,2)+pow(p2.y-p1.y,2))))> | p1, p2 in Positions };
     
     
     int distMatrix[p1 in Positions][p2 in Positions] = ftoi(round(sqrt(pow(p2.x-p1.x,2)+pow(p2.y-p1.y,2)))); 
    int distMatrixById[p1 in Customers][p2 in Customers] = distMatrix[<p1>][<p2>];  
     
     dexpr float truckDistance[t in 1..m] = sum(d in Demands) distMatrixById[d.id][typeOfNext(truck[t], tvisit[d][t], d.id, d.id)];
     dexpr float totalDistance = sum(t in 1..m) truckDistance[t];      
            
     execute {
        writeln(Dist);
     };
      
      
      
     execute {
     
       cp.param.TimeLimit =3600;
       cp.param.TimeMode                = "ElapsedTime";
        cp.param.Workers                 = 1;
        cp.param.NoOverlapInferenceLevel = "Medium";
      cp.param.ElementInferenceLevel   = "Low";
      
     }
      minimize totalDistance;
     
     
     
     constraints {
     forall ( t in 1..m)  {
    forall (d  in Demands: 101>d.id>=1)  {
           upperbound[d].u1 >=startOf(visit[d])>= lowerbound[d].l1   || upperbound[d].u2>=startOf(visit[d])>= lowerbound[d].l2||upperbound[d].u3>=startOf(visit[d])>= lowerbound[d].l3;
       }
       forall(t in 1..m) {   
       
        noOverlap(truck[t],Dist); 
        first(truck[t],tvisit[<0>][t]); // Truck t starts at depot
        last (truck[t],tvisit[<101>][t]); // Truck t ends at depot
        //startOf(tvisit[<101>][t])<=ud;
         
         sum(d in Demands) presenceOf(tvisit[d][t])*d.q <= K;
        }
        
                          
       forall(d in Demands: 101>d.id>=1) {
     // ud>=startOf(visit[d])>=ld;
       alternative(visit[d], all(t in 1..m) tvisit[d][t]); // Truck selection
                                         }
     }

    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 10.  Re: CP- Cplex hybrdization

    Posted 03/22/18 08:28 AM

    Hi

    out of

    dvar interval tvisit[d in Demands][t in 1..m] optional (101>d.id>=1) size d.s;

    you could write a dvar boolean array

    dvar boolean isTruckUsed[t in 1..m]

    and use that array in your objective.

    regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer


  • 11.  Re: CP- Cplex hybrdization

    Posted 04/26/18 06:38 AM

    Originally posted by: AMM1


    Hello Mr. Alex,

    I tried to combine MIP and CP using the same method mentioned and it worked for small sized problems of vehicle routing problem.

     

    Now, I am trying to combine both MIP and CP in one model ( relating MIP variables to CP variables such as:

    1.relating x(i)(j)(k) which is a boolean variable which give value 1 if  j immediately  precedes i, to the interval variable tvisit[d in Demands][t in 1..m] optional (101>d.id>=1) size d.s which ) 

    2. relating sequence variable to z(i)(k) which is a boolean variable which gives value 1 if client i is served using vehicle k)

    so I want to solve the combination of CP and Cplex in one model 

    how can I do that?

     

    Regards


    #DecisionOptimization
    #OPLusingCPLEXOptimizer