Changeset 1028

Show
Ignore:
Timestamp:
06/02/10 10:44:35 (14 years ago)
Author:
prikryl
Message:

New global variables NumLanes, LaneQueuesSectIds, NumLaneQueuesSectIds, LaneQueueOffsets, LaneQueuesStatPos, LaneQueuesLaneIds, QueueLengthOffsets.
Corrected the computation of NumIntersections.
Added queue lengths to Drv and dt.
The step() methods fetches the last statistical data from Aimsun as well.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • applications/doprava/aimsun_bdm/aimsun_ds.cpp

    r986 r1028  
    2121const TCHAR * ControllerList[NUM_CONTROLLERS] = { TEXT("K_5_495"), TEXT("K_5_601") }; 
    2222const TCHAR * WindowStr[NUM_CONTROLLERS]      = { TEXT("els3@5.495"), TEXT("els3@5.601") }; 
    23 const int IntersectionIDs[] = { 495, 601 };  
    24 const int NumIntersections = sizeof ( IntersectionIDs ); 
     23const int IntersectionIDs[] = { 495, 601 }; 
     24const int NumLanes[] = { 6, 6 }; 
     25const int NumIntersections = sizeof ( IntersectionIDs )/sizeof(int); 
    2526 
    2627/* Entrance sections are hardwired for Aimsun scenario `zlicin_495_601.sce` */ 
     
    3738const int NumStatIds = sizeof(StatIds)/sizeof(int); 
    3839 
     40const 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 }; 
     55const 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). */ 
     61int 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. */ 
     69int * LaneQueuesStatPos; 
     70 
     71const 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 
    3987 
    4088const TCHAR * PatternsELS3[] = { TEXT("GetramELS3.dll"), TEXT("GetramELS3d.dll") }; 
     
    4391/* Offsets of `dt` components (dt is the vector returned by AimsunDS, it contains composite 
    4492   values of all measurements for all intersections in the system). */ 
    45 const int SignalPlanOffsets[] = {  0, 36 }; 
    46 const int MeasurementOffsets[]  = {  6, 42 }; 
     93const int SignalPlanOffsets[]  = {  0, 42 }; 
     94const int QueueLengthOffsets[] = {  6, 48 }; 
     95const int MeasurementOffsets[] = { 12, 54 }; 
    4796 
    4897AimsunDS::AimsunDS () : DS() 
     
    51100  Drv = RV ( "{" 
    52101    "495_VA  495_VB   495_VC   495_VD   495_VE   495_VF " 
     102    "495_QA  495_QB   495_QC   495_QD   495_QE   495_QF " 
    53103    "495_DVA 495_DVB  495_DVA1 495_DVB1 495_DVC  495_DVD  495_DVE  495_DVF  495_DVF1 " 
    54104    "495_S1  495_S2   495_S3   495_S4   495_S5   495_S5a " 
    55105    "601_VA  601_VB   601_VC   601_VD   601_VE   601_SE " 
     106    "601_QA  601_QB   601_QC   601_QD   601_QE   601_QSE " 
    56107        "601_DVA 601_DVAa 601_DVB  601_DVBa 601_DVB1 601_DVC  601_DVD  601_DVD1 601_DSE 601_DVE 601_DSE1 601_DVE1 " 
    57108    "601_S6  601_S6a  601_S7   601_S8   601_S9   601_S9a " 
     
    60111    "}", 
    61112        "    1,      1,      1,      1,      1,       1,      " 
     113        "    1,      1,      1,      1,      1,       1,      " 
    62114        "    2,      2,      2,      2,      2,       2,      2,      2,      2," 
    63115        "    2,      2,      2,      2,      2,       2," 
     116        "    1,      1,      1,      1,      1,       1,      " 
    64117        "    1,      1,      1,      1,      1,       1,      " 
    65118        "    2,      2,      2,      2,      2,       2,       2,       2,       2,       2,       2,       2," 
     
    304357                StringCbCat ( szExePath, MAX_EXE_PATH, TEXT("\" ") ); 
    305358                StringCbCat ( szExePath, MAX_EXE_PATH, szELS3Path ); 
     359                StringCbCat ( szExePath, MAX_EXE_PATH, TEXT(" -a") ); 
    306360                StringCbCat ( szExePath, MAX_EXE_PATH, TEXT(" -l frm,det,spl") ); 
    307361                StringCbCat ( szExePath, MAX_EXE_PATH, TEXT(" -c 12.12.2007 00:00:00") ); 
     
    333387                TEXT("glob_stats.csv") 
    334388                ); 
     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        } 
    335407 
    336408} 
     
    345417    int res; 
    346418         
     419        /* Allocate space for the section statistics. 
     420           TODO: This is ugly. This should be part of VGS API. */ 
     421        sections_stats.queues = (int*) calloc ( MAX_SECTS*MAX_LANES, sizeof(int) ); 
     422        sections_stats.stats  = (vgs_se_stat_entry*) calloc ( MAX_SECTS, sizeof(vgs_se_stat_entry) ); 
     423 
    347424        /* Pass information about entrance sections to VGS API (and so to the 
    348425       GetramVGS extension that will be generating vehicles for these 
     
    436513                        printf ( "\n" ); 
    437514                } 
     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; 
    438551        } 
    439552 
     
    553666                printf(" but got no data ???\n"); 
    554667        } 
     668 
     669        /* Finally we will also read the last statistical information 
     670           from the VGS interface. */ 
     671        vgs_get_last_stats ( &sections_stats ); 
    555672}