TCTS

No preview image

1 collaborator

Default-person Adrien Lammoglia (Author)

Tags

african transport 

Tagged by Adrien Lammoglia over 9 years ago

demande responsive transport 

Tagged by Adrien Lammoglia over 9 years ago

flexible transport 

Tagged by Adrien Lammoglia over 9 years ago

para-transit transport 

Tagged by Adrien Lammoglia over 9 years ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.4 • Viewed 189 times • Downloaded 14 times • Run 0 times
Download the 'TCTS' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Info tab cannot be displayed because of an encoding error

Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; breeds
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

breed [vehicles vehicle]
breed [stations station]
breed [clients client]
breed [buses bus]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Variables
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

globals
[
list_final_destinations  ; list with the identifiant of each final_destination station
list_vehicles  ; list with the identifiant of each vehicle
list-buses; list with the identifiant of each bus
patterns  ; number of patterns simulated
total_nb_clients_final_destination   ; number of clients arrived at final_destination
total_nb_clients_created  ; number of clients created during the simulation (= patterns * nb-clients)
total_nb_clients_created_bus_line  ; number of clients created during the simulation, with a final_destination station of the bus line
servincing_rate  ; (total_nb_clients_final_destination / total_nb_clients_created) * 100
servincing_rate_bus_line  ; (total_nb_clients_final_destination / total_nb_clients_created_bus_line) * 100
client_station_rate  ; number of stations with some clients waiting a vehicle, divided by the total number of stations
max_nb_clients_droped
max_gross_potential_buses
max_gross_potential
max_clients_station_waiting   ; maximum number of clients waiting on a station
mean_pick_up_rate   ; mean of the pick up rate of vehicles
mean_pick_up_rate_buses ; mean of the pick up rate of buses
mean_vpk   ; mean of the vpk of vehicles
mean_vpk_buses  ; mean of the vpk of buses
list_stations_clients_waiting    ; list of stations with some clients waiting a vehicle
path_bus_line_1    ; list of stations of the bus line 1
path_bus_line_2    ; list of stations of the bus line 2 
nb_stations    ; number of stations
nb_destinations
contrainte-distance
nb_destination_manhattan
max_distance_links
shp_network
conect.O
conect.D
file_name
distance_station_manhattan
nb_bus_line    ; number of active bus line
final_destination_push
time
plot_patterns
mean_clients_waiting
mean_waiting_time_clients
hybrid_state ; model curently in operation
nb_clients_alive

]

vehicles-own
[
current_node  ; station where is the vehicle at the t time
next_node  ; next station reached by the vehicle (at t+1)
state   ; Variable allows the sequencing of vehicle's processes
nb_clients_picked_up  ; number of clients in the vehicle at the t time         
selected_clients  ; clients with the same final_destination of the vehicle, picked up at t+1
my_clients  ; list of clients in the vehicule at the t time
final_destination_vehicle ; station final_destination of the vehicle when it is occupied by one or more clients
nb_stations_crossed  ; number of stations crossed by the vehicle during the simulation
nb_stations_picked_up_clients  ; number of stations where the vehicle had picked up clients
pick_up_rate  ; (nb_stations_picked_up_clients / nb_stations_crossed)*100
total_nb_clients_picked_up    ; total number of clients picked up during the simulation
vpk ; ((total_nb_clients_picked_up * 5) / distance_travelled)
occupation_rate_vehicle ; (nb_clients_picked_up / capacity_occupation) * 100
distance_travelled    ; distance travelled during the simulation
push
s1
s2
s3
next_link_neighbors
last_node
next_link_neighbors_push
count_last_node
count_last_node_push
route
waiting
model; 1=potential 2=cooperation 3=random 4=distance 5=modulobus 6=clandos
]

buses-own
[
current_node  ; station where is the vehicle at the t time
next_node  ; next station reached by the vehicle (at t+1)
state   ; Variable allows the sequencing of bus's processes
nb_clients_picked_up  ; number of clients in the bus at the t time         
selected_clients  ; clients with the same final_destination of the bus, picked up at t+1
my_clients  ; list of clients in the bus at the t time
clients_to_drop    ; clients to drop at the current station
nb_stations_crossed  ; number of stations crossed by the bus during the simulation
nb_stations_picked_up_clients  ; number of stations where the bus had picked up clients
pick_up_rate  ; (nb_stations_picked_up_clients / nb_stations_crossed)*100
distance_travelled    ; distance travelled during the simulation
total_nb_clients_picked_up    ; total number of clients picked up during the simulation
vpk ; ((total_nb_clients_picked_up * 20) / (distance_travelled * 2))
direction ; direction of the bus (0 or 1) according to the order of the stations on the bus line
position_station_bus_line_1    ; position of the current station on the bus line 1
position_station_bus_line_2    ; position of the current station on the bus line 2
occupation_rate_bus ; (nb_clients_picked_up / capacity_occupation) * 100
bus_line??    ; id bus line of the bus
]

stations-own
[
final_destination? ; indicate if the station could be a final_destination for clients or not (0=not et 1=yes)
gross_potential  ; gross potential of attractivity of the station : number of clients picked up at the station + number of clients droped + frequentation of vehicles
net_potential  ; net potential of attractivity of the station : gross_potential / potential of the most attractive station
net_nb_clients_droped
nb_clients_waiting  ; number of clients waiting at the station
clients_station_waiting_net   ; nb_clients_waiting / max_clients_station_waiting
nb_clients_picked_up_station  ; total number of clients picked up at the station
nb_clients_droped  ; number of clients droped at the station
bus_line ; 0 = the station not belongs to a bus line, 1 = the station belongs to the bus line 1, etc...
frequentation ; number of passages of vehicles
serving_taxi    ; list of vehicles which will serve the stop
targeted
]

clients-own 
[ 
final_destination  ; final_destination final of the client (by using a transportation service)
station_to_wait  ; station where the client will wait a transportation service
bus_line?   ; indicate if the final final_destination of the client belongs to a bus line
direction-bus_line ; indicate in wich direction the client have to go on the bus line (0 or 1)
vehicle?  ; indicate if the client is in a vehicle (1) or not (0)
list_vehicles_serving_destination
push_of_vehicle
waiting_time
]

links-own 
[
gross_traffic  ; vehicle frequentation of the axe
net_traffic  ; vehicle frequentation of the axe / max vehicle frequentation of axes
]


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Initialisation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to create.clients ; create un nombre de clients grace a un slider r�partis al�atoirement dans l'espace
  ask n-of (nb_clients / 2) patches with [pcolor != 85 and pcolor != 52 ] 
  [
    sprout-clients 1  
    [
      set color white
      set shape "person"
      set size 0.6
      set list_vehicles_serving_destination []
      set push_of_vehicle []
    ]
  set total_nb_clients_created total_nb_clients_created + 1
  ]
end 

to create.clients.zone ; create un nombre de clients grace a un slider r�partis al�atoirement dans l'espace
  
  ask n-of nb_clients patches with [pcolor = 36] 
  [
    sprout-clients 1  
    [
      set color white
      set shape "person"
      set size 0.6
      set list_vehicles_serving_destination []
      set push_of_vehicle []
    ]
  set total_nb_clients_created total_nb_clients_created + 1
  ]
end 

to estimate.stations.potential ; Definir l'attractivite de chaque station a l'initialisation
  ask stations 
  [ 
    set gross_potential count clients with [distance myself <= attraction_radius_stations] ] 
    let maxpotentiel max [gross_potential] of stations 
    ask stations 
  [
    set net_potential (gross_potential / (maxpotentiel + 0.001))
    set size (5 * net_potential)
  ]
end 

to update.stations.potential  ; Mise a jour de l'attractivite des stations au cours de la simulation
  set max_gross_potential max [gross_potential] of stations
  set max_gross_potential_buses max [gross_potential] of stations
  set max_clients_station_waiting max [nb_clients_waiting] of stations
  set max_nb_clients_droped max [nb_clients_droped] of stations
  ask stations 
  [
    ifelse model_choice = "bus"
    [
      ask stations with [bus_line = 0]
      [
        set clients_station_waiting_net (nb_clients_waiting / (max_clients_station_waiting + 1))
        set size (5 * clients_station_waiting_net)
      ]
      ask stations with [bus_line > 0]
      [
        set net_potential (gross_potential / (max_gross_potential_buses + 1))
        set size (5 * net_potential)
        set net_nb_clients_droped (nb_clients_droped / (max_nb_clients_droped + 1))
        set color scale-color red net_nb_clients_droped 0 1
      ]
    ]
    [
      set net_potential (gross_potential / (max_gross_potential + 0.001) + 1)
      set size (2 * net_potential)]
  ] 
end 

to update.draw.traffic  ; Mise a jour de l'attractivite des liens au cours de la simulation
  let maxtraffic max [gross_traffic] of links
  ask links 
  [
    set net_traffic gross_traffic / maxtraffic ^ 0.9 
  ]
end 

to create.vehicles  ; create des vehicles (grace a un slider) se situant aleatoirement sur des stations
  
  create-vehicles nb_vehicles
  [
    set current_node one-of stations 
    move-to current_node
    set next_node one-of [link-neighbors] of current_node  
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set shape "van top" 
    set size 2.5 
    set color yellow
    set state 1 
    set my_clients [] 
    set selected_clients []
    set count_last_node 0
    set occupation_rate_vehicle 0
    set distance_travelled 1
    set total_nb_clients_picked_up 0
    set nb_clients_picked_up 0
    set nb_stations_crossed (nb_stations_crossed + 1)
    set nb_stations_picked_up_clients 0
    set push []
    set next_link_neighbors []
    set route []
    set waiting 0
    
    ifelse model_choice = "potential" 
      [set model 1]
      [ifelse model_choice = "cooperation"
        [set model 2]
        [ifelse model_choice = "random"
          [set model 3]
          [ifelse model_choice = "distance"
            [set model 4]
            [ifelse (model_choice = "modulobus" or model_choice = "mixte formal")
              [set model 5]
              [set model 6]
            ]
          ]
        ]
      ]
  ]
  set list_vehicles [who] of vehicles
end 

to create.vehicles.mixte.informal  ; create des vehicles (grace a un slider) se situant aleatoirement sur des stations
  
  create-vehicles nb_vehicles
  [
    set current_node one-of stations 
    move-to current_node
    set next_node one-of [link-neighbors] of current_node  
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set shape "van top" 
    set size 2.5 
    set color yellow
    set state 1 
    set my_clients [] 
    set selected_clients []
    set count_last_node 0
    set occupation_rate_vehicle 0
    set distance_travelled 1
    set total_nb_clients_picked_up 0
    set nb_clients_picked_up 0
    set nb_stations_crossed (nb_stations_crossed + 1)
    set nb_stations_picked_up_clients 0
    set push []
    set next_link_neighbors []
    set route []
    set waiting 0
    set model 2
  ]
  create-vehicles nb_vehicles
  [
    set current_node one-of stations 
    move-to current_node
    set next_node one-of [link-neighbors] of current_node  
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set shape "van top" 
    set size 2.5 
    set color grey
    set state 1 
    set my_clients [] 
    set selected_clients []
    set count_last_node 0
    set occupation_rate_vehicle 0
    set distance_travelled 1
    set total_nb_clients_picked_up 0
    set nb_clients_picked_up 0
    set nb_stations_crossed (nb_stations_crossed + 1)
    set nb_stations_picked_up_clients 0
    set push []
    set next_link_neighbors []
    set route []
    set waiting 0
    set model 6
  ]
  set list_vehicles [who] of vehicles
end 

to create.vehicles.mixte.flexible  ; create des vehicles (grace a un slider) se situant aleatoirement sur des stations
  
  create-vehicles nb_vehicles
  [
    set current_node one-of stations 
    move-to current_node
    set next_node one-of [link-neighbors] of current_node  
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set shape "van top" 
    set size 2.5 
    set color yellow
    set state 1 
    set my_clients [] 
    set selected_clients []
    set count_last_node 0
    set occupation_rate_vehicle 0
    set distance_travelled 1
    set total_nb_clients_picked_up 0
    set nb_clients_picked_up 0
    set nb_stations_crossed (nb_stations_crossed + 1)
    set nb_stations_picked_up_clients 0
    set push []
    set next_link_neighbors []
    set route []
    set waiting 0
    set model 2
  ]
  create-vehicles nb_vehicles
  [
    set current_node one-of stations 
    move-to current_node
    set next_node one-of [link-neighbors] of current_node  
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set shape "van top" 
    set size 2.5 
    set color red
    set state 1 
    set my_clients [] 
    set selected_clients []
    set count_last_node 0
    set occupation_rate_vehicle 0
    set distance_travelled 1
    set total_nb_clients_picked_up 0
    set nb_clients_picked_up 0
    set nb_stations_crossed (nb_stations_crossed + 1)
    set nb_stations_picked_up_clients 0
    set push []
    set next_link_neighbors []
    set route []
    set waiting 0
    set model 5
  ]
  set list_vehicles [who] of vehicles
end 

to create.vehicles.mixte.all  ; create des vehicles (grace a un slider) se situant aleatoirement sur des stations
  
  create-vehicles nb_vehicles
  [
    set current_node one-of stations 
    move-to current_node
    set next_node one-of [link-neighbors] of current_node  
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set shape "van top" 
    set size 2.5 
    set color grey
    set state 1 
    set my_clients [] 
    set selected_clients []
    set count_last_node 0
    set occupation_rate_vehicle 0
    set distance_travelled 1
    set total_nb_clients_picked_up 0
    set nb_clients_picked_up 0
    set nb_stations_crossed (nb_stations_crossed + 1)
    set nb_stations_picked_up_clients 0
    set push []
    set next_link_neighbors []
    set route []
    set waiting 0
    set model 6
  ]
  create-vehicles nb_vehicles
  [
    set current_node one-of stations 
    move-to current_node
    set next_node one-of [link-neighbors] of current_node  
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set shape "van top" 
    set size 2.5 
    set color red
    set state 1 
    set my_clients [] 
    set selected_clients []
    set count_last_node 0
    set occupation_rate_vehicle 0
    set distance_travelled 1
    set total_nb_clients_picked_up 0
    set nb_clients_picked_up 0
    set nb_stations_crossed (nb_stations_crossed + 1)
    set nb_stations_picked_up_clients 0
    set push []
    set next_link_neighbors []
    set route []
    set waiting 0
    set model 5
  ]
  create-vehicles nb_vehicles
  [
    set current_node one-of stations 
    move-to current_node
    set next_node one-of [link-neighbors] of current_node  
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set shape "van top" 
    set size 2.5 
    set color yellow
    set state 1 
    set my_clients [] 
    set selected_clients []
    set count_last_node 0
    set occupation_rate_vehicle 0
    set distance_travelled 1
    set total_nb_clients_picked_up 0
    set nb_clients_picked_up 0
    set nb_stations_crossed (nb_stations_crossed + 1)
    set nb_stations_picked_up_clients 0
    set push []
    set next_link_neighbors []
    set route []
    set waiting 0
    set model 2
  ]
  set list_vehicles [who] of vehicles
end 

to create.vehicles.mixte.frsn  ; create des vehicles (grace a un slider) se situant aleatoirement sur des stations
  
  create-vehicles nb_vehicles
  [
    set current_node one-of stations 
    move-to current_node
    set next_node one-of [link-neighbors] of current_node  
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set shape "van top" 
    set size 2.5 
    set color grey
    set state 1 
    set my_clients [] 
    set selected_clients []
    set count_last_node 0
    set occupation_rate_vehicle 0
    set distance_travelled 1
    set total_nb_clients_picked_up 0
    set nb_clients_picked_up 0
    set nb_stations_crossed (nb_stations_crossed + 1)
    set nb_stations_picked_up_clients 0
    set push []
    set next_link_neighbors []
    set route []
    set waiting 0
    set model 6
  ]
  create-vehicles nb_vehicles
  [
    set current_node one-of stations 
    move-to current_node
    set next_node one-of [link-neighbors] of current_node  
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set shape "van top" 
    set size 2.5 
    set color red
    set state 1 
    set my_clients [] 
    set selected_clients []
    set count_last_node 0
    set occupation_rate_vehicle 0
    set distance_travelled 1
    set total_nb_clients_picked_up 0
    set nb_clients_picked_up 0
    set nb_stations_crossed (nb_stations_crossed + 1)
    set nb_stations_picked_up_clients 0
    set push []
    set next_link_neighbors []
    set route []
    set waiting 0
    set model 5
  ]
  set list_vehicles [who] of vehicles
end 

to count.clients.waiting ; Compter le nombre de voyageurs a chaque station
  ask stations 
  [
    set nb_clients_waiting count clients-here
  ]
end 

to initialisation.agents
  ask vehicles [die]
  ask buses [die]
  ask clients [die]
  clear-output
  clear-all-plots
  clear-drawing
  set nb_stations count stations
  set total_nb_clients_created_bus_line 0
  set max_nb_clients_droped 0
  set max_gross_potential 0
  set max_clients_station_waiting 0
  set list_stations_clients_waiting []
  set client_station_rate 0
  set mean_clients_waiting 0
  set nb_clients_alive  0
  ask stations
    [
      set shape "circle"
      set color green
      set frequentation 0
      set gross_potential 0
      set net_potential 0
      set nb_clients_waiting 0
      set nb_clients_picked_up_station 0
      set nb_clients_droped 0
      set serving_taxi []
      set targeted 0
    ]
  ask stations with [final_destination? = 1] 
  [
    set color red
    set shape "flag"
  ]
  ask links 
    [
    set thickness 0.05
    set color 9.9
    set gross_traffic 0
    set net_traffic 0
    ]
  set patterns 0 
  set plot_patterns 1
  set total_nb_clients_final_destination 0 
  set total_nb_clients_created 0
  reset-ticks
  set time 0
  ifelse zone? = true
    [
      create.clients.zone
    ]
    [
      create.clients
      create.clients
    ]      
  ifelse model_choice = "bus"
    [
      ask stations with [bus_line > 0] 
      [
        set color orange
        set shape "flag"
      ]
      create.buses.first.bus.line.1
      create.buses.last.bus.line.1
      if nb_bus_line = 2 
        [
          create.buses.first.bus.line.2
          create.buses.last.bus.line.2
        ]
    ]
    [
      ifelse model_choice = "mixte informal"
      [create.vehicles.mixte.informal]
      [ifelse model_choice = "mixte flexible"
        [create.vehicles.mixte.flexible]
        [ifelse (model_choice = "mixte formal" or model_choice = "mixte rigid")
          [
            ask stations with [bus_line > 0] 
            [
              set color orange
              set shape "flag"
            ]
            create.buses.first.bus.line.1
            create.buses.last.bus.line.1
            if nb_bus_line = 2 
            [
              create.buses.first.bus.line.2
              create.buses.last.bus.line.2
            ]
            create.vehicles
          ]
          [ifelse model_choice = "mixte frsn"
            [create.vehicles.mixte.frsn]
            [ifelse model_choice = "mixte all"
              [create.vehicles.mixte.all]
              [create.vehicles]
            ]
          ]
        ]
      ]
    ]
    
  estimate.stations.potential
  update.stations.potential
  set list_stations_clients_waiting []
  choose.clients.final.destination
  set patterns 1
  ask vehicles [set state 3]
end 
 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; GO général
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go
  if ticks = 1 [reset-timer]
  ifelse model_choice = "potential" 
      [go.potential]
      [ifelse model_choice = "random"
        [go.random]
        [ifelse model_choice = "distance"
          [go.distance]
          [ifelse model_choice = "bus"
            [go.bus]
            [ifelse model_choice = "cooperation"
              [go.cooperate]
              [ifelse model_choice = "modulobus"
                [go.modulobus]
                [ifelse model_choice = "clandos"
                  [go.clandos]
                  [ifelse model_choice = "hybrid"
                    [go.hybrid]
                    [ifelse model_choice = "mixte informal"
                      [go.mixte.informal]
                      [ifelse model_choice = "mixte formal"
                        [go.mixte.formal]
                        [ifelse model_choice = "mixte flexible"                   
                          [go.mixte.flexible]
                          [ifelse model_choice = "mixte rigid"                   
                            [go.mixte.rigid]
                            [ifelse model_choice = "mixte frsn"                   
                              [go.mixte.frsn]
                              [go.mixte.all]
                            ]
                          ]
                        ]
                      ]
                    ]
                  ]
                ]    
              ]
            ]
          ]
        ]
      ]
end 









;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Generic code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to choose.clients.final.destination
  ask clients  
  [    
     if final_destination = 0
     [
       ifelse (model_choice = "bus" or model_choice = "mixte formal" or model_choice = "mixte rigid")
       [
         set final_destination one-of stations with [ final_destination? = 1]
         if [bus_line] of final_destination = 3
         [
           let nearest_station min-one-of stations with [ bus_line = 1 or bus_line = 2] [distance myself]
           let closest_bus_line [bus_line] of nearest_station
           set bus_line? closest_bus_line
           set station_to_wait nearest_station
           set total_nb_clients_created_bus_line total_nb_clients_created_bus_line + 1
         ]
         if [bus_line] of final_destination = 1
         [
           set bus_line? 1
           set total_nb_clients_created_bus_line total_nb_clients_created_bus_line + 1
           set station_to_wait max-one-of stations with [ bus_line = 1] [ gross_potential / (distance myself ^ 3 + 0.1) ]
           let id_station_to_wait [who] of station_to_wait
           let position_station_to_wait position id_station_to_wait path_bus_line_1
           let id_final_destination [who] of final_destination
           let position_id_final_destination position id_final_destination path_bus_line_1
           ifelse position_id_final_destination > position_station_to_wait
           [set direction-bus_line 0]
           [set direction-bus_line 1]
         ]
         if [bus_line] of final_destination = 2
         [
           set bus_line? 2
           set total_nb_clients_created_bus_line total_nb_clients_created_bus_line + 1
           set station_to_wait max-one-of stations with [ bus_line = 2] [ gross_potential / (distance myself ^ 3 + 0.1) ]
           let id_station_to_wait_noeud [who] of station_to_wait
           let position-station_to_wait-list position id_station_to_wait_noeud path_bus_line_2
           let id_station_to_wait_marche [who] of final_destination
           let position-finale_final_destination-list position id_station_to_wait_marche path_bus_line_2
           ifelse position-finale_final_destination-list > position-station_to_wait-list
           [set direction-bus_line 0]
           [set direction-bus_line 1]
         ]
         if [bus_line] of final_destination = 0
         [
           set station_to_wait max-one-of stations with [distance myself < max_walking_distance] [ gross_potential / (distance myself ^ 3 + 0.1) ]
         ]
       ]
       [ 
         set final_destination one-of stations with [ final_destination? = 1] 
         set station_to_wait max-one-of stations with [distance myself < max_walking_distance] [ gross_potential / (distance myself ^ 3 + 0.1) ]
       ]
     ] 
  ]  
end 

to move.clients ;
  ask clients [ set waiting_time waiting_time + 1 ]
  ask clients with [vehicle? = 0] 
  [
    face station_to_wait 
    ifelse distance station_to_wait >= moving_speed + 1
      [fd moving_speed ] 
      [if distance station_to_wait > 0 
        [ 
          move-to station_to_wait
          if station_to_wait = final_destination
            [
              set total_nb_clients_created (total_nb_clients_created - 1)
              die
            ]
        ] 
      ] 
  ]
end 

to circulate  ; Deplacement du vehicle optimis� en selon els diff�rents principes
  set heading towards next_node
  if length my_clients > 0 
    [
      ask clients with [vehicle? = [who] of myself] 
        [
          set heading [heading] of myself
        ]
    ] 
  ifelse distance next_node > moving_speed * speed_factor + 0.1 
  [
    fd moving_speed * speed_factor
    if length my_clients > 0 
      [
        ask clients with [vehicle? = [who] of myself] 
          [
            fd moving_speed * speed_factor
          ]
      ]
  ]
  [
    move-to next_node
    ifelse next_node = final_destination_vehicle
      [ set state 2 ]
      [
        if length my_clients > 0 
          [
            ask clients with [vehicle? = [who] of myself]  
              [
                move-to [next_node] of myself
              ]
           ]
        set state 1   
      ]  
  ]
  set distance_travelled  distance_travelled + 1
end 





;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; modulobus model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.modulobus
  if ticks = (patterns * nb_ticks_patterns - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
  ]
  choose.clients.station.modulobus
  move.clients
  count.clients.waiting
  go.vehicles.modulobus
  plotting
  draw.traffic
  update.draw.traffic
  tick
end 

to choose.clients.station.modulobus
  ask clients with [vehicle? = 0]
  [
    if [targeted] of final_destination = 1
    [
      set list_vehicles_serving_destination [serving_taxi] of final_destination
      set list_vehicles_serving_destination sort-by [[distance myself] of ?1 < [distance myself] of ?2] list_vehicles_serving_destination
      let vehicle_to_take first list_vehicles_serving_destination
      set push_of_vehicle [push] of vehicle_to_take
      set push_of_vehicle sort-by [[distance myself] of ?1 < [distance myself] of ?2] push_of_vehicle
      let best_station_push first push_of_vehicle
      if [distance myself] of best_station_push < max_walking_distance
        [
          set station_to_wait best_station_push
        ]
      
    ]
  ]
end 

to go.vehicles.modulobus  ; Sequence des procedures des vehicles
  ask vehicles with [model = 5]
  [
    ifelse state = 0 
      [choose.station.modulobus]
      [ifelse state = 1
        [pick.up.clients.modulobus]
        [ifelse state = 2
          [drop.clients.modulobus]
          [circulate]
        ]
      ]
  ]
end 

to choose.station.modulobus ; To choose the next stops of vehicles
  ifelse final_destination_vehicle = 0 
    [
      let na current_node
      set current_node next_node
      set next_node one-of [link-neighbors] of current_node
      let ns next_node 
      ask current_node 
        [ 
          ask link-with ns [ set gross_traffic (gross_traffic + 1)]
          set frequentation frequentation + 1
        ]
    ]
    [ 
      let dest final_destination_vehicle
      set last_node current_node
      set current_node next_node
      set next_link_neighbors [link-neighbors] of current_node
      set next_link_neighbors sort-by [[distance dest] of ?1 < [distance dest] of ?2] next_link_neighbors
      set next_node min-one-of [link-neighbors] of current_node [distance dest]
      while [next_node = last_node and length next_link_neighbors > 1]
          [
            set next_node one-of [link-neighbors] of current_node
          ]
      let ns next_node 
      ask current_node 
        [ 
          ask link-with ns [ set gross_traffic (gross_traffic + 1)]
          set frequentation frequentation + 1
          set gross_potential gross_potential + 1
        ]
    ]
  set nb_stations_crossed (nb_stations_crossed + 1)
  set state 3
end 

to make.push.modulobus
  set s1 current_node
  set final_destination_push final_destination_vehicle
  set push fput final_destination_push push
  set s2 next_node 
  set next_link_neighbors_push [link-neighbors] of s2
  set next_link_neighbors_push sort-by [[distance final_destination_push] of ?1 < [distance final_destination_push] of ?2] next_link_neighbors_push
  set s3 min-one-of [link-neighbors] of s2 [distance final_destination_push]
  while [s3 = s1 and length next_link_neighbors_push > 1]
          [
            set s3 one-of [link-neighbors] of s2
          ]
  while [s3 != final_destination_push]
  [
    set push fput s3 push
    set s1 s2
    set s2 s3
    set next_link_neighbors_push [link-neighbors] of s2
    set next_link_neighbors_push sort-by [[distance final_destination_push] of ?1 < [distance final_destination_push] of ?2] next_link_neighbors_push
    set s3 min-one-of [link-neighbors] of s2 [distance final_destination_push]
    while [s3 = s1 and length next_link_neighbors_push > 1]
          [
            set s3 one-of [link-neighbors] of s2
          ]
  ]
end 

to pick.up.clients.modulobus  ;
  if any? clients-here with [vehicle? = 0]
    [
      let nb-clients-ici [nb_clients_waiting] of next_node 
      if length my_clients = 0 
        [
          set final_destination_vehicle [final_destination] of one-of clients-here with [vehicle? = 0] 
          make.push.modulobus
          ask final_destination_vehicle 
          [ 
            set serving_taxi fput myself serving_taxi
            set targeted 1
          ]
        ] 
      let dest-vehicle final_destination_vehicle
      let nb-clients-possible count clients-here with [vehicle? = 0 and final_destination = dest-vehicle] 
      if nb-clients-possible > 0 
      [
        let nb-clients-a-prendre min (list (capacity_occupation - nb_clients_picked_up) nb-clients-possible) 
        if nb-clients-a-prendre = 1
        [ set selected_clients one-of clients-here with [vehicle? = 0 and final_destination = dest-vehicle ] ]
        if nb-clients-a-prendre > 1
        [ set selected_clients n-of nb-clients-a-prendre clients-here with [vehicle? = 0 and final_destination = dest-vehicle ] ]
        ask selected_clients 
        [ 
          set vehicle? [who] of myself  
          set color red 
        ]
        set color orange
        set my_clients fput selected_clients my_clients 
        set nb_clients_picked_up count clients with [vehicle? = [who] of myself ]
        ask next_node 
        [ 
          set nb_clients_picked_up_station (nb_clients_picked_up_station + [nb_clients_picked_up] of myself)
          set gross_potential (gross_potential + ([nb_clients_picked_up] of myself) * vehicle_atractivity_facteur)
        ]
        set occupation_rate_vehicle ((nb_clients_picked_up / capacity_occupation) * 100)
        set total_nb_clients_picked_up total_nb_clients_picked_up + nb_clients_picked_up
        set vpk ((total_nb_clients_picked_up * 20) / distance_travelled)
        set nb_stations_picked_up_clients (nb_stations_picked_up_clients + 1) 
        set pick_up_rate (nb_stations_picked_up_clients / nb_stations_crossed ) * 100
      ]    
    ]
    set state 0
end 

to drop.clients.modulobus  ;
  let n nb_clients_picked_up 
  ask final_destination_vehicle
    [
    set nb_clients_droped nb_clients_droped + n 
    set gross_potential (gross_potential + n)
    set total_nb_clients_final_destination total_nb_clients_final_destination + n
    set serving_taxi remove myself serving_taxi
    if empty? serving_taxi [set targeted 0]
    ]
  set nb_clients_picked_up 0 
  set my_clients [] 
  set selected_clients []
  set push []
  ask clients with [vehicle? = [who] of myself] 
    [die]
  set final_destination_vehicle 0
  set final_destination_push 0
  set s1 0
  set s2 0
  set s3 0
  set next_link_neighbors []
  set next_link_neighbors_push []
  set color yellow
  set state 1 
end 








;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; clandos model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.clandos
  if ticks = (patterns * nb_ticks_patterns - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
  ]
  move.clients
  count.clients.waiting
  go.vehicles.clandos
  plotting
  draw.traffic
  update.draw.traffic
  tick
end 

to go.vehicles.clandos  ; Sequence des procedures des vehicles
  ask vehicles with [model = 6]
  [
    ifelse state = 0 
      [choose.station.clandos]
      [ifelse state = 1
        [pick.up.clients.clandos]
        [ifelse state = 2
          [drop.clients]
          [circulate.clandos]
        ]
      ]
  ]
end 

to choose.station.clandos  ; Choisir le prochain noeud sur lequel va passer le vehicle
  ifelse final_destination_vehicle = 0 
    [
      set last_node current_node
      set current_node next_node
      let ne min-one-of [link-neighbors] of current_node [gross_potential] 
      set next_link_neighbors [link-neighbors] of current_node
      set next_link_neighbors sort-by [[gross_potential] of ?1 < [gross_potential] of ?2] next_link_neighbors
      set next_node max-one-of [link-neighbors] of current_node [gross_potential]
      while [next_node = last_node and length next_link_neighbors > 1]
          [
            set next_node one-of [link-neighbors] of current_node
          ]
      let ns next_node 
      ask current_node 
        [ 
          ask link-with ns [ set gross_traffic (gross_traffic + 1)]
          set frequentation frequentation + 1
        ]
    ]
    [ 
      let dest final_destination_vehicle
      set last_node current_node
      set current_node next_node
      set next_link_neighbors [link-neighbors] of current_node
      set next_link_neighbors sort-by [[distance dest] of ?1 < [distance dest] of ?2] next_link_neighbors
      set next_node min-one-of [link-neighbors] of current_node [distance dest]
      while [next_node = last_node and length next_link_neighbors > 1]
          [
            set next_node one-of [link-neighbors] of current_node
          ]
      let ns next_node 
      ask current_node 
        [ 
          ask link-with ns [ set gross_traffic (gross_traffic + 1)]
          set frequentation frequentation + 1
          set gross_potential gross_potential + 1
        ]
    ] 
  set nb_stations_crossed (nb_stations_crossed + 1)
  set state 3
end 

to pick.up.clients.clandos  ;
  ifelse any? clients-here with [vehicle? = 0]
    [
      let nb-clients-ici [nb_clients_waiting] of next_node 
      ifelse waiting = 0
      [
        if length my_clients = 0 
        [ set final_destination_vehicle [final_destination] of one-of clients-here with [vehicle? = 0] ] 
        let dest-vehicle final_destination_vehicle
        let nb-clients-possible count clients-here with [vehicle? = 0 and final_destination = dest-vehicle] 
        if nb-clients-possible > 0 
        [
          let nb-clients-a-prendre min (list (capacity_occupation - nb_clients_picked_up) nb-clients-possible) 
          if nb-clients-a-prendre = 1
          [ set selected_clients one-of clients-here with [vehicle? = 0 and final_destination = dest-vehicle ] ]
          if nb-clients-a-prendre > 1
          [ set selected_clients n-of nb-clients-a-prendre clients-here with [vehicle? = 0 and final_destination = dest-vehicle ] ]
          ask selected_clients 
          [ 
            set vehicle? [who] of myself  
            set color red 
          ]
          set color orange
          set my_clients fput selected_clients my_clients 
          set nb_clients_picked_up count clients with [vehicle? = [who] of myself ]
          ask next_node 
          [ 
            set nb_clients_picked_up_station (nb_clients_picked_up_station + [nb_clients_picked_up] of myself)
            set gross_potential (gross_potential + ([nb_clients_picked_up] of myself) * vehicle_atractivity_facteur) 
          ]
          set occupation_rate_vehicle (nb_clients_picked_up / capacity_occupation) * 100
        ]
      ]
      [
        let dest-vehicle final_destination_vehicle
        let nb-clients-possible count clients-here with [vehicle? = 0 and final_destination = dest-vehicle]
        if nb-clients-possible < 1 and nb_clients_picked_up < 2
        [ 
          ask clients with [vehicle? = [who] of myself]
          [
            set vehicle? 0
            set color white
          ]
          set final_destination_vehicle [final_destination] of one-of clients-here with [vehicle? = 0] 
        ] 
        let dest-vehicle2 final_destination_vehicle
        let nb-clients-possible2 count clients-here with [vehicle? = 0 and final_destination = dest-vehicle2] 
        if nb-clients-possible2 > 0 
        [
          let nb-clients-a-prendre min (list (capacity_occupation - nb_clients_picked_up) nb-clients-possible2) 
          if nb-clients-a-prendre = 1
          [ set selected_clients one-of clients-here with [vehicle? = 0 and final_destination = dest-vehicle2 ] ]
          if nb-clients-a-prendre > 1
          [ set selected_clients n-of nb-clients-a-prendre clients-here with [vehicle? = 0 and final_destination = dest-vehicle2 ] ]
          ask selected_clients 
          [ 
            set vehicle? [who] of myself  
            set color red 
          ]
          set color orange
          set my_clients fput selected_clients my_clients 
          set nb_clients_picked_up count clients with [vehicle? = [who] of myself ]
          ask next_node 
          [ 
            set nb_clients_picked_up_station (nb_clients_picked_up_station + [nb_clients_picked_up] of myself)
            set gross_potential (gross_potential + ([nb_clients_picked_up] of myself) * vehicle_atractivity_facteur)
          ]
          set occupation_rate_vehicle ((nb_clients_picked_up / capacity_occupation) * 100)
        ]
      ]
      ifelse occupation_rate_vehicle > 50
        [
          set state 0
          set waiting 0
          ask next_node 
          [ 
            set nb_clients_picked_up_station (nb_clients_picked_up_station + [nb_clients_picked_up] of myself)
            set gross_potential (gross_potential + ([nb_clients_picked_up] of myself) * vehicle_atractivity_facteur)
          ]
          set total_nb_clients_picked_up total_nb_clients_picked_up + nb_clients_picked_up
          set vpk ((total_nb_clients_picked_up * 20) / distance_travelled)
          set nb_stations_picked_up_clients (nb_stations_picked_up_clients + 1) 
          set pick_up_rate (nb_stations_picked_up_clients / nb_stations_crossed ) * 100
        ]
        [
          set state 1
          set waiting 1
        ]      
    ]
    [
      ifelse waiting = 0
      [set state 0]
      [set state 1]
    ]
end 

to circulate.clandos  ; Deplacement du vehicle optimis� en selon els diff�rents principes
  set heading towards next_node
  if length my_clients > 0 
    [
      ask clients with [vehicle? = [who] of myself] 
        [
          set heading [heading] of myself
        ]
    ] 
  ifelse distance next_node > moving_speed * speed_factor + 0.1 
  [
    fd moving_speed * speed_factor
    if length my_clients > 0 
      [
        ask clients with [vehicle? = [who] of myself] 
          [
            fd moving_speed * speed_factor
          ]
      ]
  ]
  [
    move-to next_node
    ifelse next_node = final_destination_vehicle
      [ set state 2 ]
      [
        if length my_clients > 0 
          [
            ask clients with [vehicle? = [who] of myself]  
              [
                move-to [next_node] of myself
              ]
           ]
        set state 1   
      ]  
  ]
  set distance_travelled  distance_travelled + 1
end 










;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; potential model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.potential
  if ticks = (patterns * nb_ticks_patterns - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
  ]
  move.clients
  count.clients.waiting
  go.vehicles.potential
  plotting
  draw.traffic
  update.draw.traffic
  tick
end 

to go.vehicles.potential  ; Sequence des procedures des vehicles
  ask vehicles with [model = 1]
  [
    ifelse state = 0 
      [choose.station.potential]
      [ifelse state = 1
        [pick.up.clients]
        [ifelse state = 2
          [drop.clients]
          [circulate]
        ]
      ]
  ]
end 

to choose.station.potential  ; Choisir le prochain noeud sur lequel va passer le vehicle
  ifelse final_destination_vehicle = 0 
    [
      set last_node current_node
      set current_node next_node
      let ne min-one-of [link-neighbors] of current_node [gross_potential] 
      set next_link_neighbors [link-neighbors] of current_node
      set next_link_neighbors sort-by [[gross_potential] of ?1 < [gross_potential] of ?2] next_link_neighbors
      set next_node max-one-of [link-neighbors] of current_node [gross_potential]
      while [next_node = last_node and length next_link_neighbors > 1]
          [
            set next_node one-of [link-neighbors] of current_node
          ]
      let ns next_node 
      ask current_node 
        [ 
          ask link-with ns [ set gross_traffic (gross_traffic + 1)]
          set frequentation frequentation + 1
        ]
    ]
    [ 
      let dest final_destination_vehicle
      set last_node current_node
      set current_node next_node
      set next_link_neighbors [link-neighbors] of current_node
      set next_link_neighbors sort-by [[distance dest] of ?1 < [distance dest] of ?2] next_link_neighbors
      set next_node min-one-of [link-neighbors] of current_node [distance dest]
      while [next_node = last_node and length next_link_neighbors > 1]
          [
            set next_node one-of [link-neighbors] of current_node
          ]
      let ns next_node 
      ask current_node 
        [ 
          ask link-with ns [ set gross_traffic (gross_traffic + 1)]
          set frequentation frequentation + 1
          set gross_potential gross_potential + 1
        ]
    ] 
  set nb_stations_crossed (nb_stations_crossed + 1)
  set state 3
end 









;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; distance model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.distance
  if ticks = (patterns * nb_ticks_patterns - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ] 
  ]
  move.clients
  count.clients.waiting
  go.vehicles.distance
  plotting
  draw.traffic
  update.draw.traffic
  tick
end 

to go.vehicles.distance  ; Sequence des procedures des vehicles
  ask vehicles with [model = 4]
  [
    ifelse state = 0 
      [choose.station.distance]
      [ifelse state = 1
        [pick.up.clients]
        [ifelse state = 2
          [drop.clients]
          [circulate]
        ]
      ]
  ]
end 

to choose.station.distance  ; Choisir le prochain noeud sur lequel va passer le vehicle
  ifelse final_destination_vehicle = 0 
    [
      let na current_node
      set current_node next_node
      let ne max-one-of [link-neighbors with [final_destination? = 0]] of current_node [distance myself] 
      set next_node min-one-of [link-neighbors with [final_destination? = 0]] of current_node [ distance myself ] 
      if next_node = na or next_node = ne
        [set next_node one-of [link-neighbors] of current_node]
      let ns next_node 
      ask current_node 
        [ 
          ask link-with ns [ set gross_traffic (gross_traffic + 1)]
          set frequentation frequentation + 1
        ]
    ]
    [ 
      let na current_node
      let dest final_destination_vehicle
      set current_node next_node 
      set next_node min-one-of [link-neighbors] of current_node [distance dest]
      while [next_node = na]
          [
            set next_node one-of [link-neighbors] of current_node
          ]
      let ns next_node 
      ask current_node 
        [ 
          ask link-with ns [ set gross_traffic (gross_traffic + 1)]
          set frequentation frequentation + 1
          set gross_potential gross_potential + 1
        ]
    ] 
  set nb_stations_crossed (nb_stations_crossed + 1)
  set state 3
end 











;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; random model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.random
  if ticks = (patterns * nb_ticks_patterns - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
  ]
  move.clients
  count.clients.waiting
  go.vehicles.random
  plotting
  draw.traffic
  update.draw.traffic
  tick
end 

to go.vehicles.random  ; Sequence des procedures des vehicles
  ask vehicles with [model = 3]
  [
    ifelse state = 0 
      [choose.station.random]
      [ifelse state = 1
        [pick.up.clients]
        [ifelse state = 2
          [drop.clients]
          [circulate]
        ]
      ]
  ]
end 

to choose.station.random  ; Choisir le prochain noeud sur lequel va passer le vehicle
  ifelse final_destination_vehicle = 0 
    [
      set current_node next_node
      set next_node one-of [link-neighbors] of current_node
      let ns next_node 
      ask current_node 
        [ 
          ask link-with ns [ set gross_traffic (gross_traffic + 1)]
          set frequentation frequentation + 1
        ]
    ]
    [  
     let dest final_destination_vehicle
      set last_node current_node
      set current_node next_node
      set next_link_neighbors [link-neighbors] of current_node
      set next_link_neighbors sort-by [[distance dest] of ?1 < [distance dest] of ?2] next_link_neighbors
      set next_node min-one-of [link-neighbors] of current_node [distance dest]
      while [next_node = last_node and length next_link_neighbors > 1]
          [
            set next_node one-of [link-neighbors] of current_node
          ]
      let ns next_node 
      ask current_node 
        [ 
          ask link-with ns [ set gross_traffic (gross_traffic + 1)]
          set frequentation frequentation + 1
          set gross_potential gross_potential + 1
        ]
    ]
  set nb_stations_crossed (nb_stations_crossed + 1)
  set state 3
end 












;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; cooperation model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.cooperate
  if ticks = ((patterns * nb_ticks_patterns) - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]  
  ]
  move.clients
  count.clients.waiting
  go.vehicles.cooperation
  plotting
  draw.traffic
  update.draw.traffic
  tick
end 

to go.vehicles.cooperation  ; Sequence des procedures des vehicles
  ask vehicles with [model = 2]
  [
    ifelse state = 0 
      [choose.station.cooperation]
      [ifelse state = 1
        [pick.up.clients.cooperation]
        [ifelse state = 2
          [drop.clients]
          [circulate]
        ]
      ]
  ]
end 

to choose.station.cooperation  ; Choisir le prochain noeud sur lequel va passer le vehicle
  ifelse final_destination_vehicle = 0 
   [
        ifelse empty? list_stations_clients_waiting
        [
          set current_node next_node
          set next_node one-of [link-neighbors] of current_node
          let ns next_node 
          ask current_node 
          [ 
            ask link-with ns [ set gross_traffic (gross_traffic + 1)]
            set frequentation frequentation + 1
          ]
        ]
        [
          set list_stations_clients_waiting sort-by [[distance myself] of ?1 < [distance myself] of ?2] list_stations_clients_waiting
          let station-a-desservir first list_stations_clients_waiting
          set last_node current_node
          set current_node next_node
          set next_link_neighbors [link-neighbors] of current_node
          set next_link_neighbors sort-by [[distance station-a-desservir] of ?1 < [distance station-a-desservir] of ?2] next_link_neighbors
          set next_node min-one-of [link-neighbors] of current_node [distance station-a-desservir]
          while [next_node = last_node and length next_link_neighbors > 1]
          [
            set next_node one-of [link-neighbors] of current_node
          ]
          if next_node = station-a-desservir and final_destination_vehicle = 0 [ set list_stations_clients_waiting remove-item 0 list_stations_clients_waiting]
          let ns next_node 
          ask current_node 
          [ 
            ask link-with ns [ set gross_traffic (gross_traffic + 1)]
            set frequentation frequentation + 1
            set gross_potential gross_potential + 1
          ]
        ]
   ]
   [
     let dest final_destination_vehicle
     set last_node current_node
     set current_node next_node
     set next_link_neighbors [link-neighbors] of current_node
     set next_link_neighbors sort-by [[distance dest] of ?1 < [distance dest] of ?2] next_link_neighbors
     set next_node min-one-of [link-neighbors] of current_node [distance dest]
     while [next_node = last_node and length next_link_neighbors > 1]
       [
         set next_node one-of [link-neighbors] of current_node
       ]
     let ns next_node 
     ask current_node 
       [ 
         ask link-with ns [ set gross_traffic (gross_traffic + 1)]
         set frequentation frequentation + 1
         set gross_potential gross_potential + 1
       ]
  ] 
  set nb_stations_crossed (nb_stations_crossed + 1)
  set state 3
end 

to cooperate
  ifelse [nb_clients_waiting] of next_node > 0
        [
           if not member? next_node list_stations_clients_waiting
           [
           set list_stations_clients_waiting fput next_node list_stations_clients_waiting
           ask next_node [set color blue]
           ]
        ]
        [
          set list_stations_clients_waiting remove next_node list_stations_clients_waiting
          ifelse [final_destination? = 0] of next_node 
          [ ask next_node [set color green]]
          [ ask next_node [set color red]]
          set state 0
        ]
end 

to pick.up.clients  ;
  if any? clients-here with [vehicle? = 0]
    [
      let nb-clients-ici [nb_clients_waiting] of next_node 
      if length my_clients = 0 
        [ set final_destination_vehicle [final_destination] of one-of clients-here with [vehicle? = 0] ] 
      let dest-vehicle final_destination_vehicle
      let nb-clients-possible count clients-here with [vehicle? = 0 and final_destination = dest-vehicle] 
      if nb-clients-possible > 0 
      [
        let nb-clients-a-prendre min (list (capacity_occupation - nb_clients_picked_up) nb-clients-possible) 
        if nb-clients-a-prendre = 1
        [ set selected_clients one-of clients-here with [vehicle? = 0 and final_destination = dest-vehicle ] ]
        if nb-clients-a-prendre > 1
        [ set selected_clients n-of nb-clients-a-prendre clients-here with [vehicle? = 0 and final_destination = dest-vehicle ] ]
        ask selected_clients 
        [ 
          set vehicle? [who] of myself  
          set color red 
        ]
        set color orange
        set my_clients fput selected_clients my_clients 
        set nb_clients_picked_up count clients with [vehicle? = [who] of myself ]
        ask next_node 
        [ 
          set nb_clients_picked_up_station (nb_clients_picked_up_station + [nb_clients_picked_up] of myself)
          set gross_potential (gross_potential + ([nb_clients_picked_up] of myself) * vehicle_atractivity_facteur)
        ]
        set occupation_rate_vehicle ((nb_clients_picked_up / capacity_occupation) * 100)
        set total_nb_clients_picked_up total_nb_clients_picked_up + nb_clients_picked_up
        set vpk ((total_nb_clients_picked_up * 20) / distance_travelled)
        set nb_stations_picked_up_clients (nb_stations_picked_up_clients + 1) 
        set pick_up_rate (nb_stations_picked_up_clients / nb_stations_crossed ) * 100
      ]    
    ]
    set state 0
end 

to pick.up.clients.cooperation  ; Choisir les clients et les embarquer
  ifelse any? clients-here with [vehicle? = 0]
    [
      let nb-clients-ici [nb_clients_waiting] of next_node 
      if length my_clients = 0 
        [ set final_destination_vehicle [final_destination] of one-of clients-here with [vehicle? = 0] ] 
      let dest-vehicle final_destination_vehicle
      let nb-clients-possibles count clients-here with [vehicle? = 0 and final_destination = dest-vehicle] 
      if nb-clients-possibles > 0 
      [
        let nb-clients-a-prendre min (list (capacity_occupation - nb_clients_picked_up) nb-clients-possibles) 
        if nb-clients-a-prendre = 1
        [ set selected_clients one-of clients-here with [vehicle? = 0 and final_destination = dest-vehicle ] ]
        if nb-clients-a-prendre > 1
        [ set selected_clients n-of nb-clients-a-prendre clients-here with [vehicle? = 0 and final_destination = dest-vehicle ] ]
        ask selected_clients 
        [ 
          set vehicle? [who] of myself  
          set color red 
        ]
        set color orange
        set my_clients fput selected_clients my_clients 
        set nb_clients_picked_up count clients with [vehicle? = [who] of myself ]
        ask next_node 
        [ 
          set nb_clients_picked_up_station (nb_clients_picked_up_station + [nb_clients_picked_up] of myself)
          set gross_potential (gross_potential + ([nb_clients_picked_up] of myself) * vehicle_atractivity_facteur)
          set nb_clients_waiting (nb-clients-ici - [nb_clients_picked_up] of myself)
        ]
        cooperate
        set nb_stations_picked_up_clients (nb_stations_picked_up_clients + 1) 
        set total_nb_clients_picked_up total_nb_clients_picked_up + nb_clients_picked_up
        set occupation_rate_vehicle (nb_clients_picked_up * 100 / capacity_occupation)
        set vpk ((total_nb_clients_picked_up * 20) / distance_travelled)
        set pick_up_rate (nb_stations_picked_up_clients / nb_stations_crossed ) * 100
      ]
      set state 0
    ]
    [
    set list_stations_clients_waiting remove next_node list_stations_clients_waiting
    ifelse [final_destination? = 0] of next_node 
    [ ask next_node [set color green]]
    [ ask next_node [set color red]]
    set state 0
    ]
end 










;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; bus model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to create.buses.first.bus.line.1  ; create des vehicles (grace a un slider) se situant aleatoirement sur des stations
  create-buses 1
  [
    set shape "bus" 
    set size 4 
    set color white
    set bus_line?? 1
    let first-station first path_bus_line_1
    set current_node station first-station
    set direction 0
    move-to current_node
    let id_station_current_node [who] of current_node
    set position_station_bus_line_2 100
    set position_station_bus_line_1 position id_station_current_node path_bus_line_1
    let id_station_next_node item (position_station_bus_line_1 + 1) path_bus_line_1
    set next_node station id_station_next_node 
    set nb_stations_crossed (nb_stations_crossed + 1) 
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set state 1 
    set my_clients [] 
    set selected_clients []
    set occupation_rate_bus 0
  ]
  set list-buses [who] of buses
end 

to create.buses.first.bus.line.2  ; create des vehicles (grace a un slider) se situant aleatoirement sur des stations
  create-buses 1
  [
    set shape "bus" 
    set size 4 
    set color white
    set bus_line?? 2
    let first-station first path_bus_line_2
    set current_node station first-station
    set direction 0
    move-to current_node
    let id_station_current_node [who] of current_node
    set position_station_bus_line_1 100
    set position_station_bus_line_2 position id_station_current_node path_bus_line_2
    let id_station_next_node item (position_station_bus_line_2 + 1) path_bus_line_2
    set next_node station id_station_next_node 
    set nb_stations_crossed (nb_stations_crossed + 1) 
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set state 1 
    set my_clients [] 
    set selected_clients []
    set occupation_rate_bus 0
  ]
  set list-buses [who] of buses
end 

to create.buses.last.bus.line.1  ; create des vehicles (grace a un slider) se situant aleatoirement sur des stations
  create-buses 1
  [
    set bus_line?? 1
    let last-station last path_bus_line_1
    set current_node station last-station
    set direction 1
    move-to current_node
    let id_station_current_node [who] of current_node
    set position_station_bus_line_2 100
    set position_station_bus_line_1 position id_station_current_node path_bus_line_1
    let id_station_next_node item (position_station_bus_line_1 - 1) path_bus_line_1
    set next_node station id_station_next_node
    set nb_stations_crossed (nb_stations_crossed + 1) 
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set shape "bus" 
    set size 4 
    set color white
    set state 1 
    set my_clients [] 
    set selected_clients []
    set occupation_rate_bus 0 
  ]
  set list-buses [who] of buses
end 

to create.buses.last.bus.line.2  ; create des vehicles (grace a un slider) se situant aleatoirement sur des stations
  create-buses 1
  [
    set bus_line?? 2
    let last-station last path_bus_line_2
    set current_node station last-station
    set direction 1
    move-to current_node
    let id_station_current_node [who] of current_node
    set position_station_bus_line_1 100
    set position_station_bus_line_2 position id_station_current_node path_bus_line_2
    let id_station_next_node item (position_station_bus_line_2 - 1) path_bus_line_2
    set next_node station id_station_next_node
    set nb_stations_crossed (nb_stations_crossed + 1) 
    let ns next_node 
    ask current_node 
       [ ask link-with ns [ set gross_traffic (gross_traffic + 1)]]
    set shape "bus" 
    set size 4 
    set color white
    set state 1 
    set my_clients [] 
    set selected_clients []
    set occupation_rate_bus 0 
  ]
  set list-buses [who] of buses
end 

to go.bus
  if ticks = (patterns * nb_ticks_patterns - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
  ]
  move.clients
  count.clients.waiting
  go.buses
  plotting
  tick
end 

to go.buses  ;
  ask buses
  [
    ifelse state = 0 
      [
        drop.clients.bus
        ifelse bus_line?? = 1 
        [choose.station.bus.1]
        [choose.station.bus.2]
        pick.up.clients.bus
      ]
      [circulate.bus]
  ]
end 

to choose.station.bus.1
  if position_station_bus_line_1 < 100
  [
    if [who] of next_node = last path_bus_line_1
    [set direction 1]
    if [who] of next_node = first path_bus_line_1
    [set direction 0]
    ifelse direction = 0
    [
      set current_node next_node
      let id_station_current_node [who] of next_node
      set position_station_bus_line_1 position id_station_current_node path_bus_line_1
      let id_station_next_node item (position_station_bus_line_1 + 1) path_bus_line_1
      set next_node station id_station_next_node
    ]
    [
      set current_node next_node
      let id_station_current_node [who] of next_node
      set position_station_bus_line_1 position id_station_current_node path_bus_line_1
      let id_station_next_node item (position_station_bus_line_1 - 1) path_bus_line_1
      set next_node station id_station_next_node
    ]
    let ns next_node
    ask current_node 
    [ 
      ask link-with ns [ set gross_traffic (gross_traffic + 1)]
      set frequentation frequentation + 1
    ]
    set nb_stations_crossed (nb_stations_crossed + 1)
  ]
end 

to choose.station.bus.2
  if position_station_bus_line_2 < 100
  [
    if [who] of next_node = last path_bus_line_2
    [set direction 1]
    if [who] of next_node = first path_bus_line_2
    [set direction 0]
    ifelse direction = 0
    [
      set current_node next_node
      let id_station_current_node [who] of next_node
      set position_station_bus_line_2 position id_station_current_node path_bus_line_2
      let id_station_next_node item (position_station_bus_line_2 + 1) path_bus_line_2
      set next_node station id_station_next_node
    ]
    [
      set current_node next_node
      let id_station_current_node [who] of next_node
      set position_station_bus_line_2 position id_station_current_node path_bus_line_2
      let id_station_next_node item (position_station_bus_line_2 - 1) path_bus_line_2
      set next_node station id_station_next_node
    ]
    let ns next_node
    ask current_node 
    [ 
      ask link-with ns [ set gross_traffic (gross_traffic + 1)]
      set frequentation frequentation + 1
    ]
    set nb_stations_crossed (nb_stations_crossed + 1)
  ]
end 

to pick.up.clients.bus ; 
  if any? clients-here with [vehicle? = 0 and bus_line? = [bus_line??] of myself and direction-bus_line = [direction] of myself]
    [
      let nb-clients-ici [nb_clients_waiting] of current_node  
      let nb-clients-possibles count clients-here with [vehicle? = 0 and bus_line? = [bus_line??] of myself and direction-bus_line = [direction] of myself] 
      if nb-clients-possibles > 0 
      [
        let nb-clients-a-prendre min (list (capacity_occupation_buses - nb_clients_picked_up) nb-clients-possibles) 
        if nb-clients-a-prendre > 0
        [
          if nb-clients-a-prendre = 1
          [ set selected_clients one-of clients-here with [vehicle? = 0 and bus_line? = [bus_line??] of myself and direction-bus_line = [direction] of myself]]
          if nb-clients-a-prendre > 1
          [ set selected_clients n-of nb-clients-a-prendre clients-here with [vehicle? = 0 and bus_line? = [bus_line??] of myself and direction-bus_line = [direction] of myself]]
          ask selected_clients 
          [ 
            set vehicle? [who] of myself  
            set color red 
          ]
          set color orange
          set my_clients fput selected_clients my_clients 
          set nb_clients_picked_up count clients with [vehicle? = [who] of myself ]
          ask current_node 
          [ 
            set nb_clients_picked_up_station (nb_clients_picked_up_station + [nb_clients_picked_up] of myself)
            set gross_potential (gross_potential + ([nb_clients_picked_up] of myself) * vehicle_atractivity_facteur)
          ]
          set occupation_rate_bus (nb_clients_picked_up * 100 / capacity_occupation_buses)
          set total_nb_clients_picked_up total_nb_clients_picked_up + nb_clients_picked_up
          set vpk ((total_nb_clients_picked_up * 20) / (distance_travelled))
          set nb_stations_picked_up_clients (nb_stations_picked_up_clients + 1) 
          set pick_up_rate (nb_stations_picked_up_clients / nb_stations_crossed ) * 100
        ]
      ]    
    ]
  set state 1
end 

to drop.clients  ;
  let n nb_clients_picked_up 
  ask final_destination_vehicle
    [
    set nb_clients_droped nb_clients_droped + n 
    set gross_potential (gross_potential + n)
    set total_nb_clients_final_destination total_nb_clients_final_destination + n 
    ]
  set nb_clients_picked_up 0 
  set my_clients [] 
  set selected_clients [] 
  ask clients with [vehicle? = [who] of myself] 
    [die]
  set final_destination_vehicle 0
  set route []
  set color yellow
  set state 1 
end 

to drop.clients.bus  ;
  set clients_to_drop count clients with [vehicle? = [who] of myself and final_destination = [next_node] of myself]
  set nb_clients_picked_up nb_clients_picked_up - clients_to_drop
  set selected_clients []
  set my_clients []
  if occupation_rate_bus < 1 [set color white]
  set occupation_rate_bus (nb_clients_picked_up * 100 / capacity_occupation_buses)
  let n clients_to_drop
  ask next_node 
    [
    set nb_clients_droped nb_clients_droped + n
    set gross_potential (gross_potential + n)
    set total_nb_clients_final_destination total_nb_clients_final_destination + n 
    ]
  ask clients with [vehicle? = [who] of myself and final_destination = [next_node] of myself] 
    [die] 
end   

to circulate.bus  ;
  set heading towards next_node
  if nb_clients_picked_up > 0 
    [
      ask clients with [vehicle? = [who] of myself] 
        [
          move-to myself
          set heading [heading] of myself
        ]
    ] 
  ifelse distance next_node > 1
  [
    fd moving_speed * speed_factor_bus
    if length my_clients > 0 
      [
        ask clients with [vehicle? = [who] of myself] 
          [
            fd moving_speed * speed_factor_bus
          ]
      ]
  ]
  [
    move-to next_node
    set state 0  
  ]
  set distance_travelled  distance_travelled + 1 
end 







;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; hybrid model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.hybrid
  if ticks = (patterns * nb_ticks_patterns - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
  ]
  ifelse (nb_clients_alive < 800)
  [
     set hybrid_state 1
     ask stations 
      [
        set targeted 0
        set serving_taxi []
      ]
     ask clients [ set list_vehicles_serving_destination []]
     set list_stations_clients_waiting []
     ask stations with [final_destination? = 0]
      [
        set color green
      ]
      ask stations with [final_destination? = 1]
      [
        set color red
      ]
    ask vehicles [set model 6]
    move.clients
    count.clients.waiting
    go.vehicles.clandos
    plotting
    draw.traffic
    update.draw.traffic
    tick
  ]
  [
    ifelse (nb_clients_alive > 1400 or mean_waiting_time_clients > 6000)
    [
      set hybrid_state 3
      set list_stations_clients_waiting []
      ask stations with [final_destination? = 0]
      [
        set color green
      ]
      ask stations with [final_destination? = 1]
      [
        set color red
      ]
      choose.clients.station.modulobus
      move.clients
      count.clients.waiting
      ask vehicles [set model 5]
      go.vehicles.modulobus
      plotting
      draw.traffic
      update.draw.traffic
      tick
    ]
    [
      set hybrid_state 2
      ask stations 
      [
        set targeted 0
        set serving_taxi []
      ]
      ask clients [ set list_vehicles_serving_destination []]
      ask vehicles [set model 2]
      move.clients
      count.clients.waiting
      go.vehicles.cooperation
      plotting
      draw.traffic
      update.draw.traffic
      tick
    ]
  ]
end 










;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; mixte informal model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.mixte.informal
  if ticks = ((patterns * nb_ticks_patterns) - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]  
  ]
  move.clients
  count.clients.waiting
  go.vehicles.cooperation
  go.vehicles.clandos
  plotting
  draw.traffic
  update.draw.traffic
  tick
end 











;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; mixte formal model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.mixte.formal
  if ticks = ((patterns * nb_ticks_patterns) - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]  
  ]
  choose.clients.station.modulobus
  move.clients
  count.clients.waiting
  go.buses
  go.vehicles.modulobus
  plotting
  draw.traffic
  update.draw.traffic
  tick
end 



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; mixte all model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.mixte.all
  if ticks = (patterns * nb_ticks_patterns - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
  ]
  go.vehicles.clandos
  go.vehicles.cooperation
  choose.clients.station.modulobus
  move.clients
  count.clients.waiting
  go.vehicles.modulobus
  plotting
  draw.traffic
  update.draw.traffic
  tick
end 






;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; mixte flexible model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.mixte.flexible
  if ticks = (patterns * nb_ticks_patterns - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
  ]
    go.vehicles.cooperation
  choose.clients.station.modulobus
  move.clients
  count.clients.waiting
  go.vehicles.modulobus
  plotting
  draw.traffic
  update.draw.traffic
  tick
end 




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; mixte rigid model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.mixte.rigid
  if ticks = ((patterns * nb_ticks_patterns) - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]  
  ]
  move.clients
  count.clients.waiting
  go.buses
  go.vehicles.clandos
  plotting
  draw.traffic
  update.draw.traffic
  tick
end 










;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; mixte frsn model
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to go.mixte.frsn
  if ticks = (patterns * nb_ticks_patterns - 1)
  [
    ifelse zone? = true
    [
      create.clients.zone
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
    [
      create.clients
      create.clients
      update.stations.potential
      choose.clients.final.destination
      set patterns (patterns + 1)
    ]
  ]
  go.vehicles.clandos
  choose.clients.station.modulobus
  move.clients
  count.clients.waiting
  go.vehicles.modulobus
  plotting
  draw.traffic
  update.draw.traffic
  tick
end 








;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Plots
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to draw.traffic  ; Trace des trajets en fonction du traffic
  ask links with [gross_traffic > 1] 
  [
    set thickness 0.01 + net_traffic 
    set color 135
  ]
end 

to plotting  ; Tracer le graphique du nombre de clients deposes sur chaque marche
  if ticks = (plot_patterns * nb_ticks_plot_pattern - 1)
  [
  
  ;;;; PICK UP RATE
  
  set-current-plot "pick up rate"
  ifelse model_choice = "bus"
  [
    set mean_pick_up_rate_buses mean [pick_up_rate] of buses
    set-current-plot-pen "buses"
    plot mean_pick_up_rate_buses
  ]
  [
    ifelse (model_choice = "mixte formal" or model_choice = "mixte rigid")
    [
      set mean_pick_up_rate_buses mean [pick_up_rate] of buses
      set-current-plot-pen "buses"
      plot mean_pick_up_rate_buses
      set-current-plot-pen "mean all"
        plot mean [pick_up_rate] of vehicles
    ]
    [
      ifelse model_choice = "mixte informal"
      [
        set-current-plot-pen "cooperation"
        plot mean [pick_up_rate] of vehicles with [model = 2]
        set-current-plot-pen "clandos"
        plot mean [pick_up_rate] of vehicles with [model = 6]
        set-current-plot-pen "mean all"
        plot mean [pick_up_rate] of vehicles
      ]
      [
          ifelse model_choice = "mixte flexible"
          [
            set-current-plot-pen "cooperation"
            plot mean [pick_up_rate] of vehicles with [model = 2]
            set-current-plot-pen "modulobus"
            plot mean [pick_up_rate] of vehicles with [model = 5]
            set-current-plot-pen "mean all"
            plot mean [pick_up_rate] of vehicles
          ]
          [
            ifelse model_choice = "mixte frsn"
            [
              set-current-plot-pen "clandos"
              plot mean [pick_up_rate] of vehicles with [model = 6]
              set-current-plot-pen "modulobus"
              plot mean [pick_up_rate] of vehicles with [model = 5]
              set-current-plot-pen "mean all"
              plot mean [pick_up_rate] of vehicles
            ]
            [
              set-current-plot-pen "mean all"
              plot mean [pick_up_rate] of vehicles
            ]
          ]
      ]
    ]
  ]
  
  
  ;;;; vpk
  
  set-current-plot "mean vpk"
  ifelse model_choice = "bus"
  [
    set mean_pick_up_rate_buses mean [vpk] of buses
    set-current-plot-pen "buses"
    plot mean_pick_up_rate_buses
  ]
  [
    ifelse (model_choice = "mixte formal" or model_choice = "mixte rigid")
    [
      set mean_vpk_buses mean [vpk] of buses
      set-current-plot-pen "buses"
      plot mean_vpk_buses
      set-current-plot-pen "mean all"
      plot mean [pick_up_rate] of vehicles
    ]
    [
      ifelse model_choice = "mixte flexible"
      [
        set mean_vpk mean [vpk] of vehicles
        set-current-plot-pen "mean all"
        plot mean_vpk
        set-current-plot-pen "cooperation"
        plot mean [vpk] of vehicles with [model = 2]
        set-current-plot-pen "modulobus"
        plot mean [vpk] of vehicles with [model = 5]
      ]
      [
           ifelse model_choice = "mixte informal"
           [
             set mean_vpk mean [vpk] of vehicles
             set-current-plot-pen "mean all"
             plot mean_vpk
             set-current-plot-pen "cooperation"
             plot mean [vpk] of vehicles with [model = 2]
             set-current-plot-pen "clandos"
             plot mean [vpk] of vehicles with [model = 6]
           ]
           [
             ifelse model_choice = "mixte frsn"
             [       
               set-current-plot-pen "mean all"
               plot mean [vpk] of vehicles
               set-current-plot-pen "modulobus"
               plot mean [vpk] of vehicles with [model = 5]
               set-current-plot-pen "clandos"
               plot mean [vpk] of vehicles with [model = 6]
             ]
             [
               set mean_vpk mean [vpk] of vehicles
               set-current-plot-pen "mean all"
               plot mean_vpk
             ]
           ]
      ]
    ]
  ]

  
  set-current-plot "waiting clients station rate"
  set client_station_rate ((count stations with [nb_clients_waiting > 0]) / nb_stations) * 100
  set-current-plot-pen "waiting clients station rate" plot client_station_rate
  
  set-current-plot "servincing rate"
  set servincing_rate (total_nb_clients_final_destination / total_nb_clients_created) * 100
  set-current-plot-pen "servincing rate" plot servincing_rate
  
  set-current-plot "mean of clients wainting"
  set mean_clients_waiting mean [nb_clients_waiting] of stations
  set-current-plot-pen "clients waiting" plot mean_clients_waiting
  
  set-current-plot "mean waiting time clients"
  set mean_waiting_time_clients mean [waiting_time] of clients
  set-current-plot-pen "waiting time" plot mean_waiting_time_clients
 
  set-current-plot "nb_clients_alive"
  plot nb_clients_alive
  
  if model_choice = "hybrid"
  [
    set-current-plot "hybrid_state"
    plot hybrid_state
  ]
  
  ifelse model_choice = "bus"
  [
    set-current-plot "occupation rate 1"
    plot [occupation_rate_bus] of one-of buses with [bus_line?? = 1]
    set-current-plot "occupation rate 2"
    plot [occupation_rate_bus] of one-of buses with [bus_line?? = 2]
  ]
  [
    ifelse (model_choice = "mixte formal" or model_choice = "mixte rigid")
    [
      set-current-plot "occupation rate 1"
      plot [occupation_rate_bus] of one-of buses
      set-current-plot "occupation rate 2"
      plot [occupation_rate_vehicle] of one-of vehicles
    ]
    [
      ifelse model_choice = "mixte informal"
      [
        set-current-plot "occupation rate 1"
        plot [occupation_rate_vehicle] of one-of vehicles with [model = 6]
        set-current-plot "occupation rate 2"
        plot [occupation_rate_vehicle] of one-of vehicles with [model = 2]
      ]
      [
        ifelse model_choice = "mixte frsn"
        [
          set-current-plot "occupation rate 1"
          plot [occupation_rate_vehicle] of one-of vehicles with [model = 6]
          set-current-plot "occupation rate 2"
          plot [occupation_rate_vehicle] of one-of vehicles with [model = 5]
        ]
        [
          ifelse model_choice = "mixte flexible"
          [
            set-current-plot "occupation rate 1"
            plot [occupation_rate_vehicle] of one-of vehicles with [model = 5]
            set-current-plot "occupation rate 2"
            plot [occupation_rate_vehicle] of one-of vehicles with [model = 2]
          ]
          [
            set-current-plot "occupation rate 1"
            if length list_vehicles > 1
            [
              plot [occupation_rate_vehicle] of (vehicle item 1 list_vehicles)
            ]
            set-current-plot "occupation rate 2"
            plot [occupation_rate_vehicle] of (vehicle item 0 list_vehicles)
          ]
        ]
      ]
    ]
  ]
  set time timer
  set plot_patterns (plot_patterns + 1)
  set nb_clients_alive count clients
  ]
end 

There is only one version of this model, created over 9 years ago by Adrien Lammoglia.

Attached files

File Type Description Last updated
bus line dakar.png jpeg Dakar network over 9 years ago, by Adrien Lammoglia Download
dakar reseau v8 world.csv word DNetwork of Dakar over 9 years ago, by Adrien Lammoglia Download
network TCTS v9.nlogo extension Network creator for TCTS over 9 years ago, by Adrien Lammoglia Download

This model does not have any ancestors.

This model does not have any descendants.