Beispiel #1
0
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();
}
Beispiel #2
0
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();
}
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;
}
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;
    
}
int main( void ){
    
    /*
     --- Daten Anordnung ---
     From	To	Amount	Date
     560739	254569	7	2682
     913338	356536	1	3497
     */
        
    string edgeListSource   = "TradingData.txt";
    string lemonFileTmp     = "DataTMP.lgf";
    string lemonFileOut     = "DataProcessed.lgf";
    
    boost::unordered_set< unsigned int >                        uniqueNodes; // Mathematische Menge (set) der Knoten
    boost::unordered_set< pair< unsigned int, unsigned int > >  uniqueArcs;  // Menge der Kanten (set von Knoten-Paaren)
    
    ifstream    myEdgeListFile( edgeListSource );
    string      foo;  // kill first line, because it has the header
    getline(myEdgeListFile, foo);    
    
    unsigned int from, to, amount, day;
    
    // Einlesen der Werte in die Menge. Paar-Erstellung.
    while ( myEdgeListFile.good() ){
        
        myEdgeListFile >> from;
        myEdgeListFile >> to;
        myEdgeListFile >> amount;
        myEdgeListFile >> day;
        
        uniqueNodes.insert( from );
        uniqueNodes.insert( to );
        uniqueArcs.insert( make_pair( from, to ) );
    }
    cout << "Nodes: " << uniqueNodes.size() << " Arcs: " << uniqueArcs.size() << endl;;
    
    // ----------------------------------------------------------------------------------------
    // Schreiben der LFG durch eigene Routine
    // ----------------------------------------------------------------------------------------
    
    ofstream myLemonFile( lemonFileTmp );
    
    // ----- Nodes -----
    myLemonFile << "@nodes" << endl;
    myLemonFile << "label" << "\t" << "name" << endl;
    for (auto iter = uniqueNodes.begin(); iter != uniqueNodes.end(); iter++) {
        myLemonFile << *iter << "\t" 
        << *iter << endl;
    }
    
    myLemonFile << endl << endl << "@arcs" << endl;
    myLemonFile << "\t\tfrom\tto" << endl;
    for (auto iterArcs = uniqueArcs.begin(); iterArcs  != uniqueArcs.end(); iterArcs++ ){
        myLemonFile << (*iterArcs).first    << "\t"         // Erster  Paar-Eintrag für LEMON, damit es mit den Nodes übereinstimmt
        << (*iterArcs).second    << "\t"
        << (*iterArcs).first    << "\t"         // Zweiter Paar-Eintrag erhält die alten IDs, damit die Daten nicht beim Umwandeln verloren gehen
        << (*iterArcs).second   << endl;
    }
    
    // =========================================================================================
    // Create Graph and Format in a Lemon friendly way
    // Hier erhalten die Knoten und Kanten LEMON IDs
    ListDigraph myCulmiGraph;
    ListDigraph::NodeMap< unsigned int >    nameNodeMap( myCulmiGraph );
    ListDigraph::ArcMap< unsigned int >     fromNdArcMap( myCulmiGraph );
    ListDigraph::ArcMap< unsigned int>      toNdArcMap   ( myCulmiGraph );
    ListDigraph::ArcMap< bool >             activeArcsMap( myCulmiGraph );
    
    timeToActiveArcs    dayActivityArcIDs; //Menge an Zeitpunkten (int) und den dazu gehörigen aktiven Kanten (vec)
    
    boost::unordered_map< unsigned int, unsigned int >              origIDtoLemon;
    
    // Hier besitzen die Knoten & Kanten noch original IDs (name) 
    digraphReader( myCulmiGraph, lemonFileTmp)
    .nodeMap( "name", nameNodeMap )
    .arcMap( "from", fromNdArcMap )
    .arcMap( "to", toNdArcMap)
    .run();
    
    
    cout << "LEMON - Nodes: " << countNodes( myCulmiGraph ) << " Arcs: " << countArcs( myCulmiGraph ) << endl;
    
    // Ausgabe der neuen LEMON IDs für Knoten und Kanten
    digraphWriter( myCulmiGraph, lemonFileOut)
    .nodeMap( "name", nameNodeMap )
    .arcMap( "from", fromNdArcMap )
    .arcMap( "to" , toNdArcMap )
    .run();
    
    // =========================================================================================
    // Create HashMap of time and active arc pairs
    
    
    // Eine Map, die original KnotenIDs zu LEMON IDs zuweist (LemonMap Umkehr, statisch)
    // Nötig, da ich die orginalIDs aus der Ursprungsdatei einlese
    for (ListDigraph::NodeIt n( myCulmiGraph ) ; n!=INVALID; ++n) {
        origIDtoLemon[ nameNodeMap[ n ] ] = myCulmiGraph.id( n );
    }
        
    myEdgeListFile.close();
    myEdgeListFile.open( edgeListSource );
    getline(myEdgeListFile, foo);    
    
    // Einlesen der Werte in die Menge. Paar-Erstellung.
    while ( myEdgeListFile.good() ){
        
        myEdgeListFile >> from;
        myEdgeListFile >> to;
        myEdgeListFile >> amount;
        myEdgeListFile >> day;
        
        (dayActivityArcIDs[ day ]).push_back( findArc( myCulmiGraph,  myCulmiGraph.nodeFromId( origIDtoLemon[ from ] ), 
                                                      myCulmiGraph.nodeFromId( origIDtoLemon[ to   ] ) ) );
    }
    
    // =========================================================================================
    // ==================    Dies art von Map kann über alle true Werte iterieren   ============
    // 
    IterableBoolMap< ListDigraph, ListDigraph::Arc >      myItBoolMap( myCulmiGraph, false );
    
    // =========================================================================================
    // =====================    Creating the NetEvo System   ==================
    // 
    
    System mapSys, odeSys;
    ActiveArcsInteractionMap interaction( myItBoolMap );
    SIRdynamic odeDyn( 10, 0.1 );
    
    mapSys.addNodeDynamic( &interaction );
    mapSys.copyDigraph( myCulmiGraph, "InteractionMap", "NoArcDynamic");
    
    odeSys.addNodeDynamic( & odeDyn );
    odeSys.copyDigraph( myCulmiGraph, "SIRdynamic", "NoArcDynamic");
    
    SimObserverToStream coutObserver(cout);
    SimObserver         nullObserver;
    ChangeLog           nullLogger;
    
    SimulateMap         simMap;
    SimulateOdeFixed    simODE( RK_4, 0.01 );
    State initial = State( mapSys.totalStates(), 1.0) ;
    initDegreeDistributed( mapSys, initial, 3, 10.0);
    
    Timer t;
    
    cout << "Days to calculate: " << dayActivityArcIDs.size() << endl;
    cout << "Starte Simulation!" << endl;
    t.restart();
    for( int i = 1; i < dayActivityArcIDs.size() ; i++){
        setBoolMapOfDay( myItBoolMap, dayActivityArcIDs, i );
        //        cout << "Zeit: " << i << " Aktive Kanten: " << myItBoolMap.trueNum() << endl  << " ODE:" << endl;
        simODE.simulate( odeSys, 1, initial, nullObserver, nullLogger);
        simMap.simulate( mapSys, 1, initial, nullObserver, nullLogger);
    } 
    cout << "Laufzeit: " << t.realTime() << endl;
}