⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 quadr.cc

📁 COOOL:CWP面向对象最优化库(CWP Object Oriented Optimization Library) COOOL是C++类的一个集合
💻 CC
字号:
//============================================================// COOOL           version 1.1           ---     Nov,  1995//   Center for Wave Phenomena, Colorado School of Mines//============================================================////   This code is part of a preliminary release of COOOL (CWP// Object-Oriented Optimization Library) and associated class // libraries. //// The COOOL library is a free software. You can do anything you want// with it including make a fortune.  However, neither the authors,// the Center for Wave Phenomena, nor anyone else you can think of// makes any guarantees about anything in this package or any aspect// of its functionality.//// Since you've got the source code you can also modify the// library to suit your own purposes. We would appreciate it // if the headers that identify the authors are kept in the // source code.////=============================================================// Authors: H. Lydia Deng, Wences Gouveia//=============================================================#include <Quadr.hh>static const char*  myNameIs =  "quadratic test";const char*  QuadraticObjFcn::className() const{ return(myNameIs);}QuadraticObjFcn::QuadraticObjFcn(int n, Matrix<double>* a, Vector<double>* v, double c):ObjectiveFunction(n){    coeff	=	a;    rhs		=	v;    offset	=	c;}QuadraticObjFcn::~QuadraticObjFcn(){	    if (coeff != NULL) coeff = NULL;    if (rhs != NULL) rhs = NULL;}	double QuadraticObjFcn::realPerformance(const Model<double>& m){    Vector<double> v(m.modParam()), u(v);    u	=	coeff->adotx(v);    double	f	=	u*v;    f   *= 0.5;    f	-=	rhs[0]*v;    f	+=	offset;    return f;}double QuadraticObjFcn::realPerformance(const Model<long>& m){    Model<double> temp(m.modSize());    temp = m;    return realPerformance(temp);}Vector<double>* QuadraticObjFcn::getGradient(const Model<double>& m){    Vector<double>* grad = new Vector<double>(nparam);	    grad[0] = coeff->adotx(m.modParam());    grad[0] -= rhs[0];        return grad;}Vector<double>* QuadraticObjFcn::getGradient(const Model<long>& m){    Vector<double>* grad = new Vector<double>(nparam);    Model<double> md(m.modSize());    md = m;    grad[0]	=	coeff->adotx(md.modParam());    return grad;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -