modelo con redes

No preview image

1 collaborator

Default-person Emiliano Alvarez (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.3.1 • Viewed 202 times • Downloaded 26 times • Run 0 times
Download the 'modelo con redes' 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

extensions [ ]
globals
[
  a ; parámetro del t-type

  b ; parámetro de la cantidad de neighbors con el mismo c-type

  c ; parámetro de la cantidad de neighbors con distinto c-type

  t1-patches
  t2-patches
  c1-patches
  c2-patches
  max-align-turn
]
turtles-own
[
  vote
  c-type ;; crowding type

  t-type ;; taste type

  tt-type ;; taste type a medida que avanza el juego

  tt-type_old ; tt-type en el período anterior

  neighbors_b
  neighbors_c
  total_1
  total_2
  total_3
  total_4
  total_5
  u
  u_old
  u_1
  u_2
  u_3
  u_4
  u_5
  xcor_old
  ycor_old
  my-neighbors
  my-c-neighbors
  no-my-c-neighbors
  num-neighbors
  num-c-neighbors

;; para cuando hay dos ct_opciones, definimos la cantidad inicial de cada uno (con la barra)

]

to setup_3
  clear-all
  set max-align-turn 180
  crt 400 [
    move-to one-of patches with [ not any? turtles-here ]
  ]
ask turtles [
    ifelse ( random-float 1.000 <= c-type_1 ) [ set c-type 1 ] [ set c-type ( 2 + random ((ct_opciones - 1)))]
    ifelse ( random-float 1.000 <= t-type_1 ) [ set t-type 1 ] [ set t-type ( 2 + random ((tt_opciones - 1)))]
     recolor-agent ]

  ask turtles [
    ifelse ( ycor < 0 ) [ set tt-type 1 ] [ set tt-type 2 ]
    set tt-type_old tt-type
    set my-neighbors (other turtles) in-radius radio
    set num-neighbors count my-neighbors
    if ( num-neighbors = 0 )  [ set my-neighbors turtles ]
;    set shape "default"

;    set color white

  ]
  set t1-patches patches with [pycor < 0]
  ask t1-patches [ set pcolor white ]

  set t2-patches patches with [pycor > 0]
  ask t2-patches [ set pcolor white ]

  set c1-patches patches with [pxcor < 0]
  set c2-patches patches with [pxcor > 0]
;  set t1c2-patches patches with [pxcor < 0 and pycor > 0]

;  ask t1c2-patches [ set pcolor green ]


;  set t2c2-patches patches with [pxcor  0 and pycor > 0]

;  ask t2c2-patches [ set pcolor green + 1]


;ask turtles

;    [ set c-type 1 + random ( ct_opciones )

;      set t-type 1 + random ( tt_opciones ) recolor-agent]



ask turtles [
  if ( c-type = 1 ) [ set my-c-neighbors ( my-neighbors with [ c-type = 1 ] ) set no-my-c-neighbors ( my-neighbors with [ c-type != 1 ] ) ]
  if ( c-type = 2 ) [ set my-c-neighbors ( my-neighbors with [ c-type = 2 ] ) set no-my-c-neighbors ( my-neighbors with [ c-type != 2 ] ) ]
  if ( c-type = 3 ) [ set my-c-neighbors ( my-neighbors with [ c-type = 3 ] ) set no-my-c-neighbors ( my-neighbors with [ c-type != 3 ] ) ]
  if ( c-type = 4 ) [ set my-c-neighbors ( my-neighbors with [ c-type = 4 ] ) set no-my-c-neighbors ( my-neighbors with [ c-type != 4 ] ) ]
  if ( c-type = 5 ) [ set my-c-neighbors ( my-neighbors with [ c-type = 5 ] ) set no-my-c-neighbors ( my-neighbors with [ c-type != 5 ] ) ]
  set num-c-neighbors count my-c-neighbors
  if ( num-c-neighbors = 0 )  [ set my-c-neighbors turtles ]
  ]
if ( comport = "Pavloviano" ) [
  set a 1
  set b 1
  set c 1
  ]
if  ( comport = "conformista" )
  [ set a 0
    set b 0
    set c 1
  ]
 if ( comport = "averso_perdida" )
 [ set a 1
   set b 1
   set c 2
  ]
if ( comport = "exclusivo" )
 [ set a 1
   set b -1
   set c -1
  ]
 ask turtles
     [ set total_1 count my-neighbors with [ c-type = 1 ]
       set total_2 count my-neighbors with [ c-type = 2 ]
       set total_3 count my-neighbors with [ c-type = 3 ]    ;; use two ask patches blocks so all patches compute "total"

       set total_4 count my-neighbors with [ c-type = 4 ]     ;; before any patches change their c-types

       set total_5 count my-neighbors with [ c-type = 5 ]
       if ( c-type = 1 ) [ set neighbors_b total_1 set neighbors_c total_2]
       if ( c-type = 2 ) [ set neighbors_b total_2 set neighbors_c total_1]
;       set neighbors_b count my-neighbors with [ c-type = ]

;       set neighbors_c count my-neighbors with [ c-type != c-type of myself ]


     set u_1 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 1 ) [ 1 ] [ 0 ] ) + b * ( neighbors_b / num-neighbors ) - c * ( neighbors_c / num-neighbors )
     set u_2 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 2 ) [ 1 ] [ 0 ] ) + b * ( neighbors_b / num-neighbors ) - c * ( neighbors_c / num-neighbors )
     set u_3 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 3 ) [ 1 ] [ 0 ] ) + b * ( neighbors_b / num-neighbors ) - c * ( neighbors_c / num-neighbors )
     set u_4 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 4 ) [ 1 ] [ 0 ] ) + b * ( neighbors_b / num-neighbors ) - c * ( neighbors_c / num-neighbors )
     set u_5 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 5 ) [ 1 ] [ 0 ] ) + b * ( neighbors_b / num-neighbors ) - c * ( neighbors_c / num-neighbors )
     set u max (list u_1 u_2 u_3 u_4 u_5) ]

 reset-ticks
end 

to go
  ask turtles
  [ set tt-type_old tt-type
    set u_old u
    set xcor_old xcor
    set ycor_old ycor
    set u max (list u_1 u_2 u_3 u_4 u_5)
]
  ask turtles [
    set my-neighbors (other turtles) in-radius radio
   if ( my-neighbors = 0 )  [ set my-neighbors turtles ]
    set num-neighbors count turtles
  ]
  ask turtles
    [    set tt-type ifelse-value (( u_1 > u_2 ) and (u_1 > u_3) and (u_1 > u_4)) [ 1 ][
          ifelse-value ((u_2 > u_1) and (u_2 > u_3) and (u_2 > u_4)) [ 2 ] [
           ifelse-value ((u_3 > u_1) and (u_3 > u_2) and (u_3 > u_4))[ 3 ] [
            ifelse-value ((u_4 > u_1) and (u_4 > u_2) and (u_4 > u_3)) [ 4 ][ 1 + random ct_opciones ] ] ] ]
    recolor-agent ]

; mutaciones

ask turtles
 [ if ( random-float 1.000 <= prob_mut ) [ set tt-type 1 + random ct_opciones ]
     recolor-agent ]


ask turtles
[ if ( tt-type = 1 and ycor > 0 ) [ set ycor ( - ycor )]
  if ( tt-type = 2 and ycor < 0 ) [ set ycor ( - ycor ) ]

  ]

; ahora se mueve

ask turtles
[ if ( tt-type = 1 and tt-type_old != 1) [ move-to one-of t1-patches ]
  if ( tt-type = 1 and tt-type_old = 1 and  u >= u_old and ycor <= -1 ) [ align fd 1 right 2] ;[ move-to one-of t1-patches ]

  if ( tt-type = 1 and tt-type_old = 1 and  u < u_old  and ycor <= -1 ) [ align fd 0  left 2] ;[ move-to one-of t1-patches ]

;  if ( tt-type = 1 and ycor >= - 1  ) [ move-to one-of t1-patches ]


  if ( tt-type = 2 and tt-type_old != 2) [ move-to one-of t2-patches ]
  if ( tt-type = 2 and tt-type_old = 2 and  u >= u_old  and ycor >= 1 ) [ align fd 1 right 2 ]
  if ( tt-type = 2 and tt-type_old = 2 and  u < u_old  and ycor >= 1 ) [ align fd 0 left 2 ] ;[ move-to one-of t2-patches ]

;  if ( tt-type = 2 and ycor <= 0  ) [ move-to one-of t2-patches ]


  ifelse (tt-type != t-type) [ set shape "square" ] [ set shape "default"]
 ;ifelse ( c-type = 1) [move-to one-of c1-patches ] [move-to one-of c2-patches ]

]

;export-interface (word "frame_25" but-first (word (100 + ticks)) ".png")


tick
; cuenta nuevamente

ask turtles
  [ set total_1 count my-neighbors with [ c-type = 1 ]
    set total_2 count my-neighbors with [ c-type = 2 ]
    set total_3 count my-neighbors with [ c-type = 3 ]    ;; use two ask patches blocks so all patches compute "total"

    set total_4 count my-neighbors with [ c-type = 4 ]     ;; before any patches change their c-types

    set total_5 count my-neighbors with [ c-type = 5 ] ]
ask turtles
  [ if ( c-type = 1 ) [ set neighbors_b total_1 set neighbors_c total_2 + total_3 + total_4 + total_5 ]
    if ( c-type = 2 ) [ set neighbors_b total_2 set neighbors_c total_1 + total_3 + total_4 + total_5 ]
    if ( c-type = 3 ) [ set neighbors_b total_3 set neighbors_c total_1 + total_2 + total_4 + total_5 ]
    if ( c-type = 4 ) [ set neighbors_b total_4 set neighbors_c total_1 + total_2 + total_3 + total_5 ]
    if ( c-type = 5 ) [ set neighbors_b total_5 set neighbors_c total_1 + total_2 + total_3 + total_4 ]
     set u_1 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 1 ) [ 1 ] [ 0 ] ) + b * ( neighbors_b / num-neighbors ) - c * ( neighbors_c / num-neighbors )
     set u_2 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 2 ) [ 1 ] [ 0 ] ) + b * ( neighbors_b / num-neighbors ) - c * ( neighbors_c / num-neighbors )
     set u_3 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 3 ) [ 1 ] [ 0 ] ) + b * ( neighbors_b / num-neighbors ) - c * ( neighbors_c / num-neighbors )
     set u_4 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 4 ) [ 1 ] [ 0 ] ) + b * ( neighbors_b / num-neighbors ) - c * ( neighbors_c / num-neighbors )
     set u_5 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 5 ) [ 1 ] [ 0 ] ) + b * ( neighbors_b / num-neighbors ) - c * ( neighbors_c / num-neighbors )
      ]


 ;      set u_1 a * ( 1 / ct_opciones ) * ( ifelse-value (tt-type = 1 ) [ 1 ] [ 0 ] ) + b * ( total_1 / num-neighbors ) - c * ( count my-neighbors with [ c-type != 1 ] / num-neighbors )

 ;      set u_2 a * ( 1 / ct_opciones ) * ( ifelse-value (tt-type = 2 ) [ 1 ] [ 0 ] ) + b * ( total_2 / num-neighbors ) - c * ( count my-neighbors with [ c-type != 2 ] / num-neighbors )

 ;      set u_3 a * ( 1 / ct_opciones ) * ( ifelse-value (tt-type = 3 ) [ 1 ] [ 0 ] ) + b * ( total_3 / num-neighbors ) - c * ( count my-neighbors with [ c-type != 3 ] / num-neighbors )

 ;      set u_4 a * ( 1 / ct_opciones ) * ( ifelse-value (tt-type = 4 ) [ 1 ] [ 0 ] ) + b * ( total_4 / num-neighbors ) - c * ( count my-neighbors with [ c-type != 4 ] / num-neighbors )

 ;      set u_5 a * ( 1 / ct_opciones ) * ( ifelse-value (tt-type = 5 ) [ 1 ] [ 0 ] ) + b * ( total_5 / num-neighbors ) - c * ( count my-neighbors with [ c-type != 5 ] / num-neighbors )


;     ]

ask turtles [
  if ( c-type = 1 ) [ set my-c-neighbors ( my-neighbors with [ c-type = 1 ] ) set no-my-c-neighbors ( my-neighbors with [ c-type != 1 ] ) ]
  if ( c-type = 2 ) [ set my-c-neighbors ( my-neighbors with [ c-type = 2 ] ) set no-my-c-neighbors ( my-neighbors with [ c-type != 2 ] ) ]
  if ( c-type = 3 ) [ set my-c-neighbors ( my-neighbors with [ c-type = 3 ] ) set no-my-c-neighbors ( my-neighbors with [ c-type != 3 ] ) ]
  if ( c-type = 4 ) [ set my-c-neighbors ( my-neighbors with [ c-type = 4 ] ) set no-my-c-neighbors ( my-neighbors with [ c-type != 4 ] ) ]
  if ( c-type = 5 ) [ set my-c-neighbors ( my-neighbors with [ c-type = 5 ] ) set no-my-c-neighbors ( my-neighbors with [ c-type != 5 ] ) ]
  set num-c-neighbors count my-c-neighbors
  if ( num-c-neighbors = 0 )  [ set my-c-neighbors turtles ]
  ]
end 

to align  ;; turtle procedure

  turn-towards average-flockmate-heading max-align-turn
end 

to-report average-flockmate-heading  ;; turtle procedure

  ;; We can't just average the heading variables here.

  ;; For example, the average of 1 and 359 should be 0,

  ;; not 180.  So we have to use trigonometry.

  let x-component ( mean [dx] of my-c-neighbors )   ; ver con la suma, la media o la mediana

  let y-component ( mean [dy] of my-c-neighbors )
  ifelse x-component = 0 and y-component = 0
    [ report heading ]
    [ report atan x-component y-component ]
end 

to turn-towards [new-heading max-turn]  ;; turtle procedure

  turn-at-most (subtract-headings new-heading heading) max-turn
end 

to turn-away [new-heading max-turn]  ;; turtle procedure

  turn-at-most (subtract-headings heading new-heading) max-turn
end 

to turn-at-most [turn max-turn]  ;; turtle procedure

  ifelse abs turn > max-turn
    [ ifelse turn > 0
        [ rt max-turn ]
        [ lt max-turn ] ]
    [ rt turn ]
end 

to recolor-agent  ;; colorear

  ifelse c-type = 1 [ set color red] [
   ifelse c-type = 2 [ set color green ] [
    ifelse c-type = 3 [ set color blue ] [
     ifelse c-type = 4 [ set color yellow ] [ set color white ]
   ]
  ]
 ]
end 

There are 3 versions of this model.

Uploaded by When Description Download
Emiliano Alvarez about 8 years ago MEJORA EN CÓDIGO Download this version
Emiliano Alvarez about 8 years ago MEJORAS EN EL CÓDIGO Download this version
Emiliano Alvarez about 8 years ago Initial upload Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.