Commit 07f8e61c authored by Colby Green's avatar Colby Green
Browse files

update

parent c323b881
......@@ -38,12 +38,14 @@ public:
v.push_back(vertex);
}
size_t length = v.size();
size_t numVisited = 0;
size_t numToVisit = v.size();
size_t numToVisit = length;
while (numVisited != numToVisit){
double minDistance = numeric_limits<double>::infinity();
size_t minIndex = numeric_limits<size_t>::infinity();
for (size_t i = 0; i < v.size(); i++){
for (size_t i = 0; i < length; i++){
Vertex &vertex = v[i];
if (!vertex.visited && vertex.minDistanceTo < minDistance){
minDistance = vertex.minDistanceTo;
......@@ -53,17 +55,17 @@ public:
v[minIndex].visited = true;
numVisited++;
for (size_t i = 0; i < v.size(); i++){
if (!v[i].visited){
double distance = distanceMatrix[v[minIndex].index][v[i].index];
for (size_t i = 0; i < length; i++){
Vertex &vertex = v[i];
if (!vertex.visited){
double distance = distanceMatrix[v[minIndex].index][vertex.index];
if (distance == 0){
distance = pokeDistance(v[minIndex].index, v[i].index);
distanceMatrix[v[minIndex].index][v[i].index] = distance;
distance = pokeDistance(v[minIndex].index, vertex.index);
distanceMatrix[v[minIndex].index][vertex.index] = distance;
}
if (distance < v[i].minDistanceTo){
v[i].minDistanceTo = distance;
v[i].precedingPokeIndex = short(minIndex);
if (distance < vertex.minDistanceTo){
vertex.minDistanceTo = distance;
vertex.precedingPokeIndex = short(minIndex);
}
}
}
......@@ -71,25 +73,27 @@ public:
} //while
double mstDistance = 0;
for (size_t i = 0; i < v.size(); i++){
if (v[i].precedingPokeIndex != -1){
mstDistance += v[i].minDistanceTo;
for (size_t i = 0; i < length; i++){
Vertex &vertex = v[i];
if (vertex.precedingPokeIndex != -1){
mstDistance += vertex.minDistanceTo;
}
}
double minDistanceFromPrev = numeric_limits<double>::infinity();
double minDistanceFromFirst = numeric_limits<double>::infinity();
for (size_t i = 0; i < v.size(); i++){
double distancePrev = distanceMatrix[v[i].index][path[permLength - 1]];
double distanceFirst = distanceMatrix[v[i].index][path[0]];
for (size_t i = 0; i < length; i++){
Vertex &vertex = v[i];
double distancePrev = distanceMatrix[vertex.index][path[permLength - 1]];
double distanceFirst = distanceMatrix[vertex.index][path[0]];
if (distancePrev == 0){
distanceMatrix[v[i].index][path[permLength - 1]] = distancePrev = pokeDistance(v[i].index, path[permLength - 1]);
distanceMatrix[vertex.index][path[permLength - 1]] = distancePrev = pokeDistance(vertex.index, path[permLength - 1]);
}
if (distancePrev < minDistanceFromPrev){
minDistanceFromPrev = distancePrev;
}
if (distanceFirst == 0){
distanceMatrix[v[i].index][path[0]] = distanceFirst = pokeDistance(v[i].index, path[0]);
distanceMatrix[vertex.index][path[0]] = distanceFirst = pokeDistance(vertex.index, path[0]);
}
if (distanceFirst < minDistanceFromFirst){
minDistanceFromFirst = distanceFirst;
......
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