📄 operators.c
字号:
/********************************************************************************//* *//* FUNCTION NAME : satis_con() *//* *//* SYNOPSIS : FLAG satis_con(child,fin_mat,rc) *//* *//* DESCRIPTION : This function returns TRUE or FALSE depending*//* on whether the vector passed satisfies all *//* the constraints or not. *//* *//* FUNCTIONS CALLED : none() *//* *//* CALLING FUNCITONS : oper5() *//* *//* AUTHOR : Swarnalatha Swaminathan *//* *//* DATE : 1/17/92 *//* *//* *//* REV DATE BY DESCRIPTION *//* --- ---- -- ----------- *//* *//* *//********************************************************************************/FLAG satis_con(child, fin_mat, rc) VECTOR child; /* The vector to be checked for * violation of constriants */ MATRIX fin_mat; /* The final matrix */ INDEX rc; /* Row and column of the final * matrix */{ int i, j; float tot; for (j = 1; j <= rc.c - 2; j++) if ((child[j] > fin_mat[j][rc.c]) || (child[j] < fin_mat[j][1])) return (FALSE); /* Substitute the values for all the variables, with the new values of */ /* the vector passed and check if the limits are crossed */ for (j = 1; j <= rc.r; j++) { tot = 0.0; for (i = 2; i <= rc.c - 1; i++) tot = tot + fin_mat[j][i] * child[i - 1]; /* If the limits are crossed, return FALSE */ if ((tot < fin_mat[j][1]) || (tot > fin_mat[j][rc.c])) return (FALSE); } /* If the limits are not crossed, return TRUE */ return (TRUE);}/********************************************************************************//* *//* FUNCTION NAME : find_range() *//* *//* SYNOPSIS : void find_range(llim,ulim,comp,fin_mat,rc *//* X,x2)*//* *//* DESCRIPTION : This function finds the upper and lower *//* limits, within which the mutation should *//* occur. *//* *//* FUNCTIONS CALLED : none() *//* *//* CALLING FUNCITONS : oper1() *//* oper2() *//* oper3() *//* *//* AUTHOR : Swarnalatha Swaminathan *//* *//* DATE : 1/17/92 *//* *//* *//* REV DATE BY DESCRIPTION *//* --- ---- -- ----------- *//* *//* *//********************************************************************************/void find_range(llim, ulim, comp, fin_mat, rc, parent) float *llim, *ulim; /* Upper and lower limits */ int comp; /* Component of the vector to be * mutated */ INDEX rc; /* Row and column of the final * matrix */ MATRIX fin_mat; /* The final matrix */ VECTOR parent; /* The vector with the values of * the variables */{ int i, j; float tot, templ, tempu, temp; FLAG _CHANGE = FALSE; /* Replace the values of the variables, and for the values of the vectors */ /* except the one which is to be mutated */ /* Find the lower and upper limits within which the mutation component's */ /* value should be found */ for (j = 1; j <= rc.r; j++) if (fin_mat[j][comp + 1] != 0.0) { tot = 0.0; for (i = 2; i <= rc.c - 1; i++) if (i != comp + 1) tot = tot + fin_mat[j][i] * parent[i - 1]; templ = (fin_mat[j][1] - tot) / fin_mat[j][comp + 1]; tempu = (fin_mat[j][rc.c] - tot) / fin_mat[j][comp + 1]; if (fin_mat[j][comp + 1] < 0) swap(&templ, &tempu);/* if(templ > tempu) swap(&templ,&tempu);*/ if (!_CHANGE) { *llim = templ; *ulim = tempu; _CHANGE = TRUE; } else { if (*llim < templ) *llim = templ; if (*ulim > tempu) *ulim = tempu; } }}/********************************************************************************//* *//* FUNCTION NAME : irange_ran() *//* *//* SYNOPSIS : int irange_ran(llim,ulim) *//* *//* DESCRIPTION : This function returns a random integer *//* between the llim and ulim. *//* *//* FUNCTIONS CALLED : None *//* *//* CALLING FUNCITONS : find_parent(), *//* oper1(). *//* oper2(). *//* oper3(). *//* oper5(). *//* *//* AUTHOR : Swarnalatha Swaminathan *//* *//* DATE : 1/17/92 *//* *//* *//* REV DATE BY DESCRIPTION *//* --- ---- -- ----------- *//* *//* *//********************************************************************************/int irange_ran(llim, ulim) int ulim, llim;{ int num; do num = llim + ((int) ((newrand() * (long) (ulim - llim + 1)) / (long) 65535)); while ((num < llim) || (num > ulim)); return (num);}/********************************************************************************//* *//* FUNCTION NAME : get_F() *//* *//* SYNOPSIS : float get_F(T,t,y,B) *//* *//* DESCRIPTION : This function returns the float value which *//* is the evaluated value of the function, *//* needed for the operators 3 and 6 *//* *//* FUNCTIONS CALLED : none() *//* *//* CALLING FUNCITONS : oper3() *//* CALLING FUNCITONS : oper6() *//* *//* AUTHOR : Tom Logan *//* *//* DATE : 2/23/93 *//* *//* *//* *//********************************************************************************/float get_F(T, t, y, B) unsigned long t, T; int B; float y;{ float factor; factor = (float) pow(1.0 - (float) t / (float) T, (float) B); factor = factor * frange_ran(0.0, 1.0); if (factor < 0.00001) factor = 0.00001; return (y * factor);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -