Topic
  • 4 replies
  • Latest Post - ‏2013-07-05T14:24:59Z by MFC
MFC
MFC
5 Posts

Pinned topic How can we set the timeLimit after getting the first feasible solution (CP Improve Solution)

‏2013-07-03T16:54:18Z |

Hi, 

Is there a way of setting the optimization parameters before and after getting the first feasible solution. I prefer to get some feasible solution, but after getting a feasible solution, don't want to spend too much time for improving it. 

So I need something like

TimeLimit (before the first feasible solution) = 1000

TimeLimit (after the first feasible solution) = 500

FailLimit (before the first feasible solution) = 3000

FailLimit (after the first feasible solution) = 600

Seems like the profiler is already keeping these times separately, such as CP Search, CP Improve Solution.

Thanks in advance, 

  • PhilippeLaborie
    PhilippeLaborie
    44 Posts
    ACCEPTED ANSWER

    Re: How can we set the timeLimit after getting the first feasible solution (CP Improve Solution)

    ‏2013-07-04T07:12:17Z  

    Hello,

    I suppose from your question that you are using OPL. You can iterate over the solutions and change the limits on the engine after the first solution is found. You can do this with some scripting in you OPL model. For instance:

    main {
      var TimeLimitFirstSolution = 1000;
      var TimeLimitImprovement   = 500;
      var FailLimitFirstSolution = 300000;
      var FailLimitImprovement   = 60000;
      cp.param.TimeLimit = TimeLimitFirstSolution;
      cp.param.FailLimit = FailLimitFirstSolution;
     
      var model = thisOplModel;
      model.generate();
      cp.startNewSearch();
      var nSol = 0;
      writeln("Searching for first solution with initial limits");
      while(cp.next()) {
        if (nSol == 0) {
          writeln("First solution found, changing limits");
          cp.param.TimeLimit = TimeLimitImprovement;
          cp.param.FailLimit = FailLimitImprovement;
          nSol++;
        }      
        model.postProcess();
      }
    }

    Philippe

  • PhilippeLaborie
    PhilippeLaborie
    44 Posts

    Re: How can we set the timeLimit after getting the first feasible solution (CP Improve Solution)

    ‏2013-07-04T07:12:17Z  

    Hello,

    I suppose from your question that you are using OPL. You can iterate over the solutions and change the limits on the engine after the first solution is found. You can do this with some scripting in you OPL model. For instance:

    main {
      var TimeLimitFirstSolution = 1000;
      var TimeLimitImprovement   = 500;
      var FailLimitFirstSolution = 300000;
      var FailLimitImprovement   = 60000;
      cp.param.TimeLimit = TimeLimitFirstSolution;
      cp.param.FailLimit = FailLimitFirstSolution;
     
      var model = thisOplModel;
      model.generate();
      cp.startNewSearch();
      var nSol = 0;
      writeln("Searching for first solution with initial limits");
      while(cp.next()) {
        if (nSol == 0) {
          writeln("First solution found, changing limits");
          cp.param.TimeLimit = TimeLimitImprovement;
          cp.param.FailLimit = FailLimitImprovement;
          nSol++;
        }      
        model.postProcess();
      }
    }

    Philippe

  • MFC
    MFC
    5 Posts

    Re: How can we set the timeLimit after getting the first feasible solution (CP Improve Solution)

    ‏2013-07-05T11:59:45Z  

    Hello,

    I suppose from your question that you are using OPL. You can iterate over the solutions and change the limits on the engine after the first solution is found. You can do this with some scripting in you OPL model. For instance:

    main {
      var TimeLimitFirstSolution = 1000;
      var TimeLimitImprovement   = 500;
      var FailLimitFirstSolution = 300000;
      var FailLimitImprovement   = 60000;
      cp.param.TimeLimit = TimeLimitFirstSolution;
      cp.param.FailLimit = FailLimitFirstSolution;
     
      var model = thisOplModel;
      model.generate();
      cp.startNewSearch();
      var nSol = 0;
      writeln("Searching for first solution with initial limits");
      while(cp.next()) {
        if (nSol == 0) {
          writeln("First solution found, changing limits");
          cp.param.TimeLimit = TimeLimitImprovement;
          cp.param.FailLimit = FailLimitImprovement;
          nSol++;
        }      
        model.postProcess();
      }
    }

    Philippe

    Thanks a lot Philippe.

    A quick question about this script: When the (timeLimit and) failLimit are set second time within the if loop, does it reset the previous failures that happened till getting the first solution, and start counting from zero? For example, if numberOfFailures is 40000 when we got the first solution, then is the remaining failLimit for the improvement 60000-40000=20000? 

    Updated on 2013-07-05T12:16:09Z at 2013-07-05T12:16:09Z by MFC
  • PhilippeLaborie
    PhilippeLaborie
    44 Posts

    Re: How can we set the timeLimit after getting the first feasible solution (CP Improve Solution)

    ‏2013-07-05T13:21:21Z  
    • MFC
    • ‏2013-07-05T11:59:45Z

    Thanks a lot Philippe.

    A quick question about this script: When the (timeLimit and) failLimit are set second time within the if loop, does it reset the previous failures that happened till getting the first solution, and start counting from zero? For example, if numberOfFailures is 40000 when we got the first solution, then is the remaining failLimit for the improvement 60000-40000=20000? 

    No, it does not restart counting from 0, it just changes the limit but the reference is always the beginning of the search. Note that you can access the current information on the engine (current number of failures, current time) in order to emulate restarting the limit:

    cp.param.TimeLimit = cp.info.SolveTime     + TimeLimitImprovement;
    cp.param.FailLimit = cp.info.NumberOfFails + FailLimitImprovement;

     

    Philippe

  • MFC
    MFC
    5 Posts

    Re: How can we set the timeLimit after getting the first feasible solution (CP Improve Solution)

    ‏2013-07-05T14:24:59Z  

    No, it does not restart counting from 0, it just changes the limit but the reference is always the beginning of the search. Note that you can access the current information on the engine (current number of failures, current time) in order to emulate restarting the limit:

    cp.param.TimeLimit = cp.info.SolveTime     + TimeLimitImprovement;
    cp.param.FailLimit = cp.info.NumberOfFails + FailLimitImprovement;

     

    Philippe

    Great!