?? quadr.cc
字號(hào):
//============================================================// 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;}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -