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

📄 probl01.h

📁 此代码是文化算法的一个例子
💻 H
字号:
/* Write in this file your function and constraints *//* Modify the following parameters */#define VARIABLES 13/* Total number of constraints */#define NUMCONSTR 9/* Number of equiality constraints (must be the last) */#define NUMEQCONSTR 0/* Number of tests for each node expansion        PRUEBAS_ARBOL = VARIABLES or more */#define PRUEBAS_ARBOL 13/* Maximum depth of the tree */#define PROFUNDIDAD_MAX 5/* n for the 2^n-tree (must be less or equal than the   number of variables, but we suggest not more than 4 */#define TREEDIMS 3/*      TREENODES = 2^TREEDIMS */#define TREENODES 8struct individuo {	float variable[VARIABLES];	float aptitud;	float g[NUMCONSTR];	float viol;	char factible;	struct celda *celda;	unsigned char victorias;};struct celda {	char clase;	char profundidad;	char d[TREEDIMS];	int factibles, noFactibles;	float lnodo[VARIABLES], unodo[VARIABLES];	struct celda *hijo, *padre;};struct creencias {	float l[VARIABLES], u[VARIABLES], L[VARIABLES], U[VARIABLES], lp[VARIABLES], up[VARIABLES];	struct celda *raiz;};void limites(float[], float[]);void evalua(struct individuo *, float, float, int);/* Give here the lower and upper bounds for the variables */void limites(float l[], float u[]) {	int i;	for (i = 0; i < 9; i++) {		l[i] = 0.0;		u[i] = 1.0;	}	for (i = 9; i < 12; i++) {		l[i] = 0.0;		u[i] = 100.0;	}	l[12] = 0.0;	u[12] = 1.0;}/* Evaluaci髇 de la aptitud y de las restricciones.   Funci髇 que cambia con el problema */void evalua(struct individuo *ind, float deltai, float deltaf, int Gmax) {	int i;	float s1 = 0.0, s2 = 0.0, s3 = 0.0;	float delta = 0.001; /* Para las restricciones de igualdad */	/* Evaluate the objective function, and store its value in ind->aptitud.	   Evaluate the constraints and store 1 in ind->factible if the point is feasible,	   or 0 if it is infeasible.	   Use the values stored in ind->variable[i]. */	for (i = 0; i < 4; i++) {		s1 += ind->variable[i];		s2 += ind->variable[i]*ind->variable[i];	}	for (i = 4; i < 13; i++) {		s3 += ind->variable[i];	}	ind->aptitud = 5*s1 - 5*s2 - s3;	ind->g[0] = 2*ind->variable[0] + 2*ind->variable[1] + ind->variable[9] + ind->variable[10] - 10;	ind->g[1] = 2*ind->variable[0] + 2*ind->variable[2] + ind->variable[9] + ind->variable[11] - 10;	ind->g[2] = 2*ind->variable[1] + 2*ind->variable[2] + ind->variable[10] + ind->variable[11] - 10;	ind->g[3] = -8*ind->variable[0] + ind->variable[9];	ind->g[4] = -8*ind->variable[1] + ind->variable[10];	ind->g[5] = -8*ind->variable[2] + ind->variable[11];	ind->g[6] = -2*ind->variable[3] - ind->variable[4] + ind->variable[9];	ind->g[7] = -2*ind->variable[5] - ind->variable[6] + ind->variable[10];	ind->g[8] = -2*ind->variable[7] - ind->variable[8] + ind->variable[11];	ind->factible = 1;	for (i = 0; i < NUMCONSTR; i++) {		if (i < NUMCONSTR - NUMEQCONSTR) {			if (ind->g[i] > 0) {				ind->factible = 0;				break;			}		}		else {			if (fabs(ind->g[i]) - delta > 0) {				ind->factible = 0;				break;			}		}	}}

⌨️ 快捷键说明

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