在delop.cpp中
struct Init Var; void deploy_server(char * topo[MAX_EDGE_NUM], int line_num,char * filename) { initial(topo,line_num); char *topo_file=new char[60000]; char *str=new char[20]; sprintf(str,"%d\n\n",Var.connode_num); strncat(topo_file,str,4); for(int i = 0;i < Var.connode_num;i++) { sprintf(str,"%d %d %d\n",Var.con_linkID[i],i,Var.con_needband[i]); strncat(topo_file,str,10); } printf("\n\n %s", topo_file); write_result(topo_file, filename); }
/*******************Graph初始化输入得到数据************************/ #define MAXnetNote 1000 //网络节点数量上限 #define MAXconNote 500 //消费节点数量上限 #define MAXnoteLink 20 //每个节点的最多链路数量 #define MAXserverPrice 5000 //每个服务器的最大价格 extern void initial(char *topo[MAX_EDGE_NUM], int line_num); struct Supply { int band; int band_price; }; struct Init { int netnode_num,netlink_num,connode_num,server_price;//网络节点数量,网络链路数量,消费节点数量,服务器单价 struct Supply Link_supply[MAXnetNote][MAXnetNote];//每个链路总带宽大小,单位网络租用费 int con_linkID[MAXconNote],con_needband[MAXconNote];//消费节点相连的网络节点,消费节点需要的带宽 }; extern struct Init Var;在Graph.cpp中
void initial(char *topo[MAX_EDGE_NUM], int line_num) { char *line; int ch,s,t,b,c,len,conID,l,n;//char,srcID,detID,bandwidth,cost,length,consumptionID,linkID,consumption_need_band for(int i = 0,j;i < line_num;i++) { line = topo[i]; len = strlen(line); j = s = t = b = c = conID = l = n = 0; if(i == 0)//第一行为网络节点数量netnode_num,网络链路数量netlink_num,消费节点数量connode_num { while(!isdigit(ch = line[j++]) && j<len); if(isdigit(ch)) Var.netnode_num = ch - '0'; else continue; while(isdigit(ch = line[j++])) Var.netnode_num = 10 * Var.netnode_num + (ch - '0'); while(!isdigit(ch = line[j++])); Var.netlink_num = ch - '0'; while(isdigit(ch = line[j++])) Var.netlink_num = 10 * Var.netlink_num + (ch - '0'); while(!isdigit(ch = line[j++])); Var.connode_num = ch - '0'; while(isdigit(ch = line[j++])) Var.connode_num = 10 * Var.connode_num + (ch - '0'); printf("%d %d %d \n\n", Var.netnode_num,Var.netlink_num,Var.connode_num); } if(i == 2)//第二行为服务器部署成本 { while(!isdigit(ch = line[j++]) && j<len); if(isdigit(ch)) Var.server_price = ch - '0'; else continue; while(isdigit(ch = line[j++])) Var.server_price = 10 * Var.server_price + (ch - '0'); printf("%d \n\n", Var.server_price); } if((i > 2)&&(i <= Var.netlink_num + 3))//总有链路数量行,分别为链路起始点ID s,终止点ID t,链路总带宽 b,单位网络租用费c { while(!isdigit(ch = line[j++]) && j<len); if(isdigit(ch)) s = ch - '0'; else continue; while(isdigit(ch = line[j++])) s = 10 * s + (ch - '0'); while(!isdigit(ch = line[j++])); t = ch - '0'; while(isdigit(ch = line[j++])) t = 10 * t + (ch - '0'); while(!isdigit(ch = line[j++])); b = ch - '0'; while(isdigit(ch = line[j++])) b = 10 * b + (ch - '0'); while(!isdigit(ch = line[j++])); c = ch - '0'; while(isdigit(ch = line[j++])) c = 10 * c + (ch - '0'); Var.Link_supply[s][t].band = b; Var.Link_supply[s][t].band_price = c; printf("%d %d %d %d\n", s,t,b,c); } if(i > Var.netlink_num + 3)//总有消费节点数量行,分别为消费节点ID conID,相连网络节点ID l,视频带宽消耗需求 n { while(!isdigit(ch = line[j++]) && j<len); if(isdigit(ch)) conID = ch - '0'; else continue; while(isdigit(ch = line[j++])) conID = 10 * conID + (ch - '0'); while(!isdigit(ch = line[j++])); l = ch - '0'; while(isdigit(ch = line[j++])) l = 10 * l + (ch - '0'); while(!isdigit(ch = line[j++])); n = ch - '0'; while(isdigit(ch = line[j++])) n = 10 * n + (ch - '0'); Var.con_linkID[conID] = l; Var.con_needband[conID] = n; printf("%d %d %d \n", conID,l,n); } } }