[Cbc] Cbc threads and derived CbcModel classes

Pietro Belotti petr.7b6 at gmail.com
Sat Oct 19 05:12:35 EDT 2013


Hi again,

I was able to make this work by modifying Cbc's source code. Essentially it
boils down to creating a (virtual) cloning method for CbcModel and using
the cloning method instead of the copy constructor when forking in
CbcThreads.cpp.

As I think the changes are tiny, I would appreciate if they could be made
standard. I'm coping a diff below, referred to CbcModel stable/2.7.

Pietro


Index: CbcModel.cpp
===================================================================
--- CbcModel.cpp    (revision 1966)
+++ CbcModel.cpp    (working copy)
@@ -4875,6 +4875,13 @@
     return ;
 }

+// Cloning method
+
+CbcModel *CbcModel::clone (bool cloneHandler) {
+  return new CbcModel (*this, cloneHandler);
+}
+
+
 // Copy constructor.

 CbcModel::CbcModel(const CbcModel & rhs, bool cloneHandler)
Index: CbcThread.cpp
===================================================================
--- CbcThread.cpp    (revision 1966)
+++ CbcThread.cpp    (working copy)
@@ -569,7 +569,8 @@
         CbcStrategy * saveStrategy = model.strategy();
         model.setStrategy(NULL);
         for (int i = 0; i < numberThreads_; i++) {
-            threadModel_[i] = new CbcModel(model, true);
+          //threadModel_[i] = new CbcModel(model, true);
+        threadModel_[i] = model. clone (true);
             threadModel_[i]->synchronizeHandlers(1);
 #ifdef COIN_HAS_CLP
             // Solver may need to know about model
Index: CbcModel.hpp
===================================================================
--- CbcModel.hpp    (revision 1966)
+++ CbcModel.hpp    (working copy)
@@ -1837,6 +1837,9 @@
     */
     CbcModel(const CbcModel & rhs, bool cloneHandler = false);

+    /** Clone */
+  virtual CbcModel *clone (bool cloneHandler);
+
     /// Assignment operator
     CbcModel & operator=(const CbcModel& rhs);




On Fri, Oct 4, 2013 at 12:54 AM, Pietro Belotti <petr.7b6 at gmail.com> wrote:

> Hello.
>
> I have implemented a BB by deriving a myModel class from CbcModel. The
> main difference is in the ::checkSolution() method, which is specialized to
> the model.
>
> The sequential version seems to work just fine. The multi-thread version,
> instead, does not: while everything works fine in the root node and the
> right solution check is run, in CbcThread.cpp:573, the new CbcModels that
> run the threads are created using the copy constructor of the original
> CbcModel, and hence during the BB the original (and invalid for my problem)
> checkSolution() method is used.
>
> Is there a clean way to make the threads use myModel objects rather than
> CbcModels?
>
> Thanks,
> Pietro
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://list.coin-or.org/pipermail/cbc/attachments/20131019/6b8fed21/attachment.html>


More information about the Cbc mailing list