|  | 40 | const int LaneQueuesSectIds[] = { | 
                          |  | 41 | 1,      2,      3,      6,      7, | 
                          |  | 42 | 3,      4,      5, | 
                          |  | 43 | 35,     28,     32,     33,     34, | 
                          |  | 44 | 26,     27,     35,     28,     29,     30,     31, | 
                          |  | 45 | 16,     17,     18,     19,     20,     14,     15, | 
                          |  | 46 | 16,     17,     18,     19,     20,     12,     13, | 
                          |  | 47 | 21,     22,     23,     24,     25,     40, | 
                          |  | 48 | 21,     22,     23,     24,     25,     40, | 
                          |  | 49 | 61,     62,     63,     64,     65, | 
                          |  | 50 | 287,288,54,     55,     56,     57,     58,     59,     60,     61,     62,     63,     64,     65, | 
                          |  | 51 | 45,     49,     51, | 
                          |  | 52 | 45,     49,     50, | 
                          |  | 53 | 43,     44, | 
                          |  | 54 | 43,     44,     42 }; | 
                          |  | 55 | const int NumLaneQueuesSectIds = sizeof(LaneQueuesSectIds)/sizeof(int); | 
                          |  | 56 |  | 
                          |  | 57 | /* This array contains offsets of particular lanes stored in LaneQueuesSectIds, | 
                          |  | 58 | plus the would-be offset of the next non-existent lane (this is used to | 
                          |  | 59 | set the limits of the index when extracting statistical data from the | 
                          |  | 60 | section_stats structure). */ | 
                          |  | 61 | int LaneQueueOffsets[] = { | 
                          |  | 62 | 0, 5, 8, 13, 20, 27, | 
                          |  | 63 | 34, 40, 46, 51, 65, 68, 70, 72, NumLaneQueuesSectIds+1 }; | 
                          |  | 64 |  | 
                          |  | 65 | /* The position of the statistics is given by the indices in the StatIds | 
                          |  | 66 | array. In order to parse the statistics correctly we have to create | 
                          |  | 67 | a copy of LaneQueuesSectIds holding indices to the StatIds array instead | 
                          |  | 68 | of the original section ids. */ | 
                          |  | 69 | int * LaneQueuesStatPos; | 
                          |  | 70 |  | 
                          |  | 71 | const int LaneQueuesLaneIds[] = { | 
                          |  | 72 | 1,      1,      2,      1,      1, | 
                          |  | 73 | 1,      1,      1, | 
                          |  | 74 | 2,      2,      1,      1,      1, | 
                          |  | 75 | 1,      1,      1,      1,      1,      1,      1, | 
                          |  | 76 | 2,      2,      2,      2,      2,      1,      1, | 
                          |  | 77 | 1,      1,      1,      1,      1,      1,      1, | 
                          |  | 78 | 2,      2,      2,      2,      2,      2, | 
                          |  | 79 | 1,      1,      1,      1,      1,      1, | 
                          |  | 80 | 2,      2,      2,      2,      2, | 
                          |  | 81 | 1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1,      1, | 
                          |  | 82 | 2,      2,      1, | 
                          |  | 83 | 1,      1,      1, | 
                          |  | 84 | 2,      2, | 
                          |  | 85 | 1,      1,      1 }; | 
                          |  | 86 |  | 
            
                  
                          |  | 389 |  | 
                          |  | 390 | /* Create LaneQueuesStatPos holding indices to the statistical data for the | 
                          |  | 391 | sections listed in LaneQueuesSectIds in the same order. */ | 
                          |  | 392 | LaneQueuesStatPos = (int *) calloc ( NumLaneQueuesSectIds, sizeof(int)); | 
                          |  | 393 | for ( int i=0 ; i < NumLaneQueuesSectIds ; i++ ) | 
                          |  | 394 | { | 
                          |  | 395 | int p = _search_index ( StatIds, NumStatIds, LaneQueuesSectIds[i] ); | 
                          |  | 396 | if ( p >= 0 ) | 
                          |  | 397 | { | 
                          |  | 398 | LaneQueuesStatPos[i] = p; | 
                          |  | 399 | } | 
                          |  | 400 | else | 
                          |  | 401 | { | 
                          |  | 402 | fprintf ( stderr, "Cannot find index  LaneQueuesStatIds[%d]=%d in StatIds!\n", | 
                          |  | 403 | i, LaneQueuesSectIds[i] ); | 
                          |  | 404 | exit(1); | 
                          |  | 405 | } | 
                          |  | 406 | } | 
            
                  
                          |  | 515 | } | 
                          |  | 516 |  | 
                          |  | 517 | /* Loop over the statistical data. We will extract the queue length for | 
                          |  | 518 | every intersection and store it into the data vector. */ | 
                          |  | 519 | int oLanes = 0; // lane offset for the actual intersection | 
                          |  | 520 | int oLpos  = 0; | 
                          |  | 521 | for ( int i = 0 ; i < NumIntersections ; i++ ) | 
                          |  | 522 | { | 
                          |  | 523 | /* Every intersection has a certain number of lanes that (roughly) | 
                          |  | 524 | correspond to the number of signal groups. */ | 
                          |  | 525 | int nLanes  = NumLanes[i]; | 
                          |  | 526 | int qoffset = QueueLengthOffsets[i]; | 
                          |  | 527 | for ( int j = 0 ; j < nLanes ; j++ ) | 
                          |  | 528 | { | 
                          |  | 529 | /* Initial queue length for this lane is zero. */ | 
                          |  | 530 | int qLen = 0; | 
                          |  | 531 | /* Every lane has one or more section identifiers at certain | 
                          |  | 532 | positions in LaneQueuesStatIds. The sequence of lanes | 
                          |  | 533 | is given by offsets in LaneQueueOffsets, the position of | 
                          |  | 534 | the statistical information is stored in LaneQueuesStatPos. */ | 
                          |  | 535 | for ( int k = oLpos ; k < LaneQueueOffsets[oLanes+j+1] ; k++ ) | 
                          |  | 536 | { | 
                          |  | 537 | /* Get the index into statistical information records. */ | 
                          |  | 538 | int pi = LaneQueuesStatPos[k]; | 
                          |  | 539 | int pl = LaneQueuesLaneIds[k]-1; // indices are not zero-based | 
                          |  | 540 | /* Now query the last queue length (section with more than | 
                          |  | 541 | one lane holds several queue lengths) and add it to the | 
                          |  | 542 | acumulated queue length value. */ | 
                          |  | 543 | qLen += sections_stats.queues[pi*sections_stats.max_lanes+pl]; | 
                          |  | 544 | } | 
                          |  | 545 | /* Move the lane position offset. */ | 
                          |  | 546 | oLpos = LaneQueueOffsets[oLanes+j+1]; | 
                          |  | 547 | /* Update the data vector. */ | 
                          |  | 548 | dt[qoffset+j] = qLen; | 
                          |  | 549 | } | 
                          |  | 550 | oLanes = oLanes + nLanes; |