IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C++ Discussion :

Compréhension de code


Sujet :

C++

  1. #1
    Nouveau Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Février 2013
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Février 2013
    Messages : 4
    Points : 0
    Points
    0
    Par défaut Compréhension de code
    Bonjour,

    voici un morceau de mon code que je vais l'ajouter à mon code aodv.cc pour l'anticipation des ruptures des liens
    merciiiiiiiiiiiiiiiiiiii
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    //*********     Fonction de prédiction de la rupture du lien                   ************************************************************************************************
    bool AODV::predict(AODV *node,nsaddr_t destAddr,nsaddr_t repAddr,double signal, double time)
    {
     
      NT *nodetable = node->node_table;
     
     
      NT_Node* theNoden = NULL;
      NT_Node* currentn=NULL;
      NT_Node* previousn=NULL;
      AODV_PWL_Node *newNode=NULL;
     
      AODV_PWL_Node *ptr=NULL;
     
      double p1, p2, p3,t1, t2, t3,tx,np,x,moy;
     
      double const discovery_period=0.25,DB_THER=3.814e-10;
     #ifdef DISPLAY_INFO
     printf("\n repnode %d node %d \n",repAddr,index);
    #endif
      //Find the insertion point. Entries are sorted in increaseing order of node addresses
     
        currentn = nodetable->head;
     
        while ((currentn != NULL) && (currentn->destAddr < destAddr)) {
        previousn = currentn;
        currentn = currentn->next;
      }//while//
     
        if((currentn==NULL)||(currentn->destAddr!=destAddr))
        { //Corresponding entry does not exist. So add entry for this destination and a value in the node table
     #ifdef DISPLAY_INFO
     printf("\n---> 1 noeud %d destnoeud %d power %g\n",index,destAddr,signal);
    #endif
            ++(nodetable->size);
     
          // initiate feilds of a node in the node table
     
            theNoden = (NT_Node *)malloc(sizeof(NT_Node));
            theNoden->destAddr = destAddr;
            theNoden->repAddr = repAddr;
            theNoden->signal = signal;
            theNoden->lasttime = 0;
     
          // initaite the list of power for the correspending node for the first time
     
            theNoden->PowerList.head = NULL;
            theNoden->PowerList.tail = NULL;
            theNoden->PowerList.size = 0;
     
              if(signal<=DB_THER)//hey
                {
            newNode = (AODV_PWL_Node*)malloc(sizeof(AODV_PWL_Node));
            newNode->SignalPower = signal;
            newNode->Time = time;
            newNode->next=NULL;
     
            theNoden->PowerList.head = theNoden->PowerList.tail = newNode;
            theNoden->PowerList.size++;
                }
     
          if (previousn == NULL)
          {
              theNoden->next = nodetable->head;
              nodetable->head = theNoden;
          } // (previousn == NULL)
          else
          {
              theNoden->next = previousn->next;
                previousn->next = theNoden;
          }
     
     
        }
        else  // (currentn!=NULL)&&(currentn->destAddr==destAddr)
        {
     
     
      while ((currentn != NULL) && (currentn->destAddr == destAddr) &&(currentn->repAddr!=repAddr)) {
        currentn = currentn->next;
      }//while//
     
     
      if((currentn != NULL) &&(currentn->destAddr==destAddr)&&(currentn->repAddr==repAddr)) //hey
        {
    if (signal<=DB_THER)//hey
    {
     
        if (currentn->PowerList.size < 2)
          {
     
          if(currentn->PowerList.tail==NULL || currentn->PowerList.tail->SignalPower != signal) //hey
            {
    #ifdef DISPLAY_INFO
    printf("\n---> 2 noeud %d destnoeud %d power %g\n",index,destAddr,signal);
    #endif
         // adding a value in  the list of power for the correspending node for the 2nd value without redendency of power values
     
          newNode = (AODV_PWL_Node*)malloc(sizeof(AODV_PWL_Node));
          newNode->SignalPower = signal;
          newNode->Time =    time;
          newNode->next=NULL;
     
    if (currentn->PowerList.tail==NULL){ //hey
          currentn->PowerList.head = currentn->PowerList.tail = newNode;}
    else{
          currentn->PowerList.tail->next = newNode;
        currentn->PowerList.tail = newNode;
         }
          currentn->PowerList.size++;
     
     
          }  // SignalPower != signal
          else
          {
                 currentn->PowerList.tail->Time = time;
     
    #ifdef DISPLAY_INFO
        printf("\n--->2 stop noeud %d destnoeud %d power %g \n",index,destAddr,signal);
    #endif
          }
        }    // PowerList.size < 3
          else
        {
     
         int t= currentn->PowerList.size + 1;
     
          if (t==3)
            {
    #ifdef DISPLAY_INFO
        printf("\n---> 3 noeud %d destnoeud %d power %g\n",index,destAddr,signal);
    #endif
     
     
                if(currentn->PowerList.tail->SignalPower != signal)
               {
     
         // adding a value in  the list of power for the correspending node for the 3rd value without redendency of power values
     
              newNode = (AODV_PWL_Node*)malloc(sizeof(AODV_PWL_Node));
                      newNode->SignalPower = signal;
                      newNode->Time = time;
                      newNode->next=NULL;
     
                      currentn->PowerList.tail->next = newNode;
                      currentn->PowerList.tail = newNode;
     
                      currentn->PowerList.size++;
     
        //after having 3 value of signal strength - the above value is the 3rd - we must predict the next value of the signal strength using linear extrapolation and testing if this new value reach he thershold of reparing link breakage
     
     
                     ptr=currentn->PowerList.head;
     
                     t1 = ptr->Time;
                     p1 = ptr->SignalPower;
     
                     ptr=ptr->next;
     
                     t2 = ptr->Time;
                     p2 = ptr->SignalPower;
     
                     ptr=ptr->next;
     
                     t3 = ptr->Time;
                     p3 = ptr->SignalPower;
     
                 moy=t3-((t1+t2+t3)/3);//hey
     
                 x = t3 + min(moy,discovery_period) ;
     
     
     //printf("%g:%g  %g:%g  %g:%g\n",t1,p1,t2,p2,t3,p3);
     np=((((x-t2)*(x-t3))/((t1-t2)*(t1-t3)))*p1) +((((x-t1)*(x-t3))/((t2-t1)*(t2-t3)))*p2) + ((((x-t1)*(x-t2))/((t3-t1)*(t3-t2)))*p3);
     
    #ifdef DISPLAY_INFO
    printf("\n node %d Now %g predict at time %g  power %g dest %d\n",index,time, x ,np,destAddr );
    #endif
         if((np <= 3.652e-10)&&(p1>p2)&&(p2>p3))
        {
    #ifdef DISPLAY_INFO
    printf("\n 3will disconnect must be repaired \n" );
    #endif
    while (currentn->PowerList.size!=0){       //hey
    ptr=currentn->PowerList.head;
             currentn->PowerList.head=currentn->PowerList.head->next;
               currentn->PowerList.size--;
             delete ptr;
             ptr=NULL;
     
    }
    currentn->PowerList.tail = NULL;
    //printf("\n node %d Now %g predict at time %g  power %g dest %d\n",index,time, x ,np,destAddr );
     
    //printf("%g:%g  %g:%g  %g:%g\n",t1,p1,t2,p2,t3,p3);
     
     
          return TRUE;
        }
               else
                   {
             #ifdef DISPLAY_INFO
               printf("\n deleting powerList struct\n" );
             #endif
     
               ptr=currentn->PowerList.head;
             currentn->PowerList.head=currentn->PowerList.head->next;
               currentn->PowerList.size--;
             delete ptr;
             ptr=NULL;
     
                  }
     
     
            }  // SignalPower != signal
          else
          {
    #ifdef DISPLAY_INFO
     printf("\n--->3 stop noeud %d destnoeud %dpower %g \n",index,destAddr,signal);
    #endif
               tx = currentn->PowerList.tail->Time;            //hey
                 currentn->PowerList.tail->Time = time;
               currentn->PowerList.head->Time=currentn->PowerList.head->Time + (time - tx);
             }
            }
     
     
        }
    }else //hey
    {
    while (currentn->PowerList.size!=0){
    ptr=currentn->PowerList.head;
             currentn->PowerList.head=currentn->PowerList.head->next;
               currentn->PowerList.size--;
             delete ptr;
             ptr=NULL;
     
    }
    currentn->PowerList.tail = NULL;
     
    }
     
     
     }
     
            else   // (destAddr==destAddr)&&(repAddr==nodeAddr))
              {
      #ifdef DISPLAY_INFO
      printf("\n---> 1 noeud %d destnoeud %d power %g\n",index,destAddr,signal);
      #endif
          ++(nodetable->size);
     
          // initiate feilds of a node in the node table
     
          theNoden = (NT_Node *)malloc(sizeof(NT_Node));
          theNoden->destAddr = destAddr;
          theNoden->repAddr = repAddr;
          theNoden->signal = signal;
          theNoden->lasttime = 0;
     
          // initaite the list of power for the correspending node for the first time
     
          theNoden->PowerList.head = NULL;
          theNoden->PowerList.tail = NULL;
          theNoden->PowerList.size = 0;
     
       if (signal<=DB_THER){//hey
          newNode = (AODV_PWL_Node*)malloc(sizeof(AODV_PWL_Node));
          newNode->SignalPower = signal;
          newNode->Time = time;
          newNode->next=NULL;
     
          theNoden->PowerList.head = theNoden->PowerList.tail = newNode;
          theNoden->PowerList.size++;
         }
     
          if (previousn == NULL)
        {
     
          theNoden->next = nodetable->head;
          nodetable->head = theNoden;
     
     
        } // (previousn == NULL)
          else
        {
          theNoden->next = previousn->next;
          previousn->next = theNoden;
        }
        }
      }
    #ifdef DISPLAY_INFO
     printf("\n \t\t\t  RAS  \n" );
    #endif
        return FALSE ;
    }
    //endModification

  2. #2
    Membre émérite
    Avatar de imperio
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2010
    Messages
    852
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Ain (Rhône Alpes)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2010
    Messages : 852
    Points : 2 298
    Points
    2 298
    Par défaut
    Tres bien. Donc mise a part la presentation absolument degueulasse, quel est le probleme ?

Discussions similaires

  1. compréhension de code en asp
    Par bidule123456 dans le forum ASP
    Réponses: 1
    Dernier message: 21/08/2007, 11h12
  2. compréhension de code (passage à une autre page)
    Par kokokaine dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 04/05/2007, 11h02
  3. Réponses: 3
    Dernier message: 12/01/2007, 09h42
  4. [VB-Access]recset! Pb de compréhension de code
    Par sk8bcn dans le forum VBA Access
    Réponses: 5
    Dernier message: 15/12/2006, 15h26
  5. Compréhension du code
    Par Ivanelis dans le forum Assembleur
    Réponses: 3
    Dernier message: 12/06/2006, 12h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo