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

📄 sort.c

📁 nsga2具体算法代码,用来多目标遗传算法的学习和研究
💻 C
字号:
/* Routines for randomized recursive quick-sort */# include <stdio.h># include <stdlib.h># include <math.h># include "global.h"# include "rand.h"/* Randomized quick sort routine to sort a population based on a particular objective chosen */void quicksort_front_obj(population *pop, int objcount, int obj_array[], int obj_array_size){    q_sort_front_obj (pop, objcount, obj_array, 0, obj_array_size-1);    return;}/* Actual implementation of the randomized quick sort used to sort a population based on a particular objective chosen */void q_sort_front_obj(population *pop, int objcount, int obj_array[], int left, int right){    int index;    int temp;    int i, j;    double pivot;    if (left<right)    {        index = rnd (left, right);        temp = obj_array[right];        obj_array[right] = obj_array[index];        obj_array[index] = temp;        pivot = pop->ind[obj_array[right]].obj[objcount];        i = left-1;        for (j=left; j<right; j++)        {            if (pop->ind[obj_array[j]].obj[objcount] <= pivot)            {                i+=1;                temp = obj_array[j];                obj_array[j] = obj_array[i];                obj_array[i] = temp;            }        }        index=i+1;        temp = obj_array[index];        obj_array[index] = obj_array[right];        obj_array[right] = temp;        q_sort_front_obj (pop, objcount, obj_array, left, index-1);        q_sort_front_obj (pop, objcount, obj_array, index+1, right);    }    return;}/* Randomized quick sort routine to sort a population based on crowding distance */void quicksort_dist(population *pop, int *dist, int front_size){    q_sort_dist (pop, dist, 0, front_size-1);    return;}/* Actual implementation of the randomized quick sort used to sort a population based on crowding distance */void q_sort_dist(population *pop, int *dist, int left, int right){    int index;    int temp;    int i, j;    double pivot;    if (left<right)    {        index = rnd (left, right);        temp = dist[right];        dist[right] = dist[index];        dist[index] = temp;        pivot = pop->ind[dist[right]].crowd_dist;        i = left-1;        for (j=left; j<right; j++)        {            if (pop->ind[dist[j]].crowd_dist <= pivot)            {                i+=1;                temp = dist[j];                dist[j] = dist[i];                dist[i] = temp;            }        }        index=i+1;        temp = dist[index];        dist[index] = dist[right];        dist[right] = temp;        q_sort_dist (pop, dist, left, index-1);        q_sort_dist (pop, dist, index+1, right);    }    return;}

⌨️ 快捷键说明

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