source: branches/pre/Test/MyMessageHandler.cpp @ 180

Last change on this file since 180 was 180, checked in by forrest, 18 years ago

new stuff

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1// Copyright (C) 2003, International Business Machines
2// Corporation and others.  All Rights Reserved.
3
4#if defined(_MSC_VER)
5#pragma warning(disable:4786)
6#pragma warning(disable:4503)
7#endif
8
9#include <cstdio>
10
11#include "ClpSimplex.hpp"
12#include "MyMessageHandler.hpp"
13#include "ClpMessage.hpp"
14
15
16//#############################################################################
17// Constructors / Destructor / Assignment
18//#############################################################################
19
20//-------------------------------------------------------------------
21// Default Constructor
22//-------------------------------------------------------------------
23MyMessageHandler::MyMessageHandler () 
24  : CoinMessageHandler(),
25    model_(NULL),
26    feasibleExtremePoints_(),
27    iterationNumber_(-1)
28{
29}
30
31//-------------------------------------------------------------------
32// Copy constructor
33//-------------------------------------------------------------------
34MyMessageHandler::MyMessageHandler (const MyMessageHandler & rhs) 
35: CoinMessageHandler(rhs),
36    model_(rhs.model_),
37    feasibleExtremePoints_(rhs.feasibleExtremePoints_),
38    iterationNumber_(rhs.iterationNumber_)
39{ 
40}
41
42MyMessageHandler::MyMessageHandler (const CoinMessageHandler & rhs) 
43  : CoinMessageHandler(),
44    model_(NULL),
45    feasibleExtremePoints_(),
46    iterationNumber_(-1)
47{ 
48}
49
50// Constructor with pointer to model
51MyMessageHandler::MyMessageHandler(ClpSimplex * model,
52               FILE * userPointer)
53  : CoinMessageHandler(),
54    model_(model),
55    feasibleExtremePoints_(),
56    iterationNumber_(-1)
57{
58}
59
60//-------------------------------------------------------------------
61// Destructor
62//-------------------------------------------------------------------
63MyMessageHandler::~MyMessageHandler ()
64{
65}
66
67//----------------------------------------------------------------
68// Assignment operator
69//-------------------------------------------------------------------
70MyMessageHandler &
71MyMessageHandler::operator=(const MyMessageHandler& rhs)
72{
73  if (this != &rhs) {
74    CoinMessageHandler::operator=(rhs);
75    model_ = rhs.model_;
76    feasibleExtremePoints_ = rhs.feasibleExtremePoints_;
77    iterationNumber_ = rhs.iterationNumber_;
78  }
79  return *this;
80}
81//-------------------------------------------------------------------
82// Clone
83//-------------------------------------------------------------------
84CoinMessageHandler * MyMessageHandler::clone() const
85{
86  return new MyMessageHandler(*this);
87}
88
89int 
90MyMessageHandler::print()
91{
92  if (currentSource()=="Clp") {
93    if (currentMessage().externalNumber()==5) {
94      // Are we feasible
95      // We can pick up two ways - check same
96      assert (model_->numberPrimalInfeasibilities()==
97        intValue(1));
98      if (!intValue(1)&&intValue(0)!=iterationNumber_) {
99        iterationNumber_ = intValue(0);
100        // Column solution
101        int numberColumns = model_->numberColumns();
102        const double * solution = model_->solutionRegion(1);
103
104        // Create vector to contain solution
105        StdVectorDouble feasibleExtremePoint;
106
107        if (!model_->columnScale()) {
108          // No scaling
109          for (int i=0;i<numberColumns;i++)
110            feasibleExtremePoint.push_back(solution[i]);
111        } else {
112          // scaled
113          const double * columnScale = model_->columnScale();
114          for (int i=0;i<numberColumns;i++)
115            feasibleExtremePoint.push_back(solution[i]*columnScale[i]);
116        }
117        // Save solution
118        feasibleExtremePoints_.push_front(feasibleExtremePoint);
119
120        // Want maximum of 10 solutions, so if more then 10 get rid of oldest
121        int numExtremePointsSaved = feasibleExtremePoints_.size();
122        if ( numExtremePointsSaved>=10 ) {
123          feasibleExtremePoints_.pop_back();
124          assert( feasibleExtremePoints_.size() == 
125                  (unsigned int) numExtremePointsSaved-1 );
126        };
127
128      }
129    }
130  }
131  return CoinMessageHandler::print();
132}
133const ClpSimplex *
134MyMessageHandler::model() const
135{
136  return model_;
137}
138void 
139MyMessageHandler::setModel(ClpSimplex * model)
140{
141  model_ = model;
142}
143
144const std::deque<StdVectorDouble> & MyMessageHandler::getFeasibleExtremePoints() const
145{ 
146  return feasibleExtremePoints_; 
147}
148void MyMessageHandler::clearFeasibleExtremePoints()
149{
150  feasibleExtremePoints_.clear();
151}
Note: See TracBrowser for help on using the repository browser.