int main(void) { #define N_NODES 6 node_t *nodes = (node_t*)calloc(sizeof(node_t), N_NODES); for (int i = 0; i < N_NODES; i++) sprintf(nodes[i].name, "%c", 'a' + i); add_edge(nodes, nodes+1, 7); //a-b add_edge(nodes, nodes+2, 9); //a-c add_edge(nodes, nodes+5, 14); //a-f add_edge(nodes+1, nodes+2, 10); //b-c add_edge(nodes+1, nodes+3, 15); //b-d add_edge(nodes+2, nodes+3, 11); //c-d add_edge(nodes+2, nodes+5, 2); //c-f add_edge(nodes+3, nodes+4, 6); //d-e add_edge(nodes+4, nodes+5, 9); //e-f heap = (node_t**)calloc(sizeof(node_t), N_NODES + 1); heap_len = 0; calc_all(nodes); for (int i = 0; i < N_NODES; i++) { show_path(nodes + i); putchar('\n'); } //free memories free_edges(); free(heap); free(nodes); return 0; }
void calc_error(double *input_data, double *output_data){ int i; for( i = 0; i < UNIT_SIZE; i++){ unit[0][i].value = input_data[i]; } calc_all(); for(i = 0; i < UNIT_SIZE; i++){ unit[LAYER_SIZE - 1][i].sigma = unit[LAYER_SIZE - 1][i].value - output_data[i]; } }
int dijkstra(const int num_nodes, int ** nodes_cost, int ** routing_table) { int i; # define N_NODES num_nodes // For each node for (int start = 0; start < N_NODES; start++) { // create the nodes node_t *nodes = calloc(sizeof(node_t), N_NODES); // give the node name (ID) for (i = 0; i < N_NODES; i++) { nodes[i].name = i; } # define E(a, b, c) add_edge(nodes + a, nodes + b, c) // load the data from the cost table to the memory for (int i = 0; i < N_NODES; i++) { for (int j = 0; j < N_NODES; j++) { if (nodes_cost[i][j] != 0) { E(i, j, nodes_cost[i][j]); } } } # undef E // Create HEAP heap = calloc(sizeof(heap_t), N_NODES + 1); heap_len = 0; // Calculate all path fro current node to al other nodes calc_all(nodes + start); for (i = 0; i < N_NODES; i++) { routing_table[(nodes + start)->name][(nodes + i)->name] = show_path(nodes + start, nodes + i); } // Free memory free_edges(); free(heap); free(nodes); } return 0; }
int main(int argc, char *argv[]) { unsigned int T, N, t, a, b, l; scanf("%u%u", &T, &N); node_t *nodes = calloc(sizeof(node_t), N); for (t = 0; t < T; ++t) { scanf("%u%u%u", &a, &b, &l); --a; --b; add_edge(nodes + a, nodes + b, l); add_edge(nodes + b, nodes + a, l); } heap = calloc(sizeof(heap_t), N); heap_len = 0; calc_all(nodes); for (i = 0; i < N; i++) { show_path(nodes + i); putchar('\n'); } free_edges(); free(heap); free(nodes); return 0; }