cassiotbatista / rwa-wdm-sim

RWA WDM Simulator: A Python simulator for the routing and wavelength assignment problem in WDM transparent networks with static traffic
GNU General Public License v3.0
18 stars 12 forks source link

bug during crossover #9

Open cassiotbatista opened 3 years ago

cassiotbatista commented 3 years ago
python -m rwa_wdm -t rnp -c 8 --rwa genetic-algorithm -y 2 -s 10 -d /tmp/results -p                                               
[2021-06-23 18:12:15] [__main__] INFO     Simulating 150 connection requests over rnp topology with 8 λ per link using genetic-algorith
m as RWA algorithm                                                                                                                     
Load:      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                                             
Blocks: Traceback (most recent call last):                                                                                             
  File "/home/cassio/anaconda3/lib/python3.8/runpy.py", line 194, in _run_module_as_main                                               
    return _run_code(code, main_globals, None,                                                                                         
  File "/home/cassio/anaconda3/lib/python3.8/runpy.py", line 87, in _run_code                                                          
    exec(code, run_globals)                                        
  File "/home/cassio/anaconda3/lib/python3.8/site-packages/rwa_wdm/__main__.py", line 107, in <module>                                 
    simulator(args)                                                                                                                    
  File "/home/cassio/anaconda3/lib/python3.8/site-packages/rwa_wdm/sim.py", line 172, in simulator                                     
    lightpath = rwa(net, args.y)                                   
  File "/home/cassio/anaconda3/lib/python3.8/site-packages/rwa_wdm/rwa/rwa.py", line 151, in genetic_algorithm_callback                
    route, wavelength = ga.run(net, k)                                                                                                 
  File "/home/cassio/anaconda3/lib/python3.8/site-packages/rwa_wdm/rwa/ga/ga.py", line 107, in run
    offspring = cross(mating_pool, self._population_size,                                                                              
  File "/home/cassio/anaconda3/lib/python3.8/site-packages/rwa_wdm/rwa/ga/env.py", line 113, in cross
    children.add_chromosome(Chromosome(son))                       
UnboundLocalError: local variable 'son' referenced before assignment     
cassiotbatista commented 3 years ago

The crossover function is sampling bad chromosomes from the mating pool. In RNP, for example, the "dad" chromosome is often a short route [3, 11], from DF to PE, which is impossible topology-wise.

from rwa_wdm.net import RedeNacionalPesquisa
RedeNacionalPesquisa(8).plot_topology()  # bad practice but OK we just wanna take a look

Figure_1

Log (try-except on env.cross()):

-> % python -m rwa_wdm -t rnp -c 8 --rwa genetic-algorithm -s 10  -d /tmp/results38 -p                                         
[2021-07-08 20:32:47] [__main__] INFO     Simulating 150 connection requests over rnp topology with 8 λ per link using genetic-
algorithm as RWA algorithm                                                                                                     
Load:      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                                                                                                 
Blocks:  0139                   
dad [3, 11]                                                                                                                    
mom [3, 9, 8, 7, 18, 17, 16, 15, 11]                                                                                           
Blocks: 0000  0000                                                                                                             
dad [3, 11]                                                                                                                    
mom [3, 22, 18, 17, 16, 15, 11]

Router indices (from rnp.py#L49):

This might be so for a couple of reasons, yet to be investigated: