What this does is generate a random path of cities to later calculate the length of the newly generated tour of cities, the TSP.
I am trying to figure out if there is a more efficient way to write this algorithm. I have tried using the std::shuffle
and std::random_shuffle
but did not notice any improvement in the run time. Any other resources I should try taking a look at?
std::vector<City> GetRandomPath(std::vector<City> oldPath)
{
std::vector<City> newPath;
newPath = oldPath;
int randPoint = rand() % (oldPath.size()-1);
int randPoint2 = rand() % (oldPath.size()-1 - randPoint) + randPoint;
int k=1;
for(int i =0; i < randPoint; i++)
{
newPath.push_back(oldPath.at(i));
}
for(int i=randPoint; i < randPoint2; i++)
{
newPath.push_back(oldPath.at(randPoint2-k));
k++;
}
for(int i=randPoint2; i < oldPath.size(); i++)
{
newPath.push_back(oldPath.at(i));
}
return newPath;
}