tree.c

Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <memory.h>
00003 #include "machine.h"
00004 
00005 #include "sci_mem_alloc.h"  /* malloc */
00006 
00007 int ctree2(int* vect,int nb,int* deput,int* depuptr,int* outoin,int* outoinptr,
00008            int* ord,int* nord,int* ok);
00009 int ctree3(int*vec,int nb,int* depu,int* depuptr,int* typl,int* bexe,int* boptr,
00010            int* blnk,int* blptr,int* ord,int* nord,int* ok);
00011 int ctree4(int* vec,int nb,int *nd,int nnd,int* typ_r,int* outoin,
00012            int* outoinptr,int* r1,int* r2, int* nr);
00013 
00014 extern int C2F(isort)();
00015 
00016 void Inver(int* vect, int nb) 
00017 {
00018   int i;   
00019   for(i = 0; i <nb; i++)
00020     {
00021       vect[i]=-vect[i];
00022     }
00023 }
00024 
00025 
00026 /************************* function tree2 *********************************/
00027 int ctree2(vect, nb, depu, depuptr,outoin, outoinptr, ord, nord, ok)
00028      int *vect,nb,*depu,*depuptr,*outoin,*outoinptr,*ord,*nord,*ok;
00029 {
00030   int fini=0,i,j,k,m,ii;
00031   
00032   *ok = 1;
00033   for (j = 1; (j <= nb+2) && (! fini); j++) 
00034     {
00035       fini = 1;
00036       for (i = 0; i < nb; i++) 
00037         {
00038           if (vect[i] == j-1 ) 
00039             {
00040               if (j == nb + 2) 
00041                 {
00042                   *ok = 0;
00043                   *nord=0;
00044                   return 0;
00045                 }
00046               if (outoinptr[i+ 1] - outoinptr[i] != 0) 
00047                 {                 
00048                   for (k = outoinptr[i]; k <= outoinptr[i + 1] - 1; k++) 
00049                     {
00050                       ii = outoin[k-1];               
00051                       if (vect[ii-1] > -1 && depu[depuptr[ii-1]-2+outoin[outoinptr[nb]+k-2]] == 1) 
00052                         {
00053                           fini = 0;
00054                           vect[ii-1] = j;
00055                         }                       
00056                     }
00057                 }
00058             }
00059         }
00060     }
00061   Inver(vect,nb);  
00062   C2F(isort)(vect,&nb,ord);
00063   for(m=0 ; m < nb; m++)
00064     {
00065       if (vect[m] < 1){
00066         if (m == 0) {
00067           *nord=nb;
00068           return 0;
00069         } else {
00070           *nord=nb-m;
00071           for (i=0; i<*nord;i++)
00072             ord[i]=ord[i+nb-*nord];
00073           return 0;      
00074         }
00075       }
00076     }
00077   *nord=0;
00078   return 0;
00079 }
00080 
00081 /* ===========================================   fin de tree2 ======================================== */ 
00082 /* ********************************************** function tree3 ***************************************** */
00083 int ctree3(vec, nb, depu,depuptr, typl, bexe, boptr, blnk, blptr,ord, nord, ok)
00084      int *vec,nb,*depu,*depuptr,*typl,*bexe,*boptr,*blnk,*blptr,*ord,*nord,*ok;
00085 {
00086   int fini=0,i,j,m,nkk,kk;
00087   
00088   *ok = 1;
00089   for( i= 0; i < nb; i++)
00090     {
00091       if ((vec[i] == 0) && (typl[i] == 1)) vec[i]=1; 
00092     }
00093   for (j = 1; (j <= nb+2) &&(! fini); j++) 
00094     {
00095       fini = 1;
00096       if (j == nb + 2) 
00097         {
00098           *ok = 0;
00099           *nord = 0;
00100           return 0;
00101         }
00102       
00103       for (i = 0; i < nb; i++) 
00104         {
00105           if (vec[i] > -1 && typl[i] != -1) 
00106             {
00107               if (typl[i] == 1) 
00108                 {
00109                   nkk = boptr[i + 1] - boptr[i];
00110                   if (nkk != 0) 
00111                     {
00112                       for (m = 0; m < nkk; m++) 
00113                         {
00114                           kk = bexe[m + boptr[i] - 1];
00115                           if (typl[kk-1] == 1) 
00116                             {
00117                               if (vec[kk-1] < vec[i]+2)
00118                                 {
00119                                   fini=0;
00120                                   vec[kk-1]=vec[i]+2;
00121                                 }
00122                             }
00123                           else
00124                             {
00125                               if (vec[kk-1] < vec[i]+1)
00126                                 {
00127                                   fini=0;
00128                                   vec[kk-1]=vec[i]+1;
00129                                 } 
00130                             }
00131                         }
00132                     }
00133                 } 
00134               else 
00135                 {
00136                   nkk = blptr[i+1]-blptr[i];
00137                   if (nkk != 0) 
00138                     {
00139                       for (m = 0; m < nkk; m++) 
00140                         {
00141                           kk = blnk[m+blptr[i]-1];
00142                           if (vec[kk-1] > -1 && (depu[depuptr[kk-1]-2+blnk[blptr[nb]+blptr[i]-2]] == 1 || typl[kk-1] == 1)) 
00143                             {
00144                               if (vec[kk-1] < vec[i])
00145                                 {
00146                                   fini=0;
00147                                   vec[kk-1]=vec[i];
00148                                 }
00149                             }
00150                         }
00151                     }
00152                 }
00153             }
00154           
00155         }
00156     }
00157   Inver(vec,nb); 
00158   C2F(isort)(vec,&nb,ord);
00159   for(m=0 ; m < nb; m++)
00160     {
00161       if (vec[m] < 1){
00162         if (m == 0) {
00163           *nord=nb;
00164           return 0;
00165         } else {
00166           *nord=nb-m;
00167           for (i=0; i<*nord;i++)
00168             ord[i]=ord[i+nb-*nord];
00169           return 0;      
00170         }
00171       }
00172     }
00173   *nord=0;  
00174   return 0;
00175 }
00176 /*===========================================   fin de tree3 ======================================== */
00177 /********************** function tree4 *********************************************/
00178 int ctree4(int* vec,int nb,int* nd,int nnd,int* typ_r,int* outoin,
00179           int* outoinptr,int* r1,int* r2, int* nr)
00180 {
00181   int i,j,fini=0,k,ii,nprt;
00182   *nr=0;
00183   for (j = 1 ; (j < nb) &&  (! fini); j++){
00184     fini=1;
00185     for (i=0;i<nb;i++){
00186       if (vec[i] > -1){
00187         if (outoinptr[i+1]-outoinptr[i] !=0){
00188           for (k=outoinptr[i];k<outoinptr[i+1];k++){                 
00189             ii=outoin[k-1];
00190             if(typ_r[ii-1] == 1){
00191               nprt=outoin[k+outoinptr[nb]-2];
00192               if (nd[nprt+(ii-1)*nnd] == 0){            
00193                 r1[*nr]=ii;
00194                 r2[*nr]=nprt;
00195                 fini=0;
00196                 vec[ii-1]=0;
00197                 nd[nprt+(ii-1)*nnd]=1;
00198                 nr[0]++;
00199               }
00200             } 
00201           } 
00202         } 
00203       } 
00204     } 
00205     if (fini ==1) return 0;
00206   } 
00207   return 0;
00208 
00209 } /* end function*/
00210 
00211 /* =================== endfunction tree4 ========================================== */
00212 
00213 

Generated on Sun Mar 4 15:04:00 2007 for Scilab [trunk] by  doxygen 1.5.1