1 | /* $Id: MyEventHandler.cpp 1665 2011-01-04 17:55:54Z lou $ */ |
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 | #if defined(_MSC_VER) |
7 | #pragma warning(disable:4786) |
8 | #pragma warning(disable:4503) |
9 | #endif |
10 | |
11 | #include "MyEventHandler.hpp" |
12 | |
13 | |
14 | //############################################################################# |
15 | // Constructors / Destructor / Assignment |
16 | //############################################################################# |
17 | |
18 | //------------------------------------------------------------------- |
19 | // Default Constructor |
20 | //------------------------------------------------------------------- |
21 | MyEventHandler::MyEventHandler () |
22 | : ClpEventHandler() |
23 | { |
24 | } |
25 | |
26 | //------------------------------------------------------------------- |
27 | // Copy constructor |
28 | //------------------------------------------------------------------- |
29 | MyEventHandler::MyEventHandler (const MyEventHandler & rhs) |
30 | : ClpEventHandler(rhs) |
31 | { |
32 | } |
33 | |
34 | // Constructor with pointer to model |
35 | MyEventHandler::MyEventHandler(ClpSimplex * model) |
36 | : ClpEventHandler(model) |
37 | { |
38 | } |
39 | |
40 | //------------------------------------------------------------------- |
41 | // Destructor |
42 | //------------------------------------------------------------------- |
43 | MyEventHandler::~MyEventHandler () |
44 | { |
45 | } |
46 | |
47 | //---------------------------------------------------------------- |
48 | // Assignment operator |
49 | //------------------------------------------------------------------- |
50 | MyEventHandler & |
51 | MyEventHandler::operator=(const MyEventHandler& rhs) |
52 | { |
53 | if (this != &rhs) { |
54 | ClpEventHandler::operator=(rhs); |
55 | } |
56 | return *this; |
57 | } |
58 | //------------------------------------------------------------------- |
59 | // Clone |
60 | //------------------------------------------------------------------- |
61 | ClpEventHandler * MyEventHandler::clone() const |
62 | { |
63 | return new MyEventHandler(*this); |
64 | } |
65 | |
66 | int |
67 | MyEventHandler::event(Event whichEvent) |
68 | { |
69 | if (whichEvent == endOfValuesPass) |
70 | return 0; // say optimal |
71 | else |
72 | return -1; // carry on |
73 | |
74 | #if 0 |
75 | // This is how one can get some progress information at the end of each iteration. |
76 | if (whichEvent == endOfIteration) { |
77 | int numIter = model_->getIterationCount(); |
78 | double sumDualInfeas = model_->sumDualInfeasibilities(); |
79 | double sumPrimalInfeas = model_->sumPrimalInfeasibilities(); |
80 | double obj = model_->getObjValue(); |
81 | } |
82 | |
83 | // This is how one can tell CLP to stop now. |
84 | // The value of cancelAsap needs to come from the application using CLP. |
85 | if ( cancelAsap ) return 5; |
86 | else return -1; |
87 | #endif |
88 | |
89 | |
90 | } |
91 | |