?? operators.c
字號:
} free_matrix(child, 1, 2, 1);}/********************************************************************************//* *//* FUNCTION NAME : oper5() *//* *//* SYNOPSIS : MATRIX oper5(p1,p2,STEP,rc,fin_mat,X,x2) *//* *//* DESCRIPTION : This function returns two new vectors *//* generated after simple arithmetical *//* crossover, from the two parent vectors. *//* *//* FUNCTIONS CALLED : irange_ran() *//* matrix(), *//* satis_con() *//* *//* CALLING FUNCITONS : optimization() *//* *//* AUTHOR : Swarnalatha Swaminathan *//* *//* DATE : 1/17/92 *//* *//* *//* REV DATE BY DESCRIPTION *//* --- ---- -- ----------- *//* *//* *//********************************************************************************/void oper5(p1, p2, STEP, rc, fin_mat) VECTOR p1, p2; /* The two parents for crossing * over */ INDEX rc; /* Row and column of the final * matrix */ MATRIX fin_mat; /* The final matrix */ int STEP; /* Parameter for the crossover */{ MATRIX child; FLAG _CHECK1 = FALSE, /* Check to see if the newly * created vectors satisfies the */ _CHECK2 = FALSE; /* set of constraints */ int i, n = 1, cut; child = matrix(1, 2, 1, rc.c - 2); /* Get a random spot on the vector for crossover */ cut = irange_ran(1, rc.c - 2); /* Copy the parent vectors on to the child vectors */ for (i = 1; i <= cut; i++) { child[1][i] = p1[i]; child[2][i] = p2[i]; } do { /* Cross the two vectors */ for (i = cut + 1; i <= rc.c - 2; i++) { child[1][i] = p1[i] * (float) n / (float) STEP + p2[i] * (1.0 - (float) n / (float) STEP); child[2][i] = p2[i] * (float) n / (float) STEP + p1[i] * (1.0 - (float) n / (float) STEP); } /* Check to see if they satisfy the constraints */ _CHECK1 = satis_con(child[1], fin_mat, rc); _CHECK2 = satis_con(child[2], fin_mat, rc); n++; /* If the constraints not satisfied, then generate another */ /* set of crossed over values */ } while ((n <= STEP) && ((_CHECK1 == FALSE) || (_CHECK2 == FALSE))); for (i = 1; i <= rc.c - 2; i++) { p1[i] = child[1][i]; p2[i] = child[2][i]; } free_matrix(child, 1, 2, 1);}/********************************************************************************//* *//* FUNCTION NAME : oper6() *//* *//* SYNOPSIS : VECTOR oper6(parent,fin_mat,r,c,T,t,B) *//* *//* DESCRIPTION : This function returns a new vector generated *//* from the parent vector, after applying *//* the operator, whole 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 *//* --- ---- -- ----------- *//* A 9/1/92 Tom Logan *//* *//********************************************************************************/void oper6(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, num, *next; float llim, ulim; next = ivector(1, rc.c - 2); for (i = 1; i <= rc.c - 2; i++) next[i] = 0; for (i = 1; i <= rc.c - 2; i++) { do comp = irange_ran(1, rc.c - 2); while (next[comp] == 1); next[comp] = 1; 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); } free_ivector(next, 1);}/********************************************************************************//* *//* FUNCTION NAME : oper7() *//* *//* SYNOPSIS : void oper7(p1,p2,rc,fin_mat,X,x2) *//* *//* DESCRIPTION : This function returns one new vector *//* *//* FUNCTIONS CALLED : frange_ran() *//* vector(), *//* satis_con() *//* *//* CALLING FUNCITONS : optimization() *//* *//* AUTHOR : Tom Logan *//* *//* DATE : 10/1/92 *//* *//* *//* REV DATE BY DESCRIPTION *//* --- ---- -- ----------- *//* *//* *//********************************************************************************/void oper7(p1, p2, rc, fin_mat) VECTOR p1, p2; /* The two parents for crossing * over */ INDEX rc; /* Row and column of the final * matrix */ MATRIX fin_mat; /* The final matrix */{ VECTOR child; FLAG _CHECK = FALSE; /* Check to see if the newly * created vector satisfies the */ /* set of constraints */ int i, n = 2, tries = 10; float A; child = vector(1, rc.c - 2); do { A = frange_ran(0.0, 1.0); for (i = 1; i <= rc.c - 2; i++) child[i] = A * (p2[i] - p1[i]) + p2[i]; /* Check to see if it satisfies the constraints */ _CHECK = satis_con(child, fin_mat, rc); n++; /* If the constraints not satisfied, then try again */ } while ((n <= tries) && (_CHECK == FALSE)); if (_CHECK) for (i = 1; i <= rc.c - 2; i++) p1[i] = child[i]; free_vector(child, 1);}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -