Systèmes Complexes : Une introduction par la pratique

Le site web du livre

1.2 Modèle des chenilles processionnaires : émergence d'un macroindividu

globals [
  D-xcor D-ycor
  A-xcor A-ycor
]

turtles-own [
  devant 
]

to setup 
  clear-all
  set D-xcor min-pxcor + 8 
  set D-ycor max-pycor - 8
  set A-xcor max-pxcor - 8 
  set A-ycor min-pycor + 8
  ask patch A-xcor A-ycor [set pcolor red]
  setup-tete
  reset-ticks
end

to setup-tete 
  create-turtles 1 [ 
     set xcor D-xcor
     set ycor D-ycor
     set size 2
     set shape "arrow"
     set color yellow
     set devant nobody 
     pen-down] 
end

to go
   go-tete
   go-suiveurs
   tick
end

to go-tete
   ask turtle 0 [
      ifelse (proche-arrive?) [
         set xcor A-xcor 
         set ycor A-ycor ]
      [
         while [not mouse-down?] [ ]
         facexy mouse-xcor mouse-ycor
         forward 1 ]
   ]
end

to go-suiveurs 
   create-turtles 1 [
      set xcor D-xcor 
      set ycor D-ycor
      set size 1 set shape "circle" 
      set devant turtle (who - 1)
   ]
   ask turtles with [0 < who] [face devant]
   ask turtles with [0 < who] [
      ifelse (proche-arrive?)
         [ set xcor A-xcor
           set ycor A-ycor] 
         [ forward 1 ]
   ]
end

to-report proche-arrive?
   report ((distancexy A-xcor A-ycor) < 3)
end	       
	     

haut

1.3 Modèle de la descente aux flambeaux : optimisation globale

globals [ 
   ... 
   delai
 ]

to setup 
   ...
   set delai 2
end

to go-suiveurs 
  if ((ticks mod delai) = 0) [ 
      create-turtles 1 [
         set xcor D-xcor
         set ycor D-ycor
         set size 1 set shape "circle" 
         set devant turtle (who - 1)
      ]
   ]
   ask turtles with [0 < who] [face devant]
   ask turtles with [0 < who] [
      ifelse (proche-arrive?) [
         set xcor A-xcor
         set ycor A-ycor]
      [forward 1]
   ]
end

to tracer
   if ([xcor] of turtle 0 = A-xcor and [ycor] of turtle 0 = A-ycor) [
      plot (longueur-ruban - longueur-diagonale)
   ]
end

to-report longueur-ruban
   let lg 0 ;; variable locale
   ask turtles with [0 < who] [set lg lg + distance devant]
   report lg
end

to-report longueur-diagonale
  report sqrt((A-xcor - D-xcor) ^ 2 + (A-ycor - D-ycor) ^ 2)
end
	     

haut

1.4 Modèle des anneaux d'agents processionnaires : cycle limite

to startup
   setup 
   set pas (2 * pi * rayon) / nombreSuiveurs 
end

to setup 
  clear-all
  set nombreSuiveurs 10
  set rayon 15
  setup-suiveurs
  reset-ticks
end

to setup-suiveurs 
  create-turtles nombreSuiveurs  [
     ifelse (who = 0) [
        set size 2 set color yellow set shape "arrow"
        set devant turtle (nombreSuiveurs - 1)
     ] 
     [ set devant turtle (who - 1)] 
  ]
  layout-circle (sort turtles) rayon
  ask turtle 0 [pen-down]
end

to go
   ask turtles [face devant]
   ask turtles [forward pas]
   tick
   tracer
end

to tracer
   set-current-plot-pen "ruban"
   plot longueur-ruban
   set-current-plot-pen "polygone"
   plot pas * nombreSuiveurs
end

to-report longueur-ruban
   let lg 0 ;; variable locale
   ask turtles [set lg lg + distance devant]
   report lg
end
	     

haut

1.5 Modèle en anneau : émergence de motifs

globals [... alpha]

turtles-own [... ancien-heading]

to go
   ask turtles [
      set ancien-heading heading 
      face devant 
      set heading (alpha * ancien-heading + (1 - alpha) * heading)
   ]
   ask turtles [forward pas]
   tick
   tracer
end
	     

haut