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 (Blaha.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: Blaha.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
]

turtles-own[
  nei
  individualist?
  updates
]

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 color one-of y
      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
  ;; 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[
    ;; 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
    ;print 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
        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]]
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 UNUSED COLORS: unused colors delimits the set in which the individualist could find new value
  ;let unused-colors all-colors  
  ;foreach x[
  ;  set unused-colors remove ? unused-colors
  ;]
  ;; finding of new colors by individualists inside nei
  let using-colors x
  ask y with [individualist?][
    ;; version where individualists prefere alternative solutions: 
    ;ifelse length unused-colors > 0 [set color (one-of unused-colors)] [set color (one-of all-colors)]
    ;; version where individualists take one of possible solution regardless it is alternative or not:
    set color (one-of all-colors)
    set using-colors lput color using-colors
  ]
  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 tohers 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[
      set z z + 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
  ;; for control purposes we could print all used lists and found values
  ;print using-colors
  ;print effort
  ;print p
  ;print item p using-colors
  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