examples/optimize/optimize.cpp

00001 /*
00002  *      Copyright (C) 2007. PARP Research Group.
00003  *      <http://perception.inf.um.es>
00004  *      University of Murcia, Spain.
00005  *
00006  *      This file is part of the QVision library.
00007  *
00008  *      QVision is free software: you can redistribute it and/or modify
00009  *      it under the terms of the GNU Lesser General Public License as
00010  *      published by the Free Software Foundation, version 3 of the License.
00011  *
00012  *      QVision is distributed in the hope that it will be useful,
00013  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *      GNU Lesser General Public License for more details.
00016  *
00017  *      You should have received a copy of the GNU Lesser General Public
00018  *      License along with QVision. If not, see <http://www.gnu.org/licenses/>.
00019  */
00020 
00038 #include <stdio.h>
00039 #include <stdlib.h>
00040 #include <iostream>
00041 
00042 #ifndef DOXYGEN_IGNORE_THIS
00043 
00044 #include <QVMultidimensionalMinimizer>
00045 
00046 class MyFunctionMinimizer: public QVMultidimensionalMinimizer
00047         {
00048         private:
00049                 double function (const QVVector &v)
00050                         { return 10+POW2(v[0] - 90.0) + POW2(v[1] - 30.0) + POW2(v[2] - 100.0); }
00051         public:
00052                 MyFunctionMinimizer(const double stepSize = 0.1): QVMultidimensionalMinimizer(3, stepSize)      { }
00053         };
00054 
00055 int main(int argc, char *argv[])
00056         {
00057         MyFunctionMinimizer minimizer;
00058         
00059         QVVector v(3,0);
00060         v[0] = 500; v[1] = 0; v[2] = 100;
00061 
00062         minimizer.setStartingVector(v);
00063 
00064         if (minimizer.iterate( 1000, 10e-7))
00065                 std::cout       << "Solution found at " << minimizer.getIterations() << " iterations:" << std::endl
00066                                 << "\tf(" << minimizer.getMinimum() << ") = " << minimizer.getMinimumValue() << std::endl;
00067         else
00068                 std::cout       << "Solution not found, at iteration " << minimizer.getIterations() << std::endl << "\t" << minimizer.getMinimum() << std::endl;
00069 
00070         return 0;
00071         }
00072 
00073 #endif
00074 
00075 

Generated on Thu Jul 17 17:23:27 2008 for QVision by  doxygen 1.5.3