Auto Commit
This commit is contained in:
@@ -14,24 +14,27 @@ std::vector<double> MakePermutationMatrix::MakePermutation(std::vector<City> sou
|
|||||||
std::vector<City> myPerm = source;
|
std::vector<City> myPerm = source;
|
||||||
std::vector<City> nextPerm = source;
|
std::vector<City> nextPerm = source;
|
||||||
auto offset = myPerm.size()/size;
|
auto offset = myPerm.size()/size;
|
||||||
if(!rank){
|
|
||||||
returnVector.resize(source.size(), 0);
|
|
||||||
}
|
|
||||||
if(rank)
|
|
||||||
std::rotate(nextPerm.begin(), nextPerm.begin()+offset*(rank+1), nextPerm.end());
|
|
||||||
else
|
|
||||||
nextPerm = source;
|
|
||||||
|
|
||||||
|
//return vector should be the size of number of processors as they are going to only return their own smallest.
|
||||||
if(rank)
|
if(rank)
|
||||||
|
returnVector.resize(source.size(), 0);
|
||||||
|
|
||||||
|
//the "nextPerm" is the permutation to stop at.
|
||||||
|
std::rotate(nextPerm.begin(), nextPerm.begin()+offset*(rank+1), nextPerm.end());
|
||||||
|
|
||||||
|
//rotate my perm.
|
||||||
std::rotate(myPerm.begin(), myPerm.begin()+offset*rank,myPerm.end());
|
std::rotate(myPerm.begin(), myPerm.begin()+offset*rank,myPerm.end());
|
||||||
|
|
||||||
do {
|
do {
|
||||||
double cost;
|
double cost;
|
||||||
|
//Add up the cost of the current permutation.
|
||||||
for (int i = 1; i < myPerm.size(); i++) {
|
for (int i = 1; i < myPerm.size(); i++) {
|
||||||
cost += costMatrix[myPerm[i].GetName()][myPerm[i-1].GetName()];
|
cost += costMatrix[myPerm[i].GetName()][myPerm[i-1].GetName()];
|
||||||
}
|
}
|
||||||
|
//Push permutation cost to the localCostVector.
|
||||||
localCostVector.push_back(cost);
|
localCostVector.push_back(cost);
|
||||||
} while (std::next_permutation(myPerm.begin(), myPerm.end()), myPerm != nextPerm);
|
} while (std::next_permutation(myPerm.begin(), myPerm.end()), myPerm != nextPerm);
|
||||||
|
//find the lowest and add it to a lowest vector.
|
||||||
auto lowest = std::vector<double>(1,localCostVector[0]);
|
auto lowest = std::vector<double>(1,localCostVector[0]);
|
||||||
for(int i = 0; i < localCostVector.size(); i++) {
|
for(int i = 0; i < localCostVector.size(); i++) {
|
||||||
if(localCostVector[i] < lowest[0])
|
if(localCostVector[i] < lowest[0])
|
||||||
|
|||||||
@@ -4,7 +4,6 @@
|
|||||||
#include "ReadFromFile.h"
|
#include "ReadFromFile.h"
|
||||||
#include "mpi.h"
|
#include "mpi.h"
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#define MCW MPI_COMM_WORLD
|
#define MCW MPI_COMM_WORLD
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
@@ -22,12 +21,12 @@ int main(int argc, char* argv[])
|
|||||||
citiesSize = cities.size();
|
citiesSize = cities.size();
|
||||||
//Make costMatrix
|
//Make costMatrix
|
||||||
costMatrix = CostMatrixGenerator::GenerateCostMatrix(cities);
|
costMatrix = CostMatrixGenerator::GenerateCostMatrix(cities);
|
||||||
for(int i =0; i < cities.size(); i++){
|
// for(int i =0; i < cities.size(); i++){
|
||||||
for(int j = 0; j< cities.size(); j++){
|
// for(int j = 0; j< cities.size(); j++){
|
||||||
std::cout << costMatrix[i][j] << " ";
|
// std::cout << costMatrix[i][j] << " ";
|
||||||
}
|
// }
|
||||||
std::cout << std::endl;
|
// std::cout << std::endl;
|
||||||
}
|
// }
|
||||||
flatMatrix = matrixTools::FlattenMatrix(costMatrix);
|
flatMatrix = matrixTools::FlattenMatrix(costMatrix);
|
||||||
}
|
}
|
||||||
MPI_Bcast(&citiesSize, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
MPI_Bcast(&citiesSize, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
||||||
|
|||||||
Reference in New Issue
Block a user