diff --git a/HW10/MakePermutationMatrix.cpp b/HW10/MakePermutationMatrix.cpp index 85e8238..e5cdba3 100644 --- a/HW10/MakePermutationMatrix.cpp +++ b/HW10/MakePermutationMatrix.cpp @@ -14,24 +14,27 @@ std::vector MakePermutationMatrix::MakePermutation(std::vector sou std::vector myPerm = source; std::vector nextPerm = source; 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) - std::rotate(myPerm.begin(), myPerm.begin()+offset*rank,myPerm.end()); + 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()); do { double cost; + //Add up the cost of the current permutation. for (int i = 1; i < myPerm.size(); i++) { cost += costMatrix[myPerm[i].GetName()][myPerm[i-1].GetName()]; } + //Push permutation cost to the localCostVector. localCostVector.push_back(cost); } while (std::next_permutation(myPerm.begin(), myPerm.end()), myPerm != nextPerm); + //find the lowest and add it to a lowest vector. auto lowest = std::vector(1,localCostVector[0]); for(int i = 0; i < localCostVector.size(); i++) { if(localCostVector[i] < lowest[0]) diff --git a/HW10/main.cpp b/HW10/main.cpp index 61641ed..80fd76a 100644 --- a/HW10/main.cpp +++ b/HW10/main.cpp @@ -4,7 +4,6 @@ #include "ReadFromFile.h" #include "mpi.h" -#include #define MCW MPI_COMM_WORLD int main(int argc, char* argv[]) { @@ -22,12 +21,12 @@ int main(int argc, char* argv[]) citiesSize = cities.size(); //Make costMatrix costMatrix = CostMatrixGenerator::GenerateCostMatrix(cities); - for(int i =0; i < cities.size(); i++){ - for(int j = 0; j< cities.size(); j++){ - std::cout << costMatrix[i][j] << " "; - } - std::cout << std::endl; - } +// for(int i =0; i < cities.size(); i++){ +// for(int j = 0; j< cities.size(); j++){ +// std::cout << costMatrix[i][j] << " "; +// } +// std::cout << std::endl; +// } flatMatrix = matrixTools::FlattenMatrix(costMatrix); } MPI_Bcast(&citiesSize, 1, MPI_INT, 0, MPI_COMM_WORLD); diff --git a/HW10/push b/HW10/push new file mode 100644 index 0000000..7f8b4b8 --- /dev/null +++ b/HW10/push @@ -0,0 +1,3 @@ +git add . +git commit -m "Auto Commit" +git push