/** * @brief reallocPackets * 重新分配数据包,根据各条链路 * @param {interge} sId * * @return {interge} */ int bulkAgent::reallocPackets(int sId) { slist<bulkPacket>* qsv = getStore(sId); if (qsv->empty()) { return 0; } double sum = qsv->size(); double allWeight = getAllWeight(); double singleWeight; int tag = OUT; slist<bulkLink*>::iterator iter; slist<bulkLink*>* pLink = _node.getOutputLink(); bulkBuffer* pBuf; int* bufSum; int count; //cout<<"sum:"<<sum<<endl; //cout<<"nodeId:"<<_node.getNodeId()<<endl; while (tag != DEFAULT) { for (iter = pLink->begin(); iter != pLink->end(); iter++) { if ((singleWeight = (*iter)->getWeight()) != 0) { count = 0; int index; double proportion = (1/singleWeight) / allWeight; double num = ROUND(sum * proportion); if (tag == OUT) { index = (*iter)->getTailId(); bufSum = &((*iter)->tailBufNum_[sId]); pBuf = &_sendbuf[index]; } else if (tag == IN) { index = (*iter)->getHeadId(); bufSum = &((*iter)->headBufNum_[sId]); pBuf = &_recvbuf[index]; } while (!qsv->empty() && count < num) { bulkPacket& packet = qsv->front(); pBuf->pushPacketsToBuf(sId, packet); qsv->pop_front(); count++; } //cout<<(*iter)->getGraphEdgeSource()<<"->"<<(*iter)->getGraphEdgeSink()<<" num:"<<count<<endl; *bufSum = count; } } pLink = _node.getInputLink(); tag++; } while (!qsv->empty()) { bulkPacket& packet = qsv->front(); pBuf->pushPacketsToBuf(sId, packet); qsv->pop_front(); count++; } *bufSum = count; qsv->~slist(); qsv = NULL; return (int)sum; }
int calRouteWeight() { int spw = NIL, i, source = NIL, dest = NIL; for (i = 0; i < 26; i++) { if (vertices[i] == NULL) { continue; } if (vertices[i]->degree % 2 != 0) { if (source == NIL) { source = i; } else { dest = i; } } } if (source == NIL) { /** * there is no odd degree vertex */ spw = getAllWeight(); } else { spw = getAllWeight() + getShortestPathWeight(source, dest); } return spw; }