00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "digcola.h"
00018 #ifdef DIGCOLA
00019 #include "matrix_ops.h"
00020 #include "conjgrad.h"
00021
00022 static void
00023 construct_b(vtx_data* graph, int n, double *b)
00024 {
00025
00026
00027
00028
00029
00030
00031 int i,j;
00032
00033 double b_i = 0;
00034
00035 for (i=0; i<n; i++) {
00036 b_i = 0;
00037 if (graph[0].edists==NULL) {
00038 continue;
00039 }
00040 for (j=1; j<graph[i].nedges; j++) {
00041 b_i += graph[i].ewgts[j]*graph[i].edists[j];
00042 }
00043 b[i] = b_i;
00044 }
00045 }
00046
00047 #define hierarchy_cg_tol 1e-3
00048
00049 void
00050 compute_y_coords(vtx_data* graph, int n, double* y_coords, int max_iterations)
00051 {
00052
00053 int i,j;
00054 double* b = N_NEW(n, double);
00055 double tol = hierarchy_cg_tol;
00056 int nedges = 0;
00057 float* uniform_weights;
00058 float* old_ewgts = graph[0].ewgts;
00059
00060 construct_b(graph, n, b);
00061
00062 init_vec_orth1(n, y_coords);
00063
00064 for (i=0; i<n; i++) {
00065 nedges += graph[i].nedges;
00066 }
00067
00068
00069
00070 uniform_weights = N_GNEW(nedges,float);
00071 for (i=0; i<n; i++) {
00072 graph[i].ewgts = uniform_weights;
00073 uniform_weights[0] = (float)-(graph[i].nedges-1);
00074 for (j=1; j<graph[i].nedges; j++) {
00075 uniform_weights[j] = 1;
00076 }
00077 uniform_weights += graph[i].nedges;
00078 }
00079
00080 conjugate_gradient(graph, y_coords, b, n, tol, max_iterations);
00081
00082
00083 free (graph[0].ewgts);
00084 for (i=0; i<n; i++) {
00085 graph[i].ewgts = old_ewgts;
00086 old_ewgts += graph[i].nedges;
00087 }
00088
00089 free(b);
00090 }
00091
00092 #endif
00093