⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rtoracle.cc

📁 模拟器提供了一个简单易用的平台
💻 CC
字号:
static char rcsid [] = "$Id: rtoracle.cc,v 1.1 2001/08/07 22:10:26 suman Exp suman $";/* * $Log: rtoracle.cc,v $ * Revision 1.1  2001/08/07 22:10:26  suman * Initial revision * */#include <assert.h>#include "graph-alg.h"#include <node.h>#include <rtoracle.h>#undef LOG_RTextern Node ** ptr_global_node_array;void RoutingTableOracle::InitNodeRT (int num_nodes) {  num_nodes = num_nodes;  valid = new bool [num_nodes];  next_hop_id = new int [num_nodes];  cost = new double [num_nodes];  for (int i = 0; i < num_nodes; i++)    valid[i] = false;  return;}int RoutingTableOracle::get_next_hop_id (int dst) {  if (valid[dst] == true) { /* has a next hop path */    return next_hop_id[dst];  }  else    return -1;}double RoutingTableOracle::get_path_cost (int dst) {  return cost[dst];}/* Creates the routing table for all nodes *//* Calls the Floyd-Warshall Algo */void createOracleRT (int num_nodes) {  double *W = new double [num_nodes * num_nodes];  double *D = new double [num_nodes * num_nodes];  int *NH = new int [num_nodes * num_nodes];  for (int j = 0; j < num_nodes * num_nodes; j++) {    if (( j % num_nodes) == (j / num_nodes))      W[j] = 0.0;    else      W[j] = LARGE_DOUBLE;  }  for (int i = 0; i < num_nodes; i++) {    assert (ptr_global_node_array[i]->id == i);    ptr_global_node_array[i]->rt = new RoutingTableOracle(ptr_global_node_array[i]);    RoutingTableOracle * this_rt = (RoutingTableOracle*)(ptr_global_node_array[i]->rt);    this_rt->InitNodeRT(num_nodes);    for (void *pos = ptr_global_node_array[i]->neighbor_list.GetHeadPosition();         pos != NULL;         ptr_global_node_array[i]->neighbor_list.GetNext(pos) ) {       NeighborInfo *nbr = ptr_global_node_array[i]->neighbor_list.GetAt(pos);       int n_id = nbr->n->id;       assert (n_id < num_nodes);       W[i*num_nodes + n_id] = nbr->cost;    }  }  floyd_warshall_all_pair(num_nodes,W,D,NH);#ifdef LOG_RT  display_all_pair_paths(num_nodes,D,NH);#endif // LOG_RT  for (int i = 0; i < num_nodes; i++) {    RoutingTableOracle * this_rt = (RoutingTableOracle *)(ptr_global_node_array[i]->rt);    for (int j = 0; j < num_nodes; j++) {      this_rt->valid[j] = true;      this_rt->next_hop_id[j] = NH[i*num_nodes+j];      this_rt->cost[j] = D[i*num_nodes+j];    }  }  delete [] W;  delete [] D;  delete [] NH;  return;}     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -