/*********************************************************************/
/* */
/* FILENAME : ITO1.c */
/* */
/* AUTHOR : Dong Wenyong */
/* */
/* LAST UPDATE : 15 / March / 2009 */
/* */
/* COMMENTS : */
/* */
/* This is a fully heuristic ITO algorithm implementation where the */
/* fitness of an individual is the same as the value of the */
/* objective function */
/* This program is to find the minima in the function */
/* */
/* COMPILER : gcc -O -o ito1 ito1.c -lm */
/* */
/* The process is as following: */
/* Initialize->loop{Evluation->Find the best and worst */
/* individuals->Calculate radius->Change temperature */
/* Calculate the wave coefficient: Delta and */
/* the Move coefficientAlfa ->Move and Wave} */
/*********************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "stdlib.h"
#include <time.h>
#include <float.h>
/* Change any of these parameters to match your needs */
#define POPSIZE 200 /* population size */
#define MAXGENS 100 /* max. number of generations */
#define NVARS 10 /* no. of problem variables */
#define MAX_EXC_D 10 /* max. excursion distance */
#define MAX_WAVE_D 1 /* max. wave distance */
#define T0 10000 /*the inintial*/
#define ANNEAL_TABLE_LENGTH 100 /*the length of anneal table*/
#define ANNEAL_SPEED 0.99 /*anneal speed*/
#define Evaluate_Times 500000 /*evaluated times*/
#define Exp_Coefficient 5 /*Exponential Coefficient*/
#define PI acos(-1)
#define PRECISION 1e-10
#define LAMUTA 1.2
#define TRUE 1
#define FALSE 0
const char input_file[]="input.txt";
const char output_file[]="output.txt";
int generation; /* current generation no. */
int cur_best_index; /* best individual */
double cur_temperature; /*current temperature*/
FILE *galog; /* an output file */
struct genotype /* genotype (GT), a member of the population */
{
double gene[NVARS]; /* a string of variables */
double upper[NVARS]; /* GT`s variables upper bound */
double lower[NVARS]; /* GT`s variables lower bound */
double fitness; /* GT`s fitness */
double radius; /*GT's radius*/
double delta; /*wave std square error*/
double alfa; /*move coefficient*/
};
struct genotype until_best; /* the best individuals until current generation */
struct genotype cur_best;
struct genotype cur_worst; /* the best and worst individuals in the current generation */
struct genotype population[POPSIZE]; /* population */
/*******************************************************/
/* */
/* Prototypes of functions used by this ITO algorithm */
/* */
/*******************************************************/
/******************************************************************************/
/* aid functions */
double randval(double, double);
void GT_copy(struct genotype *,struct genotype *);/*copy the source individual to the destination*/
void swap(double *, double * );
double NormalDistributeVariable(double deta);
void initialize(void);
void evaluate(void);
void find_the_bestandworst(void); /* find the best and worst individuals in the current population*/
void keep_the_best(void);/* after find the best individula,then perform the */
/*keep_the_best individual to store the best individual*/
void cal_the_radius(void);
void Change_temperature(void);
void cal_the_deltas(void);
void cal_the_alfas(void);
void waves(void);
void new_moves(void);
void new_moves1(void);
void moves(void);
int is_stop(void);
void report(void);
/**************************************************************************/
/* */
/* The following are some test function */
/* */
/**************************************************************************/
double De_Jong(double *x, int dim);
double Axis_parallel_hyper_ellipsoid(double *x, int dim);
double Rotated_hyper_ellipsoid(double *x, int dim);
double Rosenbrock(double *x, int dim);
double Rastrigin(double *x, int dim); /*1*/
double Schwefel(double *x, int dim); /*2*/
double Griewangk(double *x, int dim); /*4*/
double Sum_of_different_power(double *x, int dim); /*5*/
double Ackley(double *x, int dim); /*6*/
double Langermann(double *x, int dim); /*7*/
double Michalewicz(double *x, int dim);
double Branins(double *x, int dim); /*8*/
double Easom(double *x, int dim);
double Goldstein_Price(double *x, int dim); /*8*/
double Fifth_function_of_De_Jong(double *x, int dim);
double Drop_wave(double *x, int dim); /*8*/
double Shubert(double *x, int dim);
/************************************************************/
/* */
/* Implementations of functions used by this ITO algorithm */
/* */
/************************************************************/
/*******************************************************************************/
/*********************************************************************/
/* */
/* Initialization function: Initializes the values of genes */
/* within the variables bounds. It also initializes (to zero) */
/* all fitness values for each member of the population. It */
/* reads upper and lower bounds of each variable from the */
/* input file `gadata.txt'. It randomly generates values */
/* between these bounds for each gene of each genotype in the */
/* population. The format of the input file `gadata.txt' is */
/* var1_lower_bound var1_upper_bound */
/* var2_lower_bound var2_upper_bound ... */
/* */
/*********************************************************************/
void initialize(void)
{
FILE *infile;
int i, j;
double lbound, ubound;
cur_temperature = T0;
if ((infile = fopen(input_file, "r")) == NULL) {
fprintf(galog, "\nCannot open input file\n");
exit(1);
}
/* Initialise variables within the bounds */
until_best.fitness = 1e10;
for (i=0; i < NVARS; i++) {
fscanf(infile, "%lf", &lbound);
fscanf(infile, "%lf", &ubound);
for