test
This commit is contained in:
@@ -4,8 +4,7 @@
|
|||||||
|
|
||||||
#include "MakePermutationMatrix.h"
|
#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::vector<std::vector<City>> permutations;
|
||||||
std::sort(source.begin(), source.end());
|
std::sort(source.begin(), source.end());
|
||||||
std::vector<City> myPerm = source;
|
std::vector<City> myPerm = source;
|
||||||
@@ -29,3 +28,7 @@ std::vector<std::vector<City>> MakePermutationMatrix::MakePermutation(std::vecto
|
|||||||
} while (std::next_permutation(myPerm.begin(), myPerm.end()), myPerm != nextPerm);
|
} while (std::next_permutation(myPerm.begin(), myPerm.end()), myPerm != nextPerm);
|
||||||
return permutations;
|
return permutations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::vector<City>> MakePermutationMatrix::GetLowestCost(std::vector<City> source, int rank, int size, std::vector<std::vector<double>> costMatrix){
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,9 +6,14 @@
|
|||||||
#define HW10_MAKEPERMUTATIONMATRIX_H
|
#define HW10_MAKEPERMUTATIONMATRIX_H
|
||||||
|
|
||||||
#include "City.h"
|
#include "City.h"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
class MakePermutationMatrix {
|
class MakePermutationMatrix
|
||||||
public:
|
{
|
||||||
|
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);
|
static std::vector<std::vector<City>> MakePermutation(std::vector<City> source, int rank, int size);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,39 +1,45 @@
|
|||||||
|
#import "CostMatrixGenerator.h"
|
||||||
#import "MakePermutationMatrix.h"
|
#import "MakePermutationMatrix.h"
|
||||||
#import "ReadFromFile.h"
|
#import "ReadFromFile.h"
|
||||||
#import "mpi.h"
|
#import "mpi.h"
|
||||||
#import "CostMatrixGenerator.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#define MCW MPI_COMM_WORLD
|
#define MCW MPI_COMM_WORLD
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
int rank, size;
|
int rank, size, citiesSize;
|
||||||
int data;
|
int data;
|
||||||
MPI_Init(&argc, &argv);
|
MPI_Init(&argc, &argv);
|
||||||
MPI_Comm_rank(MCW, &rank);
|
MPI_Comm_rank(MCW, &rank);
|
||||||
MPI_Comm_size(MCW, &size);
|
MPI_Comm_size(MCW, &size);
|
||||||
std::vector<std::vector<double>> matrix;
|
std::vector<std::vector<double>> matrix;
|
||||||
|
std::vector<City> cities;
|
||||||
if (rank == 0) {
|
if (rank == 0) {
|
||||||
std::cout << "Reading in file" << std::endl;
|
std::cout << "Reading in file" << std::endl;
|
||||||
auto returnValue = ReadFromFile::ReadFile("../input");
|
cities = ReadFromFile::ReadFile("../input");
|
||||||
|
citiesSize = cities.size();
|
||||||
|
//Make matrix
|
||||||
std::cout << "itterating through returned vector." << std::endl;
|
matrix = CostMatrixGenerator::GenerateCostMatrix(cities);
|
||||||
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);
|
MPI_Bcast(&citiesSize, 1, MPI_INT, 0, MPI_COMM_WORLD);
|
||||||
|
if(!rank){
|
||||||
|
// reserve memory for vectors
|
||||||
std::cout << "Making Permutations" << std::endl;
|
matrix.resize(citiesSize);
|
||||||
auto t = MakePermutationMatrix::MakePermutation(returnValue, rank, size);
|
for(int i = 0; i < citiesSize; i++) {
|
||||||
std::cout << "itterating through returned permutations." << std::endl;
|
matrix[i].resize(citiesSize);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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