本文整理汇总了C++中Flow::getTopology方法的典型用法代码示例。如果您正苦于以下问题:C++ Flow::getTopology方法的具体用法?C++ Flow::getTopology怎么用?C++ Flow::getTopology使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Flow
的用法示例。
在下文中一共展示了Flow::getTopology方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute
//------------------------------------------------------------------------------
// Path SamcraBeforeAlgorithm::compute(const Flow &flow)
//------------------------------------------------------------------------------
Path SamcraBeforeAlgorithm::compute(const Flow &flow)
{
TRACE("SamcraBeforeAlgorithm::compute -->");
Path result;
Topology *topology = flow.getTopology();
int number_of_nodes = topology->getNumNodes();
int number_of_qos = topology->getNumQos();
int min_k = 0; int k_used = 0; // used by samcra
int* max = (int*) calloc(number_of_nodes + 1, sizeof(int));
int** adj = (int**) allocMatrix(number_of_nodes + 1,
number_of_nodes + 1, sizeof(int));
double* flow_qos = (double*) calloc(number_of_qos + 1, sizeof(double));
double*** datadj = (double***) calloc(number_of_qos + 1, sizeof(double**));
for (int counter=1; counter <= number_of_qos; ++counter)
{
datadj[counter] = (double**) allocMatrix(number_of_nodes + 1,
number_of_nodes + 1, sizeof(double));
flow_qos[counter] = flow.getQosCons()[counter-1];
}
// filling adj and datadj, while pruning links with insuf. available cap.
for (LinkListIterator iter = topology->getLinkIterator(); iter(); ++iter)
{
Link* link = *iter;
if (link->getReservableCapacity() >= flow.getRequestedCapacity())
{
int source = link->getSource();
int destination = link->getDestination();
adj[source + 1][++max[source + 1]] = destination + 1;
for (int qos=1; qos <= number_of_qos; ++qos)
{
datadj[qos][source+1][max[source+1]] = link->getQoS(qos-1);
} // end: for (qos
} // end: if (link
} // end: for (LinkListIterator
// allocating memory for the path
int path_length = 0;
int* path = (int*) calloc(number_of_nodes + 1, sizeof(int));
// invoking SAMCRA
TRACE("SamcraBeforeAlgorithm::compute: Invoking SAMCRA");
#ifndef NO_TIMER
Timer timer;
timer.start();
#endif // NO_TIMER
samcrapath( flow.getSource()+1, flow.getDestination()+1,
adj, max, datadj, number_of_qos, flow_qos,
number_of_nodes, path, &path_length, &min_k, &k_used);
TRACE("SamcraBeforeAlgorithm::compute: End SAMCRA");
// because function returns the path vector from the destination "d" to the
// source "s" it is necessary to invert the array
for (int counter=1; counter <= path_length; ++counter)
{
result.push_front(path[counter]-1);
}
#ifndef NO_TIMER
const_cast<Flow&>(flow).setTime(timer.read());
#endif // NO_TIMER
// freeing memory
free(path);
for (int counter = 1; counter <= number_of_qos; ++counter)
{
freeMatrix((void**) datadj[counter], number_of_nodes + 1);
}
free(datadj);
free(flow_qos);
freeMatrix((void**) adj, number_of_nodes + 1);
free(max);
TRACE("SamcraBeforeAlgorithm::compute <--");
return result;
}
示例2: compute
Path NewMIRAAlgorithm::compute(const Flow &flow)
{
TRACE("NewMIRAAlgorithm::compute -->");
Topology *topology = flow.getTopology();
const int f_src = flow.getSource();
const int f_dst = flow.getDestination();
// if link (i,j) exists, its metric is initialized with 0 (it increases each
// time a maxflow computation is performed) and it is added to the list that
// feeds the maxflow function
int numarcs = 0;
int number_of_nodes = topology->getNumNodes();
// data structure passed to maxflow function
char** network = (char**) calloc(4, sizeof(char*));
for (LinkListIterator iter = topology->getLinkIterator(); iter(); ++iter)
{
Link* link = *iter;
if (link->getCapacity() > 0.0)
{
link->metric = 0.0;
++numarcs;
network = (char**) realloc(network, (numarcs+4)*sizeof(char*));
network[numarcs+2] = (char*) calloc(20, sizeof(char));
sprintf(network[numarcs+2],"a %d %d %d",
link->getSource(), link->getDestination(),
(int) floor(link->getReservableCapacity()));
} // end: if (link->
} // end: for (LinkListIterator iter
network[0] = (char*) calloc(20, sizeof(char)); // problem description
network[1] = (char*) calloc(20, sizeof(char)); // source node
network[2] = (char*) calloc(20, sizeof(char)); // destination node
network[numarcs+3] = (char*) 0; // NULL terminated array
sprintf(network[0],"p max %d %d", number_of_nodes, numarcs);
#ifndef NO_TIMER
Timer timer;
timer.start();
#endif // NO_TIMER
// Compute maxflow for each ingress-egress pair except (source,dest).
// Each computation updates link weights
//Timer timemaxflow;
//timemaxflow.start();
//int n = 0;
const IntVector edge_nodes = topology->getEdgeNodes();
for (IntVector::const_iterator s_iter = edge_nodes.begin();
s_iter != edge_nodes.end(); ++s_iter)
{
for (IntVector::const_iterator d_iter = edge_nodes.begin();
d_iter != edge_nodes.end(); ++d_iter)
{
if (*s_iter != *d_iter && !(f_src == *s_iter && f_dst == *d_iter))
{
//PRINTLN("s: " << *s_iter << "\td: " << *d_iter << "\tn: " << n);
//n++;
// complete network with current ingress-egress pair
sprintf(network[1],"n %d s", *s_iter);
sprintf(network[2],"n %d t", *d_iter);
// needed by maxflow function
node *ndp;
arc *arp;
long *cap;
double mflow;
long nmin;
//compute maxflow
//Timer t;
//t.start();
maxflow(network,&ndp,&arp,&cap,&mflow,&nmin);
//PRINTLN("\tTimer: " << t.read());
// update link weights
for (node* in = ndp; in < (ndp + number_of_nodes); ++in)
{
for (arc* a = in->first; a != 0; a = a->next)
{
long ni = N_NODE(in);
long na = N_ARC(a);
if ( cap[na] > 0 )
{
Link* link = topology->link(ni, N_NODE(a->head));
link->metric +=(cap[na] - a->r_cap) /
(mflow*link->getReservableCapacity());
} // end: if ( cap[na] > 0 )
} // end: for ( arc*
} // end: for (node*
// free memory
free(ndp);
free(arp);
free(cap);
//.........这里部分代码省略.........