/** * Prints the graph by printing Node informations and Edge informations while iterating it * Testcase:Node:%d,%d\n with the linkaddr.u8[0] and the depth * Testcase:Edge:%d,%d\n with the linkaddr.u8[0] of the source and the linkaddr.u8[0] of the drain */ static void debug_k_hop_timer_event(void *ptr) { printf("Print Graph for Node %d\n", linkaddr_node_addr.u8[0]); uint8_t count = 0; uint8_t i = 0; printf("Saved Nodes:%d\n", get_node_count()); printf("Saved Edges:%d\n", get_edge_count()); //print nodes p_hop_t *hops = get_hop_counts(&count); printf("Count Node hops:%d\n", count); //also print root printf("Testcase:Node:%d,%d\n", linkaddr_node_addr.u8[0], 0); for (i = 0; i < count; i++) { printf("Testcase:Node:%d,%d\n", hops[i].addr.u8[0], hops[i].hop_count); } free(hops); //print edges p_edge_t **edge_array = get_all_edges(&count); printf("Count Edge:%d\n", count); for (i = 0; i < count; i++) { printf("Testcase:Edge:%d,%d\n", edge_array[i]->src.u8[0], edge_array[i]->dst.u8[0]); } }
void get_edge(int i, int j, int k, int vi[2]) { if (0 <= k && k < get_edge_count(i, j)) { struct object_edge *e = get_object_edge(i, j, k); vi[0] = e->vi[0]; vi[1] = e->vi[1]; } }
static void delete_vert(int i, int j) { struct object *o = get_object(i); int k; int l; /* Remove this vertex from the vertex vector. */ memmove(vecget(o->vv, j), vecget(o->vv, j + 1), vecsiz(o->vv) * (vecnum(o->vv) - j - 1)); vecpop(o->vv); /* Remove all references to this vertex from all meshes. */ for (k = 0; k < get_mesh_count(i); ++k) { /* Delete all referencing faces. Move later references down. */ for (l = 0; l < get_face_count(i, k); ++l) { struct object_face *f = get_object_face(i, k, l); if (f->vi[0] == j || f->vi[1] == j || f->vi[2] == j) delete_face(i, k, l--); else { if (f->vi[0] > j) f->vi[0]--; if (f->vi[1] > j) f->vi[1]--; if (f->vi[2] > j) f->vi[2]--; } } /* Delete all referencing edges. Move later references down. */ for (l = 0; l < get_edge_count(i, k); ++l) { struct object_edge *e = get_object_edge(i, k, l); if (e->vi[0] == j || e->vi[1] == j) delete_edge(i, k, l--); else { if (e->vi[0] > j) e->vi[0]--; if (e->vi[1] > j) e->vi[1]--; } } } /* Invalidate the object's vertex buffer and bounding volume. */ fini_object(i); }
int is_connected(vertex *root) { // First check if all vertices can be visited doing a DFS or A BFS // Since BFS was already done along with DFS for checking edge, for practice sake lets do a DFS graph_dfs(root); // Now check if all vertices have been marked as visited, for those with an edgecount > 0 vertex *node = root; while (node != NULL) { if (!node->visited && get_edge_count(node)) return 0; node = node->nextvertex; } return 1; }
/* * A graph is euler if it is connected (that is every vertex with degree > 0 is connected) * AND if all vertices have an even degree. This is also called a euler circuit * A graph is semi euler or euler path/walk if it has all vertices with degree > 0 connected * AND if there are 2 vertices with an odd degree. * Note that if # of odd vertices are > 2 || === 1, then it is not euler * Assumption right is that the graph is undirected, that is in this case, there is a directed edge back from * the destination to the source for the sake of explaining. */ int is_graph_euler(vertex *root) { // Check if the graph is connected int connected = is_connected(root); if (!connected) return 0; // Now if we get here, it means the graph is connected, now we need to decide if // the graph has a euler circuit or a path, count the #vertices with odd degree int odd = 0; while (root != NULL) { int edgecount = get_edge_count(root); odd += edgecount % 2 == 0 ? 0 : 1; root = root->nextvertex; } if (odd > 2) return 0; return odd == 2 ? 1 : 2; }
void invocation(const ComType com, const uint8_t *data) { switch(((MessageHeader*)data)->fid) { case FID_SET_PORT: { set_port(com, (SetPort*)data); break; } case FID_GET_PORT: { get_port(com, (GetPort*)data); break; } case FID_SET_PORT_CONFIGURATION: { set_port_configuration(com, (SetPortConfiguration*)data); break; } case FID_GET_PORT_CONFIGURATION: { get_port_configuration(com, (GetPortConfiguration*)data); break; } case FID_SET_DEBOUNCE_PERIOD: { set_debounce_period(com, (SetDebouncePeriod*)data); break; } case FID_GET_DEBOUNCE_PERIOD: { get_debounce_period(com, (GetDebouncePeriod*)data); break; } case FID_SET_PORT_INTERRUPT: { set_port_interrupt(com, (SetPortInterrupt*)data); break; } case FID_GET_PORT_INTERRUPT: { get_port_interrupt(com, (GetPortInterrupt*)data); break; } case FID_SET_PORT_MONOFLOP: { set_port_monoflop(com, (SetPortMonoflop*)data); break; } case FID_GET_PORT_MONOFLOP: { get_port_monoflop(com, (GetPortMonoflop*)data); break; } case FID_SET_SELECTED_VALUES: { set_selected_values(com, (SetSelectedValues*)data); break; } case FID_GET_EDGE_COUNT: { get_edge_count(com, (GetEdgeCount*)data); break; } case FID_SET_EDGE_COUNT_CONFIG: { set_edge_count_config(com, (SetEdgeCountConfig*)data); break; } case FID_GET_EDGE_COUNT_CONFIG: { get_edge_count_config(com, (GetEdgeCountConfig*)data); break; } default: { BA->com_return_error(data, sizeof(MessageHeader), MESSAGE_ERROR_CODE_NOT_SUPPORTED, com); break; } } }