本文整理汇总了C++中ListDigraph类的典型用法代码示例。如果您正苦于以下问题:C++ ListDigraph类的具体用法?C++ ListDigraph怎么用?C++ ListDigraph使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ListDigraph类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GenerateRandomEuclideanListDigraph
//Generate a random complete euclidean ListGraph
bool GenerateRandomEuclideanListDigraph(ListDigraph &g,
DNodeStringMap &vname, // node name
DNodePosMap &px, // x-position of the node
DNodePosMap &py, // y-position of the node
ArcValueMap & weight, // weight of edges
int n, // number of nodes
double SizeX, // coordinate x is a random number in [0,SizeX)
double SizeY) // coordinate y is a random number in [0,SizeY)
{
DNode *V;
V = new DNode[n];
if (V==NULL){
cout << "Memory allocation error, number of nodes " << n << " too large\n";
exit(0);}
for (int i=0;i<n;i++) { // insert nodes (random points in [0,100] x [0,100] )
V[i] = g.addNode(); // new node
px[V[i]] = SizeX*drand48();
py[V[i]] = SizeY*drand48();
vname[V[i]] = IntToString(i+1);// name of node is i+1
}
for (int i=0;i<n;i++)
for (int j=i+1;j<n;j++) {
Arc e = g.addArc(V[i],V[j]); // generate new arc from v_i to v_j
weight[e] = sqrt(pow(px[V[i]]-px[V[j]],2) + pow(py[V[i]]-py[V[j]],2));
Arc f = g.addArc(V[j],V[i]); // generate new arc from v_j to v_i
weight[f] = weight[e];
}
delete[] V;
return(true);
}
示例2: read_pcpath
int read_pcpath(string input_file){
std::ifstream kinput;
kinput.open(input_file.c_str()); if (!kinput) return 0;
kinput >> n >> m;
std::map<std::string, ListDigraph::Node> ref;
for ( int i=0; i<n; i++ ){
string tmp;
double r;
kinput >> tmp >> r;
ListDigraph::Node n = g.addNode();
node_names[n] = tmp;
prizes[n] = r;
ref[tmp]=n;
}
for ( int i=0; i<m; i++){
string v1, v2;
double c_tmp;
kinput >> v1 >> v2 >> c_tmp;
ListDigraph::Arc a = g.addArc(ref[v1], ref[v2]); //source, target
costs[a] = c_tmp;
}
return 1;
}
示例3: split_graph
//splits graph into connected components
void split_graph(ListDigraph& g, vector<ListDigraph*>& graphs){
Undirector<ListDigraph> undirected(g);
ListDigraph::NodeMap<int> components(g);
stronglyConnectedComponents(undirected, components);
int num_subgraphs = 0;
for(ListDigraph::NodeIt n(g); n != INVALID; ++n){
if(components[n] > num_subgraphs) num_subgraphs = components[n];
}
num_subgraphs++;
ListDigraph::NodeMap<ListDigraph::Node> map(g);
for(int i = 0; i < num_subgraphs; i++){
ListDigraph temp;
for(ListDigraph::NodeIt n(g); n != INVALID; ++n){
if(components[n] == i){
map[n] = temp.addNode();
}
}
for(ListDigraph::NodeIt n(g); n != INVALID; ++n){
if(components[n] == i){
for(ListDigraph::OutArcIt o(g, n); o != INVALID; ++o){
temp.addArc(map[g.source(o)], map[g.target(o)]);
}
}
}
graphs.push_back(&temp);
}
}
示例4: drawGraphToFile
void drawGraphToFile(ListDigraph& g){
ofstream myfile;
myfile.open("graph.dot");
myfile << "digraph g {\n";
for (ListDigraph::ArcIt a(g); a!= INVALID; ++a)
{
myfile << g.id(g.source(a)) << " -> " << g.id(g.target(a)) << "\n";
}
myfile << "}\n";
myfile.close();
}
示例5: drawGraphToFileWithArcMap
void drawGraphToFileWithArcMap(ListDigraph& g, ListDigraph::ArcMap<int>& map){
ofstream myfile;
myfile.open("graph.dot");
myfile << "digraph g {\n";
for (ListDigraph::ArcIt a(g); a!= INVALID; ++a)
{
myfile << g.id(g.source(a)) << " -> " << g.id(g.target(a)) << " [label=\"" << map[a] << "\"] \n";
}
myfile << "}\n";
myfile.close();
}
示例6: addSink
ListDigraph::Node addSink(ListDigraph& g){
ListDigraph::Node t = g.addNode();
for(ListDigraph::NodeIt n(g); n != INVALID; ++n){
if(countOutArcs(g, n) == 0 && n != t){
g.addArc(n, t);
}
}
return t;
}
示例7: addSource
ListDigraph::Node addSource(ListDigraph& g){
ListDigraph::Node s = g.addNode();
for(ListDigraph::NodeIt n(g); n != INVALID; ++n){
if(countInArcs(g, n) == 0 && n != s){
g.addArc(s, n);
}
}
return s;
}
示例8: main
int main()
{
ListDigraph g;
ListDigraph::Node u = g.addNode();
ListDigraph::Node v = g.addNode();
ListDigraph::Arc a = g.addArc( u, v );
cout << "Hello World! This is LEMON library here." << endl;
cout << "We have a directed graph with " << countNodes( g ) << " nodes "
<< "and " << countArcs( g ) << " arc." << endl;
return 0;
}
示例9: nodeValidation
/* The function purpose is to check if the node is exist, if not it create it and add it to the map*/
void nodeValidation(int input, CrossRefMap<ListDigraph, ListDigraph::Node, int> & ids, ListDigraph::Node & node, ListDigraph & g){
node = ids(input);
if (node == INVALID) { // Check if node is inavlid
node = g.addNode();
ids.set(node, input); // make a connection between the node and the string
}
}
示例10: ViewListDigraph
// This routine visualize a digraph using a pdf viewer. It uses neato (from
// graphviz.org) to generate a pdf file and a program to view the pdf file. The
// pdf viewer name is given in the viewername parameter.
int ViewListDigraph(ListDigraph &g,
DNodeStringMap &vname, // node names
DNodePosMap &px, // x-position of the nodes
DNodePosMap &py, // y-position of the nodes
DNodeColorMap &vcolor, // color of node (see myutils.h)
ArcColorMap &ecolor, // color of edge
string text) // text displayed below the figure
{
char tempname[1000],cmd[1000];
FILE *fp;
double minpx=DBL_MAX,minpy=DBL_MAX,maxpx=-DBL_MAX,maxpy=-DBL_MAX,delta,factor;
string str;
// obtain a temporary file name
strcpy(tempname,".viewdigraphtempname");
fp = fopen(tempname,"w+");
if (fp==NULL) {cout << "Error to open temporary file to visualize digraph.\n"; return(0);}
for (DNodeIt v(g); v!=INVALID; ++v) {
if (px[v] < minpx) minpx = px[v];
if (px[v] > maxpx) maxpx = px[v];
if (py[v] < minpy) minpy = py[v];
if (py[v] > maxpy) maxpy = py[v];
}
factor = 40; // using larger values makes small nodes
delta = fmax(maxpx - minpx,maxpy - minpy);
// Generate a text file with the graph format of neato program
fprintf(fp,"digraph g {\n");
fprintf(fp,"\tsize = \"10, 10\";\n");
fprintf(fp,"\tnode [style = filled, shape = \"circle\"];\n");
for (DNodeIt v(g); v!=INVALID; ++v) {
if (vcolor[v]==NOCOLOR) continue;
fprintf(fp,"\t%s [color=\"%s\", pos = \"%lf,%lf!\"];\n",
vname[v].c_str(),ColorName(vcolor[v]).c_str(),factor*(px[v]-minpx)/delta,factor*(py[v]-minpy)/delta);
}
for (ArcIt e(g); e!=INVALID; ++e) {
if (ecolor[e]==NOCOLOR) continue;
fprintf(fp,"\t%s -> %s [color=\"%s\" ];\n",vname[g.source(e)].c_str(),vname[g.target(e)].c_str(),ColorName(ecolor[e]).c_str());
}
fprintf(fp,"label=\"%s\";\nfontsize=50;\n",text.c_str());
fprintf(fp,"}\n");
fclose(fp);
sprintf(cmd,"neato -Tpdf %s -o %s.pdf",tempname,tempname); system(cmd);
str = tempname;
str = str + ".pdf";
view_pdffile(str);
return(1);
}
示例11: main
int main()
{
ListDigraph test;
ListDigraph::Node a = test.addNode();
ListDigraph::Node b = test.addNode();
ListDigraph::Node c = test.addNode();
ListDigraph::Node d = test.addNode();
ListDigraph::Node e = test.addNode();
ListDigraph::Node f = test.addNode();
ListDigraph::Arc ac = test.addArc(a, c);
ListDigraph::Arc bc = test.addArc(b, c);
ListDigraph::Arc cd = test.addArc(c, d);
ListDigraph::Arc bf = test.addArc(b, f);
ListDigraph::Arc de = test.addArc(d, e);
ListDigraph::Arc df = test.addArc(d, f);
ListDigraph::ArcMap<int> costs(test);
costs[ac] = 1;
costs[bc] = 2;
costs[cd] = 2;
costs[bf] = 32;
costs[de] = 16;
costs[df] = 8;
solve_via_minflow(test, costs);
return 0;
}
示例12: main
int main(int argc, char* argv[]){
tMax = 600;
int verbose = 0;
std::string input_file;
int option, i_f = 0;
if ( argc == 1 ){
show_usage();
return 0;
}
while ((option = getopt(argc, argv, "t:i:v"))!=-1)
switch(option){
case 't':
tMax=atoi(optarg);
break;
case 'i':
i_f = 1;
input_file.assign(optarg);
break;
case 'v':
verbose=1;
break;
default:
break;
}
if ( i_f == 0 ){
std::cout << "-i mandatory argument" << std::endl;
return 1;
}
if ( !read_pcpath(input_file) ) return 1;
for ( ListDigraph::NodeIt u(g); u!=INVALID; ++u ){
if ( node_names[u].compare("s")==0 )
s=u;
if ( node_names[u].compare("t")==0 )
t=u;
}
//if ( verbose )
// show_input();
prize_collecting_st_path_pli(g, prizes, costs, s, t, path, UB, LB, tMax);
if ( verbose ){
//make_eps_graph(path, "sol");
//set_pdfreader("okular");
//set_pdfreader("open");
//set_pdfreader("xpdf");
show_graph_mygraphlib(input_file);
}
for ( int i=0; i<(int)path.size(); i++ )
std::cout << g.id(path[i]) << " ";
std::cout << std::endl;
return 0;
}
示例13: main
int main(){
string a = "88\t567 999\t444 555\n22\t777 666\t111 000";
string file, line;
int out1, out2;
istringstream mStream( a );
// ifstream mStream( "/Users/sonneundasche/Dropbox/FLI/04_HIT_Transform/_node size/Schwein_BL_07_time_tmpArcIDs_amountOnArc.txt" );
// getline( mStream, file, '\n');
while(getline( mStream, file, '\n')){
istringstream lineStream( file );
lineStream >> out1;
cout << "time: " << out1 << "\n";
getline( lineStream, line, '\t');
while( getline( lineStream, line, '\t') ){
istringstream pairStream( line );
pairStream >> out1;
pairStream >> out2;
cout << out1 << " : " << out2 << "\n";
}
}
//
vector< int > activeTimes;
ListDigraph mGraph;
digraphReader( mGraph, "/Users/sonneundasche/Dropbox/FLI/04_HIT_Transform/_node size/Schwein_BL_07.lgf")
.run();
map< int, vector< pair <ListDigraph::Arc, int > > > activeArcsAndWeight;
activeTimes = tempGR::readTemporalArcListWeighted(mGraph, activeArcsAndWeight, "/Users/sonneundasche/Dropbox/FLI/04_HIT_Transform/_node size/Schwein_BL_07_time_tmpArcIDs_amountOnArc.txt");
for (auto i : activeArcsAndWeight[2486]) {
cout << mGraph.id( activeArcsAndWeight[2492][0].first ) << " : " << i.second << "\n";
}
cout << mGraph.id( activeArcsAndWeight[2492][0].first ) << " : " << activeArcsAndWeight[2492][0].second << endl;
}
示例14: createKPathGraph
void createKPathGraph(ListDigraph& g, int k, int n, int m, ListDigraph::ArcMap<int>& weights, ListDigraph::ArcMap<int>& demands){
srand(time(NULL));
ListDigraph::Node* nodes[k];
for (int i = 0; i < k; ++i)
{
nodes[i] = (ListDigraph::Node*) calloc(n, sizeof(ListDigraph::Node));
}
for (int i = 0; i < k; ++i)
{
for (int j = 0; j < n; ++j)
{
nodes[i][j] = g.addNode();
if(j != 0) g.addArc(nodes[i][j-1], nodes[i][j]);
}
}
for (int i = 0; i < m; ++i)
{
int k1 = rand()%k;
int k2 = rand()%k;
int n1 = rand()%(n-1);
int n2 = (rand()%(n-n1-1))+n1+1;
if(findArc(g, nodes[k1][n1], nodes[k2][n2]) == INVALID){
g.addArc(nodes[k1][n1], nodes[k2][n2]);
}
}
for (ListDigraph::ArcIt a(g); a != INVALID; ++a)
{
weights[a] = rand()%1000;
}
//this splits every node and sets demand for the edge between the halves to 1
for (ListDigraph::NodeIt n(g); n != INVALID; ++n){
ListDigraph::Node new_node = g.split(n, false);
ListDigraph::Arc new_edge = g.addArc(n, new_node);
demands[new_edge] = 1;
}
}
示例15: createRandomGraph
//Simple function for generating acyclic graphs
void createRandomGraph(ListDigraph& g, int num_nodes, float edge_prob){
srand(time(NULL));
ListDigraph::NodeMap<int> labels(g);
for(int i=0; i<num_nodes; i++){
ListDigraph::Node new_node = g.addNode();
labels[new_node] = i;
}
for(ListDigraph::NodeIt n(g); n != INVALID; ++n){
for(ListDigraph::NodeIt v(g); v != INVALID; ++v){
//no edges from bigger nodes to smaller to ensure acyclicity,
//and no edges from node to itself
//+ an attempt to create longer graphs
if(labels[n] >= labels[v] || labels[n] < labels[v]-20) continue;
if(rand()%100 <= edge_prob*100){
g.addArc(n, v);
}
}
}
}