本文整理汇总了C++中Graph::FindEdge方法的典型用法代码示例。如果您正苦于以下问题:C++ Graph::FindEdge方法的具体用法?C++ Graph::FindEdge怎么用?C++ Graph::FindEdge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph::FindEdge方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
Map *ReduceMap(Map *inputMap)
{
Graph *g = GraphSearchConstants::GetGraph(inputMap);
int biggest = LabelConnectedComponents(g);
Map *m = new Map(inputMap->GetMapWidth(), inputMap->GetMapHeight());
for (int x = 0; x < inputMap->GetMapWidth(); x++)
{
for (int y = 0; y < inputMap->GetMapHeight(); y++)
{
if (inputMap->GetTerrainType(x, y) == kTrees)
m->SetTerrainType(x, y, kTrees);
else if (inputMap->GetTerrainType(x, y) == kWater)
m->SetTerrainType(x, y, kWater);
else m->SetTerrainType(x, y, kOutOfBounds);
}
}
for (int x = 0; x < g->GetNumNodes(); x++)
{
if (g->GetNode(x)->GetLabelL(GraphSearchConstants::kTemporaryLabel) == biggest)
{
int theX, theY;
theX = g->GetNode(x)->GetLabelL(GraphSearchConstants::kMapX);
theY = g->GetNode(x)->GetLabelL(GraphSearchConstants::kMapY);
if (g->GetNode(inputMap->GetNodeNum(theX+1, theY)) &&
(g->GetNode(inputMap->GetNodeNum(theX+1, theY))->GetLabelL(GraphSearchConstants::kTemporaryLabel) == biggest) &&
(!g->FindEdge(x, inputMap->GetNodeNum(theX+1, theY))))
{
m->SetTerrainType(theX, theY, kOutOfBounds);
}
else if (g->GetNode(inputMap->GetNodeNum(theX, theY+1)) &&
(g->GetNode(inputMap->GetNodeNum(theX, theY+1))->GetLabelL(GraphSearchConstants::kTemporaryLabel) == biggest) &&
(!g->FindEdge(x, inputMap->GetNodeNum(theX, theY+1))))
{
m->SetTerrainType(theX, theY, kOutOfBounds);
}
// else if (g->GetNode(inputMap->GetNodeNum(theX+1, theY+1)) &&
// (g->GetNode(inputMap->GetNodeNum(theX+1, theY+1))->GetLabelL(GraphSearchConstants::kTemporaryLabel) == biggest) &&
// (!g->FindEdge(x, inputMap->GetNodeNum(theX+1, theY+1))))
// {
// m->SetTerrainType(theX, theY, kOutOfBounds);
// }
else {
if (inputMap->GetTerrainType(theX, theY) == kSwamp)
m->SetTerrainType(theX, theY, kSwamp);
else
m->SetTerrainType(theX, theY, kGround);
}
}
else if (inputMap->GetTerrainType(g->GetNode(x)->GetLabelL(GraphSearchConstants::kMapX),
g->GetNode(x)->GetLabelL(GraphSearchConstants::kMapY)) == kGround)
m->SetTerrainType(g->GetNode(x)->GetLabelL(GraphSearchConstants::kMapX),
g->GetNode(x)->GetLabelL(GraphSearchConstants::kMapY), kTrees);
}
return m;
}
示例2: addNodes
void MapLineAbstraction::addNodes(Graph *g)
{
int count = abstractions.back()->GetNumNodes();
//printf("Initial count: %d\n", count);
int xstep = pow(lineDistance,((abstractions.size()+1)/2));
int ystep = pow(lineDistance,((abstractions.size())/2));
int zstep = pow(lineDistance,((abstractions.size()-1)/2));
Graph *toAbstract = abstractions.back();
//printf("Size: %d.[%d] XStep: %d, YStep: %d, ZStep %d\n", abstractions.size(), lineDistance, xstep, ystep, zstep);
if (abstractUniformly)
{
for (int x = 0; x < GetMap()->GetMapWidth(); x += xstep)
{
for (int y = 0; y < GetMap()->GetMapHeight(); y+= ystep)
{
//printf("Next check starts from (%d, %d)\n", x, y);
std::vector<node *> nodes;
std::vector<node *> parents;
for (int z = 0; z < lineDistance; z++)
{
if ((abstractions.size()%2) != 0) // vertical abstraction
{
//printf("->(%d, %d)\n", x+z*zstep, y);
nodes.push_back(GetNodeFromMap(x+z*zstep, y));
}
else {
//printf("->(%d, %d)\n", x, y+z*zstep);
nodes.push_back(GetNodeFromMap(x, y+z*zstep));
}
if (nodes.back() == 0)
{
//printf("(null)\n");
nodes.resize(0);
break;
}
parents.push_back(GetNthParent(nodes.back(), abstractions.size()-1));
if ((parents.back() == 0) ||
(parents.back()->GetLabelL(kParent) != -1) ||
((z > 0) && (!toAbstract->FindEdge(parents[z]->GetNum(), parents[z-1]->GetNum()))))
{
//if (parents.back() == 0) printf("(null)\n");
//else if (parents.back()->GetLabelL(kParent) != -1) printf("(parent)\n");
//else printf("(disconnected)\n");
parents.resize(0);
break;
}
}
if ((nodes.size() == 0) || (parents.size() == 0))
continue;
//printf("Match!\n");
node *parent = createParent(g, parents[0]);
//printf("-->Creating parent (%d)\n", parent->GetNum());
for (unsigned int z = 0; z < parents.size(); z++)
{
if (parents[z]->GetLabelL(kParent) != -1)
break;
buildNodeIntoParent(parents[z], parent);
count--;
//printf("Abstracting %d, count now %d\n", parents[z]->GetNum(), count);
}
}
}
}
// node_iterator ni = toAbstract->getNodeIter();
// for (node *n = toAbstract->nodeIterNext(ni); n; n = toAbstract->nodeIterNext(ni))
std::vector<node *> stopList; // nodes with no parents aren't abstracted
while (count > 0)
{
// select a random node
node *n = abstractions.back()->GetRandomNode();
assert(n!=NULL);
if ((n->GetLabelL(kParent) == -1) && (n->GetNumEdges() != 0))
{
node *parent = createParent(g, n);
//printf("==>Creating parent (%d)\n", parent->GetNum());
buildNodeIntoParent(n, parent);
count -= 1;
//printf("Abstracting %d, count now %d\n", n->GetNum(), count);
for (int x = 0; x < lineDistance - 1; x++)
{
node *choice = 0;
double prob = 0;
neighbor_iterator nbi = n->getNeighborIter();
for (long tmp = n->nodeNeighborNext(nbi); tmp != -1; tmp = n->nodeNeighborNext(nbi))
{
node *neighbor = toAbstract->GetNode(tmp);
if (neighbor->GetLabelL(kParent) == -1)
{
prob++;
if ((random()%100) < 100.0/prob)
{
choice = neighbor;
}
}
}
if (choice)
//.........这里部分代码省略.........
示例3: Graph
Graph *BuildInconsistentGraph(int d, int w, int h, int c1, int c2)
{
//int d = 2;
gFrom = d*w*h-1;
gTo = 0;
Graph *g = new Graph();
int cost[d][w][h];
int index[d][w][h];
for (int z = 0; z < d; z++)
{
for (int x = 0; x < w; x++)
{
for (int y = 0; y < h; y++)
{
node *n;
cost[z][x][y] = MAXINT;
index[z][x][y] = g->AddNode(n = new node(""));
n->SetLabelF(GraphSearchConstants::kXCoordinate, -1.0+2.0*(double)x/(double)(w-1.0));
n->SetLabelF(GraphSearchConstants::kYCoordinate, -1.0+2.0*(double)y/(double)(h-1.0));
if (d > 1)
n->SetLabelF(GraphSearchConstants::kZCoordinate, -1.0+2.0*(double)z/(double)(d-1.0));
else
n->SetLabelF(GraphSearchConstants::kZCoordinate, 0);
}
}
}
for (int z = 0; z < d; z++)
{
for (int x = 0; x < w; x++)
{
for (int y = 0; y < h; y++)
{
if ((x == 0) && (y == 0) && (z == 0))
{
if (d > 1)
g->AddEdge(new edge(index[z+1][x][y], index[z][x][y], c2));
if (w > 1)
g->AddEdge(new edge(index[z][x+1][y], index[z][x][y], c2));
g->AddEdge(new edge(index[z][x][y+1], index[z][x][y], c2));
continue;
}
if (z+1 <d)
g->AddEdge(new edge(index[z+1][x][y], index[z][x][y], 1+random()%c1));
if (x+1 <w)
g->AddEdge(new edge(index[z][x+1][y], index[z][x][y], 1+random()%c1));
if (y+1 < h)
g->AddEdge(new edge(index[z][x][y+1], index[z][x][y], 1+random()%c1));
}
}
}
cost[0][0][0] = 0;
while (1)
{
int changes = 0;
for (int z = 0; z < d; z++)
{
for (int x = 0; x < w; x++)
{
for (int y = 0; y < h; y++)
{
if (z+1 <d)
{
int from1 = index[z][x][y];
int to1 = index[z+1][x][y];
edge *e = g->FindEdge(from1, to1);
if (cost[z+1][x][y] > cost[z][x][y] + e->GetWeight())
{
cost[z+1][x][y] = cost[z][x][y] + g->FindEdge(index[z][x][y], index[z+1][x][y])->GetWeight();
changes++;
}
}
if (x+1 <w)
{
if (cost[z][x+1][y] > cost[z][x][y] + g->FindEdge(index[z][x][y], index[z][x+1][y])->GetWeight())
{
cost[z][x+1][y] = cost[z][x][y] + g->FindEdge(index[z][x][y], index[z][x+1][y])->GetWeight();
changes++;
}
}
if (y+1 < h)
{
if (cost[z][x][y+1] > cost[z][x][y] + g->FindEdge(index[z][x][y], index[z][x][y+1])->GetWeight())
{
cost[z][x][y+1] = cost[z][x][y] + g->FindEdge(index[z][x][y], index[z][x][y+1])->GetWeight();
changes++;
}
}
}
}
}
if (changes == 0)
break;
}
for (int z = 0; z < d; z++)
{
for (int x = 0; x < w; x++)
//.........这里部分代码省略.........