zoukankan      html  css  js  c++  java
  • 多目标遗传算法 ------ NSGA-II (部分源码解析)状态报告 打印 report.c

     1 /* Routines for storing population data into files */
     2 
     3 # include <stdio.h>
     4 # include <stdlib.h>
     5 # include <math.h>
     6 
     7 # include "global.h"
     8 # include "rand.h"
     9 
    10 /* Function to print the information of a population in a file */
    11 void report_pop (population *pop, FILE *fpt)
    12 {
    13     int i, j, k;
    14     for (i=0; i<popsize; i++)
    15     {
    16         for (j=0; j<nobj; j++)
    17         {
    18             fprintf(fpt,"%e	",pop->ind[i].obj[j]);
    19         }
    20         if (ncon!=0)
    21         {
    22             for (j=0; j<ncon; j++)
    23             {
    24                 fprintf(fpt,"%e	",pop->ind[i].constr[j]);
    25             }
    26         }
    27         if (nreal!=0)
    28         {
    29             for (j=0; j<nreal; j++)
    30             {
    31                 fprintf(fpt,"%e	",pop->ind[i].xreal[j]);
    32             }
    33         }
    34         if (nbin!=0)
    35         {
    36             for (j=0; j<nbin; j++)
    37             {
    38                 for (k=0; k<nbits[j]; k++)
    39                 {
    40                     fprintf(fpt,"%d	",pop->ind[i].gene[j][k]);
    41                 }
    42             }
    43         }
    44         fprintf(fpt,"%e	",pop->ind[i].constr_violation);
    45         fprintf(fpt,"%d	",pop->ind[i].rank);
    46         fprintf(fpt,"%e
    ",pop->ind[i].crowd_dist);
    47     }
    48     return;
    49 }
    50 
    51 /* Function to print the information of feasible and non-dominated population in a file */
    52 void report_feasible (population *pop, FILE *fpt)
    53 {
    54     int i, j, k;
    55     for (i=0; i<popsize; i++)
    56     {
    57         if (pop->ind[i].constr_violation == 0.0 && pop->ind[i].rank==1)
    58         {
    59             for (j=0; j<nobj; j++)
    60             {
    61                 fprintf(fpt,"%e	",pop->ind[i].obj[j]);
    62             }
    63              if (ncon!=0)
    64             {
    65                 for (j=0; j<ncon; j++)
    66                 {
    67                     fprintf(fpt,"%e	",pop->ind[i].constr[j]);
    68                 }
    69             }
    70             if (nreal!=0)
    71             {
    72                 for (j=0; j<nreal; j++)
    73                 {
    74                     fprintf(fpt,"%e	",pop->ind[i].xreal[j]);
    75                 }
    76             }
    77             if (nbin!=0)
    78             {
    79                 for (j=0; j<nbin; j++)
    80                 {
    81                     for (k=0; k<nbits[j]; k++)
    82                     {
    83                         fprintf(fpt,"%d	",pop->ind[i].gene[j][k]);
    84                     }
    85                 }
    86             }
    87             fprintf(fpt,"%e	",pop->ind[i].constr_violation);
    88             fprintf(fpt,"%d	",pop->ind[i].rank);
    89             fprintf(fpt,"%e
    ",pop->ind[i].crowd_dist);
    90         }
    91     }
    92     return;
    93 }

    report_pop   将种群中所有个体的   目标函数值, 限制条件值, 编码值  打印出来。

    report_pop   种群中的非支配个体并且限制条件总和为0   constr_violation == 0.0的个体的   目标函数值, 限制条件值, 编码值  打印出来。

  • 相关阅读:
    [整理III]微软等数据结构+算法面试100题[最新第61-80题]
    横空出世,席卷互联网--评微软等公司数据结构+算法面试100题
    SQL Server2008创建约束图解
    sqlserver2008中如何用右键可视化的设置外键
    SQL的主键和外键约束
    Visual Basic|VB 6.0中文版
    java 用eclipse j2ee写的servlet 程序,WEB-INF下的配置文件web.xml在哪啊?谢谢!
    SQL Server数据的导入导出
    MySQL命令行导出数据库
    VS2010数据库连接问题
  • 原文地址:https://www.cnblogs.com/devilmaycry812839668/p/6262461.html
Copyright © 2011-2022 走看看