资源简介
类电磁机制算法是一种新型的基于种群的随机全局优化算法,主要用于求解连续优化问题。该算法的主要思路是利用了电磁学中空间粒子之间存在相互的吸引力和排斥力的思想,种群中可行解个体按照电磁力的方向移动,向最优解靠近。该源码是该算法创立者S. Ilker Birbil开发的。
代码片段和文件信息
#include
#include
#include
#include
// This file contains the EM class layout.
#include “EM.h“
// This file is used insted of the weak random number generator of C++
#include “randnum.h“
// Auxiliary Vector Functions
#include “auxiliary.h“
// These files contain the functions used in ‘func‘ method below.
#include “dixonszegofnc.h“
// The RAND is a random number generated by the function
// genrand() in file randnum.h
#define RAND genrand()
// Constructor
EM::EM ()
{
GLOBALCOUNT = 0;
best.objvalue = 1.0e+100;
best.index = 0;
best.count = 0;
}
// Destructor
EM::~EM ()
{
delete (Par.LB);
delete (Par.UB);
for (int i = 0; i < Par.M; i++)
{
delete (ions[i].coord);
delete (ions[i].Fi);
}
delete best.coord;
}
// Input
// The lines of the .in file is read and the parameters are assigned.
// The explanation of the parameters are given in file EM.h
int
EM::Input (char *infilename)
{
int i;
char str[80];
FILE *fin;
if ((fin = fopen (infilename “r“)) == NULL)
{
printf (“ERROR: INPUT FILE IS NOT ACCESSIBLE!“);
}
strcpy (str “ “);
while (strcmp (str “FunctionNo:“))
{
fscanf (fin “%s“ str);
}
fscanf (fin “%s“ str);
Par.FUNCNO = atoi (str);
while (strcmp (str “NumberOfIterations:“))
{
fscanf (fin “%s“ str);
}
fscanf (fin “%s“ str);
Par.MAXGEN = atoi (str);
while (strcmp (str “NumberOfRuns:“))
{
fscanf (fin “%s“ str);
}
fscanf (fin “%s“ str);
Par.NUMOFRUNS = atoi (str);
while (strcmp (str “NumberOfDimensions:“))
{
fscanf (fin “%s“ str);
}
fscanf (fin “%s“ str);
Par.N = atoi (str);
Par.UB = new long double[Par.N];
Par.LB = new long double[Par.N];
while (strcmp (str “LowerBounds:“))
{
fscanf (fin “%s“ str);
}
for (i = 0; i < Par.N; i++)
{
fscanf (fin “%s“ str);
Par.LB[i] = (long double) atof (str);
}
while (strcmp (str “UpperBounds:“))
{
fscanf (fin “%s“ str);
}
for (i = 0; i < Par.N; i++)
{
fscanf (fin “%s“ str);
Par.UB[i] = (long double) atof (str);
}
while (strcmp (str “Optimum:“))
{
fscanf (fin “%s“ str);
}
fscanf (fin “%s“ str);
Par.OPTIMUM = (long double) atof (str);
while (strcmp (str “NumberOfIons:“))
{
fscanf (fin “%s“ str);
}
fscanf (fin “%s“ str);
Par.M = atoi (str);
while (strcmp (str “LocalCount:“))
{
fscanf (fin “%s“ str);
}
fscanf (fin “%s“ str);
Par.LS = atoi (str);
while (strcmp (str “Delta:“))
{
fscanf (fin “%s“ str);
}
fscanf (fin “%s“ str);
Par.DELTA = (long double) atof (str);
while (strcmp (str “PertPar:“))
{
fscanf (fin “%s“ str);
}
fscanf (fin “%s“ str);
Par.PERTPAR = (long double) atof (str);
Reserve ();
fclose (fin);
return (1);
}
// Initialize
// m points are generated randomly from the feasible r
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2003-07-28 15:53 EmNew\
文件 1585 2002-01-27 07:07 EmNew\auxiliary.h
文件 8238 2002-02-02 22:15 EmNew\dixonszegofnc.h
文件 240 2003-07-28 15:49 EmNew\dixonszegofnc.in
文件 11163 2003-07-28 15:46 EmNew\EM.cpp
文件 2136 2002-01-31 21:17 EmNew\EM.h
目录 0 2003-07-28 15:49 EmNew\iodixonszego\
文件 195 2002-02-01 05:59 EmNew\iodixonszego\BraninN2.in
文件 191 2002-02-01 05:59 EmNew\iodixonszego\GoldsteinpriceN2.in
文件 201 2002-02-01 05:59 EmNew\iodixonszego\HartmanN3.in
文件 225 2002-02-01 06:00 EmNew\iodixonszego\HartmanN6.in
文件 215 2002-02-01 06:00 EmNew\iodixonszego\Shekel10N4.in
文件 215 2002-02-01 06:00 EmNew\iodixonszego\Shekel5N4.in
文件 215 2002-02-01 06:01 EmNew\iodixonszego\Shekel7N4.in
文件 201 2002-02-01 06:01 EmNew\iodixonszego\ShubertN2.in
文件 195 2002-02-01 06:01 EmNew\iodixonszego\SixhumpcamelN2.in
文件 1658 2003-07-28 15:49 EmNew\main.cpp
文件 2228 2002-01-27 00:18 EmNew\randnum.h
评论
共有 条评论