Commit efdf2c05 authored by Colby Green's avatar Colby Green
Browse files

changes

parent ff8ea18c
......@@ -76,6 +76,10 @@ public:
}
}
double getTotalDistance(){
return totalDistance;
}
private:
vector<Poke> pokeDex;
vector<size_t> tspPokeDex;
......
......@@ -25,11 +25,10 @@ public:
}
vector<Vertex> v;
for (size_t i = permLength - 1; i < path.size(); i++){
for (size_t i = permLength; i < path.size(); i++){
Vertex vertex;
vertex.index = (i == path.size()) ? 0 : size_t(path[i]);
//vertex.index = size_t(path[i]);
if (i == 0){
vertex.index = size_t(path[i]);
if (i == permLength){
vertex.minDistanceTo = 0;
}else {
vertex.minDistanceTo = numeric_limits<double>::infinity();
......@@ -71,15 +70,36 @@ public:
} //while
double distance = 0;
double mstDistance = 0;
for (size_t i = 0; i < v.size(); i++){
if (v[i].precedingPokeIndex != -1){
distance += v[i].minDistanceTo;
mstDistance += v[i].minDistanceTo;
}
}
distance *= 1.1;
double totalDistanceLowerBound = curPathDistance + distance;
double minDistanceFromPrev = numeric_limits<double>::infinity();
for (size_t i = 0; i < v.size(); i++){
double distance = distanceMatrix[v[i].index][path[permLength - 1]];
if (distance == 0){
distanceMatrix[v[i].index][path[permLength - 1]] = distance = pokeDistance(v[i].index, path[permLength - 1]);
}
if (distance < minDistanceFromPrev){
minDistanceFromPrev = distance;
}
}
double minDistanceFromFirst = numeric_limits<double>::infinity();
for (size_t i = 0; i < v.size(); i++){
double distance = distanceMatrix[v[i].index][path[0]];
if (distance == 0){
distanceMatrix[v[i].index][path[0]] = distance = pokeDistance(v[i].index, path[0]);
}
if (distance < minDistanceFromFirst){
minDistanceFromFirst = distance;
}
}
double totalDistanceLowerBound = curPathDistance + mstDistance + minDistanceFromPrev + minDistanceFromFirst;
return totalDistanceLowerBound < bestPathDistance;
}
......@@ -134,6 +154,8 @@ public:
fasttsp.solve();
pokeDex = fasttsp.getPokeDex();
path = fasttsp.getTspPokeDex();
bestPath = fasttsp.getTspPokeDex();
bestPathDistance = fasttsp.getTotalDistance();
distanceMatrix.resize(pokeDex.size());
for (size_t i = 0; i < pokeDex.size(); i++){
distanceMatrix[i].resize(pokeDex.size());
......@@ -158,6 +180,9 @@ private:
}
double pokeDistance(size_t pokeIndex1, size_t pokeIndex2){
if (pokeIndex1 == pokeIndex2){
return numeric_limits<double>::infinity();
}
Poke poke1 = pokeDex[pokeIndex1];
Poke poke2 = pokeDex[pokeIndex2];
double x = poke1.xcord - poke2.xcord;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment