source: trunk/Cbc/src/CbcEventHandler.cpp @ 1943

Last change on this file since 1943 was 1943, checked in by forrest, 5 years ago

more options, copy statistics structure analysis
start coding of "switch" variables i.e. badly scaled ints or hi/lo
changes to allow more influence on small branch and bound
changes to get correct printout with threads

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/* $Id: CbcEventHandler.cpp 1943 2013-07-21 09:05:45Z forrest $ */
2// Copyright (C) 2004, International Business Machines
3// Corporation and others.  All Rights Reserved.
4// This code is licensed under the terms of the Eclipse Public License (EPL).
5
6// Shamelessly adapted from ClpEventHandler.
7
8#include "CoinPragma.hpp"
9
10#include "CbcEventHandler.hpp"
11
12
13//#############################################################################
14// Constructors / Destructor / Assignment
15//#############################################################################
16
17//-------------------------------------------------------------------
18// Default Constructor
19//-------------------------------------------------------------------
20
21CbcEventHandler::CbcEventHandler (CbcModel *model)
22        : model_(model),
23        dfltAction_(CbcEventHandler::noAction),
24        eaMap_(0)
25{  /* nothing more required */ }
26
27//-------------------------------------------------------------------
28// Copy constructor
29//-------------------------------------------------------------------
30/*
31  Here we need to clone the event/action map, if it exists
32*/
33CbcEventHandler::CbcEventHandler (const CbcEventHandler & rhs)
34        : model_(rhs.model_),
35        dfltAction_(rhs.dfltAction_),
36        eaMap_(0)
37{
38    if (rhs.eaMap_ != 0) {
39        eaMap_ = new eaMapPair(*rhs.eaMap_) ;
40    }
41}
42
43//----------------------------------------------------------------
44// Assignment operator
45//-------------------------------------------------------------------
46CbcEventHandler&
47CbcEventHandler::operator=(const CbcEventHandler & rhs)
48{
49    if (this != &rhs) {
50        model_ = rhs.model_ ;
51        dfltAction_ = rhs.dfltAction_ ;
52        if (rhs.eaMap_ != 0) {
53            eaMap_ = new eaMapPair(*rhs.eaMap_) ;
54        } else {
55            eaMap_ = 0 ;
56        }
57    }
58    return (*this) ;
59}
60
61//----------------------------------------------------------------
62// Clone
63//-------------------------------------------------------------------
64CbcEventHandler*
65CbcEventHandler::clone() const
66{
67    return (new CbcEventHandler(*this)) ;
68}
69
70//-------------------------------------------------------------------
71// Destructor
72//-------------------------------------------------------------------
73/*
74  Take care to free the event/action map.
75*/
76CbcEventHandler::~CbcEventHandler ()
77{
78    if (eaMap_ != 0) delete eaMap_ ;
79}
80
81
82//-------------------------------------------------------------------
83// event() -- return the action for an event.
84//-------------------------------------------------------------------
85
86CbcEventHandler::CbcAction CbcEventHandler::event(CbcEvent event)
87/*
88  If an event/action map exists and contains an entry for the event, return it.
89  Otherwise return the default action.
90*/
91{
92    if (eaMap_ != 0) {
93        eaMapPair::iterator entry = eaMap_->find(event) ;
94        if (entry != eaMap_->end()) {
95            return (entry->second) ;
96        } else {
97            return (dfltAction_) ;
98        }
99    } else {
100        return (dfltAction_) ;
101    }
102}
103
104//-------------------------------------------------------------------
105// event() -- return the action for an event.
106//-------------------------------------------------------------------
107
108CbcEventHandler::CbcAction CbcEventHandler::event(CbcEvent event,
109                                                  void * /*data*/)
110/*
111  If an event/action map exists and contains an entry for the event, return it.
112  Otherwise return the default action.
113*/
114{
115    if (eaMap_ != 0) {
116        eaMapPair::iterator entry = eaMap_->find(event) ;
117        if (entry != eaMap_->end()) {
118            return (entry->second) ;
119        } else {
120            return (dfltAction_) ;
121        }
122    } else {
123        return (dfltAction_) ;
124    }
125}
126
Note: See TracBrowser for help on using the repository browser.