NOTICE: The NetLogo team no longer recommends using NetLogo applets. Details here.

This page was automatically generated by NetLogo 5.1.0.

The applet requires Java 5 or higher. Java must be enabled in your browser settings. Mac users must have Mac OS X 10.4 or higher. Windows and Linux users may obtain the latest Java from Oracle's Java site.


In order for this to work, this file, your model file (BlahaV02.nlogo), and the files NetLogoLite.jar and NetLogoLite.jar.pack.gz must all be in the same directory. (You can copy NetLogoLite.jar and NetLogoLite.jar.pack.gz from the directory where you installed NetLogo.)

On some systems, you can test the applet locally on your computer before uploading it to a web server. It doesn't work on all systems, though, so if it doesn't work from your hard drive, please try uploading it to a web server.

You don't need to include everything in this file in your page. If you want, you can just take the HTML code beginning with <applet> and ending with </applet>, and paste it into any HTML file you want. It's even OK to put multiple <applet> tags on a single page.

If the NetLogoLite files and your model are in different directories, you must modify the archive= and value= lines in the HTML code to point to their actual locations. (For example, if you have multiple applets in different directories on the same web server, you may want to put a single copy of the NetLogoLite files in one central place and change the archive= lines of all the HTML files to point to that one central copy. This will save disk space for you and download time for your users.)

powered by NetLogo

view/download model file: BlahaV02.nlogo

WHAT IS IT?

(a general understanding of what the model is trying to show or explain)

HOW IT WORKS

(what rules the agents use to create the overall behavior of the model)

HOW TO USE IT

(how to use the model, including a description of each of the items in the Interface tab)

THINGS TO NOTICE

(suggested things for the user to notice while running the model)

THINGS TO TRY

(suggested things for the user to try to do (move sliders, switches, etc.) with the model)

EXTENDING THE MODEL

(suggested things to add or change in the Code tab to make the model more complicated, detailed, accurate, etc.)

NETLOGO FEATURES

(interesting or unusual features of NetLogo that the model uses, particularly in the Code tab; or where workarounds were needed for missing features)

RELATED MODELS

(models in the NetLogo Models Library and elsewhere which are of related interest)

CREDITS AND REFERENCES

(a reference to the model’s URL on the web if it has one, as well as any other necessary credits, citations, and links)

CODE

globals[
  all-colors
  colors-dissemination
  individualists
  available-colors
  available-distances
]


turtles-own[
  nei
  individualist?
  updates
  peak
  disposition 
  original-color
]


to setup
  ca
  set-patch-size (760 / world-size )
  resize-world 0 (world-size - 1) 0 (world-size - 1)
  if set-random-seed? [random-seed random-seed-number]
  ;; setting the list with all possible colors
  set all-colors [5 15 25 35 45 55 65 75 85 95 105 115 125 135]
  let x all-colors
  let y []
  ;; preparing list Y with starting set of colors; LENGTH of Y equals to slider variable INITIAL-COLORS
  repeat initial-colors[
    let z random (length x) 
    set y lput (item z x) y
    set x remove-item z x
  ]
  let n (agents-density * world-size * world-size  / 100)
  ask n-of n patches[
    sprout 1[
      ;; set DISPOSITION - needed for [4b]
      set-disposition
      ;; secondly, we randomly assign the color
      set color one-of y
      ;; thirdly, we check whether the agent is able to live the assigned value
      let xx position color all-colors
      let yy item xx disposition
      if yy > 1 [ 
        ;; now, we know that the asigned value is not possible for living
        ;; so, we have to try other values of Y, whether they are possible for living
        let zz y
        set zz remove color zz
        while [length zz > 0 and yy > 1] [
          set color one-of zz
          set zz remove color zz
          set xx position color all-colors
          set yy item xx disposition
        ]
      ]
      ;; but it is possible that the agent is able to live no value of Y
      ;; so, we randomly assign any value which the agent is able to live          
      while [yy > 1] [
          set color one-of all-colors
          set xx position color all-colors
          set yy item xx disposition
      ]
      ;; lastly, we set whether the agent is INDIVIDUALIST? or not
      ifelse (random-float 1) < individualist-chance [set individualist? true] [set individualist? false]
    ]
  ]
  ask turtles[
    ifelse random-radius?
    [set nei turtles in-radius (1 + random-float (nei-radius - 0.9))]
    [set nei turtles in-radius nei-radius]
  ]
  ;; setting list COLORS-DISSEMINATION
  monitor-dissemintion
  set individualists count turtles with [individualist? = true]
  reset-ticks
end


to go
  ;; HOW WILL THE PROCESS OF BLAHA'S SOCIAL FUNCTION WORK?
  ;; 1] in one turn we randomly pick up one neigrborhood
  ;; 2] we check the color homogeneity of neighborhood, BUT also whether there are some individualists
  ;; 3] in case it is not homogenous, we find style with smallest overall effort needed for change
  ;; 4] style is picked out from list of neighbors styles, the individualists put new styles on the list, as well
  ;; 4b] distance of styles is weighted by DISPOSITION
  ;; 4c] agents are not able to live the agreed value everytime
  ;; 5] all neighborhood adopts the effortless style
  ;; (effortless = the least sum of distances from present style of turtle and the style on the list)
  ;; 6] tick, go to [1]
  
  ;; ad [1]
  ask one-of turtles[
  ;ask turtles[
    ;; just for the orientation, we change color of the black patches to the white
    ask nei [ask patch-here [set pcolor white]]    
    ;; first of all, we save the original color before all other
    ask nei [set original-color color]
    ;; preparing for ad [2] and ad [4]
    let x [color] of nei
    let i [individualist?] of nei
    ;; preparing ad [4] - actively used colors in the neighborhood AND ad [2] number of individualists
    set x remove-duplicates x
    set i remove false i
    ;; ad [2]
    if length x > 1 or length i > 0[
      ;; ad [3]
      let unified-color effortless-style (x) (nei)
      ;; ad [5]
      ask nei[
        set color unified-color
        ;; but some agents are not able to live the consensus represented by UNIFIED-COLOR
        ;; they change to one of AVAILABLE-COLORS which is both liveable value for the agent closest to the consensus
        ;; so, now we have to find it!
        ;;
        ;; here we find the position of agreed color/value
        let xx position color all-colors
        ;; here we take a DISPOSITION on the same position
        let yy item xx disposition
        ;; now we have to copy AVAILABLE-COLORS and AVAILABLE-DISTANCES
        let zz1 available-colors
        let zz2 available-distances
        ;; now we take a position of the agreed color/value and distances of AVAILABLE-COLORS to it on ZZ1 and ZZ2
        let xxx position color available-colors
        ;; now we remove agreed color/value from the ZZ1 and ZZ2
        set zz1 remove-item xxx zz1
        set zz2 remove-item xxx zz2
        while [yy > 1 and length zz1 > 0] [
          ;; now we find position PP of the color with the minimal distance to the agreed color/value
          let pp position (min zz2) zz2
          ;; now we set color of the agent to the AVAILABLE-COLOR closest to the agreed color/value
          set color item pp zz1
          ;; now we have to remove color from the color lis and distance from the distance list
          set zz1 remove-item pp zz1
          set zz2 remove-item pp zz2
          ;; now we find out whether the taken value/color is liveable
          set xx position color all-colors
          set yy item xx disposition
        ]
        if yy > 1 [set color original-color]
        set updates (updates + 1)
      ]
    ]
  ]
  
  ;; ad [6]
  tick
  ;; checking whether one color dominates all turtles
  monitor-dissemintion
  if ending? [stop]
  if minimal-updates? [if min [updates] of turtles > minimal-updates [stop]]
  ask patches with [pcolor = white] [set pcolor black]
end


to set-disposition
  ;; firstly, I have to chose the PEAK (the best lived value)
  ;; the problem is, how to chose value randomly  - as a flat, random normal, or other distribution 
  set peak -1
  if peak-disposition-distribution = "flat" [set peak random-float 140]
  if peak-disposition-distribution = "random normal" [
    while [peak < 0 or peak > 140] [set peak random-normal 70 33]
    ]
  ;;secondly, we could assign weights of values to DISPOSITION according random distribution
  set disposition []
  foreach all-colors[
    ;;a1=random value between 0 and 140
    ;;a2=one of the all-colors values [5 15 25 35 45 55 65 75 85 95 105 115 125 135]
    ;;b2=(A2*4/140)-($A$1/35)
    ;;c2=2-(EXP(-(((B2)^2)/2)))*2
    let z1 (4 * ? / 140) - (peak / 35)
    let z2 maximum-weight - (exp(0 - ((z1 ^ 2) / 2)) * maximum-weight)
    set z2 precision z2 2
    set disposition lput z2 disposition
  ]
  ;;print disposition
end   


to monitor-dissemintion
  set colors-dissemination []
  foreach all-colors[
    set colors-dissemination lput (count turtles with [color = ?]) colors-dissemination
  ]
end


;; ad [3] and ad [4]
to-report effortless-style [x y]
  ;; finding of new colors by individualists inside nei
  let using-colors x
  ask y with [individualist?][
    ;; version where individualists take one of possible solution regardless it is alternative or not:
    set color (one-of all-colors)
    let xx position color all-colors
    let yy item xx disposition
    while [yy > 1] [
       set color one-of all-colors
       set xx position color all-colors
       set yy item xx disposition
    ]
    set using-colors lput color using-colors
    ;; now, the individualist just has changed his color to the new original one, so we have to rewrite his/her ORIGINAL-COLOR by the lived color/value
    set original-color color
  ]
  set using-colors remove-duplicates using-colors
  set using-colors sort using-colors
  ;; counting effort of whole NEI in case of changing COLOR to every value from USING-COLORS
  ;; no other than USING-COLORS could be used, because Blaha said that all values should be lived and
  ;; only individuals are able to live value which is not present in the NEI (we take it that they 
  ;; "invent" new value and immediately they live it and through this they present it to others in NEI)
  let effort []
  foreach using-colors[
    ;; Z is effort needed for change to respective color from the USING-COLORS
    let z 0
    ask y[
      ;; we find the WEIGHT/DISPOSITION of respective value/color
      let xxx position ? all-colors
      let weight item xxx disposition
      ;; now, we can compute the EFFORT Z
      set z z + (weight * abs(color - ?))
    ]
    set effort lput z effort
  ]
  ;; now we find the position of minimal effort and doing so we find the effortless color
  let p position (min effort) effort
  ;; we also save USING-COLORS to AVAILABLE-COLORS, i.e. all colors/values used 
  ;; during the discussion will be available for the later use in case the agreement will not be liveable for an agent
  set available-colors using-colors
  ;; paralelly, we also save distances of AVAILABLE-COLORS
  let agreement item p using-colors
  set available-distances []
  foreach using-colors [
    ;; note: because list operations take the first item in the case of tie and we want to
    ;; bring some randomness to the process of selection, so we add to the distance [RANDOM-FLOAT 1];
    ;; it is minimal noise, because distances are 0, 10, 20, 30 etc. to the 130, 
    ;; it is never e.g. 35, 26, 17 etc.
    set available-distances lput (abs(agreement - ?) + (precision random-float 1 3)) available-distances 
  ] 
  report item p using-colors
end


to-report ending?
  ;; value of ENDING? will be TRUE when all turtles will have same color,
  ;; it means that for one color will hold TRUE that number of tortles of this color equals to number of all turtles
  ;; for all the other colors it will hold FALSE 
  
  ;; set number of all turtles as N
  let n count turtles
  ;; initializing list M where we will save logical value whether respective color is used by all turtles
  let m []
  ;; rolling over list M and saving logical values whether respective colors are used by all turtles
  foreach all-colors[
    set m lput (n = count turtles with [color = ?]) m
  ]
  ;; reducing list M, we are only interested in whether all values are FALSE, or one value of them is TRUE
  set m remove-duplicates m
  ;print m
  ;; we know that only one color could be TRUE, it means used by all turtles, in that case LENGTH of lis M is 2
  ;; otherwise list M consists of only FALSE values and after reduction its LENGTH equals to 1
  report length m = 2
  ;; so, in case one color is used by all turtles LENGTH of list M is 2 and procedure ENDING? reports value TRUE
end