Changeset 406

Show
Ignore:
Timestamp:
07/30/09 21:36:45 (15 years ago)
Author:
trnewman
Message:

Adding command line argument for using cross or random.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/trunk/src/cognitive_engines/DSA_CE/examples/gnuradio-examples/benchmark_dsa.py

    r395 r406  
    7777                return average_time 
    7878 
    79         def get_freq(hop_freq,probe_level,absent_time): 
     79        def get_freq(hop_freq,probe_level,absent_time,cross): 
    8080 
    8181                # Convert hop_freq to our unique channel list 
    8282 
    83                 if hop_freq == 462562500: 
    84                         channel = 1 
    85                 if hop_freq == 462712500: 
    86                         channel = 2 
    87                 if hop_freq == 467562500: 
    88                         channel = 3 
    89                 if hop_freq == 467712500: 
    90                         channel = 4 
    91  
    92                 currentParameters = Parameter(1) 
    93                 currentParameters[0].name = "channel" 
    94                 currentParameters[0].value = channel 
    95  
    96                 o = Observable(2) 
    97                 o[0].value = probe_level 
    98                 o[0].name = "energy" 
    99          
    100                 o[1].value = absent_time  
    101                 o[1].name = "communication_time" 
    102                  
    103                 # If time == 0 then we are scanning and we dont want to  
    104                 #  use this time in the averaging process. 
    105  
    106                 if absent_time != 0: 
    107                     UpdateParameterPerformance(currentParameters,1,o,1) 
    108  
     83                if cross == True: 
     84  
     85                        if hop_freq == 462562500: 
     86                                channel = 1 
     87                        if hop_freq == 462712500: 
     88                                channel = 2 
     89                        if hop_freq == 467562500: 
     90                                channel = 3 
     91                        if hop_freq == 467712500: 
     92                                channel = 4 
     93 
     94                        currentParameters = Parameter(1) 
     95                        currentParameters[0].name = "channel" 
     96                        currentParameters[0].value = channel 
     97 
     98                        o = Observable(2) 
     99                        o[0].value = probe_level 
     100                        o[0].name = "energy" 
     101         
     102                        o[1].value = absent_time  
     103                        o[1].name = "communication_time" 
     104                 
     105                        # If time == 0 then we are scanning and we dont want to  
     106                        #  use this time in the averaging process. 
     107 
     108                        if absent_time != 0: 
     109                                UpdateParameterPerformance(currentParameters,1,o,1) 
     110 
     111                        else: 
     112                                # Get the average communication time 
     113                                average_time = get_average_time(channel, absent_time) 
     114                                o[1].value = average_time  
     115                                o[1].name = "communication_time" 
     116                                UpdateParameterPerformance(currentParameters,1,o,2) 
     117 
     118                        p = Parameter(1) 
     119                        p = GetOptimalParameters(o,2,currentParameters,1); 
     120                 
     121                        channel = get_real_channel(int(p[0].value)) 
    109122                else: 
    110                     # Get the average communication time 
    111                     average_time = get_average_time(channel, absent_time) 
    112                     o[1].value = average_time  
    113                     o[1].name = "communication_time" 
    114                     UpdateParameterPerformance(currentParameters,1,o,2) 
    115  
    116                 p = Parameter(1) 
    117                 p = GetOptimalParameters(o,2,currentParameters,1); 
    118                  
    119                 channel = get_real_channel(int(p[0].value)) 
    120  
    121                 if channel < 8: 
     123                        channel = int(random.choice([1,7,8,14])) 
     124         
     125 
     126                if channel < 8: 
    122127                        hop_freq = float(1e6 * (462.5625+(channel-1)*0.025))#setting the centre freq frequency for sending packets 
    123                 else: 
     128                else: 
    124129                        hop_freq = float(1e6 * (467.5625+(channel-8)*0.025))#setting the centre freq frequency for sending packets       
    125  
    126                 stats_array[int(p[0].value)] = stats_array[int(p[0].value)] + 1 
     130                 
    127131                return channel,hop_freq #returning the channel number and hop frequency 
    128132         
     
    175179 
    176180        parser_tx = OptionParser(option_class=eng_option, conflict_handler="resolve") 
    177         parser_tx.add_option("", "--vtcross", action="store_true", default=False, 
     181         
     182        parser_tx.add_option("-c", "--cross", action="store_true", default=False, 
    178183                                help="Use the CROSS engine for DSA decisions: default is random.") 
    179184   
     
    223228        expert_grp_rx = parser_rx.add_option_group("Expert_rx") 
    224229        receive_path.add_options(parser_rx, expert_grp_rx) 
     230        parser_rx.add_option("-c", "--cross", action="store_true", default=False, 
     231                                help="Use the CROSS engine for DSA decisions: default is random.") 
    225232 
    226233        (options_rx, args_rx) = parser_rx.parse_args () 
     
    235242        ############# 
    236243 
     244 
     245 
     246        if options_rx.cross == True: 
     247                print "[[ Using the CROSS DSA Cognitive Engine ]]\n" 
     248        else: 
     249                print "[[ Using the RANDOM channel selection algorithm ]]\n" 
     250                 
    237251        # build the graph 
    238252 
     
    264278                                 
    265279                                if return_flag == 0: 
    266                                         ch,hop_freq = get_freq(hop_freq,ch_energy,0) 
     280                                        ch,hop_freq = get_freq(hop_freq,ch_energy,0,options_rx.cross) 
    267281                                else: 
    268                                         ch,hop_freq = get_freq(hop_freq,ch_energy,elapsed_time) 
     282                                        ch,hop_freq = get_freq(hop_freq,ch_energy,elapsed_time,options_rx.cross) 
    269283                                        return_flag = 0 
    270284