00001 /************************************************************************************************** 00002 Software License Agreement (BSD License) 00003 00004 Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt 00005 All rights reserved. 00006 00007 Redistribution and use in source and binary forms, with or without modification, are permitted 00008 provided that the following conditions are met: 00009 00010 *Redistributions of source code must retain the above copyright notice, this list of 00011 conditions and the following disclaimer. 00012 *Redistributions in binary form must reproduce the above copyright notice, this list of 00013 conditions and the following disclaimer in the documentation and/or other materials provided 00014 with the distribution. 00015 *Neither the name of the University of Aveiro nor the names of its contributors may be used to 00016 endorse or promote products derived from this software without specific prior written permission. 00017 00018 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR 00019 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 00020 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 00021 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00022 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00023 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 00024 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 00025 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 ***************************************************************************************************/ 00032 #include <mtt/hypothesis.h> 00033 00034 00035 Hypothesis::Hypothesis(int iteration, int cluster, int status) 00036 { 00037 Hypothesis(); 00038 00039 _iteration=iteration; 00040 _cluster=cluster; 00041 _status=status; 00042 } 00043 00044 Hypothesis::~Hypothesis() 00045 { 00046 // cout<<"deleted: "<<*this<<endl; 00047 // _targets.clear(); 00048 } 00049 00050 string Hypothesis::nameUI() 00051 { 00052 boost::format fm("H (%d-%d) %ld #%ld\n%.3f :%d"); 00053 fm % _iteration % _cluster % _id % _uid % _probability % _targets.size(); 00054 return fm.str(); 00055 } 00056 00057 string Hypothesis::name() 00058 { 00059 boost::format fm("H (%d-%d) %ld #%ld"); 00060 fm % _iteration % _cluster % _id % _uid; 00061 return fm.str(); 00062 } 00063 00064 void Hypothesis::setAttribute(string name,string value) 00065 { 00066 if(find(_attribute_names.begin(),_attribute_names.end(),name)==_attribute_names.end())//Not found 00067 { 00068 _attribute_names.push_back(name); 00069 _attribute_values.push_back(value); 00070 00071 return; 00072 } 00073 00074 for(uint i=0;i<_attribute_names.size();++i) 00075 if(_attribute_names[i]==name) 00076 { 00077 _attribute_values[i]=value; 00078 return; 00079 } 00080 } 00081 00082 Hypothesis::Hypothesis() 00083 { 00084 _euid++; 00085 _uid=_euid; 00086 _id=0; 00087 _status=0; 00088 _aux1=-1; 00089 _cluster=-1; 00090 _iteration=-1; 00091 _probability=0; 00092 _targets.clear(); 00093 _attribute_names.clear(); 00094 _attribute_values.clear(); 00095 00096 _n_det=0; 00097 _n_occ=0; 00098 _n_del=0; 00099 _n_new=0; 00100 _n_fal=0; 00101 _prod=1; 00102 00103 _parent_uid=-1; 00104 00105 // _n_children=0; 00106 } 00107 00108 ostream& operator<<(ostream& o,Hypothesis& h) 00109 { 00110 o<<"hypothesis uid: "<<h._uid; 00111 o<<" cluster: "<<h._cluster; 00112 o<<" iteration: "<<h._iteration; 00113 o<<" status: "<<h._status; 00114 return o; 00115 } 00116 00117 00118 bool compareHypothesesByProbability(HypothesisPtr h1,HypothesisPtr h2) 00119 { 00120 return h1->_probability < h2->_probability; 00121 } 00122 00123 bool compareHypothesesByProbabilityDescending(HypothesisPtr h1,HypothesisPtr h2) 00124 { 00125 return h1->_probability > h2->_probability; 00126 } 00127 00128 bool compareHypotheses(HypothesisPtr h1,HypothesisPtr h2) 00129 { 00130 return h1->_uid<h2->_uid; 00131 }