00001
00002
00003
00004
00005 SetUp (void * gptr, int type)
00006 {
00007 int i = 0;
00008 int allocsize = 0;
00009
00010 Graph g = (Graph) NULL;
00011 EuclidGraph xy = (EuclidGraph) NULL;
00012 MatrixGraph matg = (MatrixGraph) NULL;
00013
00014 if ( type==1 )
00015 {
00016 g = (Graph) gptr;
00017 U = Degree(g,0);
00018 V = NumEdges(g);
00019 }
00020 else if (type==2)
00021 {
00022 xy = (EuclidGraph) gptr;
00023 U = xy[0][0];
00024 V = U * (U - 1) / 2;
00025 }
00026 else if (type==3)
00027 {
00028 matg = (MatrixGraph) gptr;
00029 U = matg[0];
00030 V = U * (U - 1) / 2;
00031 }
00032
00033 allocsize = (U + 2 * V + 2) * sizeof(int);
00034
00035 #ifdef MATLAB_MEX_FILE
00036 void *mxMalloc(size_t);
00037 A = (int *) mxMalloc(allocsize);
00038 END = (int *) mxMalloc(allocsize);
00039 WEIGHT = (int *) mxMalloc(allocsize);
00040 #else
00041 A = (int *) malloc(allocsize);
00042 END = (int *) malloc(allocsize);
00043 WEIGHT = (int *) malloc(allocsize);
00044 #endif
00045
00046 for (i = 0; i < U + 2 * V + 2; i++)
00047 {
00048 A[i] = END[i] = WEIGHT[i] = 0;
00049 }
00050
00051
00052 if (type == 1)
00053 {
00054 SetStandard(g);
00055 }
00056 else if (type == 2)
00057 {
00058 SetEuclid(xy);
00059 }
00060 else if (type == 3)
00061 {
00062 SetMatrix(matg);
00063 }
00064 }
00065
00066
00067
00068
00069 SetStandard(graph)
00070 Graph graph;
00071 { int elabel, adj_node, i, j;
00072 int u, v, currentedge;
00073 Edge edge;
00074
00075 currentedge = U+2;
00076 for (i=1; i<=U; ++i) {
00077 edge = FirstEdge(graph,i);
00078 for (j = 1; j <= Degree(graph,i); ++j) {
00079 adj_node = EndPoint(edge);
00080 if (i < adj_node) {
00081 elabel = ELabel(edge)*2;
00082 WEIGHT[currentedge-1] = WEIGHT[currentedge] = 2*elabel;
00083 END[currentedge-1] = i;
00084 END[currentedge] = adj_node;
00085 if (A[i] == 0)
00086 A[i] = currentedge;
00087 else {
00088 u = i;
00089 v = A[i];
00090 while (v != 0) {
00091 if (END[v] > adj_node)
00092 break;
00093 u = v;
00094 v = A[v];
00095 }
00096 A[u] = currentedge;
00097 A[currentedge] = v;
00098 }
00099 u = adj_node;
00100 v = A[u];
00101 while (v != 0) {
00102 u = v;
00103 v = A[v];
00104 }
00105 A[u] = currentedge - 1;
00106 currentedge += 2;
00107 }
00108 edge = NextEdge(edge);
00109 }
00110 }
00111 }
00112
00113
00114
00115 SetEuclid(graph)
00116 EuclidGraph graph;
00117 { int i,j,currentedge;
00118
00119 currentedge = U+2;
00120
00121 for (i=U; i>=1; --i)
00122 for (j = i-1; j >= 1; --j) {
00123 WEIGHT[currentedge-1] = WEIGHT[currentedge]
00124 = 2*eucdist2(graph,i,j);
00125 END[currentedge-1] = i;
00126 END[currentedge] = j;
00127 A[currentedge] = A[i];
00128 A[i] = currentedge;
00129 A[currentedge-1] = A[j];
00130 A[j] = currentedge-1;
00131 currentedge += 2;
00132 }
00133 }
00134
00135 SetMatrix(graph)
00136 MatrixGraph graph;
00137 { int i,j,currentedge;
00138
00139 currentedge = U+2;
00140
00141 for (i=U; i>=1; --i)
00142 for (j = i-1; j >= 1; --j) {
00143 WEIGHT[currentedge-1] = WEIGHT[currentedge]
00144 = 2*graph[j*U+i];
00145 END[currentedge-1] = i;
00146 END[currentedge] = j;
00147 A[currentedge] = A[i];
00148 A[i] = currentedge;
00149 A[currentedge-1] = A[j];
00150 A[j] = currentedge-1;
00151 currentedge += 2;
00152 }
00153 }
00154