proj home

Files   Classes   Functions   Hierarchy  

main.cpp

Go to the documentation of this file.
00001 // Modified 10/08/03
00002 #include <iostream>
00003 #include <vector>
00004 
00005 using namespace std;
00006 
00007 #include <minmonte.h>
00008 #include <random.h>
00009 
00010 
00011 
00012 // Problem: page 92  of "Introduction to Optimization Theory",
00013 // B.S.Gottried.  
00014 class f1
00015 {
00016 public:
00017   
00018   void operator()(double& val, double* v)
00019     { val = (v[0]-3.0)*(v[0]-3.0)+(v[1]-5.0)*(v[1]-5.0)*9.0; } 
00020 };
00021 
00022 template< typename T>
00023 void print( vector<T> const & v)
00024 {
00025   cout << "[";
00026   if (v.size()==0) 
00027   {
00028     cout << "]";
00029     return;
00030   }
00031   
00032   cout << v[0];
00033 
00034   if (v.size()==1)
00035   {
00036     cout << "]";
00037     return;
00038   }
00039 
00040   for (unsigned int i=1; i<v.size(); ++i)
00041     cout << "," << v[i];
00042 
00043   cout << "]";
00044 }
00045 
00046 
00047 void test01()
00048 {
00049   minmonte< f1, random11<double> , double, 80, 2 > m;
00050 
00051   double a0[2] = {1.0,1.0};
00052   double b0[2] = {8.0,8.0};
00053 
00054   m.setboundingbox(a0,b0);
00055 
00056 /*
00057   cout << "Testing getboundingbox(a,b)" << endl;
00058   vector<double> a1(2), b1(2);
00059   m.getboundingbox(a1,b1);
00060   
00061   cout << "a=";
00062   print(a1);
00063   cout << endl;
00064 
00065   cout << "b=";
00066   print(b1);
00067   cout << endl;
00068 */
00069 
00070   m.printab();
00071   for (unsigned int k=0; k<5; ++k)
00072   {
00073     m(5);
00074     m.printab();
00075   }
00076 
00077   cout << "Testing getresult" << endl;
00078 
00079   double v[2];
00080   double val;
00081   m.getresult(val,v,0);
00082   cout << "val=" << val << " v[0]=" << v[0] << " v[1]=" << v[1] << endl;
00083 
00084 }
00085 
00086 void test02()
00087 {
00088   cout << "Pointer matrix revision." << endl;
00089 
00090   const unsigned int a(2);
00091   const unsigned int b(3);
00092   int v[a][b];
00093 
00094   unsigned int k=0;
00095   for (unsigned int i=0; i<a; ++i )
00096   {
00097     for (unsigned int j=0; j<b; ++j)
00098       v[i][j] = k++;
00099   };
00100 
00101   k=0;
00102 
00103   int* p2;
00104   p2 = (int*)v;
00105   for ( ; k<a*b; ++k, ++p2 )
00106   { 
00107     cout << "k=" << k << "#";
00108     cout << *p2 << "#" << endl;
00109   }
00110 
00111 
00112 }
00113 
00114 
00115 
00116 
00117 int main(int argc, char** argv)
00118 {
00119   test01();
00120 
00121 
00122 
00123   return 0;
00124 }
00125 
00126 
00127 

Generated on Fri Mar 4 00:49:25 2011 for Chelton Evans Source by  doxygen 1.5.8