本文整理汇总了C++中Graph::GetNumNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ Graph::GetNumNodes方法的具体用法?C++ Graph::GetNumNodes怎么用?C++ Graph::GetNumNodes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph::GetNumNodes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: buildConnectivityGroups
void MapFlatAbstraction::buildConnectivityGroups()
{
int nextNum = 0;
Graph *g = abstractions[0];
groups.resize(g->GetNumNodes());
for (unsigned int x = 0; x < groups.size(); x++)
groups[x] = -1;
node_iterator ni = g->getNodeIter();
for (node *iter = g->nodeIterNext(ni); iter; iter = g->nodeIterNext(ni))
{
std::vector<unsigned int> stack;
if (groups[iter->GetNum()] == -1)
{
stack.push_back(iter->GetNum());
while (stack.size() > 0)
{
unsigned int next = stack.back();
stack.pop_back();
if (groups[next] == -1)
{
groups[next] = nextNum;
}
neighbor_iterator n = g->GetNode(next)->getNeighborIter();
for (int val = g->GetNode(next)->nodeNeighborNext(n); val != -1; val = g->GetNode(next)->nodeNeighborNext(n))
if (groups[val] == -1)
stack.push_back(val);
}
nextNum++;
}
}
groupsValid = true;
}
示例2: DrawGraphEdges
void DrawGraphEdges(const Graph& g)
{
int num = g.GetNumNodes();
for (int i = 0; i < num; i++)
{
const EdgeList& e = g.GetEdgeList(i);
DrawEdgeList(e, g);
}
}
示例3: 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;
}
示例4: doExport
void doExport()
{
Map *map = new Map(gDefaultMap);
map->Scale(512, 512);
msa = new MapSectorAbstraction(map, 8);
msa->ToggleDrawAbstraction(1);
Graph *g = msa->GetAbstractGraph(1);
printf("g\n%d %d\n", g->GetNumNodes(), g->GetNumEdges());
for (int x = 0; x < g->GetNumNodes(); x++)
{
node *n = g->GetNode(x);
int x1, y1;
msa->GetTileFromNode(n, x1, y1);
printf("%d %d %d\n", x, x1, y1);
}
for (int x = 0; x < g->GetNumEdges(); x++)
{
edge *e = g->GetEdge(x);
printf("%d %d\n", e->getFrom(), e->getTo());//, (int)(100.0*e->GetWeight())); // %d 0
}
exit(0);
}
示例5: DrawGraphNodes
void DrawGraphNodes(const Graph& g)
{
int num = g.GetNumNodes();
for (int i = 0; i < num; i++)
{
const GraphNode& node = g.GetNode(i);
const Vec2f& v = node.GetPos();
glPushMatrix();
glTranslatef(v.x, 0, v.y);
//glutSolidCube(NODE_SIZE);
glutSolidSphere(NODE_SIZE, 8, 8);
glPopMatrix();
}
}
示例6: EstimateLongPath
void EstimateLongPath(Map *m)
{
Graph *g = GraphSearchConstants::GetGraph(m);
GraphMapHeuristic gh(m, g);
double heur = 0;
double dist = 0;
graphState from, to;
for (int x = 0; x < 20; x++)
{
node *n = g->GetRandomNode();
double newDist = FindFarDist(g, n, from, to);
if (newDist > dist)
{
dist = newDist;
heur = gh.HCost(from, to);
}
printf("%f\t%f\t%f\t%f\n", dist, dist/g->GetNumNodes(), heur, dist/heur);
}
}
示例7: MeasureHighwayDimension
void MeasureHighwayDimension(Map *m, int depth)
{
srandom(10);
Graph *g = GraphSearchConstants::GetGraph(m);
GraphEnvironment ge(g);
ge.SetDirected(true);
std::vector<graphState> endPath;
for (int x = 0; x < g->GetNumNodes(); x++)
g->GetNode(x)->SetLabelL(GraphSearchConstants::kTemporaryLabel, 0);
// 1. choose a random point
node *n = g->GetRandomNode();
// 2. search to depth d (all g-costs >= d)
TemplateAStar<graphState, graphMove, GraphEnvironment> theSearch;
theSearch.SetStopAfterGoal(false);
theSearch.InitializeSearch(&ge, n->GetNum(), n->GetNum(), endPath);
while (1)
{
double gCost;
graphState s = theSearch.CheckNextNode();
if (theSearch.DoSingleSearchStep(endPath))
break;
assert(theSearch.GetClosedListGCost(s, gCost));
if (gCost > depth)
break;
}
// 3. mark all nodes on OPEN
unsigned int radiusCount = theSearch.GetNumOpenItems();
for (unsigned int x = 0; x < radiusCount; x++)
{
g->GetNode(theSearch.GetOpenItem(x).data)->SetLabelL(GraphSearchConstants::kTemporaryLabel, 1);
}
// 4. continue search to depth 4d (all g-costs >= 4d)
while (1)
{
double gCost;
graphState s = theSearch.CheckNextNode();
if (theSearch.DoSingleSearchStep(endPath))
break;
assert(theSearch.GetClosedListGCost(s, gCost));
if (gCost > 4*depth)
break;
}
// 5. for every state on open, trace back to marked node
// (marking?)
radiusCount = theSearch.GetNumOpenItems();
for (unsigned int x = 0; x < radiusCount; x++)
{
graphState theNode = theSearch.GetOpenItem(x).data;
theSearch.ExtractPathToStart(theNode, endPath);
for (unsigned int y = 0; y < endPath.size(); y++)
{
if (g->GetNode(endPath[y])->GetLabelL(GraphSearchConstants::kTemporaryLabel) == 1)
g->GetNode(endPath[y])->SetLabelL(GraphSearchConstants::kTemporaryLabel, 2);
}
}
int dimension = 0;
// 6. count marked nodes to see how many were found
for (int x = 0; x < g->GetNumNodes(); x++)
if (g->GetNode(x)->GetLabelL(GraphSearchConstants::kTemporaryLabel) == 2)
dimension++;
printf("%d states at radius %d; %d states [highway dimension] at radius %d\n", radiusCount, depth, dimension, 4*depth);
}