culture.h

来自「文化算法的实际应用」· C头文件 代码 · 共 94 行

H
94
字号
#ifndef CAEP_CULTURE_H
#define CAEP_CULTURE_H

#include <iostream>
#include <vector>
#include <algorithm>
#include <limits>
#include "config.h"
#include "random.h"
#include "problem3.h"
#include "c2vector.h"

using namespace std;

namespace CAEP
{
	class PopulationSpace;
	class BeliefSpace;

	class BeliefSpace
	{
	private:

	public:
		vector<float> mLow;
		vector<float> mHigh;
		vector<float> mLowValue;
		vector<float> mHighValue;
		vector<float> mLowInit;
		vector<float> mHighInit;
		Cell *mRoot;
		Configer &mConfiger;
		CARandom &mRandom;

		BeliefSpace(CARandom& rnd, Configer& cfg);
		~BeliefSpace();
		void Update(PopulationSpace *ps, int currentGeneration);
		void Accept(PopulationSpace *ps);
		void Expand(Cell* nodeAct, PopulationSpace *ps);

	};

	class CompareIndividualValue
	{
	public:
		int operator()(const Individual* a, const Individual* b)
		{
			if(b->mIsFeasible && a->mIsFeasible) { return b->mValue > a->mValue; }

			if(a->mIsFeasible) { return 1; }
			if(b->mIsFeasible) { return -1; }

			return b->mValue < a->mValue;
		}
	};

	class CompareIndividualVictory
	{
	public:
		int operator()(const Individual* a, const Individual* b)
		{
			return b->mVictoryCount < a->mVictoryCount;
		}
	};

	class PopulationSpace
	{
	private:

	public:
		vector<float> mConstraintMax;
		vector<Individual*> mPopulation;
		Configer& mConfiger;
		CARandom &mRandom;
		Result* mResult;

		PopulationSpace(BeliefSpace *bs, CARandom& rnd, Configer& cfg, Result* result);
		void InitViolation();
		void Sort();
		void SortBig();
		void GenerateChildren(BeliefSpace* bs);
		void GenerateChildren(BeliefSpace* bs, ostream& o);
		void Move(int indiv, int dim, float x, BeliefSpace* bs);
		void Select();
		void Evalute();
		void FetchValue();
		void ShowInfo();
		void ShowInfo(ostream &o);
	};
}

#endif CULTURE_H

⌨️ 快捷键说明

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