Systèmes Complexes : Une introduction par la pratique

Le site web du livre

6.2 Un unique gradient relatif à la zone de rassemblement

globals[
  nombre-agents 
  distance-rassemblement-ressource
]

patches-own [
   p-rassemblement
]

to setup-zone-rassemblement
   ask patches [
      set p-rassemblement (max-pxcor - distancexy 0 0)  
      set pcolor scale-color blue p-rassemblement 0 max-pxcor
   ]
end

to-report zone-rassemblement?
   let rayon 6
   report (distancexy 0 0 <= rayon)
end

o setup-zone-ressource
   let epaisseur 6
   ask patches [
      let d distance (patch 0 0)
      if (0 <= (d - distance-rassemblement-ressource) and 
               (d - distance-rassemblement-ressource) <= epaisseur) [
         set plabel "+"
         set plabel-color red
      ]
   ]
end

to-report zone-ressource?
   report (plabel != "")
end

to setup
  clear-all
  setup-zone-rassemblement
  setup-zone-ressource
  setup-turtles
  reset-ticks
end

to setup-turtles
   create-turtles nombre-agents [ 
      setxy 0 0 
      set shape "arrow"
      set color yellow
      set size 2.5
   ]
end

to go
   ask turtles [
      ifelse (porte-ressource?)
         [chercher-rassemblement]
         [chercher-ressource]]
   tick
   tracer
end

to-report porte-ressource?
  report label != ""
end

to chercher-rassemblement
   ifelse (zone-rassemblement?) 
      [livrer-ressource]
      [aller-vers-rassemblement]
end

to chercher-ressource
   ifelse (zone-ressource?)
      [prendre-ressource]
      [aller-vers-ressource]
end

to aller-vers-rassemblement
  let angle 10 
  set heading heading + (random angle) - (angle / 2)
  forward 1 + random-float 1 
end

to aller-vers-rassemblement 
  let p (patch-set
     patch-right-and-ahead 45 2
     patch-right-and-ahead 0 2
     patch-left-and-ahead 45 2)
  face max-one-of p [p-rassemblement] 
  forward 1 + random-float 1
end

to aller-vers-ressource
  let angle 10 
  set heading heading + (random angle) - (angle / 2)
  forward 1 + random-float 1
end

to prendre-ressource
   set label plabel 
   set label-color red
   set plabel "" 
   set plabel-color black
end

to livrer-ressource
   forward random 6 
   set heading (random 360)
   set label "" 
   set label-color black
   set pcolor red 
end

to tracer
   plot (count turtles with [porte-ressource?]) / nombre-agents
end
	     

haut

6.3 Gradient de ressources

globals[
   nombre-agents
   distance-rassemblement-ressource
   taux-diffusion-p-ressource
   taux-resorption-p-ressource
]

patches-own [
   p-rassemblement
   p-ressource
]

turtles-own [
   ; temps-de-portage 
]

to setup
  clear-all
  set distance-rassemblement-ressource 80
  set nombre-agents 200
  set taux-diffusion-p-ressource 0.80
  set taux-resorption-p-ressource 0.04
  setup-zone-rassemblement
  setup-zone-ressource
  setup-turtles
  reset-ticks
end

to chercher-rassemblement
  ifelse (zone-rassemblement?)
     [livrer-ressource]
     [deposer-p-ressource aller-vers-rassemblement]  
end

to prendre-ressource
   set label plabel 
   set label-color red
   set plabel "" 
   set plabel-color black
   ;set temps-de-portage  0 
end

   set p-ressource p-ressource + max-pxcor ^ 2 
   ;set p-ressource p-ressource + (max-pxcor -  1.9 * temps-de-portage) ^ 2
end

to aller-vers-rassemblement
  let p (patch-set patch-right-and-ahead 45 2
                   patch-right-and-ahead 0 2
                   patch-left-and-ahead 45 2)
  face max-one-of p [p-rassemblement]
  forward 1 + random-float 1
  ; set temps-de-portage  temps-de-portage + 1  
end

to aller-vers-ressource
  let p (patch-set patch-right-and-ahead 45 2
                   patch-right-and-ahead 0 2
                   patch-left-and-ahead 45 2)
  face max-one-of p [p-ressource]
  forward 1 + random-float 1
end

to go
  ask turtles [
     ifelse (porte-ressource?)
        [chercher-rassemblement]
        [chercher-ressource]
  ]
  diffuser-p-ressource
  resorber-p-ressource
  tick
  tracer
end

to diffuser-p-ressource
  diffuse p-ressource (taux-diffusion-p-ressource)
end

to resorber-p-ressource
  ask patches [
    set p-ressource (p-ressource * (1 - taux-resorption-p-ressource))
    if (p-ressource < 0.1)
       [set p-ressource 0] 
    if (pcolor != red) 
       [set pcolor scale-color green p-ressource 0 5000]
  ]
end
	     

haut

6.4.1 Zone de ressources unique

to setup-zone-ressource
   let rayon 6
   ask patches with [
     (distancexy distance-rassemblement-ressource 0) <= rayon]
     [
        set plabel "+"
        set plabel-color red
     ]
end
	     

haut

6.4.2 Deux zones de ressources situées à la même distance du centre

to tracer
   set-current-plot-pen "ressources +"
   plot (count turtles with [label = "+"]) / nombre-agents
   set-current-plot-pen "ressources *"
   plot (count turtles with [label = "*"]) / nombre-agents
end

to setup-zone-ressource 
   let rayon 6
   ask patches with 
       [(distancexy distance-rassemblement-ressource 0) <= rayon]
   [
      set plabel "+"
      set plabel-color red
   ]
   ask patches with 
       [(distancexy (- distance-rassemblement-ressource) 0) <= rayon]
   [
      set plabel "*"
      set plabel-color red
   ]
end

to setup-zone-ressource 
   let rayon 6
   ask patches with 
       [(distancexy distance-rassemblement-ressource 0) <= 2 * rayon]
   [
      set plabel "+"
      set plabel-color red
   ]
   ask patches with 
       [(distancexy (- distance-rassemblement-ressource) 0) <= rayon]
   [
      set plabel "*"
      set plabel-color red
   ]
end
	     

haut

6.4.3 Zones de ressources de tailles identiques situées à des distances différentes

to setup-zone-ressource 
   let rayon 6
   let delta-distance 30
   ask patches with 
       [(distancexy distance-rassemblement-ressource 0) <= rayon]
   [
      set plabel "+"
      set plabel-color red
   ]
   ask patches with 
   [(distancexy 
      (delta-distance - distance-rassemblement-ressource) 0) <= rayon]
   [
      set plabel "*"
      set plabel-color red
   ]
end

to setup-zone-ressource 
   let rayon 6
   ask patches with 
       [(distancexy distance-rassemblement-ressource 0) <= rayon] 
   [
     set plabel "+"
     set plabel-color red
   ]
   ask patches with 
       [(distancexy (- distance-rassemblement-ressource)  90) <= rayon] 
   [
      set plabel "*"
      set plabel-color red
   ]
   ask patches with 
       [(distancexy (- distance-rassemblement-ressource) -45) <= rayon] 
   [
     set plabel "-"
     set plabel-color red
   ]
end
	     

haut