本文整理汇总了C++中Graph::InsertEdge方法的典型用法代码示例。如果您正苦于以下问题:C++ Graph::InsertEdge方法的具体用法?C++ Graph::InsertEdge怎么用?C++ Graph::InsertEdge使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph
的用法示例。
在下文中一共展示了Graph::InsertEdge方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: determine_faces_from_edges
IndexArrayPtr PGL::determine_faces_from_edges(const Point2ArrayPtr& points, const std::vector<std::pair<uint32_t, uint32_t> >& edges)
{
typedef Wm5::PlanarGraph<Vector2> Graph;
Graph graph;
int i = 0;
for (Point2Array::const_iterator it = points->begin(); it != points->end(); ++it)
graph.InsertVertex(*it,i++);
for (std::vector<std::pair<uint32_t, uint32_t> >::const_iterator itedge = edges.begin(); itedge != edges.end(); ++itedge)
graph.InsertEdge(itedge->first,itedge->second);
std::vector<Graph::Primitive*> mPrimitives;
graph.ExtractPrimitives(mPrimitives);
IndexArrayPtr result(new IndexArray());
for (std::vector<Graph::Primitive*>::const_iterator itPrim = mPrimitives.begin(); itPrim != mPrimitives.end(); ++itPrim){
if ((*itPrim)->Type == Graph::PT_MINIMAL_CYCLE){
Index lresult;
for (std::vector<std::pair<Vector2,int> >::const_iterator itSequence = (*itPrim)->Sequence.begin(); itSequence != (*itPrim)->Sequence.end(); ++itSequence)
lresult.push_back(itSequence->second);
result->push_back(lresult);
}
}
return result;
}
示例2: main
int main()
{
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
Graph<string, string> g;
g.InsertVertex("Anchorage");
g.InsertVertex("Eagle River");
g.InsertVertex("Old Glenn - AK HWY 1 - AK HWY 3 JCT");
g.InsertVertex("Wasilla");
g.InsertVertex("Palmer");
g.InsertVertex("Talkeetna");
g.InsertVertex("Fairbanks");
g.InsertEdge("Anchorage", "Eagle River", "Old Glenn Hwy", 16);
g.InsertEdge("Eagle River", "Old Glenn - AK HWY 1 - AK HWY 3 JCT", "Old Glenn", 19);
g.InsertEdge("Old Glenn - AK HWY 1 - AK HWY 3 JCT", "Palmer", "HWY 1", 6);
g.InsertEdge("Old Glenn - AK HWY 1 - AK HWY 3 JCT", "Wasilla", "HWY 3", 8);
g.InsertEdge("Wasilla", "Talkeetna", "HWY 3", 70);
g.InsertEdge("Talkeetna", "Fairbanks", "HWY 3", 300);
/*try
{
g.InsertEdge("Anchorage", "Eagle River", "Old Glenn Hwy", 16);
}
catch (Exception e)
{
cout << e << endl;
}*/
/*Graph<string, string> copy(g);
Graph<string, string> equal;
equal = g;*/
cout << "Depth:" << endl;
g.DepthFirst(&Print);
cout << "\nBreadth:" << endl;
g.BreadthFirst(&Print);
g.DeleteVertex("Fairbanks");
try {
cout << "Invalid Delete" << endl;
g.DeleteVertex("Fairbanks");
}
catch (Exception e) {
cout << e << endl;
}
cout << "\nBreadth after Delete Vertex Fairbanks:" << endl;
g.BreadthFirst(&Print);
g.DeleteEdge("Old Glenn - AK HWY 1 - AK HWY 3 JCT", "Wasilla", "HWY 3", 8);
cout << "\nDepth after Delete Edge:" << endl;
g.DepthFirst(&Print);
return 0;
}
示例3: main
int main()
{
Graph head;
std::cout << &head << std::endl;
std::cout << head.InsertVertex('a')->GetName() << std::endl;
std::cout << head.InsertVertex('b')->GetName() << std::endl;
std::cout << head.InsertVertex('c')->GetName() << std::endl;
std::cout << head.InsertVertex('d')->GetName() << std::endl;
std::cout << head.GetFirstVertex()->GetName() << std::endl;
std::cout << head.InsertEdge('a', 'b')->GetName() << std::endl;
std::cout << head.InsertEdge('a', 'c')->GetName() << std::endl;
std::cout << head.InsertEdge('a', 'd')->GetName() << std::endl;
std::cout << head.InsertEdge('b', 'a')->GetName() << std::endl;
std::cout << head.DeleteEdge('b', 'a') << std::endl;
std::cout << head.DeleteEdge('a', 'b') << std::endl;
std::cout << head.DeleteEdge('a', 'c') << std::endl;
std::cout << head.DeleteEdge('a', 'd') << std::endl;
std::cout << head.DeleteVertex('b') << std::endl;
std::cout << head.DeleteVertex('c') << std::endl;
std::cout << head.DeleteVertex('d') << std::endl;
return 0;
}
示例4: main
int main()
{
Test b;
b.Run();
Graph<char, int> a;
a.InsertNode('A');
a.InsertNode('B');
a.InsertNode('C');
a.InsertNode('D');
a.InsertNode('E');
a.InsertEdge('A','B',4,1);
a.InsertEdge('A','C',3,1);
a.InsertEdge('B','C',1,1);
a.InsertEdge('D','A',6,1);
a.InsertEdge('B','A',4,1);
a.InsertEdge('C','E',10,1);
a.InsertEdge('E','D',2,1);
a.Print();
Dijkstra(a,'A','E');
return 0;
}
示例5: main
int main(int argc, char** argv)
{
Graph graph;
graph.InsertEdge("A", "B");
graph.InsertEdge("A", "C");
graph.InsertEdge("B", "D");
graph.Print();
Search search;
search.Initialize(graph);
search.Bfs(graph, "A");
for (unordered_map<string, string>::iterator item = search.parents_.begin();
item != search.parents_.end(); ++item)
cout << item->first << ":" << item->second << endl;
search.Initialize(graph);
search.Dfs(graph, "A");
for (unordered_map<string, string>::iterator item = search.parents_.begin();
item != search.parents_.end(); ++item)
cout << item->first << ":" << item->second << endl;
return 0;
}
示例6: ReadFile
/**********************************************************************
* Purpose: Reads file and inserts info into Graph graph
* Primes all the data. If success, return true.
* Entry: string file, Graph<string, string> & graph
* Exit: returns true if successful.
************************************************************************/
bool ReadFile(const string & file, Graph<string, string> & graph)
{
ifstream map(file.c_str());
bool valid = false;
if (map.is_open())
{
valid = true;
while (!map.eof())
{
string orig, dest, hwy;
int weight = 0;
getline(map, orig, ',');
getline(map, dest, ',');
getline(map, hwy, ',');
map >> weight;
map.get(); // for end line
try
{
graph.InsertVertex(orig);
}
catch (Exception e)
{
//cout << e << endl;
}
try
{
graph.InsertVertex(dest);
}
catch (Exception e)
{
//cout << e << endl;
}
graph.InsertEdge(orig, dest, hwy, weight);
}
map.close();
}
示例7: InsertEdges
void InsertEdges(Graph<string, string>& g)
{
try {
g.InsertEdge("Anchorage", "Eagle River", "Old Glenn Hwy", 16);
g.InsertEdge("Eagle River", "Old Glenn - AK HWY 1 - AK HWY 3 JCT", "Old Glenn", 19);
g.InsertEdge("Old Glenn - AK HWY 1 - AK HWY 3 JCT", "Palmer", "HWY 1", 6);
g.InsertEdge("Old Glenn - AK HWY 1 - AK HWY 3 JCT", "Wasilla", "HWY 3", 8);
g.InsertEdge("Wasilla", "Talkeetna", "HWY 3", 70);
g.InsertEdge("Talkeetna", "Fairbanks", "HWY 3", 300);
}
catch (Exception e)
{
cout << e;
}
}
示例8: Load
void Load(Graph& mGraph, vector<Graph::Primitive*>& mPrimitives)
{
// std::string path = Environment::GetPathR("tri.txt");
//std::ifstream inFile(path.c_str());
ifstream inFile("./PlanarGraph.txt");
//ofstream verify;
//verify.open("verify.txt",ios::out|ios::app);
int numVertices;
inFile >> numVertices;
//verify<< numVertices<<"\n";
int i;
for (i = 0; i < numVertices; ++i)
{
double x, y;
inFile >> x;
inFile >> y;
// verify<< x <<"\t"<< y <<"\n";
//y = GetHeight() - 1 - y;
mGraph.InsertVertex(Vec2(x, y), i);
}
int numEdges;
inFile >> numEdges;
//verify<< numEdges<<"\n";
for (i = 0; i < numEdges; ++i)
{
int v0, v1;
inFile >> v0;
inFile >> v1;
// verify<< v0 <<"\t"<< v1 <<"\n";
mGraph.InsertEdge(v0, v1);
}
#ifdef EXTRACT_PRIMITIVES
mGraph.ExtractPrimitives(mPrimitives);
#endif
}