23个测试函数C语言代码(23个函数来自论文:Evolutionary Programming Made Faster)
- 格式:doc
- 大小:119.50 KB
- 文档页数:12
c语言库函数大全Afx全局函数AfxBeginThread:开始一个新的线程AfxEndThread:结束一个旧的线程AfxFormatString1:类似printf一般地将字符串格式化AfxFormatString2:类似printf一般地将字符串格式化AfxMessageBox:类似Windows API 函数MessageBoxAfxOuputDebugString:将字符串输往除错装置AfxGetApp:获得application object (CWinApp派生对象)的指针AfxGetMainWnd:获得程序主窗口的指针AfxGetInstance:获得程序的instance handleMFC数据类型下面这些是和Win32程序共同使用的数据类型BOOL:布尔值,取值为TRUE or FALSEBSTR:32-bit 字符指针BYTE:8-bit整数,未带正负号COLORREF:32-bit数值,代表一个颜色值DWORD:32-bit整数,未带正负号LONG:32-bit整数,带正负号LPARAM:32-bit整数,作为窗口函数或callback函数的一个参数LPCSTR:32-bit指针,指向一个常数字符串LPSTR:32-bit指针,指向一个字符串LPCTSTR:32-bit指针,指向一个常数字符串,此字符串可以移植到Unicode(世界性的字符集)和DBCS(亚洲字符集)LPTSTR:32-bit指针,指向一个字符串,此字符串可以移植到Unicode和DBCSLPVOID:32-bit指针,指向一个未指定类型的数据LPRESULT:32-bit数值,作为窗口函数或callback函数的返回值UINT:在Win16中是一个16-bit 未带正负号整数,在Win32中是一个32-bit 未带正负号整数,WNDPROC:32-bit指针,指向一个窗口函数WORD:16-bit 整数,未带正负号WPARAM:窗口函数或callback函数的一个参数,在Win16中是16-bit,在Win32中是32-bit下面这些是MFC独特的数据类型POSITION:一个数值,代表collection对象(例如数组或链表)中的元素位置,常用于MFC collection classes (即数据处理类,如CArray)LPCRECT:32-bit指针,指向一个不变的RECT结构CSize说明一个矩形的高和宽,调用CDC::GetTextExtent成员函数计算使用当前字体的一行文字的高和宽决定的尺寸。
C语言函数大全C语言作为一种广泛应用的计算机编程语言,其函数是程序设计中不可或缺的部分。
C语言函数大全涵盖了C语言中常用的各种函数,包括数学函数、字符串函数、输入输出函数等,本文将对这些函数进行详细介绍。
一、数学函数。
1. abs函数。
abs函数用于返回一个整数的绝对值,其原型为int abs(int x)。
2. pow函数。
pow函数用于计算一个数的幂,其原型为double pow(double x, double y)。
3. sqrt函数。
sqrt函数用于计算一个数的平方根,其原型为double sqrt(double x)。
4. sin函数。
sin函数用于计算一个角度的正弦值,其原型为double sin(double x)。
5. cos函数。
cos函数用于计算一个角度的余弦值,其原型为double cos(double x)。
6. tan函数。
tan函数用于计算一个角度的正切值,其原型为double tan(double x)。
二、字符串函数。
1. strlen函数。
strlen函数用于返回一个字符串的长度,其原型为size_t strlen(const char s)。
2. strcpy函数。
strcpy函数用于将一个字符串复制到另一个字符串中,其原型为charstrcpy(char dest, const char src)。
3. strcat函数。
strcat函数用于将一个字符串追加到另一个字符串的末尾,其原型为char strcat(char dest, const char src)。
4. strcmp函数。
strcmp函数用于比较两个字符串,其原型为int strcmp(const char s1, const char s2)。
5. strchr函数。
strchr函数用于在一个字符串中查找指定字符的位置,其原型为charstrchr(const char s, int c)。
23个标准测试函数表达式和名字一、前言在软件开发中,测试函数是非常重要的一环,它可以帮助开发人员验证代码的正确性,确保软件的质量。
而在测试函数中,标准测试函数更是起着至关重要的作用。
本文将就23个标准测试函数表达式和名字进行深入探讨,帮助读者更全面地了解这些标准测试函数。
二、23个标准测试函数表达式和名字1.assertEquals:用于验证两个值是否相等。
2.assertNotEquals:用于验证两个值是否不相等。
3.assertTrue:用于验证某个条件是否为真。
4.assertFalse:用于验证某个条件是否为假。
5.assertNull:用于验证某个值是否为空。
6.assertNotNull:用于验证某个值是否不为空。
7.assertArrayEquals:用于验证两个数组是否相等。
8.assertThat:用于验证某个条件是否满足特定的条件。
9.assertThrows:用于验证是否抛出了预期的异常。
10.assertTimeout:用于验证某个操作是否在规定的时间内完成。
11.assertAll:用于验证多个断言是否都通过。
12.assertSame:用于验证两个对象是否引用同一个对象。
13.assertNotSame:用于验证两个对象是否不引用同一个对象。
14.assertLinesMatch:用于验证两个字符串列表是否匹配。
15.assertIterableEquals:用于验证两个Iterable对象是否相等。
16.assertTimeoutPreemptively:用于验证某个操作是否在规定的时间内完成,且在超时时终止该操作。
17.assertDoesNotThrow:用于验证是否没有抛出任何异常。
18.assertDoesNotThrowThrowable:用于验证是否没有抛出特定类型的异常。
19.assertNotEqualsIgnoreCase:用于验证两个字符串是否不相等,忽略大小写。
23种基准测试函数
1. Sphere Function:球面函数
2. Rosenbrock Function:罗森布洛克函数
3. Rastrigin Function:拉斯特里金函数
4. Ackley Function:阿克利函数
5. Griewank Function:格里文克函数
6. Schwefel Function:施韦费尔函数
7. Styblinski-Tang Function:斯蒂布林斯基-唐函数
8. Levy Function:莱维函数
9. Dixon-Price Function:迪克森-普赖斯函数
10. Powell Function:鲍威尔函数
11. Zakharov Function:扎哈罗夫函数
12. Alpine Function:阿尔派因函数
13. Bohachevsky Function:博哈切夫斯基函数
14. Branin Function:布拉宁函数
15. Bukin Function:布金函数
16. Camel Function:骆驼函数
17. Easom Function:伊索姆函数
18. Goldstein-Price Function:高斯坦-普赖斯函数
19. Himmelblau Function:希梅布劳函数
20. Michalewicz Function:米卡列维奇函数
21. Rosen Function:罗森函数
22. Schaffer Function:谢弗函数
23. Six-Hump Camel Function:六峰骆驼函数。
c语言常用函数大全超详细C语言常用函数大全:A Comprehensive Guide in ChineseC语言是一种非常流行且广泛应用的编程语言,其提供了许多内置函数来处理各种任务。
在本文中,我们将详细介绍一些C语言常用的函数,以帮助初学者和有经验的程序员更好地理解和应用这些函数。
1. printf()函数:该函数用于输出文本到屏幕或文件。
使用格式化字符串可以实现不同类型的输出,如整数、浮点数和字符串。
2. scanf()函数:该函数用于从用户输入中读取数据,并将其保存到变量中。
和printf()函数一样,scanf()函数也使用格式化字符串来指定输入的数据类型。
3. strlen()函数:该函数用于计算字符串的长度。
它返回一个无符号整数,表示字符串中字符的数量,不包括空结束符。
4. strcpy()函数:该函数用于将一个字符串复制到另一个字符串。
它将源字符串中的字符复制到目标字符串中,并在目标字符串的末尾添加空结束符。
5. strcat()函数:该函数用于将一个字符串连接到另一个字符串的末尾。
它将源字符串中的字符连接到目标字符串的末尾,并确保目标字符串以空结束符结尾。
6. atoi()函数:该函数将一个字符串转换为整数并返回结果。
7. atof()函数:该函数将一个字符串转换为浮点数并返回结果。
8. srand()函数:该函数用于初始化随机数生成器。
通过提供一个种子值,可以生成伪随机数序列。
9. rand()函数:该函数生成一个伪随机数。
在调用srand()函数之后,可以使用rand()函数来获取一系列不同的随机数。
10. fopen()函数:该函数用于打开文件,并返回一个指向该文件的指针。
可以指定不同的模式来进行读取、写入或同时读写文件。
11. fclose()函数:该函数用于关闭已经打开的文件。
在完成文件操作后调用该函数是一个良好的编程实践,以确保文件资源被正确释放。
12. fgets()函数:该函数用于从文件中读取一行文本。
C语言常用函数包括:1.printf函数:用于在控制台输出数据。
2.scanf函数:用于从控制台读取用户输入的数据。
3.strlen函数:用于计算字符串的长度。
4.strcmp函数:用于比较两个字符串的大小。
5.strcpy函数:用于将一个字符串复制到另一个字符串中。
6.strcat函数:用于将一个字符串连接到另一个字符串的末尾。
7.strchr函数:用于查找字符串中指定字符的位置。
8.strstr函数:用于查找字符串中指定子串的位置。
9.atoi函数:用于将字符串转换为整数。
10.atof函数:用于将字符串转换为浮点数。
11.malloc函数:用于动态分配内存空间。
12.free函数:用于释放动态分配的内存空间。
13.memcpy函数:用于将一段内存区域的数据复制到另一段内存区域。
14.memset函数:用于将一段内存区域的数据设置为指定的值。
15.abs函数:用于计算整数的绝对值。
16.rand函数:用于生成随机数。
17.srand函数:用于设置随机数生成器的种子。
18.time函数:用于获取当前的系统时间。
19.localtime函数:用于将时间戳转换为本地时间。
20.strtol函数:用于将字符串转换为长整型数。
21.strtod函数:用于将字符串转换为双精度浮点数。
22.fprintf函数:用于将数据格式化输出到文件中。
23.fscanf函数:用于从文件中读取格式化的数据。
24.fgets函数:用于从文件中读取一行数据。
25.fputs函数:用于将数据写入文件中。
26.fopen函数:用于打开文件。
27.fclose函数:用于关闭文件。
28.feof函数:用于判断文件是否已经到达文件末尾。
29.ferror函数:用于判断文件操作是否发生错误。
30.fprintf函数:用于将数据格式化输出到文件中。
24个标准测试函数在计算机编程中,测试函数是用来测试程序的函数。
测试函数可以检查程序的正确性、性能和可靠性。
下面是24个标准测试函数:1. assertEqual(a, b):判断a和b是否相等。
2. assertNotEqual(a, b):判断a和b是否不相等。
3. assertTrue(x):判断x是否为True。
4. assertFalse(x):判断x是否为False。
5. assertIs(a, b):判断a和b是否是同一个对象。
6. assertIsNot(a, b):判断a和b是否不是同一个对象。
7. assertIsNone(x):判断x是否为None。
8. assertIsNotNone(x):判断x是否不为None。
9. assertIn(a, b):判断a是否在b中。
10. assertNotIn(a, b):判断a是否不在b中。
11. assertIsInstance(a, b):判断a是否是b的实例。
12. assertNotIsInstance(a, b):判断a是否不是b的实例。
13. assertAlmostEqual(a, b):判断a和b是否近似相等。
14. assertNotAlmostEqual(a, b):判断a和b是否不近似相等。
15. assertGreater(a, b):判断a是否大于b。
16. assertGreaterEqual(a, b):判断a是否大于等于b。
17. assertLess(a, b):判断a是否小于b。
18. assertLessEqual(a, b):判断a是否小于等于b。
19. assertRegex(s, r):判断s是否匹配正则表达式r。
20. assertNotRegex(s, r):判断s是否不匹配正则表达式r。
21. assertCountEqual(a, b):判断a和b是否包含相同的元素,不考虑顺序。
22. assertMultiLineEqual(a, b):判断a和b是否相等,忽略换行符。
c语言常用函数大全及详解C语言是一种通用的、面向过程的编程语言,被广泛应用于系统软件、嵌入式开发以及科学计算领域。
在C语言中,函数是一种模块化编程的基本方法,通过函数可以将一段代码进行封装和复用,提高了代码的可读性和可维护性。
本文将介绍一些C语言中常用的函数,并详细解释其用法及重要参数。
一、数学函数1. abs()函数函数原型:int abs(int x);函数功能:返回x的绝对值。
参数说明:x为一个整数。
2. pow()函数函数原型:double pow(double x, double y);函数功能:计算x的y次方。
参数说明:x和y为两个double类型的实数。
3. sqrt()函数函数原型:double sqrt(double x);函数功能:计算x的平方根。
参数说明:x为一个double类型的实数。
二、字符串函数1. strcpy()函数函数原型:char* strcpy(char* destination, const char* source);函数功能:将source字符串复制到destination字符串。
参数说明:destination为目标字符串,source为源字符串。
2. strlen()函数函数原型:size_t strlen(const char* str);函数功能:计算str字符串的长度。
参数说明:str为一个以'\0'结尾的字符串。
3. strcat()函数函数原型:char* strcat(char* destination, const char* source);函数功能:将source字符串拼接到destination字符串的末尾。
参数说明:destination为目标字符串,source为源字符串。
三、文件操作函数1. fopen()函数函数原型:FILE* fopen(const char* filename, const char* mode);函数功能:打开一个文件,并返回文件指针。
C语言函数大全(q,r开头)函数名: qsort功能: 使用快速排序例程进行排序用法: void qsort(void *base, int nelem, int width, int (*fcmp)()); 程序例:#include#include#includeint sort_function( const void *a, const void *b);char list[5][4] = { "cat", "car", "cab", "cap", "can" };int main(void){int x;qsort((void *)list, 5, sizeof(list[0]), sort_function);for (x = 0; x < 5; x++)printf("%s\n", list[x]);return 0;}int sort_function( const void *a, const void *b){return( strcmp(a,b) );}函数名: qsort功能: 使用快速排序例程进行排序用法: void qsort(void *base, int nelem, int width, int (*fcmp)()); 程序例:#include#includeint sort_function( const void *a, const void *b);char list[5][4] = { "cat", "car", "cab", "cap", "can" }; int main(void){int x;qsort((void *)list, 5, sizeof(list[0]), sort_function); for (x = 0; x < 5; x++)printf("%s\n", list[x]);return 0;}int sort_function( const void *a, const void *b){return( strcmp(a,b) );}函数名: raise功能: 向正在执行的程序发送一个信号用法: int raise(int sig);程序例:#includeint main(void){int a, b;a = 10;b = 0;if (b == 0)/* preempt divide by zero error */raise(SIGFPE);a = a / b;}函数名: rand功能: 随机数发生器用法: void rand(void);程序例:#include#includeint main(void){int i;printf("Ten random numbers from 0 to 99\n\n");for(i=0; iprintf("%d\n", rand() % 100);return 0;}函数名: randbrd功能: 随机块读用法: int randbrd(struct fcb *fcbptr, int reccnt); 程序例:#include#include#include#includeint main(void){char far *save_dta;char line[80], buffer[256];struct fcb blk;int i, result;/* get user input file name for dta */printf("Enter drive and file name (no path - i.e. a:file.dat)\n"); gets(line);/* put file name in fcb */if (!parsfnm(line, &blk, 1)){printf("Error in call to parsfnm\n");exit(1);}printf("Drive #%d File: %s\n\n", blk.fcb_drive, blk.fcb_name);/* open file with DOS FCB open file */bdosptr(0x0F, &blk, 0);/* save old dta, and set new one */save_dta = getdta();setdta(buffer);/* set up info for the new dta */blk.fcb_recsize = 128;blk.fcb_random = 0L;result = randbrd(&blk, 1);/* check results from randbrd */if (!result)printf("Read OK\n\n");else{perror("Error during read");exit(1);}/* read in data from the new dta */printf("The first 128 characters are:\n");for (i=0; iputchar(buffer[i]);/* restore previous dta */setdta(save_dta);return 0;}函数名: randbwr功能: 随机块写用法: int randbwr(struct fcp *fcbptr, int reccnt);程序例:#include#include#include#includeint main(void){char far *save_dta;char line[80];char buffer[256] = "RANDBWR test!";struct fcb blk;int result;/* get new file name from user */printf("Enter a file name to create (no path - ie. a:file.dat\n"); gets(line);/* parse the new file name to the dta */parsfnm(line,&blk,1);printf("Drive #%d File: %s\n", blk.fcb_drive, blk.fcb_name);/* request DOS services to create file */if (bdosptr(0x16, &blk, 0) == -1){perror("Error creating file");exit(1);}/* save old dta and set new dta */save_dta = getdta();setdta(buffer);/* write new records */blk.fcb_recsize = 256;blk.fcb_random = 0L;result = randbwr(&blk, 1);if (!result)printf("Write OK\n");else{perror("Disk error");exit(1);}/* request DOS services to close the file */ if (bdosptr(0x10, &blk, 0) == -1){perror("Error closing file");exit(1);}/* reset the old dta */setdta(save_dta);return 0;}函数名: random功能: 随机数发生器用法: int random(int num);程序例:#include#include#include/* prints a random number in the range 0 to 99 */int main(void){randomize();printf("Random number in the 0-99 range: %d\n", random (100)); return 0;}函数名: randomize功能: 初始化随机数发生器用法: void randomize(void);程序例:#include#include#includeint main(void){int i;randomize();printf("Ten random numbers from 0 to 99\n\n");for(i=0; iprintf("%d\n", rand() % 100);return 0;}函数名: read功能: 从文件中读用法: int read(int handle, void *buf, int nbyte);程序例:#include#include#include#include#include#includeint main(void){void *buf;int handle, bytes;buf = malloc(10);/*Looks for a file in the current directory named TEST.$$$ and attempts to read 10 bytes from it. To use this example you should create the file TEST.$$$*/if ((handle =open("TEST.$$$", O_RDONLY | O_BINARY, S_IWRITE | S_IREAD)) == -1) {printf("Error Opening File\n");exit(1);}if ((bytes = read(handle, buf, 10)) == -1) {printf("Read Failed.\n");exit(1);else {printf("Read: %d bytes read.\n", bytes);}return 0;}函数名: realloc功能: 重新分配主存用法: void *realloc(void *ptr, unsigned newsize);程序例:#include#include#includeint main(void){char *str;/* allocate memory for string */str = malloc(10);/* copy "Hello" into string */strcpy(str, "Hello");printf("String is %s\n Address is %p\n", str, str);str = realloc(str, 20);printf("String is %s\n New address is %p\n", str, str); /* free memory */free(str);return 0;}函数名: rectangle功能: 画一个矩形用法: void far rectangle(int left, int top, int right, int bottom); 程序例:#include#include#include#includeint main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int left, top, right, bottom;/* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode));printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}left = getmaxx() / 2 - 50;top = getmaxy() / 2 - 50;right = getmaxx() / 2 + 50;bottom = getmaxy() / 2 + 50;/* draw a rectangle */rectangle(left,top,right,bottom);/* clean up */getch();closegraph();return 0;}函数名: registerbgidriver功能: 登录已连接进来的图形驱动程序代码用法: int registerbgidriver(void(*driver)(void));程序例:#include#include#include#includeint main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;/* register a driver that was added into graphics.lib */ errorcode = registerbgidriver(EGAVGA_driver);/* report any registration errors */if (errorcode < 0){printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}/* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}/* draw a line */line(0, 0, getmaxx(), getmaxy());/* clean up */getch();closegraph();return 0;}函数名: remove功能: 删除一个文件用法: int remove(char *filename);程序例:#includeint main(void){char file[80];/* prompt for file name to delete */printf("File to delete: ");gets(file);/* delete the file */if (remove(file) == 0)printf("Removed %s.\n",file);elseperror("remove");return 0;}函数名: rename功能: 重命名文件用法: int rename(char *oldname, char *newname); 程序例:#includeint main(void){char oldname[80], newname[80];/* prompt for file to rename and new name */ printf("File to rename: ");gets(oldname);printf("New name: ");gets(newname);/* Rename the file */if (rename(oldname, newname) == 0)printf("Renamed %s to %s.\n", oldname, newname); elseperror("rename");return 0;}函数名: restorecrtmode功能: 将屏幕模式恢复为先前的imitgraph设置用法: void far restorecrtmode(void);程序例:#include#include#includeint main(void){/* request auto detection */int gdriver = DETECT, gmode, errorcode;int x, y;/* initialize graphics and local variables */initgraph(&gdriver, &gmode, "");/* read result of initialization */errorcode = graphresult();if (errorcode != grOk) /* an error occurred */{printf("Graphics error: %s\n", grapherrormsg(errorcode)); printf("Press any key to halt:");getch();exit(1); /* terminate with an error code */}x = getmaxx() / 2;y = getmaxy() / 2;/* output a message */settextjustify(CENTER_TEXT, CENTER_TEXT);outtextxy(x, y, "Press any key to exit graphics:");getch();/* restore system to text mode */restorecrtmode();printf("We're now in text mode.\n");printf("Press any key to return to graphics mode:");/* return to graphics mode */setgraphmode(getgraphmode());/* output a message */settextjustify(CENTER_TEXT, CENTER_TEXT);outtextxy(x, y, "We're back in graphics mode.");outtextxy(x, y+textheight("W"), "Press any key to halt:"); /* clean up */getch();closegraph();return 0;}。
//F1函数 Spheredouble calculation(double *sol){int i;double result=0;fit++; //标记评估次数for (i=0; i<dim; i++){result+= sol[i]*sol[i];}return result;}//***********************************//F2函数 Schwefel's P2.22double calculation(double *sol){int i;fit++;double result=0;double tmp1=0,tmp2=1.0;for(i=0;i<dim;i++){double temp=fabs(sol[i]);tmp1+=temp;tmp2*=temp;}result=tmp1+tmp2;return result;}//***********************************//F3函ˉ数簓 Quadricdouble calculation(double *sol){int i,j;fit++;double result=0;double tmp2=0.0;for(i=0;i<dim;i++){double tmp1=0.0;for(j=0;j<i+1;j++){tmp1+=sol[j];}tmp2+=tmp1*tmp1;}result=tmp2;return result;}//***********************************//F4函ˉ数簓double calculation(double *sol){int i,j;double result=fabs(sol[0]);fit++;for(i=1;i<dim;i++){if(result<fabs(sol[i])){result=fabs(sol[i]);}}return result;}//***********************************//F5函ˉ数簓 Rosenbrockdouble calculation(double *sol){int i,j;fit++;double result=0;double tmp1=0,tmp2=0;for(i=0;i<dim-1;i++){tmp1=100*(sol[i]*sol[i]-sol[i+1])*(sol[i]*sol[i]-sol[i+1]);tmp2=(sol[i]-1)*(sol[i]-1);result+=tmp1+tmp2;}return result;}//***********************************//F6函ˉ数簓 Stepdouble calculation(double *sol){int i;fit++;double result=0;for (i=0; i<dim; i++){result+=(floor(sol[i]+0.5))*(floor(sol[i]+0.5));}return result;}//***********************************//F7函ˉ数簓 Quadric Noisedouble calculation(double *sol){int i;fit++;double result=0;for (i=0; i<dim; i++){result+=(i+1)*sol[i]*sol[i]*sol[i]*sol[i];}result=result+1.0*rand()/RAND_MAX;return result;}//***********************************//F8函ˉ数簓 Schwefeldouble calculation(double *sol){int i;fit++;double result=0;for (i=0; i<dim; i++){result+=(-1*sol[i])*sin(sqrt(fabs(sol[i])));}return result;}//***********************************//F9函ˉ数簓 Rastrigrindouble calculation(double *sol){int i;fit++;double result=0;for (i=0; i<dim; i++){result+=(sol[i]*sol[i]-10*cos(2*pi*sol[i])+10);}return result;}//***********************************//F10函ˉ数簓 Ackley函ˉ数簓double calculation(double *sol){int i;fit++;double result=0;double tmp1=0.0,tmp2=0.0;for (i=0; i<dim; i++){tmp1+=sol[i]*sol[i];tmp2+=cos(2*pi*sol[i]);}result=20+exp(1)-20*exp(-0.2*sqrt(tmp1/dim))-exp(tmp2/dim);return result;}//***********************************//F11函ˉ数簓 griewangdouble calculation(double *sol){int i;fit++;double result=0;double temp1=0.0,temp2=1.0;for (i=0; i<dim; i++){temp1+=(sol[i]*sol[i])/4000;temp2*=cos(sol[i]/sqrt(i+1));}result=temp1-temp2+1;}//***********************************//F12函ˉ数簓 Generalized Penalizeddouble calculation(double *sol){int i;fit++;double x[dim];double result=0;double temp1=0.0,temp2=0.0;for (i=0; i<dim; i++){x[i]=1+(sol[i]+1)/4;if(sol[i]>10){temp1=100*(sol[i]-10)*(sol[i]-10)*(sol[i]-10)*(sol[i]-10);}else{if(sol[i]<-10){temp1=100*(-sol[i]-10)*(-sol[i]-10)*(-sol[i]-10)*(-sol[i]-10);}elsetemp1=0;}temp2+=temp1;}for(i=0;i<dim-1;i++){result+=(x[i]-1)*(x[i]-1)*(1+10*sin(pi*x[i+1])*sin(pi*x[i+1]));}result=pi/dim*(10*sin(pi*x[0])*sin(pi*x[0])+result+(x[dim-1]-1)*(x[dim-1]-1))+temp2;return result;}//***********************************//F13函ˉ数簓double calculation(double *sol){int i;double temp1=0.0,temp2=0.0;fit++;for (i=0; i<dim; i++){if(sol[i]>5){temp1=100*(sol[i]-5)*(sol[i]-5)*(sol[i]-5)*(sol[i]-5);}else{if(sol[i]<-5){temp1=100*(-sol[i]-5)*(-sol[i]-5)*(-sol[i]-5)*(-sol[i]-5);}elsetemp1=0;}temp2+=temp1;}for(i=0;i<dim-1;i++){result+=(sol[i]-1)*(sol[i]-1)*(1+sin(3.0*pi*sol[i+1])*sin(3.0*pi*sol[i+1]));}result=0.1*(sin(3.0*pi*sol[0])*sin(3.0*pi*sol[0])+result+(sol[dim-1]-1)*(1.0+1.0*si n(2.0*pi*sol[dim-1])))+temp2;return result;}//***********************************//F14函ˉ数簓double calculation(double sol[2]){int i,j;double top=0.0,tmp1=0.0,tmp2=0.0;fit++;double a[2][25]={{-32,-16,0,16,32,-32,-16,0,16,32,-32,-16,0,16,32,-32,-16,0,16,32,-32,-16,0,16,32},{-32,-32,-32,-32,-32,-16,-16,-16,-16,-16,0,0,0,0,0,16,16,16,16,16,32,32,32,32,32}};for(j=0;j<25;j++){top=0.0;for(i=0;i<D;i++)//这a里?D=2{tmp1=sol[i]-a[i][j];tmp1=pow(tmp1,(double)6);top=top+tmp1;}top=(j+1)+top;top=1.0/top;tmp2=tmp2+top;}top=1.0/500+tmp2;top=1.0/top;return top;}//***********************************//F15函ˉ数簓double calculation(double sol[4]){int i;fit++;double top=0.0,tmp1=0.0,tmp2=0.0;doublea[11]={0.1957,0.1947,0.1735,0.1600,0.0844,0.0627,0.0456,0.0342,0.0323,0.0235,0.0246};double b[11]={4.0,2.0,1.0,0.5,0.25,1.0/6,1.0/8,1.0/10,1.0/12,1.0/14,1.0/16};for(i=0;i<11;i++){tmp1=sol[0]*(b[i]*b[i]+b[i]*sol[1]);tmp2=1.0*tmp1/(b[i]*b[i]+b[i]*sol[2]+sol[3]);top=top+(a[i]-tmp2)*(a[i]-tmp2);}return top;}//***********************************//F16函ˉ数簓double calculation(double sol[2]){double top=0;fit++;top=4*pow(sol[0],(double)2)-2.1*pow(sol[0],(double)4)+1.0*pow(sol[0],(double)6)/3+sol[0 ]*sol[1]-4*pow(sol[1],(double)2)+4*pow(sol[1],(double)4);return top;}//***********************************//F17函ˉ数簓double calculation(double sol[2]){ double top=0;fit++;top=sol[1]-(5.1/(4*pi*pi))*pow(sol[0],(double)2)+(5.0/pi)*sol[0]-6;top=pow(top,(double)2);top=top+10.0*(1.0-1.0/(8*pi))*cos(sol[0])+10.0;return top;}//***********************************//F18函ˉ数簓double calculation(double sol[2]){fit++;double top=0,tmp1=0,tmp2=0;top=19.0-14.0*sol[0]+3.0*sol[0]*sol[0]-14*sol[1]+6.0*sol[0]*sol[1]+3.0*sol[1]*sol[1]; tmp1=(sol[0]+sol[1]+1)*(sol[0]+sol[1]+1);tmp2=18.0-32.0*sol[0]+12.0*sol[0]*sol[0]+48*sol[1]-36.0*sol[0]*sol[1]+27.0*sol[1]*sol[1 ];tmp2=30.0+(2.0*sol[0]-3.0*sol[1])*(2.0*sol[0]-3.0*sol[1])*tmp2;top=(1.0+tmp1*top)*tmp2;return top;}//***********************************//该?函ˉ数簓sol[D]是?一?个?四?维?函ˉ数簓,?搜?索÷范?围§:阰[0,1],最?优?值μ是?:阰-3.86//F19函ˉ数簓double calculation(double sol[D]){ int i,j;fit++;double top=0.0,tmp1=0.0;double c[4]={1,1.2,3,3.2};//这里a[4][D]和p[4][D]数据可能有些错误,正确的应该有4*4个数据,这里只有4*3个数据,不清楚是不是最后一个默认为0,大家在应用的时候要特别注意了double a[4][D]={{3,10,30},{0.1,10,35},{3,10,30},{0.1,10,35}};double p[4][D]={{0.3689,0.1170,0.2673},{0.4699,0.4387,0.7470},{0.1091,0.8732,0.5547},{0.03815,0.5743,0.8828}};for(i=0;i<4;i++){top=0.0;for(j=0;j<D;j++){top=top+a[i][j]*(sol[j]-p[i][j])*(sol[j]-p[i][j]);}top=-1.0*top;top=exp(top);tmp1=tmp1+c[i]*top;}tem1=-1.0*tmp1;return tem1;}//***********************************//F20函ˉ数簓double calculation(double sol[D]){int i,j;fit++;double top=0.0,tmp1=0.0;double c[4]={1,1.2,3,3.2};double a[4][D]={{10,3,17,3.5,1.7,8},{0.05,10,17,0.1,8,14},{3,3.5,1.7,10,17,8},{17,8,0.05,10,0.1,14}};double p[4][D]={{0.1312,0.1696,0.5569,0.0124,0.8283,0.5886},{0.2329,0.4135,0.8307,0.3736,0.1004,0.9991},{0.2348,0.1415,0.3522,0.2883,0.3047,0.6650},{0.4047,0.8828,0.8732,0.5743,0.1091,0.0381}};for(i=0;i<4;i++){top=0.0;for(j=0;j<D;j++){top=top+a[i][j]*(sol[j]-p[i][j])*(sol[j]-p[i][j]);}top=-1.0*top;top=exp(top);tmp1=tmp1+c[i]*top;}tem1=-1.0*tmp1;return tem1;}//***********************************//F21函ˉ数簓double calculation(double sol[D]){int i;fit++;double top=0.0,tmp1=0.0;double c[5]={0.1,0.2,0.2,0.4,0.4};double a[5][4]={{4.0,4.0,4.0,4.0},{1.0,1.0,1.0,1.0},{8.0,8.0,8.0,8.0},{6.0,6.0,6.0,6.0},{3.0,7.0,3.0,7.0}};for(i=0;i<5;i++){tmp1=(sol[0]-a[i][0])*(sol[0]-a[i][0])+(sol[1]-a[i][1])*(sol[1]-a[i][1])+(sol[2]-a[i][2])*(sol[2]-a[i][2])+(sol[3]-a[i][3])*(sol[3]-a[i][3]);tmp1=tmp1+c[i];tmp1=1.0/tmp1;top=top+tmp1;}top=-1.0*top;return top;}//***********************************//F22函ˉ数簓double calculation(double sol[D]){int i;fit++;double top=0.0,tmp1=0.0;double c[7]={0.1,0.2,0.2,0.4,0.4,0.6,0.3};double a[7][4]={{4.0,4.0,4.0,4.0},{1.0,1.0,1.0,1.0},{8.0,8.0,8.0,8.0},{6.0,6.0,6.0,6.0},{3.0,7.0,3.0,7.0},{2.0,9.0,2.0,9.0},{5.0,5.0,3.0,3.0}};for(i=0;i<7;i++){tmp1=(sol[0]-a[i][0])*(sol[0]-a[i][0])+(sol[1]-a[i][1]) *(sol[1]-a[i][1])+(sol[2]-a[i][2])*(sol[2]-a[i][2])+(sol[3]-a[i][3])*(sol[3]-a[i][3]);tmp1=tmp1+c[i];tmp1=1/tmp1;top=top+tmp1;}top=0.0-top;return top;}//***********************************//F23函ˉ数簓double calculation(double sol[D]){int i;fit++;double top=0.0,tmp1=0.0;double c[10]={0.1,0.2,0.2,0.4,0.4,0.6,0.3,0.7,0.5,0.5};double a[10][4]={{4.0,4.0,4.0,4.0},{1.0,1.0,1.0,1.0},{8.0,8.0,8.0,8.0},{6.0,6.0,6.0,6.0},{3.0,7.0,3.0,7.0},{2.0,9.0,2.0,9.0},{5.0,5.0,3.0,3.0},{8.1,1.0,8.0,1.0},{6.0,2.0,6.0,2.0},{7.0,3.6,7.0,3.6}};for(i=0;i<10;i++){tmp1=(sol[0]-a[i][0])*(sol[0]-a[i][0])+(sol[1]-a[i][1])*(sol[1]-a[i][1])+(sol[2]-a[i][2 ])*(sol[2]-a[i][2])+(sol[3]-a[i][3])*(sol[3]-a[i][3]);tmp1=tmp1+c[i];tmp1=1.0/tmp1;top=top+tmp1;}top=-1.0*top;return top;}。