macro-neighbours-micro

No preview image

This model is seeking new collaborators — would you please help?

1 collaborator

Default-person Shipra Ghosh Ray (Author)

Tags

neighbors 

Tagged by Shipra Ghosh Ray about 8 years ago

politics 

Tagged by Shipra Ghosh Ray about 8 years ago

voter 

Tagged by Shipra Ghosh Ray about 8 years ago

voting 

Tagged by Shipra Ghosh Ray about 8 years ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 5.3.1 • Viewed 716 times • Downloaded 28 times • Run 0 times
Download the 'macro-neighbours-micro' modelDownload this modelEmbed this model

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


Info tab cannot be displayed because of an encoding error

Comments and Questions

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

Click to Run Model

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; PLEASE USE THE SPEED SLIDER TO MAKE     ;;;
;;; THE SPEED REALLY SLOW IN ORDER TO       ;;;
;;; VIEW IN DETAIL. THANKS. LOOK FORWARD TO ;;;
;;; CONSTRUCTIVE COMMENTS :)                ;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;



breed[red-influentials red-influential]   ;; classifies the red agent contesting as a separate breed
breed[blue-influentials blue-influential] ;; classifies the blue agent contesting as a separate breed
breed[persons person]                     ;; classifies the non-contesting agents as a different breed

persons-own [red-factor  ;; each person has a red-factor associated with it
             blue-factor ;; each person has a blue factor associated with it
             red-reward  ;; each person gets a reward in terms of its spatial
                         ;; relationship with red-influential
             blue-reward ;; each person gets a reward in terms of its spatial
                         ;; relationship with blue-influential

             ]
globals[red-influence  ;; the red-influential has an influence that spreads across all agents
        blue-influence ;; the blue-influential has an influence that spreads across all agents
        red-flux       ;; this deterines the changing prominence of the red-influential in the world
        blue-flux      ;; this determines the changing prominence of the blue-influential in the world
        red-count      ;; counts the number of persons with the colour red in the world after alignment
                       ;; has taken place
        blue-count     ;; counts the number of persons with the colour blue in the world after alignment
                       ;; has taken place
        neutral-count  ;; gives the number of beige persons in the world before and after alignment
        alignment      ;; gives the number of non-beige persons after alignment has taken place (sum of
                       ;; red and blue persons)
        ]

to setup
  clear-all

  create-red-influentials 1                  ;; there is only 1 agent contesting from the red side
  ask red-influentials [set color red       ;; set colour of red-influential to red
                        set size 1.5        ;; set size of red-influential to 1.5
                        setxy -2.344534561015166 5.675315858632209 ;; set aapproximate coordinates
                        fd 5]               ;; move forward 5
  set-default-shape red-influentials "flag" ;; the observer should see the red-influential appear
                                            ;; as a flag

  create-blue-influentials 1                ;; there is only 1 agent contesting from the blue side
  ask blue-influentials [set color blue     ;; set colour of blue-influential to blue
                         set size 1.5       ;; set size of blue-influential to 1.5
                         setxy 2.344534561015166 -5.675315858632209 ;; set approximate coordinates
                         fd 5]              ;; move forward 5
  set-default-shape blue-influentials "flag";; the observer should see the blue-influential appear
                                            ;; as a flag

  create-persons num-persons [              ;;creates non-contesting persons in the neighbourhood
                                            ;; their number can be determined from the num-persons
                                            ;; slider by the user
    set shape "person"                      ;; persons agents should appear in the persons shape
    set color 35 + 3                        ;; the color of these agents should be beige
    setxy random-xcor random-ycor           ;; they can be located anywhere at random in the world
    set red-reward 0                        ;; the initial red-reward at setup should be 0
    set blue-reward 0                       ;; the initial blue-reward at setup should be zero
    set red-influence 5                     ;; since red-influence is a global variable, it has to
                                            ;; be defined at setup and its value is chosen to be 5
    set blue-influence 5                    ;; since blue-influence is a global variable, it has to
                                            ;; be defined at setup and its value is chosen to be 5
                                            ;; since the views of red-influential and blue-influential
                                            ;; are both extreme and opposite, therefore it has been
                                            ;; assumed that they exert equal and opposite influence
                                            ;; in society their colours indicate the opposite viewpoints
                                            ;; but their influence has equal weight

     ]



  ask turtles [ create-links-with n-of 1 other turtles ] ;; in order to indicate that a neighbourhood exists,s,
                                                         ;; the turtles have been linked
                                                         ;; only turtles with links can align
                                                         ;; each turtle has only one neighbour at most

  repeat num-persons [layout-spring turtles links 0.2 5 1] ;; the spring layout has been chosen according to
                                                           ;; model documentation and its repetition number
                                                           ;; is dependent on the number of persons selected by
                                                           ;; the user

  reset-ticks
end 

to go

ask persons[align]                                          ;; persons are required to align

tick

ask turtles[flux-act]                                       ;; the turtles and not persons only are required to
                                                            ;; change alignment depending on changes in fluxes of red and blue

tick

ask persons [re-align]                                      ;; persons then perform the re-alignment procedure

tick
end 

to align


  ask persons [check-distance                               ;; persons perform the check-distance procedure which determines
                                                            ;; values of red-reward and blue-reward
               color-self                                   ;; persons color themselves and align according to changes to
                                                            ;; red-factor and blue-factor
  ]
end 

to check-distance                                            ;; this procedure calculate values of red-reward, blue-reward,
                                                             ;; red-factor and blue-factor

  ask persons [ if any? my-links [                           ;; this determines whether the persons are linked .
                                                             ;; i.e have neighbours


                  if (distancexy -2.344534561015166 5.675315858632209) > 10 [set red-reward 0 ]
                  ;; if the distance of person from specified coordinates is greater than 10, then,
                  ;; they are really not interested in aligning or non-aligning with red-influential
                  if (distancexy -2.344534561015166 5.675315858632209) <= 5 [set red-reward red-reward - 0.01]
                  ;; if the distance between person and specified coordinates is less than or equal to 5, then'
                  ;; they are interested in incrementally not aligning with red
                  if (distancexy -2.344534561015166 5.675315858632209) > 5 [set red-reward red-reward + 0.01]
                  ;; if the distance between person andspecified coordinates is greater than 5 and less than 10, then,
                  ;; they are interested in incrementally aligning with red
                  if (distancexy 2.344534561015166 -5.675315858632209) > 10 [set blue-reward 0]
                  ;; if the distance of person from specified coordinates is greater than 10, then,
                  ;; they are really not interested in aligning or non-aligning with blue-influential
                  if (distancexy 2.344534561015166 -5.675315858632209) <= 5 [set blue-reward blue-reward - 0.01]
                  ;; if the distance between person and specified coordinates is less than or equal to 5, then,
                  ;; they are interested in incrementally not aligning with blue
                  if (distancexy 2.344534561015166 -5.675315858632209) > 5 [set blue-reward blue-reward + 0.01]
                  ;; if the distance of person from specified coordinates is greater than 5, then,
                  ;; they are  interested in incrementally aligning with blue-influential
                  if (distancexy -2.344534561015166 5.675315858632209) = (distancexy 2.344534561015166 -5.675315858632209) [set red-reward red-reward = blue-reward]
                  ;; if the distance between the person and red-influential and person and blue-influential
                  ;; is equal, then, they are not interested in aligning with either candidate,
                  ;; even incrementally


                  set red-factor red-influence + red-reward
                  ;;  red-factor is unique to every person and is the sum of the global red-influence
                  ;;  and unique red-reward
                  set blue-factor blue-influence + blue-reward
                  ;;  blue-factor is unique to every person and is the sum of the global blue-influence
                  ;;  and unique blue-reward

                      ]

                                ]
end 

to color-self                                            ;; this procedure carries the visual nature of
                                                         ;; the alignment process

  ifelse red-factor > blue-factor                        ;; for every person, when red-factor is greater
                         [set color red]                 ;; than blue-factor, their colour changes to red
                         [set color blue]                ;; and if otherwise, their colour changes to blue;
                                                         ;; if both the factors are equal, then, their colour
  if red-factor = blue-factor [set color 35 + 3]         ;; remains beige
end 

to flux-act                                              ;; this procedure re-aligns the red and blue-influentials
                                                         ;; themselves

  set red-count count persons with [color = red]         ;; counts persons with colour red after alignment
  set blue-count count persons with [color = blue]       ;; counts persons with colour blue after alignment
  set neutral-count count persons with [color = 35 + 3]  ;; counts persons with colour beige after alignment

  set alignment count persons with [color = red] + count persons with [color = blue] ;; counts sum of persons
                                                                                     ;; with colour red or blue


  if blue-count + neutral-count = 0 [stop
                                     print "stopped as cannot divide by zero"
                                     ];; stops running the model as it is
  if red-count + neutral-count = 0 [stop
                                    print "stopped as cannot divide by zero"
                                    ] ;; impossible to divide by zero





  set red-flux red-count / (blue-count + neutral-count)  ;; calculates the force from the other colours
                                                         ;; on red-influential once alignment has taken place
  set blue-flux blue-count / (red-count + neutral-count) ;; calculates the force from the other colours
                                                         ;; on blue-influential once alignment has taken place



  if (red-flux) < 0.25 [ ask red-influentials [set breed blue-influentials ;; sets threshold for red-flux below which
                                                                           ;; its breed changes to blue-influential
                                               set color blue              ;; and colour changes to blue

                                               ]

                         ]
  if (blue-flux) < 0.25 [ask blue-influentials [set breed red-influentials ;; sets threshold for blue-flux below which
                                                                           ;; its breed changes to red-influential
                                                set color red              ;; and colour changes to red
                                                ]

                         ]
end 

to re-align                                            ;; the persons re-align if any change in alignment
                                                       ;; of influentials has taken place

  ifelse blue-factor > red-factor                      ;; for every person, when red-factor is greater
                         [set color red                ;; than blue-factor, their colour changes to red
                          fd 10 rt 90]                 ;; and if otherwise, their colour changes to blue;
                         [set color blue               ;; if both the factors are equal, then, their colour
                          fd 10 rt 90]                 ;; remains beige. When re-alignment takes place, the
                                                       ;; turtles move forward 10 and turn right by 90 degrees.
  if red-factor = blue-factor [set color 35 + 3]       ;; no movement for non-aligned turtles

  set red-count count persons with [color = red]         ;; counts persons with colour red after re-alignment
  set blue-count count persons with [color = blue]       ;; counts persons with colour blue after re-alignment
  set neutral-count count persons with [color = 35 + 3]  ;; counts persons with colour beige after re-alignment
end 

There is only one version of this model, created about 8 years ago by Shipra Ghosh Ray.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.