种群解码函数  decode_pop  为包装函数, 核心调用函数为  decode_ind  , 对每个个体进行解码。

  1. /* Routines to decode the population */
  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 decode a population to find out the binary variable values based on its bit pattern */
  11. void decode_pop (population *pop)
  12. {
  13. int i;
  14. if (nbin!=)
  15. {
  16. for (i=; i<popsize; i++)
  17. {
  18. decode_ind (&(pop->ind[i]));
  19. }
  20. }
  21. return;
  22. }

核心解码操作:

  1. /* Function to decode an individual to find out the binary variable values based on its bit pattern */
  2. void decode_ind (individual *ind)
  3. {
  4. int j, k;
  5. int sum;
  6. if (nbin!=)
  7. {
  8. for (j=; j<nbin; j++)
  9. {
  10. sum=;
  11. for (k=; k<nbits[j]; k++)
  12. {
  13. if (ind->gene[j][k]==)
  14. {
  15. sum += pow(,nbits[j]--k);
  16. }
  17. }
  18. ind->xbin[j] = min_binvar[j] + (double)sum*(max_binvar[j] - min_binvar[j])/(double)(pow(,nbits[j])-);
  19. }
  20. }
  21. return;
  22. }

其中,15行,

  1. sum += pow(,nbits[j]--k);

将个体某变量的比特编码  转换为  实数。

  1. ind->xbin[j] = min_binvar[j] + (double)sum*(max_binvar[j] - min_binvar[j])/(double)(pow(,nbits[j])-);

因为需要考虑精度问题,所以二进制编码的个体长度表示的范围空间(double)(pow(2,nbits[j])-1)在考虑精度的情况下   要大于 该变量的 范围空间 ( max_binvar[j] - min_binvar[j] ) 。

因此, 需要进行空间映射转换,以上代码便是此意。

多目标遗传算法 ------ NSGA-II (部分源码解析) 二进制编码的个体解码操作 decode.c的更多相关文章

  1. 多目标遗传算法 ------ NSGA-II (部分源码解析)辅助变量 双链表操作 list.c

    /* A custom doubly linked list implemenation */ # include <stdio.h> # include <stdlib.h> ...

  2. 多目标遗传算法 ------ NSGA-II (部分源码解析)介绍

    NSGA(非支配排序遗传算法).NSGA-II(带精英策略的快速非支配排序遗传算法),都是基于遗传算法的多目标优化算法,是基于pareto最优解讨论的多目标优化. 在官网: http://www.ii ...

  3. 多目标遗传算法 ------ NSGA-II (部分源码解析) 交叉操作 crossover.c

    遗传算法中的交叉操作是 对NSGA-II  源码分析的  最后一部分, 这一部分也是我 从读该算法源代码和看该算法论文理解偏差最大的  函数模块. 这里,首先提一下,遗传算法的  交叉操作.变异操作都 ...

  4. 多目标遗传算法 ------ NSGA-II (部分源码解析)目标函数 problemdef.c

    /* Test problem definitions */ # include <stdio.h> # include <stdlib.h> # include <ma ...

  5. 多目标遗传算法 ------ NSGA-II (部分源码解析)状态报告 打印 report.c

    /* Routines for storing population data into files */ # include <stdio.h> # include <stdlib ...

  6. 多目标遗传算法 ------ NSGA-II (部分源码解析) 拥挤距离计算 crowddist.c

    /* Crowding distance computation routines */ # include <stdio.h> # include <stdlib.h> # ...

  7. 多目标遗传算法 ------ NSGA-II (部分源码解析)README 算法的部分英文解释

    This is the Readme file for NSGA-II code. About the Algorithm--------------------------------------- ...

  8. 多目标遗传算法 ------ NSGA-II (部分源码解析) 实数、二进制编码的变异操作 mutation.c

    遗传算法的变异操作 /* Mutation routines */ # include <stdio.h> # include <stdlib.h> # include < ...

  9. 多目标遗传算法 ------ NSGA-II (部分源码解析)两个个体支配判断 dominance.c

    /* Domination checking routines */ # include <stdio.h> # include <stdlib.h> # include &l ...

  10. 多目标遗传算法 ------ NSGA-II (部分源码解析)二元锦标赛选择 tourselect.c

    tourselect.c  文件中共有两个函数: selection (population *old_pop, population *new_pop) individual* tournament ...

随机推荐

  1. UIImageView之我的动画为什么停了?UIImageView, highLighted,animationImages

    如果你的动画总是停了!停了!停了!不管你想不想都停,这里有个参考,你可以看看!这只是一种可能性!!! 受最近看到段子影响,画风略诡异,不喜勿喷. 最近在“刻”动画!!! 为什么是“刻”,动画写了3周啊 ...

  2. Java OAuth开发包资料

    原文地址:http://www.oschina.net/project/tag/307/oauth?lang=19&sort=time

  3. android实现json数据的解析和把数据转换成json格式的字符串

    利用android sdk里面的 JSONObject和JSONArray把集合或者普通数据,转换成json格式的字符串 JSONObject和JSONArray解析json格式的字符串为集合或者一般 ...

  4. lc面试准备:Implement Queue using Stacks

    1 题目 Implement the following operations of a queue using stacks. push(x) -- Push element x to the ba ...

  5. Android4.0窗口机制和创建过程分析

    一  前言 在谈到这个话题的时候,脑海里面千头万绪,因为它涉及到了方方面面的知识… 比如Activity管理,窗口添加,Token权限验证等等… 既然这么复杂,那么我们就复杂的问题简单化,可以分成下面 ...

  6. android5.0中RecycleView的用法

    最近学习了android5.0中新增的一个组件RecycleView,是用来代替当前的listview开发的,是因为在RecycleView中已经有了viewholder缓存,并且不同的item之间可 ...

  7. 短信验证码js实现

    短信验证码实现 我们在使用移动.电信等运营商网上营业厅的时候,为确保业务的完整和正确性,经常会需要用到短信的验证码.最近因为某省业务需要,也做了个类似的功能. 原理很简单,就是在用户点击"获 ...

  8. Linux Shell编程(10)——引用变量

    当要引用一个变量的值时,一般推荐使用双引号.使用双引号除了变量名前缀($).后引符(`)和转义符(\)外,会使shell不再解释引号中其它所有的特殊字符.用双引号时$仍被当成特殊字符,允许引用一个被双 ...

  9. (转)WS2008远程桌面连接时提示:“要登录到此远程计算机,您必须被授予允许通过终端服务登录的权限”的解决办法

    原文:http://www.chunfengxiyu.com/ws2008-mstsc-privilege.html WS2008远程桌面连接时提示:“要登录到此远程计算机,您必须被授予允许通过终端服 ...

  10. ContentProvider初阶Cookbook

    在Android世界里,ContentProvider将数据存储抽象成了类似SQL的形式,通过insert, delete, update, query等接口实现对数据的增删改查.通过ContentP ...