MusiqueMulti-Agents

No preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 3D Preview 5 • Viewed 304 times • Downloaded 31 times • Run 1 time
Download the 'MusiqueMulti-Agents' modelDownload this modelEmbed this model

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


WHAT IS IT?

Mod?le exp?rimental multi-agents pour la cr?ation musicale.

Chaque agents a un comportement tr?s simple. La mise en oeuvre d'une multitude d'agents et leurs interactions entre eux (et avec un signal entrant), donnent une ?mergence de forme musicale.

HOW IT WORKS

Un agent poss?de un g?nome de 13 g?nes. Chaque g?ne code une particularit? de l'agent.

Il y a 3 codons distincts.

le codons musical:

le g?ne 0 code la fr?quence

le g?ne 1 code l'amplitude

le g?ne 2 code la dur?e

le g?ne 3 code le timbre

le codons comportemental:

le g?ne 4 code le temps que passe l'agent dans le stade "enfance"

le g?ne 5 code le temps que passe l'agent dans le stade "vieillesse"

le g?ne 6 code la vitesse de vieillissement de l'agent

le g?ne 7 code la vitesse de d?placement au sein de l'environnement.

le g?ne 8 code la distance de vision en radius

le g?ne 9 code la d?viance de d?placement

le g?ne 10 code la distance d'?coute (du/des signal/aux) en radius

le g?ne 11 code la dur?e de la m?moire de l'agent.

le codon adaptation:

le g?ne 12 code la fitness (adaptation) de l'agent.

Au d?but chaque agent re?oit un patrimoine au hasard.

Les r?gles de comportement sont les suivantes:

l'agent se d?place au hasard dans l'espace.

Premi?re r?gle:

Si dans son champ de vision il y a d'autres agents alors il se joint au groupe. Dans se groupe si il y a un ou plusieurs agents qui ont une fitness meilleure que lui alors il passe en mode apprentissage. Il choisit un g?ne au hasard dans le codon comportemental d'un agent pris au hasard (avec meilleure fitness).

Si il est "adulte" il peut se reproduire avec un autre adulte du groupe (AG).

Deuxi?me r?gle:

Si dans son champs de vision il y a un ou plusieurs signaux alors l'agent "?coute" le plus proche. Il prend la fr?quence la dur?e la v?locit? et le timbre du signal. Ce sont ces donn?es qu'il va garder en m?moire et jouer le temps donn? par le g?ne 11.

De plus l'agent aura la pr?f?rence de rester au plus pr?s des ?ventuels signaux .

Avec ces r?gles simples les agents "apprennent" ? maximiser leurs comportements pour voir et entendre.

HOW TO USE IT

Vous pouvez exp?rimenter divers univers.

Le g?nome est normaliser [o <= g?ne <= 1]. Donc se sont les sliders qui d?finissent l 'amplitude des param?tres du syst?me.

THINGS TO NOTICE

This section could give some ideas of things for the user to notice while running the model.

THINGS TO TRY

This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.

EXTENDING THE MODEL

Dans ce mod?le les agents jouent un seul ?v?nement musical.

Nous pourrions imaginer qu'ils calculent des datas plus compl?xes....

NETLOGO FEATURES

This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.

RELATED MODELS

Musique Multi-Agents

CREDITS AND REFERENCES

http://membres.lycos.fr/herveprovini/

You can use this without restriction

Comments and Questions

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

Click to Run Model

extensions [ sound ]

globals [mean-fitness timing temps population]
breed [agents]
breed [signal]
patches-own [ ]
agents-own [deplacement voisins signaux vie age genome freq amp duree timbre
  fitness deviance enfants signal-voisin couleur memoire]
signal-own [freq amp duree timbre signal-on-off]

to go
signal-in
algorithme-agents
if music = true [musique]
moving-agent
calculation
if population <= 0 [sound:stop-music stop] ; stop si plus d'agents
affichage-datas
end 

to setup
sound:stop-music
ca
cp
set timing 0
set population nombre-agent
setup-signal
setup-agent
reset-timer
end 

to setup-signal
create-signal nombre-signal [
set shape "circle"
set color red
set heading random-float 360
set pitch random-float 360
fd random 360
set duree 0
set timbre instrument-signal - 1
]
end 

to setup-agent
create-agents nombre-agent
[
set heading random-float 360 set pitch random-float 360 fd random-float 360
set vie duree-maximum-vie; duree maximale de vie
set duree 0 ; pret pour jouer un evenement musical
set age "jeune"
set color blue
set enfants 0
set fitness 0
set memoire 0
;normalisation du genome pour mutation et croisement
set genome []
set genome lput random-float 1 genome ; freq 0
set genome lput random-float 1 genome ; amp 1
set genome lput random-float 1 genome ; duree 2
set genome lput random-float 1 genome ; timbre 3
set genome lput random-float 1 genome ; constante jeunesse 4
set genome lput random-float 1 genome ; constante vieillesse 5
set genome lput random-float 1 genome ; constante de vieillissement 6
set genome lput random-float 1 genome ; constante de vitesse de deplacement 7
set genome lput random-float 1 genome ; constante de vision in radius 8
set genome lput random-float 1 genome ; constante de deviance de deplacement 9
set genome lput random-float 1 genome ; constante d'ecoute in radius 10
set genome lput random-float 1 genome ; constante de memoire 11
set genome lput 0 genome ; fitness 12
]
end 

to algorithme-agents
let sort-age-enfant 0
  let sort-fitness 0

ask agents [without-interruption ; Attention important pour parallelisme
[
set deplacement (item 7 genome)  * vitesse-deplacement
set deviance (item 9 genome) * deviance-agent
set duree duree - 1
set memoire memoire - 1
set vie vie - (random-float (item 6 genome) * vitesse-generation)
ifelse vie >= (duree-maximum-vie - ((item 4 genome) * %tranche-age)) [set age "jeune" set color blue + couleur]
  [ifelse vie >= ((item 5 genome) * %tranche-age) [set age "adulte" set color green + couleur]
    [ifelse vie > 0 [set age "vieux" set color yellow + couleur
      if random-float 1 <= %mutation [mutation-gene-vieux]]
        [die]]
          ]
set voisins agents in-radius ((item 8 genome) * distance-agent) with [self != myself]
if any? voisins [
  set color pink + couleur
  set fitness fitness + 1
  set genome replace-item 12 genome (fitness / max [fitness] of agents)
  set sort-fitness voisins with [[fitness] of self >= [fitness] of myself]
  set sort-age-enfant sort-fitness with [age = "adulte" and enfants < maximum-enfants]
  if random-float 1 <= %learning and any? sort-fitness
    [learning-agent one-of (sort-fitness with-max [fitness])]
  if random-float 1 <= %naissance and age = "adulte" and enfants < maximum-enfants and any? sort-age-enfant
    [accouplement who one-of (sort-age-enfant with-max [fitness])]
  ]
]
]
end 

to mutation-gene-vieux
set genome replace-item random 13 genome random-float 1
end 

to learning-agent [gagnant]
let gene-gagnant 0
  let item-gene 0

set item-gene random 6 + 6 ; selection du genome important
set gene-gagnant item item-gene [genome] of gagnant
set genome replace-item item-gene genome gene-gagnant
end 

to accouplement [moi lui]
let genome1 0
  let genome2 0
  let gene 0

set genome1 []
set genome2 []
foreach [0 1 2 3 4 5 6 7 8 9 10 11 12] [set gene ?
ifelse random-float 1 <= %croisement [
ifelse random-float 1 <= %mutation [
  set genome1 lput random-float 1 genome1] [set genome1 lput (item gene genome) genome1]
  ifelse random-float 1 <= %mutation [set genome2 lput random-float 1 genome2]
  [set genome2 lput (item gene [genome] of lui) genome2]
  ]
    [ifelse random-float 1 <= %mutation [
    set genome1 lput random-float 1 genome1] [set genome1 lput (item gene [genome] of lui) genome1]
    ifelse random-float 1 <= %mutation [set genome2 lput random-float 1 genome2]
    [set genome2 lput (item gene genome) genome2]
  ]
]
hatch-agents 1 [
set heading random-float 360 set pitch random-float 360 fd random-float 360
set vie duree-maximum-vie
set duree 0
set age "jeune"
set enfants 0
set memoire 0
ifelse random-float 1 <= 0.5 [set genome genome1] [set genome genome2] ; choix d'un des enfants
set fitness item 12 genome * max [fitness] of agents
]
set enfants enfants + 1
ask lui [set enfants enfants + 1]
if count agents > maximum-population [ask turtle moi [die] ask turtle lui [die]];mort des parents
end 

to musique
ask agents [
if (any? signaux or any? voisins) and duree <= 0 and memoire > 0 [
  sound:stop-note item timbre sound:instruments freq
  set fitness fitness + 0.5 ; a verifier si necessaire
  set genome replace-item 12 genome (fitness / max [fitness] of agents)
  set freq item 0 genome * 87 + 21
  set amp 127 - (item 1 genome * 127) ; inverse pycor pour velocite reelle
  set duree item 2 genome * tempo-musique
  set timbre floor (item 3 genome * 128)
  sound:play-note item timbre sound:instruments freq amp * volume duree
  ]
]
end 

to signal-in
let signal-winner 0

ask signal [
set duree duree - 1
if duree <= 0 [
 ;stop-note item timbre instruments freq
    ifelse random-float 1 <  %signal-in [
      show-turtle
      set signal-on-off "on"
      set heading random-float 360
      set pitch random-float 360
      fd random-float 360 * %mouvement-signal / 10
      set freq (abs zcor / max-pzcor) * 87 + 21
      set amp 127 - ((abs ycor / max-pycor) * 127) ; inverse pycor pour velocite reelle
      set duree (abs xcor / max-pxcor) * tempo-musique
      if random-float 1 < %change-timbre [set timbre random 128]
      ;if music = true [play-note item timbre instruments freq amp * volume duree]
      ]
        [
        hide-turtle
        set signal-on-off "off"
        set heading random-float 360
        set pitch random-float 360
        fd random-float 360 * %mouvement-signal / 10
        set duree (abs xcor / max-pxcor) * tempo-musique
        ]
]
]
ask agents [
set signaux signal in-radius ((item 10 genome) * distance-signal) with [signal-on-off = "on"]
ifelse any? signaux [
  set signal-winner one-of (signaux with-min [distance myself])
    set genome replace-item 0 genome [abs zcor / max-pzcor] of signal-winner
      set genome replace-item 1 genome [abs ycor / max-pycor] of signal-winner
        set genome replace-item 2 genome [abs xcor / max-pxcor] of signal-winner
          set genome replace-item 3 genome [timbre / 128] of signal-winner
              set fitness fitness + 1.5
                set genome replace-item 12 genome (fitness / max [fitness] of agents)
                  set memoire item 11 genome * duree-memoire
                    set couleur 4.9
                      ]
                        [set couleur 0]
]
end 

to moving-agent
ask agents [
ifelse any? signaux [
  set heading mean [heading] of signaux + random-float deviance - (deviance / 2)
  set pitch mean [pitch] of signaux + random-float deviance - (deviance / 2)
  set deplacement mean [distance myself] of signaux
  ]
    [ifelse any? voisins [
    set heading mean [heading] of voisins + random-float deviance - (deviance / 2)
    set pitch mean [pitch] of voisins + random-float deviance - (deviance / 2)
    set deplacement mean [distance myself] of voisins
    ]
      [
      set heading heading + random-float deviance - (deviance / 2)
      set pitch pitch + random-float deviance - (deviance / 2)
      set deplacement (item 7 genome)  * vitesse-deplacement
      ]
]
fd vitesse-deplacement * deplacement
]
end 

to calculation
set timing timing + 1
set temps timer
set population count agents
end 

to affichage-datas
if plot-genes != "off" [
set-current-plot "genomes agents"
set-plot-y-range 0 population
set-histogram-num-bars population
plot-pen-reset
if plot-genes = "gene0-freq" [set-current-plot-pen "gene0-freq"
  histogram [item 0 (item 0 ([genome] of agents ))] of agents]
if plot-genes = "gene1-amp" [set-current-plot-pen "gene1-amp"
  histogram [item 1 (item 0 ([genome] of agents ))] of agents]
if plot-genes = "gene2-duree" [set-current-plot-pen "gene2-duree"
  histogram [item 2 (item 0 ([genome] of agents ))] of agents]
if plot-genes = "gene3-timbre" [set-current-plot-pen "gene3-timbre"
  histogram [item 3 (item 0 ([genome] of agents ))] of agents]
if plot-genes = "gene4-jeunesse" [set-current-plot-pen "gene4-jeunesse"
  histogram [item 4 (item 0 ([genome] of agents ))] of agents]
if plot-genes = "gene5-vieillesse" [set-current-plot-pen "gene5-vieillesse"
  histogram [item 5 (item 0 ([genome] of agents))] of agents]
if plot-genes = "gene6-vieillissement" [set-current-plot-pen "gene6-vieillissement"
  histogram [item 6 (item 0 ([genome] of agents))] of agents]
if plot-genes = "gene7-deplacement" [set-current-plot-pen "gene7-deplacement"
  histogram [item 7 (item 0 ([genome] of agents))] of agents]
if plot-genes = "gene8-vision-radius" [set-current-plot-pen "gene8-vision-radius"
  histogram [item 8 (item 0 ([genome] of agents))] of agents]
if plot-genes = "gene9-deviance" [set-current-plot-pen "gene9-deviance"
  histogram [item 9 (item 0 ([genome] of agents))] of agents]
if plot-genes = "gene10-ecoute-radius" [set-current-plot-pen "gene10-ecoute-radius"
  histogram [item 10 (item 0 ([genome] of agents))] of agents]
if plot-genes = "gene11-memoire" [set-current-plot-pen "gene11-memoire"
  histogram [item 11 (item 0 ([genome] of agents))] of agents]
if plot-genes = "gene12-fitness" [set-current-plot-pen "gene12-fitness"
  histogram [item 12 (item 0 ([genome] of agents ))] of agents]
]
end 

There are 2 versions of this model.

Uploaded by When Description Download
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago MusiqueMulti-Agents Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.