/********************************************************************\
*** NON-DOMINATED SORTING ***
*** using ***
*** GENETIC ALGORITHM ***
*** for ***
*** MULTI OBJECTIVE OPTIMIZATION ***
*** ***
*** Developed by : Kalyanmoy Deb and Mayank Goyal ***
*** The Department of Mechanical Engineering ***
*** Indian Institute of Technology, Kanpur ***
*** Kanpur, PIN 208 016, INDIA ***
***................................................................***
*** This is a GA implementation for multi-objective optimization. ***
*** For multi-objective optimization, non-domonated sorting has ***
*** been used. The design variables can be Binary, Integer, Real ***
*** or Enumerated data type. Moreover a design vector can have ***
*** design variables where each variable can be any of the above ***
*** mentioned types. The order in which the design variables ***
*** are needed is also maintained in the code. For multi-objective***
*** optimization, sharing is done using either of two ways : ***
*** Sharing on Fitness Space or Sharing on Parameter Space. After ***
*** completion, results are stored in a 'result.out' and for ***
*** detailed inspection in a file 'report'. For a detail discussion***
*** please refer to Journal paper: ***
*** Srinivas, N. and Deb, K. (1994). Multiobjective optimization ***
*** using nondominated sorting genetic algorithms. Evolutionary ***
*** Computation. Vol. 2, No. 3. Pages 221--248. ***
*** ***
*** Please send your comments or bug information at ***
*** deb@ls11.informatik.uni-dortmund.de or deb@iitk.ernet.in ***
*** ***
*** All rights reserved. Not to be used for commercial purposes. ***
*** In case of a publication resulted by use of this code, ***
*** an acknowledgement will be appreciated. ***
*** ***
*** Last update 15 June 1998 Kalyanmoy Deb ***
\********************************************************************/
#include<stdio.h>
#include<math.h>
#define BITS_PER_BYTE 8
#define UINTSIZE (BITS_PER_BYTE*sizeof(unsigned))
#define INFINITY 1e7
#define EPSILON 1e-6
#define PI 3.1415927
#define MAXVECSIZE 30
#define MAXPOPSIZE 500
#define MAXENUMDATA 100
#define MAXOBJ 5
#define MINSCHEME 1 /* do not change */
#define TRUE 1 /* ,, */
#define FALSE 0 /* ,, */
#define ONESITE 1 /* ,, */
#define UNIF 2 /* ,, */
#define BIN 1 /* ,, */
#define INT 2 /* ,, */
#define ENUM 3 /* ,, */
#define CONT 4 /* ,, */
#define square(x) ((x)*(x))
#define cube(x) ((x)*(x)*(x))
#define PENALTY_COEFF 1.0e3
/*=============================
Choose your problem here (put your problem at the end of code)
===========================*/
#define book
/*=================
TYPE DEFINTIONS :
=================*/
struct indiv
{
unsigned *chrom; /* chrosome string */
float fitness[MAXOBJ]; /* fitness functions */
float x[MAXVECSIZE]; /* variables */
float dumfitness; /* modified objective */
int flag; /* flag as follows
0 => untouched
1 => dominated
2 => non-dominated
3 => exhausted */
int front; /* Front of the indiv. */
int parent1; /* two parents */
int parent2;
};
typedef struct indiv INDIVIDUAL ;
typedef INDIVIDUAL *POPULATION ; /* array of individuals */
/*====================
FUNCTION PROTOTYPES :
====================*/
float randomperc();
float get_beta();
float get_delta();
float get_beta_rigid();
double noise();
float rndreal();
int small(float);
/*==================
GLOBAL VARIABLES :
==================*/
int pop_size, /* Population Size */
gen_no, /* Current generation number */
max_gen, /* Maximum no. of generations */
no_xover, /* No. of cross overs done */
no_mutation, /* No. of mutations done */
num_var, /* Number of total design variables */
num_bin_var, /* Number of binary variables */
num_int_var, /* Number of integer variables */
num_enum_var, /* Number of enumerated variables */
num_cont_var, /* Number of continuous variables */
num_obj, /* Number of objectives */
lchrom[MAXVECSIZE], /* Length of chromosome */
chromsize, /* Number of bytes needed to store
lchrom strings */
x_strategy, /* Crossover strategy UNIF,ONESITE etc. */
REPORT, /* Flag for Full reports (True/False) */
var_RIGID[MAXVECSIZE], /* Flag for rigid boundaries (T/F) */
BINGA, /* Flag for binary GA (T/F) */
REALGA, /* Flag for real-GA (T/F) */
FITNESS, /* Flag for sharing strategy (T/F) */
PARAM,
minmax[MAXOBJ], /* min or max flag */
tourneylist[MAXPOPSIZE],/* List of indices of individuals for
tournament selection routine */
tourneypos, /* Current position of tournament */
tourneysize, /* Tournament size ( = 2 for binary )*/
var_type[MAXVECSIZE], /* Temp. variable type */
TotalChromLength, /* Total Chromosome Length */
num_enum_data[MAXVECSIZE];/* Number of Enumerated Data for
each enumerated variable */
float seed, /* Random seed number */
n_distribution_c, n_distribution_m, /* Distribution
index for SBX */
p_xover, /* Cross over probability */
p_mutation, /* Mutation probability */
closeness, /* Closeness epsilon */
minx[MAXVECSIZE], /* Minimum value of design variables */
maxx[MAXVECSIZE], /* Maximum value of design variables */
x_lower[MAXVECSIZE], /* Lower and Upper bounds on each */
x_upper[MAXVECSIZE], /* design variable */
afmin[MAXOBJ], /* approx min value of obj funs. */
afmax[MAXOBJ], /* approx max value of obj funs */
dshare, /* Sharing distance */
max_spread, /* Maximum spread */
maxf[MAXOBJ], /* Maximum fitness values */
minf[MAXOBJ], /* Minimum fitness values */
avgfitness[MAXOBJ], /* Average fitness values */
dum_avg, min_dum, /* Avg. and min. dummy fitness */
init_dum,delta_dum, /* Initial and delta dummy fitness */
c1=0.0,c2=0.0, /* Children */
weightage[MAXOBJ], /* Weightage assigned to fitness */
EnumData[MAXVECSIZE][MAXENUMDATA]; /* Enumerated Data */
POPULATION oldpop, newpop; /* Old and New populations */
int *choices, nremain;
float *fraction;
/*====================================================================
SUBROUTINE FOR INPUTTING GLOBAL PARAMETERS :
====================================================================*/
input_parameters()
{
int k,temp2,count;
char ans;
float temp1, sumweight;
printf("\nNumber of objective functions (2) --> ");
scanf("%d",&num_obj);
printf("\nSpecify minimization (1) or maximization (-1) for each function ");
for (count=0; count<num_obj; count++)
{
printf("\n Objective function #%2d (1 or -1) --> ",count+1);
sca