1. /* Routines for randomized recursive quick-sort */
  2.  
  3. # include <stdio.h>
  4. # include <stdlib.h>
  5. # include <math.h>
  6.  
  7. # include "global.h"
  8. # include "rand.h"
  9.  
  10. /* Randomized quick sort routine to sort a population based on a particular objective chosen */
  11. void quicksort_front_obj(population *pop, int objcount, int obj_array[], int obj_array_size)
  12. {
  13. q_sort_front_obj (pop, objcount, obj_array, , obj_array_size-);
  14. return;
  15. }
  16.  
  17. /* Actual implementation of the randomized quick sort used to sort a population based on a particular objective chosen */
  18. void q_sort_front_obj(population *pop, int objcount, int obj_array[], int left, int right)
  19. {
  20. int index;
  21. int temp;
  22. int i, j;
  23. double pivot;
  24. if (left<right)
  25. {
  26. index = rnd (left, right);
  27. temp = obj_array[right];
  28. obj_array[right] = obj_array[index];
  29. obj_array[index] = temp;
  30. pivot = pop->ind[obj_array[right]].obj[objcount];
  31. i = left-;
  32. for (j=left; j<right; j++)
  33. {
  34. if (pop->ind[obj_array[j]].obj[objcount] <= pivot)
  35. {
  36. i+=;
  37. temp = obj_array[j];
  38. obj_array[j] = obj_array[i];
  39. obj_array[i] = temp;
  40. }
  41. }
  42. index=i+;
  43. temp = obj_array[index];
  44. obj_array[index] = obj_array[right];
  45. obj_array[right] = temp;
  46. q_sort_front_obj (pop, objcount, obj_array, left, index-);
  47. q_sort_front_obj (pop, objcount, obj_array, index+, right);
  48. }
  49. return;
  50. }

按照个体的不同  目标函数 序号(objcount),  对种群序号数组obj_array按照拥挤距离进行快速排序。

  1. /* Randomized quick sort routine to sort a population based on crowding distance */
  2. void quicksort_dist(population *pop, int *dist, int front_size)
  3. {
  4. q_sort_dist (pop, dist, , front_size-);
  5. return;
  6. }
  7.  
  8. /* Actual implementation of the randomized quick sort used to sort a population based on crowding distance */
  9. void q_sort_dist(population *pop, int *dist, int left, int right)
  10. {
  11. int index;
  12. int temp;
  13. int i, j;
  14. double pivot;
  15. if (left<right)
  16. {
  17. index = rnd (left, right);
  18. temp = dist[right];
  19. dist[right] = dist[index];
  20. dist[index] = temp;
  21. pivot = pop->ind[dist[right]].crowd_dist;
  22. i = left-;
  23. for (j=left; j<right; j++)
  24. {
  25. if (pop->ind[dist[j]].crowd_dist <= pivot)
  26. {
  27. i+=;
  28. temp = dist[j];
  29. dist[j] = dist[i];
  30. dist[i] = temp;
  31. }
  32. }
  33. index=i+;
  34. temp = dist[index];
  35. dist[index] = dist[right];
  36. dist[right] = temp;
  37. q_sort_dist (pop, dist, left, index-);
  38. q_sort_dist (pop, dist, index+, right);
  39. }
  40. return;
  41. }

将带排序的个体索引序号  按照  拥挤距离  排序。(快速排序法)

多目标遗传算法 ------ NSGA-II (部分源码解析) 快速排序代码 sort.c的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  10. 多目标遗传算法 ------ NSGA-II (部分源码解析) 临时种群生成新父代种群 fillnds.c

    /* Nond-domination based selection routines */ # include <stdio.h> # include <stdlib.h> ...

随机推荐

  1. windows下安装php真正的多线程扩展pthreads教程

    扩展地址:http://docs.php.net/manual/zh/book.pthreads.php 注意事项php5.3或以上,且为线程安全版本.apache和php使用的编译器必须一致.通过p ...

  2. AD认证

    这两天接触到一个新的知识点,AD验证.什么是AD验证?Active Directory——活动目录,活动目录只是LDAP的一个实现,提供LDAP认证.Radius认证和NTML认证,都是标准认证方式 ...

  3. AC-BM算法原理与代码实现(模式匹配)

    AC-BM算法原理与代码实现(模式匹配) AC-BM算法将待匹配的字符串集合转换为一个类似于Aho-Corasick算法的树状有限状态自动机,但构建时不是基于字符串的后缀而是前缀.匹配 时,采取自后向 ...

  4. android webview js交互 第一节 (java和js交互)

    转载请注明出处         挺帅的移动开发专栏  http://blog.csdn.net/wangtingshuai/article/details/8631835        在androi ...

  5. WCF简单教程

    WCF是DotNet体系中很重要的一项技术,但是组内很多组员通过书籍自学的时候 感觉涉及面太广.配置文件太复杂,新名词太多.抓不到头绪,有感于此,决定进行一次组内技术培训,顺便把培训讲义整理到blog ...

  6. logstash快速入门 (这篇文章很不错 ) | 两种方式往logstash传输数据实例:Apache 日志(从文件获取)、Syslog方式

    原文地址:http://www.2cto.com/os/201411/352015.html 原文地址:http://logstash.net/docs/1.4.2/tutorials/getting ...

  7. JavaScript高级程序设计39.pdf

    第13章 事件 JavaScript与HTML之间的交互式通过事件来实现的. 事件流 事件流描述的是从页面中接收事件的顺序,IE和Netscape提出了完全相反的事件流概念,IE是事件冒泡流,Nets ...

  8. Android JNI 由C/C++本地代码向Java层传递数据

    最近做的Android项目需要调用C代码,进行串口通信及与硬件设备通信,因此要用到JNI,其中本地代码需要向Java层返回三个参数,分别为 参数一:int型: 参数二: 通信指令,本地代码中为unsi ...

  9. Tornado自定义分布式session框架

    一.session框架处理请求执行的流程: 1.服务器端生成随机的cookie字符串 2.浏览器发送请求,服务器将cookie返回给浏览器. 3.服务器在生成一个字典.字典的key为cookie,va ...

  10. 什么时候使用Shell

    因为Shell似乎是各UNIX系统之间通用的功能,并且经过了POSIX的标准化.因此,Shell脚本只要“用心写”一次,即可应用到很多系统上.因此,之所以要使用Shell脚本是基于: 简单性:Shel ...