Ignore:
Timestamp:
Aug 10, 2007 12:18:20 PM (12 years ago)
Author:
forrest
Message:

event handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cbc/examples/driver4.cpp

    r739 r741  
    8585  return returnCode;
    8686}
     87#include "CbcEventHandler.hpp"
     88/** This is so user can trap events and do useful stuff. 
     89
     90    CbcModel model_ is available as well as anything else you care
     91    to pass in
     92*/
     93
     94class MyEventHandler3 : public CbcEventHandler {
     95 
     96public:
     97  /**@name Overrides */
     98  //@{
     99  virtual CbcAction event(CbcEvent whichEvent);
     100  //@}
     101
     102  /**@name Constructors, destructor etc*/
     103  //@{
     104  /** Default constructor. */
     105  MyEventHandler3();
     106  /// Constructor with pointer to model (redundant as setEventHandler does)
     107  MyEventHandler3(CbcModel * model);
     108  /** Destructor */
     109  virtual ~MyEventHandler3();
     110  /** The copy constructor. */
     111  MyEventHandler3(const MyEventHandler3 & rhs);
     112  /// Assignment
     113  MyEventHandler3& operator=(const MyEventHandler3 & rhs);
     114  /// Clone
     115  virtual CbcEventHandler * clone() const ;
     116  //@}
     117   
     118   
     119protected:
     120  // data goes here
     121};
     122//-------------------------------------------------------------------
     123// Default Constructor
     124//-------------------------------------------------------------------
     125MyEventHandler3::MyEventHandler3 ()
     126  : CbcEventHandler()
     127{
     128}
     129
     130//-------------------------------------------------------------------
     131// Copy constructor
     132//-------------------------------------------------------------------
     133MyEventHandler3::MyEventHandler3 (const MyEventHandler3 & rhs)
     134: CbcEventHandler(rhs)
     135
     136}
     137
     138// Constructor with pointer to model
     139MyEventHandler3::MyEventHandler3(CbcModel * model)
     140  : CbcEventHandler(model)
     141{
     142}
     143
     144//-------------------------------------------------------------------
     145// Destructor
     146//-------------------------------------------------------------------
     147MyEventHandler3::~MyEventHandler3 ()
     148{
     149}
     150
     151//----------------------------------------------------------------
     152// Assignment operator
     153//-------------------------------------------------------------------
     154MyEventHandler3 &
     155MyEventHandler3::operator=(const MyEventHandler3& rhs)
     156{
     157  if (this != &rhs) {
     158    CbcEventHandler::operator=(rhs);
     159  }
     160  return *this;
     161}
     162//-------------------------------------------------------------------
     163// Clone
     164//-------------------------------------------------------------------
     165CbcEventHandler * MyEventHandler3::clone() const
     166{
     167  return new MyEventHandler3(*this);
     168}
     169
     170CbcEventHandler::CbcAction
     171MyEventHandler3::event(CbcEvent whichEvent)
     172{
     173  // If in sub tree carry on
     174  if (!model_->parentModel()) {
     175    if (whichEvent==solution||whichEvent==heuristicSolution)
     176      return stop; // say finished
     177    else
     178      return noAction; // carry on
     179  } else {
     180      return noAction; // carry on
     181  }
     182}
    87183
    88184int main (int argc, const char *argv[])
     
    107203  CbcModel model(solver1);   
    108204  CbcMain0(model);
     205  // Event handler
     206  MyEventHandler3 eventHandler;
     207  model.passInEventHandler(&eventHandler);
    109208  /* Now go into code for standalone solver
    110209     Could copy arguments and add -quit at end to be safe
Note: See TracChangeset for help on using the changeset viewer.