#include "stdafx.h"
#include <math.h>
#include <time.h>
#include <iostream>
#include <fstream>
using namespace std;
int c1=2; //加速因子
int c2=2; //加速因子
double w=1; //惯性权重
double Wmax=1; //最大惯性权重
double Wmin=0.6; //最小惯性权重
int Kmax=110; //迭代次数
int GdsCnt; //物资总数
int const Dim=10; //粒子维数
int const PNum=50; //粒子个数
int GBIndex=0; //最优粒子索引
double a=0.6; //适应度调整因子
double b=0.5; //适应度调整因子
int Xup[Dim]; //粒子位置上界数组
int Xdown[Dim]=; //粒子位置下界数组
int Value[Dim]; //初始急需度数组
int Vmax[Dim]; //最大速度数组
class PARTICLE; //申明粒子节点
void Check(PARTICLE&,int); //约束函数
void Input(ifstream&); //输入变量
void Initial(); //初始化相关变量
double GetFit(PARTICLE&); //计算适应度
void CalculateFit(); //计算适应度
void BirdsFly(); //粒子飞翔
void Run(ofstream&,int=2000); //运行函数
//微粒类
class PARTICLE
{
public:
int X[Dim]; //微粒的坐标数组
int XBest[Dim]; //微粒的最好位置数组
int V[Dim]; //粒子速度数组
double Fit; //微粒适合度
double FitBest; //微粒最好位置适合度
};
PARTICLE Parr[PNum]; //粒子数组
int main() //主函数
{
ofstream outf("out.txt");