updated floyd.cc
git-svn-id: svn://anubis/gvsu@193 45c1a28c-8058-47b2-ae61-ca45b979098e
This commit is contained in:
parent
daa05f633f
commit
fcb800e858
@ -6,8 +6,77 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <omp.h>
|
#include <omp.h>
|
||||||
|
#include <math.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
#include <vector>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
void usage(char * progname);
|
||||||
|
int readFile(char * fileName, vector<int> & v);
|
||||||
|
void convertToMatrix(const vector<int> & v, int num_verts, int * vals);
|
||||||
|
|
||||||
|
void usage(char * progname)
|
||||||
|
{
|
||||||
|
cout << "Usage: " << progname << " <adjacency-file>" << endl;
|
||||||
|
exit(42);
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char * argv[])
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
|
if (argc < 1)
|
||||||
|
usage(argv[0]);
|
||||||
|
|
||||||
|
vector<int> v;
|
||||||
|
|
||||||
|
int num_verts = readFile(argv[1], v);
|
||||||
|
int D[2][num_verts][num_verts];
|
||||||
|
convertToMatrix(v, num_verts, (int *) &D[0]);
|
||||||
|
|
||||||
|
for (int i = 0; i < num_verts; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < num_verts; j++)
|
||||||
|
{
|
||||||
|
cout << D[0][i][j] << " ";
|
||||||
|
}
|
||||||
|
cout << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int readFile(char * fileName, vector<int> & v)
|
||||||
|
{
|
||||||
|
ifstream in(fileName);
|
||||||
|
if (!in.is_open())
|
||||||
|
{
|
||||||
|
cerr << "Error opening " << fileName << endl;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
int weight;
|
||||||
|
in >> weight;
|
||||||
|
if (in.eof())
|
||||||
|
break;
|
||||||
|
v.push_back(weight);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int) sqrt(v.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
void convertToMatrix(const vector<int> & v, int num_verts, int * vals)
|
||||||
|
{
|
||||||
|
int vidx = 0;
|
||||||
|
int (*V)[num_verts][num_verts] = (int (*)[num_verts][num_verts]) vals;
|
||||||
|
for (int i = 0; i < num_verts; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < num_verts; j++)
|
||||||
|
{
|
||||||
|
(*V)[i][j] = v[vidx++];
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user