From 30458e0e6de4e1bf80801df011cfdb12094f6f15 Mon Sep 17 00:00:00 2001 From: bbod Date: Tue, 31 Mar 2020 00:36:16 -0600 Subject: [PATCH] Auto Commit --- HW10/MakePermutationMatrix.cpp | 12 ++++++++---- HW10/MakePermutationMatrix.h | 4 ++-- HW10/main.cpp | 4 ++-- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/HW10/MakePermutationMatrix.cpp b/HW10/MakePermutationMatrix.cpp index 5bb629d..64a4338 100644 --- a/HW10/MakePermutationMatrix.cpp +++ b/HW10/MakePermutationMatrix.cpp @@ -8,7 +8,7 @@ #include #include -std::vector MakePermutationMatrix::MakePermutation(std::vector source, int rank, int size, std::vector> costMatrix){ +long double MakePermutationMatrix::MakePermutation(std::vector source, int rank, int size, std::vector> costMatrix){ std::vector returnVector; std::vector localCostVector; int vectorOffset = source.size()/size; @@ -77,9 +77,13 @@ std::vector MakePermutationMatrix::MakePermutation(std::vector sou std::cout << std::endl; //MPI_Gather(&localCostVector,1, MPI_DOUBLE, &returnVector,1, MPI_DOUBLE,0, MPI_COMM_WORLD); - return returnVector; + return lowest; } -std::vector MakePermutationMatrix::GetLowestCost(std::vector source, int rank, int size, std::vector> costMatrix){ - return MakePermutation(source, rank, size, costMatrix); +long double MakePermutationMatrix::GetLowestCost(std::vector source, int rank, int size, std::vector> costMatrix){ + std::vector l(size,0); + auto lowest = MakePermutation(source, rank, size, costMatrix); + MPI_Gather(&lowest,1,MPI_LONG_DOUBLE,l.data(),1,MPI_LONG_DOUBLE,0,MPI_COMM_WORLD); + std::sort(l.begin(), l.end()); + return l[l.size()-1]; } \ No newline at end of file diff --git a/HW10/MakePermutationMatrix.h b/HW10/MakePermutationMatrix.h index 969b713..88ff1c1 100644 --- a/HW10/MakePermutationMatrix.h +++ b/HW10/MakePermutationMatrix.h @@ -10,10 +10,10 @@ class MakePermutationMatrix { public: - static std::vector GetLowestCost(std::vector source, int rank, int size, std::vector> costMatrix); + long double GetLowestCost(std::vector source, int rank, int size, std::vector> costMatrix); private: - static std::vector MakePermutation(std::vector source, int rank, int size, std::vector> costMatrix); + long double MakePermutation(std::vector source, int rank, int size, std::vector> costMatrix); }; #endif // HW10_MAKEPERMUTATIONMATRIX_H diff --git a/HW10/main.cpp b/HW10/main.cpp index b63ec7b..1be0194 100644 --- a/HW10/main.cpp +++ b/HW10/main.cpp @@ -9,7 +9,7 @@ int main(int argc, char* argv[]) { int rank, size, citiesSize; - int data; + long double lowestCost = 0; MPI_Init(&argc, &argv); MPI_Comm_rank(MCW, &rank); MPI_Comm_size(MCW, &size); @@ -56,7 +56,7 @@ int main(int argc, char* argv[]) //Make permutations } - costs = MakePermutationMatrix::GetLowestCost(cities, rank, size, costMatrix); + lowestCost = MakePermutationMatrix::GetLowestCost(cities, rank, size, costMatrix); // if(!rank){ // std::cout << costs.size() << std::endl; // std::cout << costs[0];