Main Page   Class Hierarchy   Compound List   File List   Contact   Download   Symbolic Constraints   Examples  

transform.c

00001 #include<LEDA/graph.h>
00002 #include<LEDA/tuple.h>
00003 #include<LEDA/stream.h>
00004 #include<LEDA/string.h>
00005 #include<fstream.h>
00006 #include<iostream.h>
00007 
00008 #define MULT 2
00009 #define BIG_M 300000
00010 
00011 using namespace LEDA;
00012 
00013 typedef two_tuple<node, node> prec;
00014 
00015 LEDA::string read_next_line(istream& is) {
00016   LEDA::string s="#";
00017   while((!is.eof()) && ((s.head(1)=="#") || (s.length()==0) || (s.head(1)==" "))) {
00018     s.read_line(is);
00019   };
00020   if(is.eof()) s="";
00021   return s;
00022 };
00023 
00024 
00025 int main(int argc, char** argv) {
00026 
00027   // READ_GRAPH
00028 
00029   ifstream is(argv[1]);
00030 
00031   GRAPH<int,int> G;
00032 
00033   LEDA::string_istream si(read_next_line(is));
00034   int n,i,j,k,l;
00035 
00036   si>>n;
00037   LEDA::string Names[n];
00038 
00039   //cout<<n<<" nodes in the graph\n";
00040 
00041   int M[n*n+n+1][n*n+n+1];
00042 
00043   list<int> L[n];
00044   int SUCC[n*n+n];
00045 
00046   for(int i=0; i<=n*n+n; i++) {
00047     for(int j=0; j<=n*n+n; j++) {
00048       M[i][j]=100000000;
00049     };
00050   };
00051 
00052   for(int i=0; i<n*n; i++) 
00053     L[i/n].append(i);
00054 
00055   for(int i=0; i<n; i++) {
00056     L[i].append(n*n+i);
00057   }
00058 
00059   list_item li;
00060   for(int i=0; i<n; i++) {
00061     forall_items(li, L[i]) {
00062       M[L[i][li]][L[i][L[i].cyclic_succ(li)]]=0;
00063       M[L[i][li]][n*n+n]=0;
00064       SUCC[L[i][li]]=L[i][L[i].cyclic_succ(li)];
00065     }
00066   }
00067 
00068   for(int i=0; i<n; i++) {
00069     M[n*n+n][SUCC[n*n+i]]=0;
00070   }
00071 
00072   for(int i=0; i<n; i++) Names[i]=read_next_line(is);
00073 
00074   while(!is.eof()) {
00075     string_istream si(read_next_line(is));
00076     si>>i;
00077     if(!si.eof()) {
00078       si>>j; si>>k; 
00079       leda_string ls;
00080       char ch;
00081       ls.read_line(si);
00082       l=0;
00083       bool neg=false;
00084       for(int in=0; in<ls.length(); in++) {
00085         ch=ls[in];
00086         if(ch=='-') neg=true;
00087         if(ch==',') l*=MULT;
00088         if(ch=='0') l=10*l  ;
00089         if(ch=='1') l=10*l+1;
00090         if(ch=='2') l=10*l+2;
00091         if(ch=='3') l=10*l+3;
00092         if(ch=='4') l=10*l+4;
00093         if(ch=='5') l=10*l+5;
00094         if(ch=='6') l=10*l+6;
00095         if(ch=='7') l=10*l+7;
00096         if(ch=='8') l=10*l+8;
00097         if(ch=='9') l=10*l+9;
00098       }     
00099       if(neg) l=-l;
00100       if(i!=-1) {
00101         M[j*n+i][SUCC[k*n+j]]=l+BIG_M;
00102       } else {
00103         M[n*n+j][SUCC[k*n+j]]=l+BIG_M;
00104       }
00105     }
00106   };
00107 
00108   // END_READ_GRAPH
00109 
00110 
00111   cout<<n*n+n+1<<endl;
00112   //for(int i=0; i<n*n+1; i++) cout<<"bla\n";
00113   
00114   for(int i=0; i<=n*n+n; i++) {
00115     for(int j=0; j<=n*n+n; j++) {
00116       cout<<M[i][j]<<" ";
00117       if(j%10==9) cout<<endl;
00118       //if(M[i][j]<1000000) cout<<i<<" "<<j<<" "<<M[i][j]<<endl;
00119     }
00120     cout<<endl;
00121   }
00122   cout<<endl;
00123 
00124  
00125 };
00126 

Generated on Tue Nov 16 15:18:22 2004 for SCIL by doxygen1.2.16