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

📄 main.c

📁 很好的一个约束遗传算法优化程序
💻 C
📖 第 1 页 / 共 2 页
字号:
    /* Allocating memory for all the vectors and matrices */    final_mat = matrix(1, fin.r, 1, fin.c);    equalities = matrix(1, tot_equ, 1, tot_var + 1);    eq_co = ivector(1, tot_var);    eq_rhs = vector(1, tot_equ);    a1 = matrix(1, tot_equ, 1, tot_equ);    a2 = matrix(1, tot_equ, 1, x2_vari);    inv_a1 = matrix(1, tot_equ, 1, tot_equ);    inva1_a2 = matrix(1, tot_equ, 1, x2_vari);    inva1_b = vector(1, tot_equ);    new_in_eq = matrix(1, tot_equ, 1, fin.c);    inequalities = matrix(1, tot_ine, 1, tot_var + 1);    ineq_co = ivector(1, tot_var);    ineq_rhs = vector(1, tot_ine);    c1 = matrix(1, tot_ine, 1, tot_equ);    c2 = matrix(1, tot_ine, 1, x2_vari);    org_ineq = matrix(1, tot_ine, 1, org_col);    domains = matrix(1, tot_var, 1, 3);    ldomain = vector(1, tot_var);    udomain = vector(1, tot_var);    l1 = vector(1, tot_equ);    u1 = vector(1, tot_equ);    x1 = ivector(1, tot_equ);    l2 = vector(1, x2_vari);    u2 = vector(1, x2_vari);    x2 = ivector(1, x2_vari);    X = vector(1, tot_var);    var_order = imatrix(1, tot_var, 1, 2);    cart = ivector(1, tot_equ);    /* Reading the data file */    read_file(equalities, inequalities, domains, tot_arr);    /* Initialization */    for (i = 1; i <= tot_var; i++)    {	eq_co[i] = i;	ineq_co[i] = i;    }    for (i = 1; i <= tot_equ; i++)	eq_rhs[i] = equalities[i][tot_var + 1];    for (i = 1; i <= tot_ine; i++)	ineq_rhs[i] = inequalities[i][tot_var + 1];    print_equalities(equalities, tot_var, tot_equ, eq_co, eq_rhs);    print_inequalities(inequalities, tot_var, tot_ine, ineq_co, ineq_rhs);    print_domains(domains, tot_var);    free_ivector(eq_co, 1);    free_ivector(ineq_co, 1);    do    {	if (tot_equ != 0)	{	    /*	     * From 'cart' the order of variables is got, p-variables	     * followed by the rest	     */	    get_var_order(tot_arr, cart, var_order);	    /*	     * The original vector X is divided into x1(p-variables) and	     * x2(the rest)	     */	    find_x1_x2(tot_var, var_order, x1, x2);	    /*	     * The original equalities is divided into two matrices	     * a1(p-equalities and a2	     */	    find_ac1_ac2(tot_equ, tot_equ, x2_vari, x1, x2, equalities, a1, a2);	    /* This procedure finds the inverse of a1 */	    inverse(a1, inv_a1, tot_equ);	    /* Matrix product of inverse of a1 and a2 */	    mmprod(tot_equ, tot_equ, x2_vari, inva1_a2, inv_a1, a2);	    /* Vector product of inverse of a1 and the RHS of the equalities */	    mvprod(tot_equ, tot_equ, inva1_b, inv_a1, eq_rhs);	    /* The original inequalities divided into c1 and c2 */	    find_ac1_ac2(tot_equ, tot_ine, x2_vari, x1, x2, inequalities, c1, c2);	    /* split the domain matrix into Llim and Ulim vectors */	    find_limits(tot_var, domains, ldomain, udomain);	    /* find the Llim and Ulim corresponding to x1 and x2 */	    find_lu1_lu2(tot_arr, x1, x2, ldomain, l1, l2);	    find_lu1_lu2(tot_arr, x1, x2, udomain, u1, u2);	    /* Find the new inequalities from the original equalities */	    find_new_in_eq(inva1_b, inva1_a2, l1, u1, newin, new_in_eq);	    /* find the new inequalities from the original inequalities */	    find_org_in_eq(inva1_b, inva1_a2, ineq_rhs, c1, c2, tot_ine, a1a2, org_ineq);	    /* initializing the final output matrix */	    initialize(final_mat, fin);	    /*	     * append the remaining domains, converted equalities and	     * ineqalites to form the final matrix	     */	    find_final_mat1(l2, u2, final_mat, x2_vari, fin.c);	    find_final_mat2(new_in_eq, tot_equ, fin.c, org_col, final_mat);	    find_final_mat3(org_ineq, tot_ine, org_col, tot_var + 1, final_mat);	} else	{	    for (i = 1; i <= tot_var; i++)	    {		l2[i] = domains[i][1];		x2[i] = domains[i][2];		u2[i] = domains[i][3];	    }	    initialize(final_mat, fin);	    find_final_mat1(l2, u2, final_mat, tot_var, fin.c);	    if (tot_ine != 0)		find_final_mat3(inequalities, tot_ine, org_col, tot_var + 1, final_mat);	}	/* This function gets a set of starting points for the variables */	/* _PROGEND = initialize_x2(final_mat,fin,x1,x2,tot_equ,X,inva1_b); */    } while ( /* (!_PROGEND)&& */ (cart_count < tot_combi));    free_vector(eq_rhs, 1);    free_vector(ineq_rhs, 1);    free_vector(ldomain, 1);    free_vector(udomain, 1);    free_vector(l1, 1);    free_vector(l2, 1);    free_vector(u1, 1);    free_vector(u2, 1);    free_ivector(cart, 1);    if (tot_equ != 0)    {	/*	 * if(cart_count >= tot_combi) { fprintf(output,"Incorrect data");	 * exit(1); }	 *//*    write_file(final_mat,fin,inva1_b,x1,x2,tot_equ,x2_vari,tot_var+1); */	/*	 * This procedure initializes the initial population with the values	 * generated and applies the genetic operators and reproduces a new	 * generation; evaluates each agent of the new generation, and again	 * goes through the cycle of reproduction and evaluation, for the	 * number of times, user has specified and prints out a final	 * population with best agents	 */	optimization(X, x1, x2, final_mat, fin, tot_equ, inva1_b);    } else	optimization(X, x2, x2, final_mat, fin, tot_equ, inva1_b);    stop_time = time(NULL);    delta_time = (unsigned long) stop_time - start_time;    fprintf(output, "\n\nTotal run time : %lu seconds\n", delta_time);    fclose(output);    free_matrix(final_mat, 1, fin.r, 1);    free_matrix(equalities, 1, tot_equ, 1);    free_matrix(a1, 1, tot_equ, 1);    free_matrix(a2, 1, tot_equ, 1);    free_matrix(inv_a1, 1, tot_equ, 1);    free_matrix(inva1_a2, 1, tot_equ, 1);    free_vector(inva1_b, 1);    free_matrix(new_in_eq, 1, tot_equ, 1);    free_matrix(inequalities, 1, tot_ine, 1);    free_matrix(c1, 1, tot_ine, 1);    free_matrix(c2, 1, tot_ine, 1);    free_matrix(org_ineq, 1, tot_ine, 1);    free_matrix(domains, 1, tot_var, 1);    free_ivector(x1, 1);    free_ivector(x2, 1);    free_vector(X, 1);    free_imatrix(var_order, 1, tot_var, 1);    exit(0);}

⌨️ 快捷键说明

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