[Cbc] Fwd: Beginner here

Patrik Dufresne info at patrikdufresne.com
Sun Oct 6 12:12:06 EDT 2013


Hello,

I follow your recommendation and it seams their is an issue to reuse the
same OsiClpSolverInterface instance multiple time. After the
branchAndBound(), the bounds of the variables has change to matche the
solution. The following is my original code in Java.

public Status solve(SWIGTYPE_p_OsiClpSolverInterface lp) {
  // Run Pre-solver
  SWIGTYPE_p_CglPreProcess preProcessor = javacbc.newCglPreProcess();
  SWIGTYPE_p_OsiSolverInterface presolvedLp =
javacbc.preProcess(preProcessor, lp, false, 5);
  if (presolvedLp == null) {
      // The solution problem is not feasible.
      return Status.INFEASIBLE;
  }
  javacbc.resolve(presolvedLp);

  SWIGTYPE_p_CbcModel cbcModel = javacbc.newCbcModel(presolvedLp);
  javacbc.initialSolve(cbcModel);
  javacbc.branchAndBound(cbcModel);

  // Get the solver status.
  Status status = checkStatus(cbcModel);

  // Write the solution back to the original model
  SWIGTYPE_p_OsiSolverInterface solver = javacbc.solver(cbcModel);
  javacbc.postProcess(preProcessor, solver);

  // Release the pre-processor
  javacbc.deleteCglPreProcess(preProcessor);

  return status;
}

The problem seams to be related to postProcess(). When it's called, it has
a side effect on "lp" variable. Thus updating the variables bounds. An easy
way to fix this is to create a copy of "lp", but I would prefer to avoid
this.


--
Patrik Dufresne Service Logiciel
http://patrikdufresne.com/
514-971-6442
438-738-1376
114 rue des Hautbois, app1
St-Colomban, QC J5K 2H6


On Sun, Sep 15, 2013 at 9:18 AM, Patrik Dufresne <info at patrikdufresne.com>wrote:

> Hi,
>
> Thanks everyone. Your help make me save a lot of time. I'm very thankful.
>
> --
> Patrik Dufresne Service Logiciel
> http://patrikdufresne.com/
> 514-971-6442
> 438-738-1376
> 114 rue des Hautbois, app1
> St-Colomban, QC J5K 2H6
>
>
> On Thu, Sep 12, 2013 at 3:15 PM, Haroldo Gambini Santos <
> haroldo.santos at gmail.com> wrote:
>
>>  On 12-09-2013 08:08, Patrik Dufresne wrote:
>>
>>
>>  Hi Haroldo,
>>
>> Your answer are very comprehensible. I'm very thankful to get a reply. As
>> I understand, the main idea is to create the problem using
>> OsiClpSolverInterface#addCol() or OsiClpSolverInterface#addRow(). Then I
>> need to call OsiClpSolverInterface#initialSolve(). Questions:
>>
>>  1. I had a look at all the Cbc examples and it does involve the class
>> CbcModel. Should I care about it?
>>
>>  2. As I understand, clp is used to run the simplex algorithm. Cbc is
>> used to run the branch and bound. So I guess I need to run both step
>> explicitly?
>> OsiClpSolverInterface#initialSolve()
>>  CbcModel#branchAndBound()
>>
>> Yes. initialSolve must be called before.
>> CbcModel.branchAndBound will perform a "pure" branch-and-bound (no cuts
>> and heuristics). You can explicitly bind it to other Cbc classes to include
>> these features (which often speed up a lot the search)  or use the function
>>   CbcMain   which will run everything using the same features as if you
>> started the search from the command line.  the code would look more or less
>> as:
>>
>>             CbcModel modelA(*linearProgram);
>>             CbcModel *model = &modelA;
>>             CbcMain0(modelA);
>>             const char * argv2[]={"problemName","-solve","-quit"};
>>             CbcMain1(3, argv2, modelA);
>>
>>
>>
>>
>>
>>  3. Reading the doc about CbcModel, it copy the solver passed in the
>> constructor. What is the suggested approach if I need to reuse the problem
>> over and over?
>> The following is what I think I should do:
>>
>> Since for MIPs there is no good reoptimization technique the cost of
>> creating CbcModel again will probably be small comparedto the cost of
>> reoptimizing an Integer Program.  But the OsiClpSolverInterface you can
>> change and do not need to recreated it again, probably.
>>
>>   a. create new instance of OsiClpSolverInterface named solver1
>> b. call solver1.addCol() and solver1.addRow() to build the problem
>> c. set objective value using solver1.setObjCoeff() and
>> solver1.setObjSense()
>> d. call solver1.initialSolve()
>> e. create new instance of CbcModel(solver1) named model1
>> f. call model1.branchAndBound()
>> g. get the objective value model1.getObjValue()
>>
>> reusing the problem:
>> h. call addCol() or addRow() on solver1
>> i. run step c to g again
>>
>> The end result: I will create a single instance of OsiClpSolverInterface
>> and multiple instance of CbcModel. I also sees a different approach to
>> create a single CbcModel and call CbcModel.solver() to update the problem
>> multiple time. I guess both would work, but what is the "faster" one. The
>> one avoiding memory copy, useless recomputation etc.
>>
>>  4. Using the command line, I notice a performance improvement to solve
>> my problem using the following arguments: cbc .. mps -feas both -doh -solve
>> ... Basically, activating the feasibility pump help alot. As I understand,
>> I need to create a new instance of CbcHeuristicFPump and call
>> CbcModel.addHeuristic( ).
>>
>>
>>
>>  --
>> Patrik Dufresne Service Logiciel
>> http://patrikdufresne.com/
>>  514-971-6442
>> 438-738-1376
>> 114 rue des Hautbois, app1
>> St-Colomban, QC J5K 2H6
>>
>>
>>   On Wed, Sep 11, 2013 at 8:47 PM, Haroldo Gambini Santos <
>> haroldo.santos at gmail.com> wrote:
>>
>>>  Hi Patrick,
>>>
>>>
>>>
>>> On 11-09-2013 21:23, Patrik Dufresne wrote:
>>>
>>> Hello,
>>>
>>>  I'm just getting started with CoinCbc. I found the learning curve very
>>> steep compare to GLPK where everything is documented in details. I'm
>>> struggling with all the object available to create a model and solve it. To
>>> avoid any beginner mistake, I'm asking the mailing list in hope to get tips
>>> for my very specific needs.
>>>
>>>  1. If I want to create a representation of my problem using
>>> variables(columns) and constraints(rows), should I use the OsiClpSolverInterface
>>> or CoinModel?
>>>
>>>  *OsiClpSolverInterface* - this class inherits from OsiSolverInterface
>>> so that any method you use to create/modify your problem will be compatible
>>> with other Osi Interfaces (e.g.: cplex
>>> by using OsiCpxSolverInterface)
>>>
>>> http://www.coin-or.org/Doxygen/Osi/classOsiSolverInterface.html
>>>
>>>
>>>
>>>  2. If I need to do subsequent modification to the problem (e.g.:
>>> adding variables or constraints), can I reuse the same object over and over
>>> again?
>>>
>>>  *Yes*
>>>
>>>  Basically, I need to create a problem. Solve it. Add a new constraint.
>>> Solve it. etc. etc. A snippet would be very welcome.
>>>
>>>  I do not have a small code here, but basically what you need to do is:
>>>
>>> create an OsiClpSolverInterface
>>>
>>> after that you can cast the object to an OsiSolverInterface pointer, so
>>> that all your calls will be solver independent (not required)
>>>
>>> to create your problem:
>>> use methods
>>>
>>>  addCol/addCols, addRow/addRows
>>>
>>> you can also use a CoinBuild object to to create and populate
>>> constraints (I think this is easier) :
>>> http://www.coin-or.org/Doxygen/CoinAll/class_coin_build.html
>>>
>>> basically you add rows to a CoinBuild object and then add this object to
>>> OsiSolverInterface
>>>
>>> after your problem is built you can   call   initialSolve   to solve the
>>> LP
>>>
>>> Cheers
>>>
>>>
>>>  Thanks
>>>
>>>   --
>>> Patrik Dufresne Service Logiciel
>>> http://patrikdufresne.com/
>>>  514-971-6442
>>> 438-738-1376
>>> 114 rue des Hautbois, app1
>>> St-Colomban, QC J5K 2H6
>>>
>>>
>>>  _______________________________________________
>>> Cbc mailing listCbc at list.coin-or.orghttp://list.coin-or.org/mailman/listinfo/cbc
>>>
>>>
>>> --
>>> ==================================================
>>> Haroldo Gambini Santos
>>> D.Sc, Computer Science
>>> Universidade Federal de Ouro Pretohttp://www.decom.ufop.br/haroldo/
>>>
>>>
>>
>>
>>
>> _______________________________________________
>> Cbc mailing listCbc at list.coin-or.orghttp://list.coin-or.org/mailman/listinfo/cbc
>>
>>
>> --
>> ==================================================
>> Haroldo Gambini Santos
>> D.Sc, Computer Science
>> Universidade Federal de Ouro Pretohttp://www.decom.ufop.br/haroldo/
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cbc/attachments/20131006/d1ff20f2/attachment.html>


More information about the Cbc mailing list