Auto Commit

This commit is contained in:
2020-03-30 10:17:11 -06:00
parent cb83ba5491
commit 426061b78b
3 changed files with 20 additions and 15 deletions

View File

@@ -14,24 +14,27 @@ std::vector<double> MakePermutationMatrix::MakePermutation(std::vector<City> sou
std::vector<City> myPerm = source;
std::vector<City> 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<double>(1,localCostVector[0]);
for(int i = 0; i < localCostVector.size(); i++) {
if(localCostVector[i] < lowest[0])

View File

@@ -4,7 +4,6 @@
#include "ReadFromFile.h"
#include "mpi.h"
#include <iostream>
#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);

3
HW10/push Normal file
View File

@@ -0,0 +1,3 @@
git add .
git commit -m "Auto Commit"
git push