<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">Alessio,<br>
      <br>
      I would not use OsiCbc.<br>
      <br>
      To avoid Cbc getting confused, it is probably best to create a
      clean CbcModel from the master CoinModel each time - that way
      bounds won't be preset.<br>
      <br>
      John Forrest<br>
      On 10/06/15 19:49, Alessio Melosi wrote:<br>
    </div>
    <blockquote
cite="mid:CAC5qgMiWt8g1AbycGAARYaAdRcSgdfuABd2s5pvGhNr6yvE-Pg@mail.gmail.com"
      type="cite">
      <div dir="ltr">
        <div>
          <div>
            <div>
              <div>
                <div>
                  <div>
                    <div>
                      <div>
                        <div>
                          <div>
                            <div>
                              <div>
                                <div>
                                  <div>Hello, I have some problem with
                                    my c++ code for the resolution of
                                    the capacitated facility location
                                    problem (CFL) with the Benders
                                    method. It is an iterative method
                                    that at each step has to solve a
                                    continuous subproblem, generate a
                                    new constraint for the master
                                    problem (which has one continuous
                                    variable and m-1 binary variables),
                                    solve the master problem and use the
                                    master solution to update the
                                    righthandsides of the subproblem for
                                    the next iteration. Here is the
                                    pseudo-code of my algorithm:<br>
                                    <br>
*****************************************************************<br>
                                    BEGIN<br>
                                    read the input;<br>
                                    create a model for the master
                                    problem using CoinModel;<br>
                                  </div>
                                </div>
                              </div>
                              <div>add variables and rows to the master
                                CoinModel according to the input;<br>
                              </div>
                              create a model for the subproblem using
                              CoinModel;<br>
                            </div>
                            <div>add variables and rows to the
                              subproblem CoinModel according to the
                              input;<br>
                            </div>
                            create the solver for the master problem
                            using OsiCbcSolverInterface;<br>
                          </div>
                          create the solver for the subproblem using
                          OsiClpSolverInterface;<br>
                        </div>
                        FOR( iter = 0 ; iter &lt; maxiter ; iter++) <br>
                      </div>
                        load the subproblem CoinModel into the
                      OsiClpSolverInterface;<br>
                    </div>
                      solve the subproblem with initialSolve() and
                    update the LB;<br>
                  </div>
                  <div>  IF( UB - LB &lt; eps ) break;<br>
                  </div>
                    get the new constraint and add it to the master
                  CoinModel;<br>
                </div>
                  load the master CoinModel into the
                OsiCbcSolverInterface;<br>
              </div>
                solve the master problem with branchAndBound() and
              update the UB;<br>
            </div>
              update the righthandsides of the subproblem CoinModel;<br>
          </div>
          ENDFOR<br>
        </div>
        <div>END<br>
        </div>
        <div>******************************************************************<br>
          <br>
        </div>
        <div>Initially the master problem has no rows. At the first
          iteration the first row is added to the master problem and so
          on. The problem is the following: at the first iteration
          branchAndBound() solves the master, but at the second
          iteration it doesn't, in the sense that at the second
          iteration the binary variables are blocked to the values of
          the previous iteration, and the solver works only with the
          (only one) continuous variable. Because of it the program
          makes only two iterations. Before running branchAndBound in
          the second iteration, a simple instance of the CFL gives the
          following master problem in lp format:<br>
          <br>
          \Problem name: <br>
          <br>
          Minimize<br>
          obj: 1500 x0 + 1500 x1 + x2<br>
          Subject To<br>
          cons0:  1000000 x0 + 1000000 x1 &gt;= 500000<br>
          cons1:  40000 x1 + x2 &gt;= 25000<br>
          Bounds<br>
           0 &lt;= x0 &lt;= 1<br>
           0 &lt;= x1 &lt;= 1<br>
          Integers<br>
          x0 x1 <br>
          End<br>
          <br>
        </div>
        <div><br>
        </div>
        <div>clearly the opt. solution is x0=0, x1=1, x2=0, but
          branchAndBound() x0=1, x1=0, x2=25000. At the first iteration
          the constraint cons1 wasn't there, and branchAndBound() in
          that case gave the right opt.solution x0=1, x1=0, x2=0. As I
          said before It seems that the binary variables are blocked at
          the values of the first iteration, even if the lp file says 0
          &lt;= x0 &lt;= 1 &amp; 0 &lt;= x1 &lt;= 1.<br>
        </div>
        <div>Gdb says that during the call to branchAndBound() in the
          second iteration, the program receives signal of <br>
          <pre><span style="font-family:arial,helvetica,sans-serif">SIGTRAP, Trace/breakpoint trap
0x08089194 in CbcModel::setPointers(OsiSolverInterface const*) ()</span>


</pre>
          <pre><font face="arial,helvetica,sans-serif">and Valgrind in that point gives an invalid read:

</font>
<span style="font-family:arial,helvetica,sans-serif">==3989== Invalid read of size 4
==3989==    at 0x8089194: CbcModel::setPointers(OsiSolverInterface const*)
(in /home/alessio/Documenti/CWL/cwl8/cwl8)
==3989==    by 0x80AE664: CbcModel::branchAndBound(int) (in
/home/alessio/Documenti/CWL/cwl8/cwl8)
==3989==    by 0x80800EF: OsiCbcSolverInterface::branchAndBound() (in
/home/alessio/Documenti/CWL/cwl8/cwl8)
==3989==    by 0x8051AB4: main (cwl8.cpp:657)
==3989==  Address 0x4a17570 is 40 bytes inside a block of size 52 free'd
==3989==    at 0x402D7B8: operator delete(void*) (in
/usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==3989==    by 0x82C2986: OsiSolverInterface::~OsiSolverInterface() (in
/home/alessio/Documenti/CWL/cwl8/cwl8)
==3989==    by 0x80712FD: OsiClpSolverInterface::~OsiClpSolverInterface()
(in /home/alessio/Documenti/CWL/cwl8/cwl8)
==3989==    by 0x80AE64B: CbcModel::branchAndBound(int) (in
/home/alessio/Documenti/CWL/cwl8/cwl8)
==3989==    by 0x80800EF: OsiCbcSolverInterface::branchAndBound() (in
/home/alessio/Documenti/CWL/cwl8/cwl8)
==3989==    by 0x8051AB4: main (cwl8.cpp:657)</span>


</pre>
          <pre><font face="arial,helvetica,sans-serif">what can i do? Thanks in advance for your help,

</font></pre>
          <pre><font face="arial,helvetica,sans-serif">Alessio</font> 
</pre>
          <pre>
</pre>
        </div>
      </div>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
Cbc mailing list
<a class="moz-txt-link-abbreviated" href="mailto:Cbc@list.coin-or.org">Cbc@list.coin-or.org</a>
<a class="moz-txt-link-freetext" href="http://list.coin-or.org/mailman/listinfo/cbc">http://list.coin-or.org/mailman/listinfo/cbc</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>