I am trying to calculate the time complexity of my fitness function for the genetic algorithm that I wrote.
What I did: I already read some articles and examples.
However, not all of them were really satisfactory, where I could say: now I know how to apply this in my code.
Let me show you my fitness function, where I guessed several times.
public static List<double> calculateFitness(List<List<Point3d>> cF, Point3d startpoint)
{
List<double> Fitness = new List<double>();
for (int i = 0; i < cF.Count; i++)
{
Point3d actual;
Point3d next;
double distance;
double totalDistance = startpoint.DistanceTo(cF[i][0]);
for (int j = 0; j < cF[i].Count - 1; j++)
{
actual = cF[i][j];
next = cF[i][j + 1];
distance = actual.DistanceTo(next);
totalDistance += distance;
}
totalDistance += cF[i][cF[i].Count - 1].DistanceTo(startpoint);
Fitness.Add(totalDistance);
}
return Fitness;
}
- , , , , .
, , - . , : double totalDistance = startpoint.DistanceTo(cF[i][0]); → (1 + 1) N?
: actual = cF[i][j]; → (1 + 1) NN?
, : 1 + 1 + (1 + N + 1 + N + N + N + N + 4N + N * {1 + N + N-1 + 2 * (N-1 ) + 2 * (N-1) + 4 * (N-1) + 2 * (N-1)} + 4N + N) = 2 + (2 + 14N + N * {12N-10}) = 12N ^ 2 + 4N + 4 = O (N ^ 2)