亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? equationgenome.cs

?? 基因表達(dá)式編程 基本算法 能夠完成術(shù)用于公式發(fā)現(xiàn)、函數(shù)挖掘
?? CS
字號:
using System;
using System.Collections;
using GEPAlgorithm;

namespace GeneticAlgorithm
{
	/// <summary>
	/// Summary description for EquationNode.
	/// Equation node represents a symbolic equation that solves a problem
	/// In this case we'll use the following keys to represent our node
	/// 0: a 1: b 2: *  3: / 4: + 5: -  6: Q (square root)
	/// </summary>
	/// 
	public class EquationGenome : Genome
	{
		EquationNode TheNode;
		ArrayList TheArray = new ArrayList();
		public static Random TheSeed = new Random((int)DateTime.Now.Ticks);
		int TheMin = 0;
		int TheMax = 6;
		int CurrentXPos = 0;
		int CurrentYPos = 0;
		int PreviousSeed = 2;
		public bool TrialFitness; // this needs to be perfect or else we have to throw out the gene

		public override int CompareTo(object a)
		{
			EquationGenome Gene1 = this;
			EquationGenome Gene2 = (EquationGenome)a;
			return Math.Sign(Gene2.CurrentFitness  -  Gene1.CurrentFitness);
		}


		public override void SetCrossoverPoint(int crossoverPoint)
		{
			CrossoverPoint = 	crossoverPoint;
		}

		public EquationGenome()
		{
		}


		public EquationGenome(long length, object min, object max)
		{
			//
			// TODO: Add constructor logic here
			//
			Length = length;
			TheMin = (int)min;
			TheMax = (int)max;
			CurrentXPos = 0;
			CurrentYPos = 0;
			for (int i = 0; i < Length; i++)
			{
				int nextValue = (int)GenerateGeneValue(min, max);
				TheArray.Add(nextValue);
			}
		}

		public override void Initialize()
		{

		}

		public override bool CanDie(float fitness)
		{
			if (CurrentFitness <= (int)(fitness * 100.0f))
			{
				return true;
			}

			return false;
		}


		public override bool CanReproduce(float fitness)
		{
			if (EquationGenome.TheSeed.Next(100) >= (int)(fitness * 100.0f))
			{
				return true;
			}

			return false;
		}


		public override object GenerateGeneValue(object min, object max)
		{
			int nextSeed = 0;
			nextSeed = TheSeed.Next((int)min, (int)max);
			return nextSeed;
		}

		#region GenerateSmartGene
		/*
				public override object GenerateGeneValue(object min, object max)
				{
					bool hasWall = true;
					int nextSeed = 0;
					int counter = 0;
					while (hasWall)
					{
						nextSeed = TheSeed.Next((int)min, (int)max);
						switch (nextSeed)
						{
							case 0:  // up
								if (PreviousSeed == 2)
								{	
									break; // don't backtrack
								}
								hasWall = TheMaze.HasWall(CurrentXPos, this.CurrentYPos, CurrentXPos, CurrentYPos - 1);
								if (hasWall == false)
								{
								 CurrentYPos--;
								}
								break;
							case 1:  // left
								if (PreviousSeed == 3)
								{	
									break; // don't backtrack
								}

								hasWall = TheMaze.HasWall(CurrentXPos, this.CurrentYPos, CurrentXPos - 1, CurrentYPos);
								if (hasWall == false)
								{
									CurrentXPos--;
								}
								break;
							case 2:  // down
								if (PreviousSeed == 0)
								{	
									break; // don't backtrack
								}
								hasWall = TheMaze.HasWall(CurrentXPos, this.CurrentYPos, CurrentXPos, CurrentYPos + 1);
								if (hasWall == false)
								{
									CurrentYPos++;
								}
								break;
							case 3:  // right
								if (PreviousSeed == 1)
								{	
									break; // don't backtrack
								}

								hasWall = TheMaze.HasWall(CurrentXPos, this.CurrentYPos, CurrentXPos + 1, CurrentYPos);
								if (hasWall == false)
								{
									CurrentXPos++;
								}
								break;
						}

						counter++;
						if (counter > 10)
							break;

					}

					return nextSeed;

				}

		*/

#endregion 



		public override void Mutate()
		{
			int AffectedGenes = TheSeed.Next((int)this.Length); // determine how many genes to mutate
			for (int i = 0; i < AffectedGenes; i++)
			{
				MutationIndex = TheSeed.Next((int)Length);
				//				int val = (int)GenerateGeneValue(TheMin, TheMax);
				TheArray[MutationIndex] = ((int)TheArray[MutationIndex] + 1) % 7;
			}

		}

		// This fitness function calculates the closest product sum
		private float CalculateClosestProductSum()
		{
			// fitness for a perfect number

			float sum = 0.0f;
			float product = 1.0f;
			for (int i = 0; i < Length; i++)
			{
				sum += (int)TheArray[i];
				product *= (int)TheArray[i];
			}
			if (product == sum)
			{
				CurrentFitness = 1;
			}
			else
			{
				CurrentFitness = Math.Abs(Math.Abs(1.0f/(product - sum)) - 0.02f);
			}
			
			return CurrentFitness;
		}


		// This fitness function calculates the closest product sum
		private float CalculateClosestSumTo10()
		{
			float sum = 0.0f;
			for (int i = 0; i < Length; i++)
			{
				sum += (int)TheArray[i];
			}

			if (sum == 10)
				return 1;
			else
				return Math.Abs(Math.Abs(1.0f/(sum - 10)) - 0.02f);

		}

		// This fitness function calculates the fitness of distance travelled
		// from upper left to lower right



		#region fitness2

		// This fitness function calculates the fitness of distance travelled
		/*		// from upper left to lower right
				private float CalculateMazeDistanceFitness()
				{
					float sum = 0.0f;
					int cellPreviousPosX = 0;
					int cellPreviousPosY = 0;
					int cellPosX = 0;
					int cellPosY = 0;
					int trialnumber = 0;
					int backTrack = 0;
					int hasWall = 0;
					int maxConsecutiveNoWalls = 0;
					int consecutiveNoWalls = 0;
					int previousDirection = 0;
					for (int i = 0; i < Length; i++)
					{
						switch ((int)TheArray[i])
						{
							case 0:  // up
								cellPosY--;
								break;
							case 1:  // left
								cellPosX--;
								break;
							case 2:  // down
								cellPosY++;
								break;
							case 3:  // right
								cellPosX++;
								break;
						}

						if ( (previousDirection + 2) % 4 == (int)TheArray[i])
						{
							backTrack++;
						}

						previousDirection = (int)TheArray[i];

						if (maxConsecutiveNoWalls < consecutiveNoWalls)
								maxConsecutiveNoWalls = consecutiveNoWalls;

						if (TheMaze.HasWall(cellPreviousPosX, cellPreviousPosY, cellPosX, cellPosY))
						{
							consecutiveNoWalls = 0;
						}
						else
						{
							consecutiveNoWalls++;
						}

		//				trialnumber++;


						cellPreviousPosX = cellPosX;
						cellPreviousPosY = cellPosY;
					}

					// the score is the distance squared from the origin
					// since the greatest distance is the distance to the destination
					// the lower right hand corner
		//			sum = ((float)(cellPosX*cellPosX + cellPosY*cellPosY))/((float)(Maze.kDimension*Maze.kDimension));  

					sum = sum + ((float)(maxConsecutiveNoWalls))/((float)this.Length);
					sum = sum + ((float)(Length - backTrack))/((float)this.Length);

					sum = sum/2;

					return sum;
				}
		*/

		#endregion 


		Stack _stack = new Stack();

		public string ReturnOperationString(string a, string b, int operation)
		{
			string result = "";
			switch(operation)
			{
				case 2: // *
					result += "(" + a + "*" + b + ")";
					break;
				case 3: // / 
					result += "(" + a + "/" + b + ")";
					break;
				case 4: // +
					result += "(" + a + "+" + b + ")";
					break;
				case 5: // - 
					result += "(" + a + "-" + b + ")";
					break;
				case 6: // Q
					result += "Sqrt(" + a +  ")";
					break;
				default:
					// +
					break;
			} // end switch

			return result;

		}


		public float DoOperation(float a, float b, int operation)
		{
			float result = 0.0f;
			switch(operation)
			{
				case 2: // *
					result = a * b;
					break;
				case 3: // / 
					if (b == 0.0f) // problem just set b to small number
					{
						b = .0001f;
					}
					result = a/b;
					break;
				case 4: // +
					result = a + b;
					break;
				case 5: // - 
					result = a - b;
					break;
				case 6: // Q
					result = (float)Math.Sqrt(a);
					break;
				default:
					// +
					break;
			} // end switch

			return result;

		}

		public string FormEquationString()
		{
			string _result = "";
			string x;
			string y;

			_stack.Clear();

			for (int i = 0; i < TheArray.Count; i++)
			{
				if ((int)TheArray[i] <= 1) // its a number
				{
					if ((int)TheArray[i] == 0) // put a on the stack
					{
						_stack.Push("a");
					}

					if ((int)TheArray[i] == 1) // put a on the stack
					{
						_stack.Push("b");
					}

				}
				else
				{
					// check if unary
					if ((int)TheArray[i] == 6) // sqrt
					{
						if (_stack.Count > 0)
						{
							x = (string)_stack.Pop();
							_result = ReturnOperationString(x, "", (int)TheArray[i]);
							_stack.Push(_result);
						}
					}
					else
					{
						if (_stack.Count > 0)
						{
							x = (string)_stack.Pop();
							if (_stack.Count > 0)
							{
								y = (string)_stack.Pop();
								_result = ReturnOperationString(x, y, (int)TheArray[i]);
								_stack.Push(_result);
							}
						}
					}

				}

			}

			return _result;
		}

		public string PostFixString = "";
		public float PerformPostFixCalculation(float a, float b)
		{
			float _result = 0.0f;
			float x;
			float y;

			_stack.Clear();

			for (int i = 0; i < TheArray.Count; i++)
			{
				if ((int)TheArray[i] <= 1) // its a number
				{
					if ((int)TheArray[i] == 0) // put a on the stack
					{
						_stack.Push(a);
					}

					if ((int)TheArray[i] == 1) // put a on the stack
					{
						_stack.Push(b);
					}

				}
				else
				{
					// check if unary
					if ((int)TheArray[i] == 6) // sqrt
					{
						if (_stack.Count > 0)
						{
							x = (float)_stack.Pop();
							_result = DoOperation(x, 0, (int)TheArray[i]);
							_stack.Push(_result);
						}
					}
					else
					{
						if (_stack.Count > 0)
						{
							x = (float)_stack.Pop();
							if (_stack.Count > 0)
							{
								y = (float)_stack.Pop();
								_result = DoOperation(x, y, (int)TheArray[i]);
								_stack.Push(_result);
				
							}
						}
					}

				}
			} // end for

			return _result;
		}

		float[,] measure = new float[8,3]{{3,4,5}, {1, 1, 1.4142f}, {1, 2, 2.23607f}, {3, 1, 3.16228f}, {6, 13, 14.31782f}, {4,3,5}, {1,3, 3.16228f}, {2, 1, 2.23607f}};

		public float CalculatePythagoreanFitness()
		{
			int index = 0;
			TheNode = new EquationNode(this, null, ref index);
			// use the node to calculate the fitness

//			Console.WriteLine (EquationNode.OutputStraightEquation(this));

			float calc = 0.0f;
			float sum = 0.0f;
			int count = measure.GetLength(0);
			for (int i = 0; i < count; i++)
			{
				calc = PerformPostFixCalculation(measure[i, 0],  measure[i, 1]);
				sum +=  100 - Math.Abs(measure[i,2] - calc);
			}
			CurrentFitness = sum;

			if (float.IsNaN(CurrentFitness))
				CurrentFitness = 0.01f;

			return CurrentFitness;
		}

		public override float CalculateFitness()
		{
			// CurrentFitness = CalculateClosestProductSum();
			//			CurrentFitness =  CalculateClosestSumTo10();
			//			CurrentFitness = CalculateMazeDistanceFitness();
			CurrentFitness = CalculatePythagoreanFitness();
			return CurrentFitness;
		}


		public override string ToString()
		{
			string strResult = "";
			//			for (int i = 0; i < Length; i++)
			//			{
			//			  strResult = strResult + ((int)TheArray[i]).ToString() + " ";
			//			}

			int index = 0;
			//			TheArray[0] = 5;			
			//			TheArray[1] = 3;			
			//			TheArray[2] = 1;			
			//			TheArray[3] = 0;			
			//			TheArray[4] = 2;			
			TheNode = new EquationNode(this, null, ref index);
			strResult += " -->  " + EquationNode.OutputStraightEquation(this);
			strResult += " -->  " + this.FormEquationString();

			strResult += " --> " + CurrentFitness.ToString();

			return strResult;
		}

		public override void CopyGeneInfo(Genome dest)
		{
			EquationGenome theGene = (EquationGenome)dest;
			theGene.Length = Length;
			theGene.TheMin = TheMin;
			theGene.TheMax = TheMax;
		}


		public override Genome Crossover(Genome g)
		{
			EquationGenome aGene1 = new EquationGenome();
			EquationGenome aGene2 = new EquationGenome();
			g.CopyGeneInfo(aGene1);
			g.CopyGeneInfo(aGene2);

			// Pick a random crossover point
			CrossoverPoint = TheSeed.Next(1, (int)Length);

			EquationGenome CrossingGene = (EquationGenome)g;
			for (int i = 0; i < CrossoverPoint; i++)
			{
				aGene1.TheArray.Add(CrossingGene.TheArray[i]);
				aGene2.TheArray.Add(TheArray[i]);
			}

			for (int j = CrossoverPoint; j < Length; j++)
			{
				aGene1.TheArray.Add(TheArray[j]);
				aGene2.TheArray.Add(CrossingGene.TheArray[j]);
			}

			// 50/50 chance of returning gene1 or gene2
			EquationGenome aGene = null;
			if (TheSeed.Next(2) == 1)			
			{
				aGene = aGene1;
			}
			else
			{
				aGene = aGene2;
			}

			return aGene;
		}

		public int this[int arrayindex]
		{
			get
			{
				return (int)TheArray[arrayindex];
			}
		}

	}
}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91福利视频网站| 国产伦精一区二区三区| 精品久久一区二区三区| 成人午夜视频福利| 日韩国产欧美在线观看| 综合自拍亚洲综合图不卡区| 欧美日韩国产高清一区| 成人国产亚洲欧美成人综合网| 婷婷六月综合亚洲| 亚洲精品老司机| 亚洲国产精品成人综合色在线婷婷 | 欧美一a一片一级一片| 国内外精品视频| 偷偷要91色婷婷| 亚洲美女屁股眼交| 亚洲美女屁股眼交3| 国产女人18水真多18精品一级做| 日韩一区二区三免费高清| 91国产免费观看| 成人免费av在线| 韩国精品免费视频| 美日韩黄色大片| 天堂av在线一区| 亚洲综合男人的天堂| 中文字幕一区二区三区四区| 久久久久国产精品人| 日韩精品中文字幕在线一区| 91精品视频网| 欧美日韩日本视频| 欧美午夜在线观看| 色哟哟国产精品| 色狠狠av一区二区三区| 成人国产在线观看| 成人美女在线观看| 国产成a人无v码亚洲福利| 经典三级一区二区| 国产麻豆欧美日韩一区| 狠狠久久亚洲欧美| 精品一区二区三区在线观看国产 | 欧美日韩一区二区不卡| 欧美性大战久久| 日本韩国精品一区二区在线观看| 一本大道久久精品懂色aⅴ| av爱爱亚洲一区| 91网站在线播放| 日本韩国一区二区| 欧美性三三影院| 欧美日韩一区二区三区高清 | 欧美综合一区二区| 色一情一伦一子一伦一区| 色哟哟一区二区在线观看| 91欧美激情一区二区三区成人| 99久久国产综合精品麻豆| 91蜜桃免费观看视频| 91国产视频在线观看| 欧美日高清视频| 91精品国产免费| 精品国产一区二区三区忘忧草| 久久精品一区四区| 中文字幕亚洲电影| 亚洲午夜国产一区99re久久| 日韩精品欧美精品| 久久成人精品无人区| 国产成人自拍高清视频在线免费播放| 国产91富婆露脸刺激对白| 91麻豆国产香蕉久久精品| 色噜噜偷拍精品综合在线| 欧美日韩一区小说| 精品国产一区a| 国产精品护士白丝一区av| 一区二区三区四区视频精品免费| 日韩福利视频网| 国产一区二区不卡在线 | 在线观看视频一区二区欧美日韩| 欧美日韩黄色一区二区| 欧美精品一区二区三区蜜桃| 国产精品国模大尺度视频| 五月天激情综合网| 国产毛片精品视频| 欧美午夜寂寞影院| 久久精品一区二区三区不卡| 激情久久五月天| eeuss鲁片一区二区三区在线看| 欧美日韩国产中文| 国产精品三级在线观看| 亚洲国产一区二区在线播放| 老司机精品视频导航| 色一情一乱一乱一91av| 日韩精品一区二区三区视频播放 | 国产精品不卡在线| 午夜精品视频在线观看| 国产99久久久国产精品潘金| 欧美综合一区二区| 日本一区二区三区视频视频| 午夜视频在线观看一区| 国产v日产∨综合v精品视频| 欧美美女网站色| 亚洲欧洲日产国产综合网| 老司机免费视频一区二区| 91在线精品一区二区三区| 欧美成人在线直播| 亚洲午夜电影在线观看| www.欧美色图| 精品久久五月天| 一区二区三区电影在线播| 极品少妇xxxx精品少妇| 欧美又粗又大又爽| 国产精品网站导航| 激情六月婷婷综合| 欧美一区日本一区韩国一区| 一级精品视频在线观看宜春院| 高清成人免费视频| 欧美成人女星排行榜| 午夜精品一区二区三区三上悠亚| av中文字幕亚洲| 日本一区二区不卡视频| 韩国欧美国产1区| 欧美日韩一区二区在线观看| 综合色中文字幕| 国产91精品免费| 久久久久久久久久看片| 蜜臀av性久久久久蜜臀av麻豆| 在线观看国产精品网站| 亚洲激情网站免费观看| www.在线欧美| 日韩理论片在线| 99久久综合精品| 中文字幕日韩欧美一区二区三区| 成人一区二区视频| 国产拍欧美日韩视频二区| 国产一区二区在线观看免费| 精品国产一区二区三区av性色 | 懂色av一区二区三区免费观看| 欧美精品一区二区在线播放| 免费看欧美女人艹b| 欧美电影在线免费观看| 水野朝阳av一区二区三区| 337p亚洲精品色噜噜| 日本视频免费一区| 91精品福利在线一区二区三区| 首页综合国产亚洲丝袜| 91精品国产全国免费观看| 青青草一区二区三区| 欧美成人欧美edvon| 国产麻豆精品在线观看| 中国色在线观看另类| 99久久精品一区二区| 亚洲男女毛片无遮挡| 欧美性猛交xxxxxx富婆| 亚洲bt欧美bt精品777| 91精品国产综合久久精品app| 日本亚洲天堂网| 精品福利av导航| a级高清视频欧美日韩| 亚洲一区成人在线| 欧美高清精品3d| 精品在线免费观看| 国产精品网友自拍| 一道本成人在线| 日韩国产精品久久久| www久久精品| 99久久久国产精品免费蜜臀| 亚洲午夜电影在线观看| 欧美大片在线观看一区| 国产一区二区三区精品视频| 国产精品丝袜在线| 欧美性猛交xxxx黑人交 | 成人的网站免费观看| 亚洲精品久久7777| 日韩欧美在线综合网| 成人av第一页| 日韩精品久久理论片| 国产日韩欧美精品在线| 972aa.com艺术欧美| 蜜臀久久久久久久| 日本一区二区三区免费乱视频| 色综合久久久久综合| 美女脱光内衣内裤视频久久影院| 国产清纯美女被跳蛋高潮一区二区久久w| 99精品黄色片免费大全| 日产国产欧美视频一区精品 | 亚洲国产精品一区二区久久| 欧美成人三级电影在线| 色综合天天天天做夜夜夜夜做| 亚洲国产精品人人做人人爽| 久久日韩精品一区二区五区| 色综合久久88色综合天天免费| 激情综合色综合久久| 亚洲一区二区在线观看视频| 久久久综合视频| 欧美肥大bbwbbw高潮| youjizz久久| 麻豆精品久久久| 亚洲综合在线电影| 国产性天天综合网| 91精品中文字幕一区二区三区 | 日韩一区二区三区四区| 色综合久久综合中文综合网| 久久激情五月激情| 亚洲一区二区三区免费视频|