1 // Copyright (C) 2004, 2006 International Business Machines and others. 2 // All Rights Reserved. 3 // This code is published under the Eclipse Public License. 4 // 5 // $Id$ 6 // 7 // Authors: Carl Laird, Andreas Waechter IBM 2004-08-13 8 9 #include "IpFilter.hpp" 10 #include "IpJournalist.hpp" 11 12 namespace Ipopt 13 { 14 15 #if COIN_IPOPT_VERBOSITY > 0 16 static const Index dbg_verbosity = 0; 17 #endif 18 19 /////////////////////////////////////////////////////////////////////////// 20 // Filter entries // 21 /////////////////////////////////////////////////////////////////////////// 22 FilterEntry(std::vector<Number> vals,Index iter)23 FilterEntry::FilterEntry(std::vector<Number> vals, Index iter) 24 : 25 vals_(vals), 26 iter_(iter) 27 {} 28 ~FilterEntry()29 FilterEntry::~FilterEntry() 30 {} 31 32 /////////////////////////////////////////////////////////////////////////// 33 // Filter // 34 /////////////////////////////////////////////////////////////////////////// 35 Filter(Index dim)36 Filter::Filter(Index dim) 37 : 38 dim_(dim) 39 {} 40 Acceptable(std::vector<Number> vals) const41 bool Filter::Acceptable(std::vector<Number> vals) const 42 { 43 DBG_START_METH("FilterLineSearch::Filter::Acceptable", dbg_verbosity); 44 DBG_ASSERT((Index)vals.size()==dim_); 45 bool acceptable = true; 46 std::list<FilterEntry*>::iterator iter; 47 for (iter = filter_list_.begin(); iter != filter_list_.end(); 48 iter++) { 49 if (!(*iter)->Acceptable(vals)) { 50 acceptable = false; 51 break; 52 } 53 } 54 return acceptable; 55 } 56 AddEntry(std::vector<Number> vals,Index iteration)57 void Filter::AddEntry(std::vector<Number> vals, Index iteration) 58 { 59 DBG_START_METH("FilterLineSearch::Filter::AddEntry", dbg_verbosity); 60 DBG_ASSERT((Index)vals.size()==dim_); 61 std::list<FilterEntry*>::iterator iter; 62 iter = filter_list_.begin(); 63 while (iter != filter_list_.end()) { 64 if ((*iter)->Dominated(vals)) { 65 std::list<FilterEntry*>::iterator iter_to_remove = iter; 66 iter++; 67 FilterEntry* entry_to_remove = *iter_to_remove; 68 filter_list_.erase(iter_to_remove); 69 delete entry_to_remove; 70 } 71 else { 72 iter++; 73 } 74 } 75 FilterEntry* new_entry = new FilterEntry(vals, iteration); 76 filter_list_.push_back(new_entry); 77 } 78 Clear()79 void Filter::Clear() 80 { 81 DBG_START_METH("FilterLineSearch::Filter::Clear", dbg_verbosity); 82 while (!filter_list_.empty()) { 83 FilterEntry* entry = filter_list_.back(); 84 filter_list_.pop_back(); 85 delete entry; 86 } 87 } 88 Print(const Journalist & jnlst)89 void Filter::Print(const Journalist& jnlst) 90 { 91 DBG_START_METH("FilterLineSearch::Filter::Print", dbg_verbosity); 92 jnlst.Printf(J_DETAILED, J_LINE_SEARCH, 93 "The current filter has %d entries.\n", filter_list_.size()); 94 if (!jnlst.ProduceOutput(J_VECTOR, J_LINE_SEARCH)) { 95 return; 96 } 97 std::list<FilterEntry*>::iterator iter; 98 Index count = 0; 99 for (iter = filter_list_.begin(); iter != filter_list_.end(); 100 iter++) { 101 if (count % 10 == 0) { 102 jnlst.Printf(J_VECTOR, J_LINE_SEARCH, 103 " phi theta iter\n"); 104 } 105 count++; 106 jnlst.Printf(J_VECTOR, J_LINE_SEARCH, "%5d ", count); 107 for (Index i=0; i<dim_; i++) { 108 jnlst.Printf(J_VECTOR, J_LINE_SEARCH, "%23.16e ", (*iter)->val(i)); 109 } 110 jnlst.Printf(J_VECTOR, J_LINE_SEARCH, "%5d\n",(*iter)->iter()); 111 } 112 } 113 114 } // namespace Ipopt 115