Hybrid Query Processing Engine for Coprocessing in Database Systems
HyPE
operation.cpp
Go to the documentation of this file.
00001 
00002 #include <core/operation.hpp>
00003 #include <core/plotscriptgenerator.hpp>
00004 
00005 namespace hype{
00006    namespace core{
00007 
00008       Operation::Operation(const std::string& name) : map_algorithmname_to_pointer_(), ptr_to_optimization_criterion_(), name_(name),number_of_right_decisions_(0), number_of_total_decisions_(0), logical_time_(0){
00009          this->setNewOptimizationCriterion("Response Time");
00010       }
00011 
00012       Operation::~Operation(){
00013          
00014          std::string title = std::string("Execution time curves for Operation ") + name_ ;
00015          std::vector<std::string> algorithm_names;
00016 
00017          MapNameToAlgorithm::iterator it;
00018          for(it=map_algorithmname_to_pointer_.begin();it!=map_algorithmname_to_pointer_.end();it++){
00019             algorithm_names.push_back(it->second->getName());
00020          }
00021          
00022 
00023 
00024          if(!PlotScriptGenerator::create(title, "Data size in number of Elements (int)", "Execution time in ns", name_, algorithm_names)){
00025             std::cout << "Error Creating Gnuplot Skript for Operation" << name_ << "!" << std::endl;
00026          }
00027 
00028          if(!PlotScriptGenerator::createRelativeErrorScript(name_, algorithm_names)){
00029             std::cout << "Error Creating Gnuplot Skript for relative errors for Operation" << name_ << "!" << std::endl;
00030          }
00031 
00032          if(!PlotScriptGenerator::createAverageRelativeErrorScript(name_, algorithm_names)){
00033             std::cout << "Error Creating Gnuplot Skript for average relative errors for Operation" << name_ << "!" << std::endl;
00034          }
00035 
00036          if(!PlotScriptGenerator::createWindowedAverageRelativeErrorScript(name_, algorithm_names)){
00037             std::cout << "Error Creating Gnuplot Skript for windowed average relative errors for Operation" << name_ << "!" << std::endl;
00038          }
00039          
00040       }
00041 
00042       /*
00043       void Operation::addAlgorithm(std::string name){
00044 
00045 
00046 
00047       }*/
00048 
00049       bool Operation::addAlgorithm(const std::string& name_of_algorithm, 
00050                         DeviceSpecification comp_dev,
00051                         const std::string& name_of_statistical_method, 
00052                         const std::string& name_of_recomputation_strategy){
00053 
00054          std::map<std::string, std::tr1::shared_ptr<Algorithm> >::iterator it;
00055          it = map_algorithmname_to_pointer_.find(name_of_algorithm);
00056           //map_algorithmname_to_pointer_;
00057          //std::tr1::shared_ptr<Algorithm> alg;
00058 
00059          if(it==map_algorithmname_to_pointer_.end()){ //algorithm does not exist
00060             //alg = std::tr1::shared_ptr<Algorithm>(new Algorithm(name_of_algorithm,name_of_statistical_method,name_of_recomputation_strategy,*this));
00061             //map_algorithmname_to_pointer_[name_of_algorithm]=alg;
00062             if(!quiet && verbose && debug)
00063                std::cout << "add Algorithm '" << name_of_algorithm <<  "' to operation '" << name_ << "'" << std::endl; 
00064             map_algorithmname_to_pointer_[name_of_algorithm]=std::tr1::shared_ptr<Algorithm>(new Algorithm(name_of_algorithm,name_of_statistical_method,name_of_recomputation_strategy,*this,comp_dev));
00065             return true;
00066             
00067          }else{
00068             //alg=it->second; //std::tr1::shared_ptr<Operation> (it->second);
00069             return false; //algorithm already exists!
00070          }
00071 
00072       }
00073 
00074       void Operation::removeAlgorithm(const std::string& name){
00075          std::cout << "Error: Operation::removeAlgorithm() not yet implemented!" << std::endl;
00076          std::cout << name << std::endl;
00077          std::exit(-1);
00078       }
00079       
00080       const AlgorithmPtr Operation::getAlgorithm(const std::string& name_of_algorithm){
00081          MapNameToAlgorithm::iterator it = map_algorithmname_to_pointer_.find(name_of_algorithm);
00082          if(it==map_algorithmname_to_pointer_.end()){
00083             return AlgorithmPtr(); //return NULL Pointer
00084          }
00085          return it->second;
00086       }
00087       
00088       
00089       const std::vector<AlgorithmPtr> Operation::getAlgorithms(){
00090          std::vector<AlgorithmPtr> result;
00091          MapNameToAlgorithm::const_iterator it;
00092          for(it=map_algorithmname_to_pointer_.begin();it!=map_algorithmname_to_pointer_.end();it++){
00093             result.push_back(it->second);
00094          }
00095          return result;
00096       }
00097 
00098       bool Operation::setNewOptimizationCriterion(const std::string& name_of_optimization_criterion){
00099          //calls factory function
00100          ptr_to_optimization_criterion_=std::tr1::shared_ptr<OptimizationCriterion_Internal>( getNewOptimizationCriterionbyName(name_of_optimization_criterion));
00101          if(!ptr_to_optimization_criterion_){
00102             std::cout << "FATEL ERROR! Operation " << name_ << " has no assigned optimization criterion! Exiting..." << std::endl;
00103             exit(-1);
00104          }
00105          return true;
00106       }
00107 
00108       //const std::vector< std::tr1::shared_ptr<Algorithm> >
00109       const SchedulingDecision Operation::getOptimalAlgorithm(const Tuple& input_values, DeviceTypeConstraint dev_constr){
00110 
00111          if(!ptr_to_optimization_criterion_){
00112             std::cout << "FATEL ERROR! Operation " << name_ << " has no assigned optimization criterion! Exiting..." << std::endl;
00113             exit(-1);
00114          }
00115 
00116          return ptr_to_optimization_criterion_->getOptimalAlgorithm(input_values,*this, dev_constr);
00117       }
00118 
00119 
00120       bool Operation::hasAlgorithm(const std::string& name_of_algorithm)
00121       {
00122 
00123          //std::map<std::string,std::tr1::shared_ptr<Algorithm> >::iterator it;
00124          MapNameToAlgorithm::iterator it;
00125          //std::map<std::string,std::tr1::shared_ptr<Algorithm> > map_algorithmname_to_pointer_;
00126          //it=map_algorithmname_to_pointer_.begin();
00127          for(it=map_algorithmname_to_pointer_.begin();it!=map_algorithmname_to_pointer_.end();it++){
00128             if(it->second->getName()==name_of_algorithm) return true;
00129          }
00130          return false;
00131       }
00132 
00133 
00134       bool Operation::addObservation(const std::string& name_of_algorithm, const MeasurementPair& mp){
00135 
00136          MapNameToAlgorithm::iterator it;
00137          for(it=map_algorithmname_to_pointer_.begin();it!=map_algorithmname_to_pointer_.end();it++){
00138             if(it->second->getName()==name_of_algorithm){
00139                return it->second->addMeasurementPair(mp);
00140             }
00141          }
00142 
00143          return false;
00144       }
00145 
00146 
00147       const std::map<double,std::string> Operation::getEstimatedExecutionTimesforAlgorithms(const Tuple& input_values){
00148          std::map<double,std::string> map_execution_times_to_algorithm_name;
00149          MapNameToAlgorithm::iterator it;
00150          for(it=map_algorithmname_to_pointer_.begin();it!=map_algorithmname_to_pointer_.end();it++){
00151             EstimatedTime estimated_time = it->second->getEstimatedExecutionTime(input_values);
00152             std::string name = it->second->getName();
00153             double time_in_nanosecs = estimated_time.getTimeinNanoseconds();
00154             map_execution_times_to_algorithm_name[time_in_nanosecs]=name;
00155             if(!quiet && verbose && debug)
00156                std::cout << "Operation::getEstimatedExecutionTimesforAlgorithms() Algorithm: '" << name << "'" << std::endl; 
00157             
00158          }
00159          //std::cout << "Size:" << map_execution_times_to_algorithm_name.size() << std::endl;
00160          return map_execution_times_to_algorithm_name;
00161       }
00162 
00163       const std::string Operation::getName() const throw(){
00164          return name_;
00165       }
00166 
00167       void Operation::incrementNumberOfRightDecisions() throw(){
00168          ++number_of_right_decisions_;
00169       }
00170       void Operation::incrementNumberOfTotalDecisions() throw(){
00171          ++number_of_total_decisions_;
00172       }
00173       
00174       uint64_t Operation::getNextTimestamp() throw(){
00175          return ++logical_time_;
00176       }
00177       
00178       uint64_t Operation::getCurrentTimestamp() const throw(){
00179          return logical_time_;
00180       }
00181 
00182 
00183 
00184    }; //end namespace core
00185 }; //end namespace hype
00186 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines