Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

the constraint to sum of total time very very slow

  • 1.  the constraint to sum of total time very very slow

    Posted Fri January 23, 2015 10:37 AM

    Originally posted by: JuanCarlosPego


    Hi, I'm trying to model the OPL CrewScheduling example within CP OPTIMIZER. The calculation of the solution works pretty fast for 100 but when I try to throw for more than 100 hangs. The last test flights realized for 1500 and I had to kill the process after 24 hours of calculation. Specifically cvrpair.mod file. The constraint that makes you go slow is number 6.

        IloInt nSeq    = 10;
        IloInt maxTime = 600;    // maximum time between the nSeq flights
        IloInt nbFlight=100;  // Flights

        IloIntVarArray vloMembers(env, nSeq, 0, nbFlight);    

        // Constraint 1
        // El vuelo X tiene que estar en el pair
            model.add(IloCount(vloMembers, IdVlo) == 1);

        // Constraint 2        
        // El pair tiene que comenzar en la base X
            model.add(citySeq[vloMembers[0]] == IdBase);

        // Constraint 3    
        // el origen del pair tiene que ser igual al final
             model.add(citySeq[vloMembers[0]] == citySeq[vloMembers[nSeq-1]]);
            
        // Constraint 4                
            for (IloInt i = 1; i < nSeq; i++){
                 model.add(Arr[vloMembers[i-1]]+minStop<Dep[vloMembers[i]] || (Arr[vloMembers[i-1]]+minStop>=Dep[vloMembers[i]] && Arr[vloMembers[i]]==0));
                 model.add(citySeq[vloMembers[i-1]]==citySeq[vloMembers[i]]);
            }        

        // Constraint 5                
            for(IloInt i = 1; i < nSeq; i++){
                for(IloInt j = i+1; j < nSeq; j++){
                    model.add(IloIfThen(env,(citySeq[vloMembers[i-1]]==citySeq[vloMembers[i]]),(citySeq[vloMembers[j-1]]==citySeq[vloMembers[j]])));
                }
             }        
            
        // Constraint 6        ** very very slow  ***        
            IloIntExpr Sum_time(env);
             for (i = 0; i < nSeq; i++){
                 Sum_time=Sum_time+(Arr[vloMembers[i]]-Dep[vloMembers[i]]);
             }
             model.add(Sum_time<maxTime);
            Sum_time.end();
            
            
             // order the vloMembers to break symmetry
            for (i = 0; i < nSeq-1; i++)    model.add(vloMembers[i] <= vloMembers[i+1]);
            
            IloCP cp(model);
            cp.setParameter(IloCP::LogVerbosity, IloCP::Quiet);
            cp.setParameter(IloCP::SearchType, IloCP::DepthFirst);
            cp.setParameter(IloCP::Workers, 1);
            cp.startNewSearch();
            int contador=0;
            while (cp.next() && contador<10) {
                for (i = 0; i < nSeq; i++){
                    tuple[i] = cp.getValue(vloMembers[i]);
                    ....
                
                contador++;            
            }
            ...

     

     

    thank you very much.

    Juan Carlos


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: the constraint to sum of total time very very slow

    Posted Mon January 26, 2015 12:41 PM

    Originally posted by: ol


    Hello,

    I see:

        cp.setParameter(IloCP::SearchType, IloCP::DepthFirst);

    Did you try without this line? Depth first search is not a good approach for large search space, which seems to be your case. Removing this line will allow CP Optimizer to launch a much more powerful search method.

    Regards,

    Olivier


    #CPOptimizer
    #DecisionOptimization