本文整理汇总了C++中Digraph类的典型用法代码示例。如果您正苦于以下问题:C++ Digraph类的具体用法?C++ Digraph怎么用?C++ Digraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Digraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
main(int argc, char *argv[]) {
if (argc != 2) fatal("usage: cgraph type");
string s;
if (strcmp(argv[1],"graph") == 0) {
Graph g; g.read(cin); Graph g1(1,1);
g1.copyFrom(g); cout << g1.toString(s);
} else if (strcmp(argv[1],"wgraph") == 0) {
Wgraph wg; wg.read(cin); Wgraph wg1(1,1);
wg1.copyFrom(wg); cout << wg1.toString(s);
} else if (strcmp(argv[1],"digraph") == 0) {
Digraph dig; dig.read(cin); Digraph dig1(1,1);
dig1.copyFrom(dig); cout << dig1.toString(s);
} else if (strcmp(argv[1],"wdigraph") == 0) {
Wdigraph wdig; wdig.read(cin); Wdigraph wdig1(1,1);
wdig1.copyFrom(wdig); cout << wdig1.toString(s);
} else if (strcmp(argv[1],"flograph") == 0) {
Flograph fg; fg.read(cin); Flograph fg1(2,1);
fg1.copyFrom(fg); cout << fg1.toString(s);
} else if (strcmp(argv[1],"wflograph") == 0) {
Wflograph wfg; wfg.read(cin); Wflograph wfg1(2,1);
wfg1.copyFrom(wfg); cout << wfg1.toString(s);
} else {
fatal("usage: cgraph type");
}
}
示例2: createTinyDigraph
Digraph< int > createTinyDigraph( void )
{
Array< int > edges = {
0, 1,
0, 5,
0, 6,
2, 0,
2, 3,
3, 5,
5, 4,
6, 4,
6, 9,
7, 6,
8, 7,
9, 10,
9, 11,
9, 12,
11, 12,
};
Digraph< int > d;
for ( int i = 0; i < edges.size() / 2; i++ ) {
d.addEdge( edges[ i * 2 ], edges[ i * 2 + 1 ] );
}
return d;
}
示例3: main
int main()
{
srand((unsigned int)time(NULL));
//srand(2);
Digraph<VertexBase> myDigraph;
// ExcThrower<Exception>::Throw(0.6, "Wyjatek z pawdopodobnienstwem 0.6");
myDigraph.generate(100);
cout << myDigraph << endl ;
ofstream output("../graf.txt");
if( output.is_open() )
{
while (myDigraph.shortenCriticalPath()){
cout << myDigraph << endl;
try{
myDigraph.SaveStructure(output);
}catch(FileWriteException& fwEx)
{
cout << fwEx.getMessage() << " numer wyjatku " << fwEx.Count() << endl;
}
}
output.close();
}
system("pause");
return 0;
}
示例4: Digraph
Digraph* Digraph::reverse() {
Digraph* dg = new Digraph(n(), e());
for (int v = 0; v < n(); v++)
for (int w = first(v); w < n(); w = next(v, w))
dg->addEdge(w, v, getWeight(v, w));
return dg;
}
示例5: bfs
/* @brief breadth first search to compute bfs tree(forest)
* @param g digraph
* @param sources vertices to start
*
* @note may be not the shortest path
*/
void BFSDirectedPaths::bfs(const Digraph &g, const vector<int> &sources){
queue<int> q;
int sz = sources.size();
for(int i=0; i<sz; ++i){
int v = sources[i];
marked[v] = true;
distTo[v] = 0;
edgeTo[v] = v;
q.push(v);
}
while( !q.empty() ){
int v = q.front();
list<int>::const_iterator it;
for(it = g.adj(v).begin(); it != g.adj(v).end(); ++it){
int w = *it;
if( !marked[w] ){
marked[w] = true;
distTo[w] = distTo[v] + 1;
edgeTo[w] = v;
q.push(w);
}
}
//deque
q.pop();
}
}
示例6: dfs
/* @brief depth first search to detect cycle
*
*/
void DirectedCycle::dfs(const Digraph &dg, int v){
marked[v] = true;
onStack[v] = true;
list<int>::const_iterator it;
for( it = (dg.adj(v)).begin(); it != dg.adj(v).end(); ++it){
//there exists a cycle
if( hasCycle() ){
return ;
}
if( !marked[*it] ){
edgeTo[*it] = v;
dfs(dg, *it);
}else{
//cycle detected
if( onStack[*it] ){
for(int u = v; u != *it; u = edgeTo[u] ){
cyc.push_front(u);
}
cyc.push_front(*it);
cyc.push_front(v);
}
}
}
//v has been searched
onStack[v] = false;
}
示例7: ILT_Helper
static void ILT_Helper( Digraph& dg, ILT_EdgeDataMap2& datas, ArcFilter& ef, NodeFilter& nf, EdgeArray& sortedAirEdges, IntMap& cmap )
{
// 记录用风地点的始末搜索得到的count
AcDbIntArray sAirs, tAirs;
double st = Timer::rdtscSeconds();
// 显示排序后,用风地点的顺序编号
//DisplayAirEdgeNum(sortedAirEdges, datas);
int len = sortedAirEdges.length();
acutPrintf( _T( "\n用风地点个数:%d" ), len );
for( int i = 0; i < len; i++ )
{
Digraph::Arc e = sortedAirEdges[i];
Digraph::Node u = dg.source( e );
Digraph::Node v = dg.target( e );
sAirs.append( CountInFlowNodes( dg, ef, nf, u, cmap ) );
tAirs.append( CountOutFlowNodes( dg, ef, nf, v, cmap ) );
//acutPrintf(_T("\n第%d个用风地点【始节点】=%d 【末节点】=%d"), i, sAirs[i], tAirs[i]);
}
/*for(Digraph::NodeIt n(dg); n!=INVALID; ++n)
{
if(nf[n] && imap[n]==0) imap[n] = 1;
}*/
double et = Timer::rdtscSeconds();
acutPrintf( _T( "\n第1次正反dfs查找耗费时间:%.5f" ), et - st );
// 显示分支的始末节点的cmap值(测试用)
//DisplayEdgeCMapValue(dg, sortedAirEdges, datas, cmap, sAirs, tAirs);
//assert(sAirs.length() == len);
//assert(tAirs.length() == len);
st = Timer::rdtscSeconds();
for( int i = len - 1; i >= 0; i-- )
{
Digraph::Arc e = sortedAirEdges[i];
Digraph::Node u = dg.source( e );
Digraph::Node v = dg.target( e );
MinusInFlowNodes( dg, ef, nf, u, cmap, sAirs[i] );
PlusOutFlowNodes( dg, ef, nf, v, cmap, tAirs[i] );
}
et = Timer::rdtscSeconds();
acutPrintf( _T( "\n第2次正反dfs查找耗费时间:%.5f" ), et - st );
/*
* 处理完之后,可能出现一些分支的始节点(或末节点)的cmap=0
* 而末节点(或始节点)的cmap不等于0
* 这些分支中可能有部分分支也可视为主要进回风之间的联络巷
*/
// 显示分支的始末节点的cmap值(测试用)
//DisplayEdgeCMapValue(dg, sortedAirEdges, datas, cmap, sAirs, tAirs);
}
示例8: PrintVN
static void PrintVN(Digraph& dg, EdgeIdMap& eid, NodeIdMap& nid, VNO_EdgeMap& ed, VNO_FanMap&fd, VNO_NodeMap& nd, double Q)
{
cout<<"初始总风量:"<<Q<<endl;
cout<<setiosflags(ios::left)<<setw(12);
cout<<"ID\t分支(始节点,末节点)\t风阻\t调节风阻\t风量\t始节点压力\t末节点压力"<<endl;
for(Digraph::ArcIt e(dg); e!=INVALID; ++e)
{
int id = eid[e];
Digraph::Node u = dg.source(e);
Digraph::Node v = dg.target(e);
double r = ed[e]->r;
double q = ed[e]->q;
double delta_r = ed[e]->delta_r;
cout<<dg.id(e)<<"\t"<<"e("<<id<<")=("<<nid[u]<<","<<nid[v]<<")"<<"\t"
<<"r(e"<<id<<")="<<r<<"\t"
<<"d_r(e"<<id<<")="<<delta_r<<"\t"
<<"q(e"<<id<<")="<<q<<"\t"
<<"p(v"<<nid[u]<<")="<<nd[u]->p<<"\t"
<<"p(v"<<nid[v]<<")="<<nd[v]->p<<endl;
if(fd[e]!=0)
{
cout<<"\t-->分支e"<<id<<"上有风机\n"
<<fd[e]->a0<<" "
<<fd[e]->a1<<" "
<<fd[e]->a2<<" "
<<endl;
}
if(ed[e]->fq > 0)
{
cout<<"\t-->分支e"<<id<<"固定风量:"<<ed[e]->fq<<endl;
}
}
}
示例9: order
/* @brief construct a SCC with a graph and compute
* strongly connected component
* @param dg Digraph
*/
SCC::SCC(const Digraph &dg){
//initialize private menber
marked = vector<bool>(dg.V(),false);
__id = vector<int>(dg.V());
__count = 0;
for(int i=0; i<dg.V(); ++i){
__id[i] = i;
}
//dg's reverse graph
const Digraph rdg = dg.reverse();
//rdg's order
DFSOrder order(rdg);
//reverse order of dg's reverse graph
deque<int> reverseOrder = order.reverseOrder();
//depth first searh in reverseOrder
__count = 0;
int num = reverseOrder.size();
for(int i=0; i<num; ++i){
int v = reverseOrder[i];
if( !marked[v] ){
dfs(dg,v);
//search one strongly connected component
++__count;
}
}
}
示例10: dfs
void KosarajuSCC::dfs(Digraph& dg, int v) {
marked[v] = true;
id[v] = count;
for (int w = dg.first(v); w < dg.n(); w = dg.next(v, w)) {
if (!marked[w])
dfs(dg, w);
}
}
示例11:
//====================Digraph====================//
Digraph::Digraph(const Digraph &G){
__V = G.V();
__adj = vector<list<int> >(G.V());
for(int v=0; v<G.V(); ++v){
for(list<int>::const_iterator it=G.__adj[v].begin();
it != G.__adj[v].end(); ++it){
addEdge(v,*it);
}
}
}
示例12: DirectedCycle
DirectedCycle(const Digraph &graph) : marked(graph.arrSize()), edgeto(graph.arrSize()), on_stack(graph.arrSize())
{
for (size_t i = 0; i < graph.arrSize(); i++)
marked[i] = on_stack[i] = false;
for (size_t i = 0; i < graph.arrSize(); i++)
{
if (!marked[i])
dfs(graph, i);
}
}
示例13: DepthFirstOrder
DepthFirstOrder(const Digraph &graph) : marked(graph.arrSize())
{
for (size_t i = 0; i < marked.size(); i++)
marked[i] = false;
for (size_t i = 0; i < graph.arrSize(); i++)
{
if (!marked[i])
dfs(graph, i);
}
}
示例14: SortAirEdges
// 使用宽度优先搜索BFS计算最短距离
static void SortAirEdges( Digraph& dg, ArcFilter& ef, Digraph::Node s, Digraph::Node t, const EdgeArray& airEdges, EdgeArray& es )
{
AFGraph afg( dg, ef );
Bfs<AFGraph> aBfs( afg );
aBfs.run( s );
//if(!aDfs.reached(t)) return; // s->t不可达
typedef ReverseDigraph<AFGraph> RDigraph;
RDigraph rdg( afg );
Bfs<RDigraph> bBfs( rdg );
bBfs.run( t );
//if(!bDfs.reached(s)) return;
typedef std::vector<AirEdgeDist> AirEdgeArray;
AirEdgeArray aes;
int len = airEdges.length();
for( int i = 0; i < len; i++ )
{
Digraph::Arc e = airEdges[i];
Digraph::Node u = dg.source( e );
Digraph::Node v = dg.target( e );
AirEdgeDist aed;
aed.e = e;
if( aBfs.reached( u ) )
{
aed.sd = aBfs.dist( u );
}
else
{
acutPrintf( _T( "\n第%d个用风地点【始点】不可达" ), i );
}
if( bBfs.reached( v ) )
{
aed.td = bBfs.dist( v );
}
else
{
acutPrintf( _T( "\n第%d个用风地点【末点】不可达" ), i );
}
aes.push_back( aed );
}
// 降序排序
std::sort( aes.begin(), aes.end() );
for( AirEdgeArray::iterator itr = aes.begin(); itr != aes.end(); itr++ )
{
es.append( itr->e );
}
}
示例15: toposort
void toposort(Digraph& dg, int *pos, int *vert) {
// Compute a topological ordering of dg. On return, pos[u]
// is the position of vertex u in the ordering and vert[i]
// is the vertex in the i-th position in the ordering.
int i; vertex u,v; edge e;
UiList q(dg.n());
int *nin = new int[dg.n()+1];
// Let nin[u]=in-degree of u and put nodes u with nin[u]=0 on q
for (u = 1; u <= dg.n(); u++) {
nin[u] = 0;
for (e = dg.firstIn(u); e != 0; e=dg.nextIn(u,e)) {
nin[u]++;
}
if (nin[u] == 0) q.addLast(u);
}
i = 0;
while (!q.empty()) { // q contains nodes u with nin[u] == 0
u = q.first(); q.removeFirst(); pos[u] = ++i; vert[i] = u;
for (e = dg.firstOut(u); e != 0; e = dg.nextOut(u,e)) {
v = dg.head(e);
if ((--(nin[v])) == 0) q.addLast(v);
}
}
if (i < dg.n()) fatal("toposort: graph has cycle");
}