source/numeric/rosenbrock_test.cxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  The Contents of this file are made available subject to
00004  *  the terms of GNU Lesser General Public License Version 2.1.
00005  *
00006  *
00007  *    GNU Lesser General Public License Version 2.1
00008  *    =============================================
00009  *    Copyright 2008 by Kohei Yoshida.
00010  *    1039 Kingsway Dr., Apex, NC 27502, USA
00011  *
00012  *    This library is free software; you can redistribute it and/or
00013  *    modify it under the terms of the GNU Lesser General Public
00014  *    License version 2.1, as published by the Free Software Foundation.
00015  *
00016  *    This library is distributed in the hope that it will be useful,
00017  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *    Lesser General Public License for more details.
00020  *
00021  *    You should have received a copy of the GNU Lesser General Public
00022  *    License along with this library; if not, write to the Free Software
00023  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024  *    MA  02111-1307  USA
00025  *
00026  ************************************************************************/
00027 
00028 #include "numeric/rosenbrock.hxx"
00029 #include "numeric/funcobj.hxx"
00030 #include "numeric/type.hxx"
00031 #include "numeric/nlpmodel.hxx"
00032 #include "numeric/exception.hxx"
00033 #include "numeric/testtool.hxx"
00034 
00035 using namespace ::scsolver::numeric;
00036 using namespace ::std;
00037 using ::scsolver::numeric::nlp::Rosenbrock;
00038 
00039 class TestFunc1 : public BaseFuncObj
00040 {
00041 public:
00042     TestFunc1() :
00043         BaseFuncObj(2)
00044     {
00045         // initial values
00046         setVar(0, 0);
00047         setVar(1, 3);
00048     }
00049 
00050     virtual ~TestFunc1()
00051     {
00052     }
00053 
00054     virtual double eval() const
00055     {
00056         const vector<double>& vars = getVars();
00057         double term1 = vars[0] - 2;
00058         term1 *= term1*term1*term1;
00059 
00060         double term2 = vars[0] - 2.0*vars[1];
00061         term2 *= term2;
00062 
00063         return term1 + term2;
00064     }
00065 
00069     virtual const string getFuncString() const
00070     {
00071         return string("(x1 - 2)^4 + (x1 - 2*x2)^2");
00072     }
00073 };
00074 
00075 int main()
00076 {
00077     runNonLinearTest(new Rosenbrock, new TestFunc1);
00078 }

Generated on Mon Jul 28 09:13:20 2008 for scsolver by  doxygen 1.5.3