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

📄 shhtest.cc

📁 在linux下面实现的单纯性算法的源代码
💻 CC
字号:
// SHHtest.cc//  used to test the NMSearch////  Adam Gurson, College of William and Mary//      comments revised by Anne Shepherd 5/01//     //  to compile:  g++ -g -DDOUBLE SHHSearch.cc SHHtest.cc objective.cc \//                  rngs.c rvgs.c -lm -o SHHtest#if !defined _testblock_#define _testblock_#include "objective.h"#include "vec.h"#include "SHHSearch.h"#include "maps_general.h"#include "rngs.h"#include "rvgs.h"#include <iostream.h>#include <stdio.h>#include <malloc.h>long TRIALS;long SEED;int n;int numLocMins=1; //this is a placeholderchar Fname[120];long maxCalls;Bounds BOUNDS;void prep() {  long i;  cout<<"SEED=";cin>>SEED;  cout<<"RUNS=";cin>>TRIALS;  cout<<"dim=";cin>>n;  cout<<"maxCalls=";cin>>maxCalls;  cout<<"Fname=";cin>>Fname;  BOUNDS.lower.newsize(n);BOUNDS.upper.newsize(n);  cout<<"Lower bound (space separated)=";  for(i=0;i<n;i++) cin>>BOUNDS.lower[i];  cout<<"Upper bound (space separated)=";  for(i=0;i<n;i++) cin>>BOUNDS.upper[i];  cout<<endl;  PlantSeeds(SEED);  }void runme(void){  for(int iterations=0; iterations<1; iterations++) {    //     incrementInitialStep();  long seed;  SelectStream(0);  SHHSearch Rsearcher(n);  //function value minimums  double RMinimum;  //function point  Vector<double>* RMinimumPt;  //tolerance hit?  int RtoleranceHit;  //number of function calls for each search  int Rcalls;  //counters for total number of function calls   double tot_Rcalls=0.0;  //counters for sum of number of function calls squared  double tot_Rcalls_sq=0.0;  //counters for instances when number of function calls reaches maxCalls  //int RmaxCalls=0;       //counters for tallying number of times local minimums found by each search  int Rmin[numLocMins];  for(int i=0; i<numLocMins; i++)    Rmin[i]=0;  int Rnon_min=TRIALS;  Vector<double> *basePoint = new Vector<double>(n);  for(int trials=0; trials<TRIALS; trials++)     {      for( int k = 0; k < n; k++ )       (*basePoint)[k] = Uniform(BOUNDS.lower[k],BOUNDS.upper[k]);      Rsearcher.InitRegularTriangularSimplex(basePoint, initialStepLength);       //Rsearcher.InitFixedLengthRightSimplex(basePoint, initialStepLength);      Rsearcher.ExploratoryMoves();      RMinimum = Rsearcher.GetMinVal();      Rcalls = Rsearcher.GetFunctionCalls();      RtoleranceHit = Rsearcher.GetTolHit();      if(RtoleranceHit) 	Rsearcher.GetMinPoint(RMinimumPt);      //update total number of function calls for each search      tot_Rcalls+=Rcalls;      //update the sum of the number of function calls squared      tot_Rcalls_sq+=Rcalls*Rcalls;      //write fn val found to file      cout<<"SHHSearch calls="<<Rcalls<<", Value="<<RMinimum;      if(RtoleranceHit) {	cout<<", TolHit="<<RtoleranceHit<<", Point=";	for(int tolIndex = 0; tolIndex < n; tolIndex++)	  cout << (*RMinimumPt)[tolIndex] << " ";	delete RMinimumPt;      }      cout << endl;      if(trials < (TRIALS-1))	{          GetSeed(&seed);          SelectStream(0);          	}//if not over                 }//for trials    delete basePoint;      for(int i=0; i<numLocMins; i++)    {      Rnon_min-=Rmin[i];    }  cout<<"INITIAL STEP LENGTH = "<<initialStepLength<<endl<<endl;   }//for iterations}//mainint main() {  prep();  runme();  return 0;}#endif

⌨️ 快捷键说明

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