?? operators.c
字號:
#include "genocop.h"/********************************************************************************//* *//* FUNCTION NAME : oper1() *//* *//* SYNOPSIS : VECTOR oper1(parent,fin_mat,rc) *//* *//* DESCRIPTION : This function returns a new vector generated *//* from the parent vector, after applying *//* the operator, uniform mutation. *//* *//* FUNCTIONS CALLED : find_range(), *//* frange_ran(), *//* irange_ran(), *//* vector(). *//* *//* CALLING FUNCITONS : optimization() *//* *//* AUTHOR : Swarnalatha Swaminathan *//* *//* DATE : 1/17/92 *//* *//* *//* REV DATE BY DESCRIPTION *//* --- ---- -- ----------- *//* *//* *//********************************************************************************/void oper1(parent, fin_mat, rc) VECTOR parent; /* The parent vector */ MATRIX fin_mat; /* The final matrix */ INDEX rc; /* Row and column of the final * matrix */{ int comp, i; float llim, ulim; /* Lower and Upper limits of the * value to be mutated */ comp = irange_ran(1, rc.c - 2); /* * Finding the lower and upper limits between which the values are to be * mutated */ find_range(&llim, &ulim, comp, fin_mat, rc, parent); /* * Find a random value between the lower and the upper limits, to * substitute */ /* for the old value */ parent[comp] = frange_ran(llim, ulim);}/********************************************************************************//* *//* FUNCTION NAME : oper2() *//* *//* SYNOPSIS : VECTOR oper2(parent,fin_mat,rc) *//* *//* DESCRIPTION : This function returns a new vector generated *//* from the parent vector, after applying *//* the operator, boundary mutation. *//* *//* FUNCTIONS CALLED : find_range(), *//* flip(), *//* irange_ran(), *//* vector(). *//* *//* CALLING FUNCITONS : optimization() *//* *//* AUTHOR : Swarnalatha Swaminathan *//* *//* DATE : 1/17/92 *//* *//* *//* REV DATE BY DESCRIPTION *//* --- ---- -- ----------- *//* *//* *//********************************************************************************/void oper2(parent, fin_mat, rc) VECTOR parent; /* The parent vector */ MATRIX fin_mat; /* The final matrix */ INDEX rc; /* Row and column of the final * matrix */{ int comp, i; float llim, ulim; /* Lower and Upper limits of the * value to be mutated */ comp = irange_ran(1, rc.c - 2); /* * Finding the lower and upper limits between which the values are to be * mutated */ find_range(&llim, &ulim, comp, fin_mat, rc, parent); /* Replace either the lower limit or the upper limit at random, */ /* for the old value */ parent[comp] = (flip() == TAIL) ? llim : ulim;}/********************************************************************************//* *//* FUNCTION NAME : oper3() *//* *//* SYNOPSIS : VECTOR oper3(parent,fin_mat,r,c,T,t,B) *//* *//* DESCRIPTION : This function returns a new vector generated *//* from the parent vector, after applying *//* the operator, non-uniform mutation. *//* *//* FUNCTIONS CALLED : find_range(), *//* flip(), *//* get_F(), *//* irange_ran(), *//* vector(). *//* *//* CALLING FUNCITONS : optimization() *//* *//* AUTHOR : Swarnalatha Swaminathan *//* *//* DATE : 1/17/92 *//* *//* *//* REV DATE BY DESCRIPTION *//* --- ---- -- ----------- *//* *//* *//********************************************************************************/void oper3(parent, fin_mat, rc, T, t, B) VECTOR parent; MATRIX fin_mat; INDEX rc; unsigned long T; /* Total number of generations */ unsigned long t; /* Current generation number */ int B;{ int comp, i; float llim, ulim; comp = irange_ran(1, rc.c - 2); find_range(&llim, &ulim, comp, fin_mat, rc, parent); /* * From the current value of the component to be mutated, chooose at * random */ /* whether to mutate with a lesser value or a greater value */ /* Then find a value lesser or greater than the original value from the */ /* function get_f() */ parent[comp] = (flip() == TAIL) ? parent[comp] - get_F(T, t, parent[comp] - llim, B) : parent[comp] + get_F(T, t, ulim - parent[comp], B);}/********************************************************************************//* *//* FUNCTION NAME : oper4() *//* *//* SYNOPSIS : MATRIX oper4(p1,p2,x2_vari) *//* *//* DESCRIPTION : This function returns two new vectors *//* generated after whole arithmetical *//* crossover, from the two parent vectors. *//* *//* FUNCTIONS CALLED : matrix() *//* *//* CALLING FUNCITONS : optimization() *//* *//* AUTHOR : Swarnalatha Swaminathan *//* *//* DATE : 1/17/92 *//* *//* *//* REV DATE BY DESCRIPTION *//* --- ---- -- ----------- *//* A 10/1/92 Tom Logan Parameter A is now *//* random(0-1) *//* *//********************************************************************************/void oper4(p1, p2, x2_vari) VECTOR p1, p2; /* The two parents chosen for * crossover */ int x2_vari; /* Length of the vector */{ MATRIX child; int i; float A; child = matrix(1, 2, 1, x2_vari); do A = frange_ran(0.0, 1.0); while (A == 0); /* insure A is above 0 */ for (i = 1; i <= x2_vari; i++) { child[1][i] = p1[i] * A + p2[i] * (1.0 - A); child[2][i] = p2[i] * A + p1[i] * (1.0 - A); } for (i = 1; i <= x2_vari; i++) { p1[i] = child[1][i]; p2[i] = child[2][i];
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -