Beispiel #1
0
void eqnsys<nr_type_t>::solve (void) {
#if DEBUG && 0
  time_t t = time (NULL);
#endif
  switch (algo) {
  case ALGO_INVERSE:
    solve_inverse ();
    break;
  case ALGO_GAUSS:
    solve_gauss ();
    break;
  case ALGO_GAUSS_JORDAN:
    solve_gauss_jordan ();
    break;
  case ALGO_LU_DECOMPOSITION_CROUT:
    solve_lu_crout ();
    break;
  case ALGO_LU_DECOMPOSITION_DOOLITTLE:
    solve_lu_doolittle ();
    break;
  case ALGO_LU_FACTORIZATION_CROUT:
    factorize_lu_crout ();
    break;
  case ALGO_LU_FACTORIZATION_DOOLITTLE:
    factorize_lu_doolittle ();
    break;
  case ALGO_LU_SUBSTITUTION_CROUT:
    substitute_lu_crout ();
    break;
  case ALGO_LU_SUBSTITUTION_DOOLITTLE:
    substitute_lu_doolittle ();
    break;
  case ALGO_JACOBI: case ALGO_GAUSS_SEIDEL:
    solve_iterative ();
    break;
  case ALGO_SOR:
    solve_sor ();
    break;
  case ALGO_QR_DECOMPOSITION:
    solve_qr ();
    break;
  case ALGO_QR_DECOMPOSITION_LS:
    solve_qr_ls ();
    break;
  case ALGO_SV_DECOMPOSITION:
    solve_svd ();
    break;
  case ALGO_QR_DECOMPOSITION_2:
    solve_qrh ();
    break;
  }
#if DEBUG && 0
  logprint (LOG_STATUS, "NOTIFY: %dx%d eqnsys solved in %ld seconds\n",
	    A->getRows (), A->getCols (), time (NULL) - t);
#endif
}
Beispiel #2
0
int
layout_rest(GraphFrame *gf, LNode_type *the_rest, int rest_cnt)
{
  int i,j;
  double **M = (double **)malloc(rest_cnt * sizeof(double *));
  LNode_type *ptr;

  if(!M) {
    fprintf(stderr,"Out of Memory layout_rest\n");
    abort();
  }

  for(i=0;i<rest_cnt;i++)
    {
      M[i]=(double *)malloc((rest_cnt+2)*sizeof(double));
      if(!M[i]) {
	  fprintf(stderr,"Out of Memory layout_rest\n");
	  abort();
      }
    }
  
  for(i = 0; i< rest_cnt; i++)
    {
      for(j=0;j< rest_cnt+2; j++)
	M[i][j]=0.0;
    }

  /* Fill in the matrix with -1.0 if i,j are adjacent, 0.0 otherwise (default)
   */
  
  ptr = gf->the_rest;
  for(i=0; i< rest_cnt; i++)
    {
      struct pt *v = (struct pt *)ptr->back->info;
      int degree = 0;
      LNode_type *poed;

      for(poed = v->ledges_out; poed->next != v->ledges_out; poed = poed->next)
	{
	  struct edge *e = (struct edge *)poed->next->info;
	  struct pt * tv = e->to;
	  int col = tv->level;
	  ++degree;
	  if(col == -1) continue;
	  M[i][col] = -1.0;

	}
      for(poed = v->ledges_in; poed->next != v->ledges_in; poed = poed->next)
	{
	  struct edge *e = (struct edge *)poed->next->info;
	  struct pt * tv = e->from;
	  int col;

	  if(tv == v)
	    tv = e->to;
	  ++degree;
	  col = tv->level;
	  if(col == -1) continue;
	  M[i][col] = -1.0;

	}
      M[i][i] = degree ;
      ptr = ptr->back;
    }
  /* Fill in the x and y columns with the sum of adjacent nodes'x and y's. */
  ptr = gf->the_rest;
  for(i=0; i < rest_cnt; i++)
    {
      struct pt *u = (struct pt *)ptr->back->info;
      double x = 0.0, y = 0.0;
      LNode_type *poed;
      for(poed = u->ledges_in; poed->next != u->ledges_in; poed = poed->next)
	{
	  struct edge *e = (struct edge *)poed->next->info;
	  struct pt *v = (struct pt *)e->from;
	  if(u == v)
	    v = e->to;

	  if(v->level == -1)
	    {
	      x += (double)(v->loc.x);
	      y += (double)(v->loc.y);
	    }
	}
      for(poed = u->ledges_out; poed->next != u->ledges_out; poed = poed->next)
	{
	  struct edge *e = (struct edge *)poed->next->info;
	  struct pt *v = (struct pt *)e->to;
	  if(v->level == -1)
	    {
	      x += (double)(v->loc.x);
	      y += (double)(v->loc.y);
	    }
	}
      M[i][rest_cnt] = x;
      M[i][rest_cnt+1] = y;
      ptr = ptr->back;
    }
  /*print_matrix(M,rest_cnt,rest_cnt+2);*/
  solve_gauss_jordan(M, rest_cnt, rest_cnt+2);
  /*print_matrix(M,rest_cnt,rest_cnt+2);*/

  i = 0;
  for(ptr = gf->the_rest; ptr->back != gf->the_rest ; ptr = ptr->back)
    {
      struct pt *v = (struct pt *)ptr->back->info;
      Node_type *nver;

      v->loc.x = (int)(M[i][rest_cnt]);
      v->loc.y = (int)(M[i][rest_cnt + 1]);

      nver = select_nearest_vertex(&(v->loc), gf);
      if(nver)
	{
	  if(find_near_spot(v,gf))
	    return WINDOW_FULL;
	}
	  
      /*printf(" %d:%d, %d\n", i , v->loc.x, v->loc.y);*/
      i++;

      insert_v(v, gf);
    }
  delete_matrix_double(M,rest_cnt);
  return 0;
}