Go to the documentation of this file.00001
00015 #ifndef _SMP_DEBUGGING_TOOLS_CHECK_TREE_STRUCTURE_H_
00016 #define _SMP_DEBUGGING_TOOLS_CHECK_TREE_STRUCTURE_H_
00017
00018
00033 template< class typeparams >
00034 int sanity_check_tree (list<vertex_t*> &list_vertices_in) {
00035
00036 typedef vertex<typeparams> vertex_t;
00037 typedef edge<typeparams> edge_t;
00038
00039 bool errors_present = false;
00040
00041 int num_root_vertices = 0;
00042
00043 for (list<vertex_t*>::iterator it_vertex = list_vertices_in.begin();
00044 it_vertex != list_vertices_in.end(); it_vertex++) {
00045
00046 vertex_t *vertex_curr = *it_vertex;
00047
00048
00049
00050 if (vertex_curr->incoming_edges.size() > 1) {
00051 cout << "Error: has more than one parent" << endl;
00052 errors_present = true;
00053 }
00054
00055
00056 if (vertex_curr->incoming_edges.size() == 0) {
00057 num_root_vertices++;
00058 if (fabs (vertex_curr->data.total_cost) > 0.000001) {
00059 cout << "Error: Root vertex with non-zero cost" << endl;
00060 errors_present = true;
00061 }
00062 }
00063 else {
00064
00065 edge_t *edge_incoming = vertex_curr->incoming_edges.front();
00066
00067
00068 if (edge_incoming->vertex_dst != vertex_curr) {
00069 cout << "Error: Destination vertex does not make sense" << endl;
00070 errors_present = true;
00071 }
00072
00073
00074 if (edge_incoming->vertex_src == NULL) {
00075 cout << "Error: No destination vertex" << endl;
00076 errors_present = true;
00077 }
00078
00079
00080 vertex_t *vertex_src = edge_incoming->vertex_src;
00081 if (find (vertex_src->outgoing_edges.begin(), vertex_src->outgoing_edges.end(), edge_incoming)
00082 == vertex_src->outgoing_edges.end()){
00083 cout << "Error: Edge not found in the outgoing edges of the source vertex" << endl;
00084 errors_present = true;
00085 }
00086
00087
00088 if (vertex_src == vertex_curr) {
00089 cout << "Error: Vertex is its own parent" << endl;
00090 errors_present = true;
00091 }
00092
00093
00094 double cost_diff = vertex_curr->data.total_cost - (vertex_src->data.total_cost + edge_incoming->data.edge_cost);
00095 if (fabs(cost_diff) > 0.0001) {
00096 cout << "Cost diff : " << cost_diff
00097 << " :: Cost: parent + edge = curr : "
00098 << vertex_src->data.total_cost << " + "
00099 << edge_incoming->data.edge_cost << " = "
00100 << vertex_src->data.total_cost + edge_incoming->data.edge_cost << " : "
00101 << vertex_curr->data.total_cost << endl;
00102 errors_present = true;
00103 }
00104 }
00105
00106
00107 for (list<edge_t*>::iterator it_edge = vertex_curr->outgoing_edges.begin();
00108 it_edge != vertex_curr->outgoing_edges.end(); it_edge++) {
00109
00110 edge_t *edge_outgoing = *it_edge;
00111
00112
00113 if (edge_outgoing->vertex_src != vertex_curr) {
00114 cout << "Error: Outgoing edge has an incorrect label" << endl;
00115 errors_present = true;
00116 }
00117
00118
00119 vertex_t *vertex_dst = edge_outgoing->vertex_dst;
00120 if (vertex_dst == NULL) {
00121 cout << "Error: Destination vertex is NULL" << endl;
00122 errors_present = true;
00123 }
00124
00125
00126 if (vertex_dst == vertex_curr) {
00127 cout << "Error: Vertex is its own child" << endl;
00128 errors_present = true;
00129 }
00130
00131
00132 if (find (vertex_dst->incoming_edges.begin(), vertex_dst->incoming_edges.end(), edge_outgoing)
00133 == vertex_dst->incoming_edges.end()) {
00134 cout << "Error: Outgoing edge is not legitimate" << endl;
00135 errors_present = true;
00136 }
00137 }
00138 }
00139
00140
00141 if (num_root_vertices != 1) {
00142 cout << "Error: encountered " << num_root_vertices << " number of root vertices" << endl;
00143 errors_present = true;
00144 }
00145
00146
00147 if (errors_present)
00148 return 0;
00149 else
00150 return 1;
00151
00152 }
00153
00154
00170 template< class typeparams >
00171 int sanity_check_monotonicty (list<vertex_t*> &list_vertices_in) {
00172
00173 typedef vertex<typeparams> vertex_t;
00174 typedef edge<typeparams> edge_t;
00175
00176 bool errors_present = false;
00177
00178
00179
00180 return 1;
00181 }
00182
00183
00184
00200 template< class typeparams >
00201 int sanity_check_additivity (list<vertex_t*> &list_vertices_in) {
00202
00203 typedef vertex<typeparams> vertex_t;
00204 typedef edge<typeparams> edge_t;
00205
00206 bool errors_present = false;
00207
00208
00209
00210 return 1;
00211 }
00212
00213
00214 #endif