<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-15">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    Hello,<br>
    <br>
    I have a little problem adding a preprocessing step to program doing
    MIP solving using the CBC library. The problem is, that the program
    fails with more or less random memory corruption (and in the better
    cases: with a segfault) some of the time.<br>
    <br>
    The CbcModel instance is created programmatically<br>
    <blockquote><small><font face="Courier New, Courier, monospace">OsiClpSolverInterface
          iface;<br>
          CoinPackedMatrix pmx(false, num_columns, num_rows,
          num_elements, matrix, columns, starts, lengths);<br>
                          <br>
          iface.setObjSense(-1.0);<br>
          iface.loadProblem(pmx, 0, 0, objective, senses, rights, 0);<br>
          iface.passInMessageHandler(&amp;printer);<br>
                          <br>
          model_ptr LP(new CbcModel(iface));<br>
          ... adding stuff via LP-&gt;addObjects(...) to declare integer
          constraints on variables and a few SOSes ...</font></small><br>
    </blockquote>
    Things work fine, if we directly compute a solution without further
    preprocessing via<br>
    <blockquote><font face="Courier New, Courier, monospace"><small>LP-&gt;initialSolve();<br>
          LP-&gt;branchAndBound();</small></font><br>
    </blockquote>
    We now try to add a pre-processing step to the solution process. As
    a starting point, we used the driver code generated by the CBC
    command line tool ("-cpp 0", which doesn't compile). <br>
    <blockquote><small><font face="Courier New, Courier, monospace">OsiSolverInterface*
          original_solver = LP-&gt;solver();<br>
          OsiSolverInterface* cloned_solver =
          original_solver-&gt;clone();<br>
          OsiSolverInterface* configured_solver = 0;<br>
          <br>
cloned_solver-&gt;passInMessageHandler(LP-&gt;messageHandler());<br>
          cloned_solver-&gt;setHintParam(OsiDoInBranchAndCut, true,
          OsiHintDo);<br>
          <br>
          CglPreProcess processor;<br>
          <br>
                      {<br>
                          CglProbing prober;<br>
                          prober.setUsingObjective(1);<br>
                          prober.setMaxPass(3);<br>
                         
          prober.setMaxProbeRoot(cloned_solver-&gt;getNumCols());<br>
                          prober.setMaxElements(100);<br>
                          prober.setMaxLookRoot(50);<br>
                          prober.setRowCuts(3);<br>
                          processor.addCutGenerator(&amp;prober);<br>
                      }<br>
          <br>
          configured_solver =
          processor.preProcessNonDefault(*cloned_solver, 2, 10); <br>
                      <br>
          cloned_solver-&gt;setHintParam(OsiDoInBranchAndCut, false,
          OsiHintDo);<br>
                      <br>
          if (!configured_solver)<br>
          {<br>
              delete cloned_solver;<br>
              return status::infeasible;<br>
          }<br>
                      <br>
          configured_solver-&gt;setHintParam(OsiDoInBranchAndCut, false,
          OsiHintDo);<br>
          <br>
          OsiSolverInterface* configured_clone =
          configured_solver-&gt;clone();<br>
                      <br>
          LP-&gt;assignSolver(configured_clone, true /* Kill previous
          solver */); /*-- XXX --*/<br>
          LP-&gt;initialSolve();<br>
          LP-&gt;branchAndBound();<br>
                      <br>
          int n_cols = cloned_solver-&gt;getNumCols();<br>
          processor.postProcess(*LP-&gt;solver());<br>
                      <br>
          LP-&gt;assignSolver(cloned_solver, true /* Kill previous
          solver */);<br>
          memcpy(LP-&gt;bestSolution(),
          LP-&gt;solver()-&gt;getColSolution(), n_cols *
          sizeof(double));</font></small><br>
    </blockquote>
    It seems, that we are violating one or two unwritten laws of memory
    management with CBC, but I am at loss as what we are doing wrong
    here. Any help, hints, pointer to documentation, etc. is highly
    appreciated.<br>
    <br>
    Cheers,<br>
    Dirk Eßer<br>
  </body>
</html>