Exemplo n.º 1
0
void GLEABC::set_BBT(const DMatrix& nBBT)
{
    if (n==0) set_size(nBBT.rows());
    if (A.rows()>0) fr_init=true;
    if (n!=nBBT.rows()) ERROR("Use set_size if you want to change matrix size.");
    if (n!=nBBT.cols()) ERROR("Square matrix expected.");
    BBT=nBBT; fr_c=false;
}
Exemplo n.º 2
0
int main(int argc, char *argv[])
{
  /*
  DMatrix W { 5, 5, 
      {   0,   4, inf,   2, inf, 
	inf,   0,   3, inf,   1, 
	  5, inf,   0,   1, inf, 
          7, inf, inf,   0,   5,
	  3, inf, inf, inf,   0 } };
  */

  // Checking that the value of n is given
  if (argc != 2) {
    cerr << "floyd-sequential n" << endl;
    exit(1);
  }
  int n = atoi(argv[1]);
  if (n == 0) {
    cerr << argv[1] << " is a wrong parameter" << endl;
    exit(1);
  }
   
  srand(10);

  DMatrix W = generate_matrix(n);

  DMatrix dist(W.rows(),W.cols(),inf);
  IMatrix next(W.rows(),W.cols(),-1);


  double start = omp_get_wtime();
  floyd_warshall(W, dist, next); 

  
  path_t p = recover_path(dist,next,0,(rand()%(n-1))+1);
  double end = omp_get_wtime();

  if (p.size() == 0) {
    cout << "No path" << endl;
  } else {
    copy(p.begin(), p.end(), ostream_iterator<int>(cout, " "));
    cout << "\n";
    double cost = 0;
    #pragma omp parallel for reduction (+:cost)
    for (uint32_t i = 0; i < p.size()-1; ++i) {
      cost += dist(p[i],p[i+1]);
    }
    cout << "Cost: " << cost << "\n";
  }
  
  cout << "Elapsed time: " << (end-start) << endl;
}
Exemplo n.º 3
0
void GLEABC::set_C(const DMatrix& nC)
{
    if (n==0) set_size(nC.rows());
    if (A.rows()>0) fr_init=true;
    if (n!=nC.rows()) ERROR("Use set_size if you want to change matrix size.");
    if (n!=nC.cols()) ERROR("Square matrix expected.");
    C=nC; fr_c=true;
    if (fr_init && fr_c)
    {
        //update BBT, it's so cheap we can do it routinely;
        DMatrix T; mult(A, C, BBT); transpose(BBT, T);  incr(BBT,T);
    }
}
Exemplo n.º 4
0
/**
 * save a real matrix into a text file
 *
 * row_index  col_index   matrix_element
 */
void saveMatrixText(std::string filename, DMatrix& m, bool exactValue) {
	std::ofstream out(filename.c_str());
	// print to full precision
	if (exactValue) {
		out.precision(dbl::digits10 + 2);
	}
	// use default precision to save space
	for (int row=0; row< m.rows(); ++row) {
		for (int col=0; col<m.cols(); ++col) {
			double v = m(row, col);
			out << row <<"  " << col << "  "
			<< v << std::endl;
		}
	}
	out.close();
}