#ifndef POW_MODEL_H_ #define POW_MODEL_H_ #include #include namespace opt_utilities { template class pow_model :public model { private: model* do_clone()const { return new pow_model(*this); } private: pow_model() { } private: model* pm1; typename value_type_trait::value_type idx; public: pow_model(const model& m1, const typename value_type_trait::value_type& index) :pm1(m1.clone()),idx(index) { int np1=m1.get_num_params(); for(int i=0;i p(m1.get_param_info(i)); //param_info p1(p.get_name(),p.get_default_value()); this->push_param_info(p); } } pow_model(const pow_model& rhs) :pm1(NULL),idx(0) { int np1(0); if(rhs.pm1) { pm1=rhs.pm1->clone(); np1=rhs.pm1->get_num_params(); for(int i=0;i p(rhs.pm1->get_param_info(i)); param_info p1(p.get_name()+"1",p.get_default_value()); this->push_param_info(p1); } } idx=rhs.idx; } pow_model& operator=(const pow_model& rhs) { if(this==&rhs) { return *this; } if(!pm1) { //delete pm1; pm1->destroy(); } int np1(0); if(rhs.pm1) { pm1=rhs.pm1->clone(); np1=rhs.pm1->get_num_params(); for(int i=0;i p(rhs.pm1->get_param_info(i)); // param_info p1(p.get_name()+"1",p.get_default_value()); this->push_param_info(p); } } idx=rhs.idx; return *this; } ~pow_model() { if(!pm1) { //delete pm1; pm1->destroy(); } } public: Ty do_eval(const Tx& x,const Tp& param) { if(!pm1) { throw opt_exception("incomplete model!"); } return std::pow(pm1->eval(x,param),idx); } }; template pow_model pow(const model& m1, const typename value_type_trait::value_type& idx) { return pow_model(m1,idx); } }; #endif //EOF