Changeset 1081

Show
Ignore:
Timestamp:
06/11/10 00:37:01 (14 years ago)
Author:
ondrak
Message:

changing offset only ever n-th cycle and some minor changes

Location:
applications/doprava
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • applications/doprava/Zlicingw.cfg

    r1074 r1081  
    5454        // simulation in our case starts always at 00:00:00. Default simulation 
    5555        // length is 24 hours (24:00:00). 
    56         stop_time = "01:00:00"; 
     56        stop_time = "00:15:00"; 
    5757         
    5858}; 
  • applications/doprava/traffic_agent_offset.h

    r1071 r1081  
    2828        string accepted_from; 
    2929 
     30        //TODO currently useless list of neighbours asking for expectations 
    3031        list<string> seznam; 
    3132         
    3233        double car_leaving; //s; how long is 1 car leaving queue 
    3334 
     35        // some state variables 
    3436        bool need_exps; 
    3537        bool new_stable_state; 
     
    3739        bool final_state; 
    3840        //bool reset_negot_offset; 
     41 
     42        //! sum of final planned_offset values since last reach of cycle_count 
     43        int total_offset; 
     44        //! number of finished cycles since last reach of cycle_count 
     45        int negot_cycle; 
     46        //! after cycle_count cycles, we count avarege planned_offseta send it to Aimsun 
     47        int cycle_count; 
    3948 
    4049        //! counts all expected cars going from each lane, saves to outputs and rv_outputs 
     
    95104                RV rv_vector; 
    96105                vec vector; 
    97                 datalink exps2vector; 
    98106 
    99107                for (int i=0;i<lanes.length();i++) { 
     
    105113                                int l=0;                 
    106114                                for (int j=0;j<rv_recieved_exps.length();j++) { 
    107                                         t_cars_begin.set_size(l+1,true); 
    108                                         t_cars_end.set_size(l+1,true); 
    109                                         cars_count.set_size(l+1,true); 
    110115                                 
    111116                                        int result=rv_recieved_exps.name(j).find(lanes(i).inputs(k)+"-"); 
    112117                                        if (result>=0) { 
     118 
     119                                                t_cars_begin.set_size(l+1,true); 
     120                                                t_cars_end.set_size(l+1,true); 
     121                                                cars_count.set_size(l+1,true); 
     122 
    113123 
    114124                                                rv_vector = RV(rv_recieved_exps.name(j),3); 
     
    124134                                } 
    125135                                if (found) {                     
     136 
    126137                                        //counting rating 
    127138                                        string group = name+"_"+lanes(i).sg;            //e.g. 495_VA 
     
    138149                                        virtual_queue=lanehs(i)->queue; 
    139150 
    140                                         //cycle goes through all stopping points and counts queue lenght at these points 
     151                                        //cycle goes through all "stopping" points and counts queue lenght at these points 
    141152                                        do { 
    142153                                                k=min_i(t_cars_begin); 
     
    151162                                                                if (t_cars_end(k)<=t_act) { 
    152163                                                                        virtual_queue+=cars_count(k); 
    153                                                                         //jen prodlouzime, t_act zustava, odstranime k-ty predpoklad (mozna hned, mozna az na konci 
     164                                                                         
    154165                                                                        cars_count.del(k); 
    155166                                                                        t_cars_begin.del(k); 
     
    158169                                                                } 
    159170                                                                else { 
    160                                                                         //prodlouzujeme do casu t_green_begin,  
    161                                                                         //pak bud green_begin posuneme do t_act 
    162171                                                                        double pomer=(t_cars_begin(k)-t_act)/(t_cars_end(k)-t_cars_begin(k)); 
    163172                                                                        virtual_queue+=cars_count(k)*pomer; 
     
    166175                                                        } 
    167176                                                        else if (t_cars_begin(k)==t_act) { 
    168                                                                 //mixujeme az do t_cars_end nebo t_green_end 
    169                                                                 //posuneme t_act na jeden z tech casu 
    170177                                                                if (t_cars_end(k)<t_green_end) { 
    171178                                                                        virtual_queue+=cars_count(k)-(t_cars_end(k)-t_act)/car_leaving; 
     
    176183                                                                        t_cars_end.del(k); 
    177184                                                                } 
    178                                                                 //t_cars_end>=t_green_end 
     185                                                                //if t_cars_end>=t_green_end 
    179186                                                                else { 
    180187                                                                        virtual_queue+=cars_count(k)-(t_green_end-t_act)/car_leaving; 
     
    188195 
    189196                                                        } 
    190                                                         //t_cars_begin(k)>=t_act 
     197                                                        //if t_cars_begin(k)>=t_act 
    191198                                                        else { 
    192                                                                 //zkracujeme frontu az do t_cars_end(k) nebo t_green_end a posuneme t_act 
    193199                                                                if (t_cars_end(k)<t_green_end) { 
    194200                                                                        virtual_queue-=(t_cars_end(k)-t_act)/car_leaving; 
     
    201207                                                        } 
    202208                                                } 
     209                                                //if no other expectations found 
    203210                                                else { 
    204211                                                        virtual_queue-=(t_green_end-t_act)/car_leaving; 
     
    219226        //! finds best offset using recieved_exps. Returns found offset 
    220227        int find_best_offset(const int center, int interval) { 
    221                 //! rating if offset is rised 
     228                //! rating if offset is rised  
    222229                double rating_p; 
    223230                //! rating if offset is unchaged (=center) 
     
    368375        } 
    369376         
    370         //! returns offset value shifted to fit interval <0;cycle_length> 
    371         int normalize_offset(int offset) { 
    372                 while (offset<0 || offset>cycle_length) { 
    373                         if (offset<0) { 
    374                                 offset+=cycle_length; 
    375                         } 
    376                         else { 
    377                                 offset-=cycle_length; 
    378                         } 
    379                 } 
    380                 return offset; 
    381         } 
     377        /*!  
     378        returns offset value shifted to fit interval <-cycle_length/2;cycle_length/2>  
     379        or (when second parameter is false)) <0;cycle_length> 
     380        */ 
     381        int normalize_offset(int offset, bool zero=true) { 
     382                if (zero) { 
     383                        while ((offset<(-cycle_length/2)) || (offset>(cycle_length/2))) { 
     384                                if (offset<0) { 
     385                                        offset+=cycle_length; 
     386                                } 
     387                                else { 
     388                                        offset-=cycle_length; 
     389                                } 
     390                        } 
     391                        return offset; 
     392                } 
     393                else { 
     394                        while (offset<0 || offset>cycle_length) { 
     395                                if (offset<0) { 
     396                                        offset+=cycle_length; 
     397                                } 
     398                                else { 
     399                                        offset-=cycle_length; 
     400                                } 
     401                        } 
     402                        return offset; 
     403                } 
     404        } 
     405 
     406 
    382407         
    383408        //! returns value shifted to fit interval <0;cycle_length> 
     409        //currently not in use 
    384410        template<class T> T normalize(T time) { 
    385411                while (time<0 && time<cycle_length) { 
     
    394420        } 
    395421 
     422        //! converts t to string 
    396423        template <class T> inline string to_string (const T& t) 
    397424        { 
     
    414441        } 
    415442 
    416         //! returns index of smallest element in vectorsx 
     443        //! returns index of smallest element in vector 
    417444        int min_i(vec vector) { 
    418445                if (vector.length()>0) { 
     
    440467        double planned_rating; 
    441468        //! rating of planned next offset 
    442         double planned_next_rating; 
    443          
     469        double planned_next_rating;      
    444470        //! avarage speed of cars 
    445471        int VP; 
     
    653679                RV rv_exp; 
    654680 
    655                 std::ofstream ofile; 
    656                 ofile.open("greentimes.txt"); 
    657                 ofile.close(); 
    658  
    659681                car_leaving=2; 
    660682                VP=45; 
    661683                actual_time=0; 
     684                 
     685                negot_cycle=1; 
     686                cycle_count=5; 
     687                total_offset=0; 
    662688 
    663689                negot_offset=8; 
     
    681707 
    682708        void act(vec &glob_ut){ 
    683                 vec action; 
    684                 action.set_size(rv_action._dsize()); 
    685                  
    686                 ivec index = rv_action.dataind(RV(name+"_offset",1)); 
    687  
    688                 action(index(0))=planned_offset; 
     709                if (negot_cycle==cycle_count) { 
     710                 
     711                        vec action; 
     712                        action.set_size(rv_action._dsize()); 
     713                 
     714                        ivec index = rv_action.dataind(RV(name+"_offset",1)); 
     715 
     716                        action(index(0))=normalize_offset(total_offset/cycle_count, false); 
     717                        action2ds.filldown(action,glob_ut); 
     718 
     719                        total_offset=0; 
     720                        negot_cycle=1; 
     721 
     722                } 
     723                else { 
     724                        total_offset+=planned_offset; 
     725 
     726                        negot_cycle++; 
     727                } 
     728 
    689729                last_offset=planned_offset; 
    690                 action2ds.filldown(action,glob_ut); 
    691  
    692730                actual_time+=step_length; 
    693731        } 
     732 
    694733 
    695734};