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

📄 main.c

📁 很好的一个约束遗传算法优化程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/********************************************************************************//*                                                                              *//*           FUNCTION NAME     :   main()                                       *//*                                                                              *//*           SYNOPSIS          :   void main()                                  *//*                                                                              *//*           DESCRIPTION       :   Given a function with linear constraints,    *//*                                  which is to be optimized, subject to a set  *//*                                  of Equalities, Inequalities and Domains,    *//*                                  this program will eliminate all the         *//*                                  equalities, and hence reduce the total      *//*                                  number of variables to be dealt with. It    *//*                                  will then produce a set of equations all of *//*                                  all of which are domain constraints only.   *//*                                  An initial population of variables vectors  *//*                                  is created, satisfying all the constraints. *//*                                  The process of evaluation, selection and    *//*                                  recombination is repeated for the total     *//*                                  number of generations specified by the user.*//*                                  The final output is a population of vectors *//*                                  with various values generated during the    *//*                                  process of evaluation.                      *//*                                                                              *//*           FUNCTIONS CALLED  :    evaluate()                                  *//*                                  find_ac1_ac2(),                             *//*                                  find_final_mat1(),                          *//*                                  find_final_mat2(),                          *//*                                  find_final_mat3(),                          *//*                                  find_limits(),                              *//*                                  find_lu1_lu2(),                             *//*                                  find_new_in_eq(),                           *//*                                  find_org_in_eq(),                           *//*                                  find_x1_x2,                                 *//*                                  get_var_order(),                            *//*                                  imatrix(),                                  *//*                                  initialize(),                               *//*                                  initialize_x2(),                            *//*                                  inverse(),                                  *//*                                  ivector(),                                  *//*                                  matrix(),                                   *//*                                  mmprod(),                                   *//*                                  mvprod(),                                   *//*                                  optimization(),                             *//*                                  p_equalities(),                             *//*                                  print_equalities(),                         *//*                                  print_inequalities(),                       *//*                                  print_domains(),                            *//*                                  read_file(),                                *//*                                  seed(),                                     *//*                                  vector(),                                   *//*                                  write_file().                               *//*                                                                              *//*           CALLING FUNCITONS :   None                                         *//*                                                                              *//*           AUTHOR            :   Swarnalatha Swaminathan                      *//*                                                                              *//*           DATE              :   1/17/92                                      *//*                                                                              *//*                                                                              *//*           REV            DATE            BY           DESCRIPTION            *//*           ---            ----            --           -----------            *//*                                                                              *//*                                                                              *//********************************************************************************/#include "genocop.h"voidmain(argc, argv)    int             argc;    char           *argv[];{    MATRIX          equalities,		    /* Matrix for equalities */                    inequalities,	    /* Matrix for inequalities */                    domains,		    /* Matrix for Domains */                    a1,			    /* Eqalities split into a1 and a2 */                    a2, inv_a1,		    /* Inverse matrix of a1 */                    c1, c2,		    /* Inequalities split into c1 and					     * c2 */                    new_in_eq,		    /* Inequalities obtained from					     * Equalities */                    org_ineq,		    /* Modified original Inequalities */                    final_mat,		    /* The final Domain */                    inva1_a2;		    /* Product of Inverse of a1 and					     * a2 */    VECTOR          inva1_b,		    /* Product of InverseA1 and					     * vector, rhs of equalities */                    eq_rhs,		    /* Right hand side of the					     * equalities */                    ineq_rhs,		    /* Right hand side of the					     * inequalities */                    ldomain,		    /* Lower limits of the domains */                    udomain,		    /* Upper limits of the domains */                    l1,			    /* lower and upper limits					     * corresponding to the variables */                    l2,			    /* in x1 and x2 */                    u1, u2, X;		    /* Initial values for the					     * variables */    IMATRIX         var_order;		    /* Order of the variables x1					     * followed by x2 */    IVECTOR         eq_co,		    /* Vector X for the Equalities */                    ineq_co,		    /* Vector X for the Inequalities */                    x1,			    /* eq_co divided into x1 and x2 */                    x2, cart;		    /* Array containing the 'p'					     * variables */    FLAG            _PROGEND;		    /* Flag to check the correctness					     * of input data */    INDEX           fin,		    /* Size of final matrix */                    newin,		    /* Size of new inequalities */                    a1a2;		    /* Size of the product matrix					     * a1_a2 */    int             cart_count = 0,	    /* Get a different combination of					     * x2 variables */                    tot_combi = 0,		    /* Total combinations of x2					     * variables */                    i,			    /* Counter variable */                    org_col,		    /* Final inequalities col -					     * x2_variables + RHS of ineq */                    tot_var,		    /* Total number of variables in					     * the problem */                    tot_equ,		    /* Total number of equalities,					     * also p-equalities */                    tot_ine,		    /* Total number of inequalities */                    tot_dom,		    /* Total number of domains, given					     * in the input file */                    x2_vari,		    /* Remaining variables after					     * p-variables were eliminated */                    tot_arr[4];		    /* Array holding total number of					     * variables, equalities,    					     * inequalites, domains, NL    					     * inequalities in    					     * the same order */    time_t          start_time, stop_time;    unsigned long   delta_time;    char            time_str[27];/********************************************************************************/    if (argc < 3)    {	printf("******* Invalid command line syntax *******\n\n");	printf("Syntax is:genocop <infilename> <outfilename>\n\n");	exit(1);    }    start_time = time(NULL);    strcpy(time_str, ctime(&start_time));    seed();    input = fopen(argv[1], "r");    if (input == NULL)    {	printf("Open of %s for input failed", argv[1]);	exit(1);    }    output = fopen(argv[2], "w");    if (output == NULL)    {	printf("Open of %s for output failed", argv[2]);	fclose(input);	exit(1);    }    fprintf(output, "%s", time_str);    fscanf(input, " %d", &tot_arr[0]);	    /* total variables */    tot_arr[1] = 0;    /*fscanf(input, " %d", &tot_arr[1]);*/	    /* total equalities */    fscanf(input, " %d", &tot_arr[2]);	    /* total inequalities */    fscanf(input, " %d", &tot_arr[3]);	    /* total domains */    fin.r = tot_arr[2] + tot_arr[0];	    /* total number of inequalities +					     * domains */    fin.c = tot_arr[0] - tot_arr[1] + 2;    /* x2 variables + lower limits +					     * upper limits */    org_col = tot_arr[0] - tot_arr[1] + 1;  /* x2 variables + rhs */    tot_var = tot_arr[0];		    /* total number of variables */    if (tot_var > MAX_VAR)	printf("Too many variables - Increase MAX_VAR in header file");    tot_equ = tot_arr[1];		    /* total number of equalities */    tot_ine = tot_arr[2];		    /* total number of inequalities */    x2_vari = tot_arr[0] - tot_arr[1];	    /* total variables - p-equalities */    newin.r = tot_equ;    newin.c = fin.c;    a1a2.r = tot_equ;    a1a2.c = org_col;

⌨️ 快捷键说明

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