test
This commit is contained in:
@@ -4,8 +4,7 @@
|
||||
|
||||
#include "MakePermutationMatrix.h"
|
||||
|
||||
std::vector<std::vector<City>> MakePermutationMatrix::MakePermutation(std::vector<City> source, int rank, int size)
|
||||
{
|
||||
std::vector<std::vector<City>> MakePermutationMatrix::MakePermutation(std::vector<City> source, int rank, int size){
|
||||
std::vector<std::vector<City>> permutations;
|
||||
std::sort(source.begin(), source.end());
|
||||
std::vector<City> myPerm = source;
|
||||
@@ -28,4 +27,8 @@ std::vector<std::vector<City>> MakePermutationMatrix::MakePermutation(std::vecto
|
||||
permutations.push_back(currentPerm);
|
||||
} while (std::next_permutation(myPerm.begin(), myPerm.end()), myPerm != nextPerm);
|
||||
return permutations;
|
||||
}
|
||||
|
||||
std::vector<std::vector<City>> MakePermutationMatrix::GetLowestCost(std::vector<City> source, int rank, int size, std::vector<std::vector<double>> costMatrix){
|
||||
|
||||
}
|
||||
@@ -6,10 +6,15 @@
|
||||
#define HW10_MAKEPERMUTATIONMATRIX_H
|
||||
|
||||
#include "City.h"
|
||||
|
||||
#include <vector>
|
||||
class MakePermutationMatrix {
|
||||
public:
|
||||
static std::vector<std::vector<City>> MakePermutation(std::vector<City> source, int rank, int size);
|
||||
class MakePermutationMatrix
|
||||
{
|
||||
public:
|
||||
static std::vector<std::vector<City>> GetLowestCost(std::vector<City> source, int rank, int size, std::vector<std::vector<double>> costMatrix);
|
||||
|
||||
private:
|
||||
static std::vector<std::vector<City>> MakePermutation(std::vector<City> source, int rank, int size);
|
||||
};
|
||||
|
||||
#endif // HW10_MAKEPERMUTATIONMATRIX_H
|
||||
|
||||
@@ -1,39 +1,45 @@
|
||||
#import "CostMatrixGenerator.h"
|
||||
#import "MakePermutationMatrix.h"
|
||||
#import "ReadFromFile.h"
|
||||
#import "mpi.h"
|
||||
#import "CostMatrixGenerator.h"
|
||||
|
||||
#include <iostream>
|
||||
#define MCW MPI_COMM_WORLD
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int rank, size;
|
||||
int rank, size, citiesSize;
|
||||
int data;
|
||||
MPI_Init(&argc, &argv);
|
||||
MPI_Comm_rank(MCW, &rank);
|
||||
MPI_Comm_size(MCW, &size);
|
||||
std::vector<std::vector<double>> matrix;
|
||||
|
||||
std::vector<City> cities;
|
||||
if (rank == 0) {
|
||||
std::cout << "Reading in file" << std::endl;
|
||||
auto returnValue = ReadFromFile::ReadFile("../input");
|
||||
|
||||
|
||||
std::cout << "itterating through returned vector." << std::endl;
|
||||
for (int i = 0; i < returnValue.size(); i++) {
|
||||
std::cout << returnValue[i].GetX() << " " << returnValue[i].GetY() << " " << returnValue[i].GetName() << std::endl;
|
||||
}
|
||||
matrix = CostMatrixGenerator::GenerateCostMatrix(returnValue);
|
||||
|
||||
|
||||
std::cout << "Making Permutations" << std::endl;
|
||||
auto t = MakePermutationMatrix::MakePermutation(returnValue, rank, size);
|
||||
std::cout << "itterating through returned permutations." << std::endl;
|
||||
for (int i = 0; i < t.size(); i++) {
|
||||
for (int j = 0; j < t[i].size(); j++) {
|
||||
std::cout << t[i][j].GetName() << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
cities = ReadFromFile::ReadFile("../input");
|
||||
citiesSize = cities.size();
|
||||
//Make matrix
|
||||
matrix = CostMatrixGenerator::GenerateCostMatrix(cities);
|
||||
}
|
||||
MPI_Bcast(&citiesSize, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
||||
if(!rank){
|
||||
// reserve memory for vectors
|
||||
matrix.resize(citiesSize);
|
||||
for(int i = 0; i < citiesSize; i++) {
|
||||
matrix[i].resize(citiesSize);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
MPI_Bcast(&matrix[0][0], citiesSize*citiesSize, MPI_FLOAT, 0, MPI_COMM_WORLD);
|
||||
|
||||
if(!rank){
|
||||
for(int i = 0; i < citiesSize; i++){
|
||||
for(int j = 0; j < citiesSize; j++) {
|
||||
std::cout<<"Process " << rank << " has value " << matrix[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// //Make permutations
|
||||
// auto perms = MakePermutationMatrix::GetLowestCost(cities, rank, size, matrix);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user