本文整理汇总了C++中Arc::GetRCost方法的典型用法代码示例。如果您正苦于以下问题:C++ Arc::GetRCost方法的具体用法?C++ Arc::GetRCost怎么用?C++ Arc::GetRCost使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Arc
的用法示例。
在下文中一共展示了Arc::GetRCost方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Augment
void MinCost<FlowType, CostType>::Dijkstra(Node* start)
{
assert(start->excess > 0);
Node* i;
Node* j;
Arc* a;
CostType d;
Node* permanentNodes;
int FLAG0 = ++ counter; // permanently labeled nodes
int FLAG1 = ++ counter; // temporarily labeled nodes
start->parent = NULL;
start->flag = FLAG1;
queue.Reset();
queue.Add(start, 0);
permanentNodes = NULL;
while ( (i=queue.RemoveMin(d)) )
{
if (i->excess < 0)
{
FlowType delta = Augment(start, i);
cost += delta*(d - i->pi + start->pi);
for (i=permanentNodes; i; i=i->next_permanent) i->pi += d;
break;
}
i->pi -= d;
i->flag = FLAG0;
i->next_permanent = permanentNodes;
permanentNodes = i;
for (a=i->firstNonsaturated; a; a=a->next)
{
j = a->head;
if (j->flag == FLAG0) continue;
d = a->GetRCost();
if (j->flag == FLAG1)
{
if (d >= queue.GetKey(j)) continue;
queue.DecreaseKey(j, d);
}
else
{
queue.Add(j, d);
j->flag = FLAG1;
}
j->parent = a;
}
}
}
示例2: assert
void MinCost<FlowType, CostType>::TestOptimality() {
Node* i;
Arc* a;
for (i = nodes; i < nodes + nodeNum; i++) {
if (i->excess != 0) {
assert(0);
}
for (a = i->firstSaturated; a; a = a->next) {
if (a->r_cap != 0) {
assert(0);
}
}
for (a = i->firstNonsaturated; a; a = a->next) {
CostType c = a->GetRCost();
if (a->r_cap <= 0 || a->GetRCost() < -1e-5) {
assert(0);
}
}
}
}
示例3: PushFlow
void MinCost<FlowType, CostType>::Init() {
Node* i;
Arc* a;
for (a = arcs; a < arcs + 2 * edgeNum; a++) {
if (a->r_cap > 0 && a->GetRCost() < 0)
PushFlow(a, a->r_cap);
}
Node** lastActivePtr = &firstActive;
for (i = nodes; i < nodes + nodeNum; i++) {
if (i->excess > 0) {
*lastActivePtr = i;
lastActivePtr = &i->next;
} else
i->next = NULL;
}
*lastActivePtr = &nodes[nodeNum];
}