private int GetFitness(List <Point> path, List <Point> designerPath, bool isOrdering) { //path = new List<Point>() // { // new Point(460, 400), // new Point(460, 40), // new Point(200, 400), // new Point(200, 40) // }; List <int> distances = new List <int>(); int lnPIndexInConst = -1; bool firstTime = true; Point lnP = new Point(-100, -100); List <Point> constPath = new List <Point>(path); int seqPCounter = 0; int dlengthCounter = 0; int pBiasedCounter = 0; foreach (Point designerPoint in designerPath) { if (path.Count > 0) { Point nP = FindNearestPoint(path, designerPoint); if (isOrdering) { if (lnPIndexInConst + 1 < constPath.Count) { if (nP != constPath[lnPIndexInConst + 1]) { seqPCounter += 1; } } else { pBiasedCounter += 1; } } else { // NO ORDERING } Vector2 v1 = new Vector2(designerPoint.X, designerPoint.Y); Vector2 v2 = new Vector2(nP.X, nP.Y); int dist = (int)(v1 - v2).Length(); distances.Add(dist); lnP = nP; lnPIndexInConst = constPath.IndexOf(lnP); path.Remove(nP); } else { dlengthCounter += 1; } } float fitness = 0; //Prepare data int nrPPointsUsed = distances.Count; int diffLength = Math.Abs(designerPath.Count - nrPPointsUsed); //float avg = MathHelperModule.CalcAvg(distances); float stdDist = MathHelperModule.CalcStd(distances); float maxStdDist = CalcStdMax(distances); //Calculate data float seqPCounterN = MathHelperModule.Normalize(seqPCounter, designerPath.Count, 0); //float dlengthCounterN = MathHelperModule.Normalize(dlengthCounter, designerPath.Count, 0); //float pBiasedCounterN = MathHelperModule.Normalize(pBiasedCounter, path.Count, 0); //float diffLengthN = MathHelperModule.Normalize(diffLength, 1, 0); float stdDistN = MathHelperModule.Normalize(stdDist, maxStdDist, 1); fitness = 35 * seqPCounterN //+ 10 * dlengthCounterN //+ 10*pBiasedCounterN //+ 13*diffLengthN + 65 * stdDistN; if (float.IsNaN(fitness)) { fitness = 0; } StreamWriter sw = new StreamWriter(@"C:\CTREngine\EntraPathFitnessParams.txt", true); sw.WriteLine( String.Format("{0:0.00}", fitness) + "\t" + String.Format("{0:0.00}", seqPCounterN) //+ "\t" + String.Format("{0:0.00}", dlengthCounterN) //+ "\t" + String.Format("{0:0.00}", pBiasedCounterN) //+ "\t" + String.Format("{0:0.00}", diffLengthN) + "\t" + String.Format("{0:0.00}", stdDistN) + "\t" + "\t" + "\t" + "\t" + String.Format("{0:0.00}", seqPCounter) //+ "\t" + String.Format("{0:0.00}", dlengthCounter) //+ "\t" + String.Format("{0:0.00}", pBiasedCounter) //+ "\t" + String.Format("{0:0.00}", diffLength) + "\t" + String.Format("{0:0.00}", stdDist)); sw.Flush(); sw.Close(); return((int)Math.Truncate(fitness)); }