modelo t-types c-types

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 166 times • Downloaded 30 times • Run 0 times
Download the 'modelo t-types c-types' 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

  tt_opciones
]
patches-own
[
  c-type ;; crowding type

  c-type_old ; crowding type del período anterior

  t-type ;; taste type

  total_1
  total_2
  total_3
  total_4
  total_5
  u_1
  u_2
  u_3
  u_4
  u_5
  cluster
  clus
  dato_cluster
]

to setup

  clear-all
 set tt_opciones ct_opciones ; para tener la misma cantidad de crowding types y de taste types

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 patches [
   set cluster nobody ; para contar los grupos

   ifelse ( c_type_valor? ) [ ; le damos un porcentaje de agentes con c-type 1 y el resto se divide aleatoriamente

    ifelse ( random-float 1.000 <= c-type_1 ) [ set c-type 1 ] [ set c-type ( 2 + random ((ct_opciones - 1)))]
      set t-type 1 + random ( tt_opciones ) ; los taste types se dividen de manera aleatoria

      recolor-patch ]
   ; en este caso, el porcentaje de crowding types también se genera de manera aleatoria

    [ set c-type 1 + random ( ct_opciones )
      set t-type 1 + random ( tt_opciones )
      recolor-patch ]
    ]
; en este caso, se setea el modelo para las vecindades de Moore o Von Neumann

ask patches
[ if ( vecindad = "Moore" )
     [ set total_1 count neighbors with [ c-type = 1 ]
       set total_2 count neighbors with [ c-type = 2 ]
       set total_3 count neighbors with [ c-type = 3 ]
       set total_4 count neighbors with [ c-type = 4 ]
       set total_5 count neighbors with [ c-type = 5 ]
      ; ahora, para cada individuo se calcula la utilidad de cada c-type

      ; notar que cuando coincide el t-type con el c-type, es mayor la utilidad

       set u_1 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 1 ) [ 1 ] [ 0 ] ) + b * ( total_1 / count neighbors ) - c * ( count neighbors with [ c-type != 1 ] / count neighbors )
       set u_2 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 2 ) [ 1 ] [ 0 ] ) + b * ( total_2 / count neighbors ) - c * ( count neighbors with [ c-type != 2 ] / count neighbors )
       set u_3 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 3 ) [ 1 ] [ 0 ] ) + b * ( total_3 / count neighbors ) - c * ( count neighbors with [ c-type != 3 ] / count neighbors )
       set u_4 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 4 ) [ 1 ] [ 0 ] ) + b * ( total_4 / count neighbors ) - c * ( count neighbors with [ c-type != 4 ] / count neighbors )
       set u_5 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 5 ) [ 1 ] [ 0 ] ) + b * ( total_5 / count neighbors ) - c * ( count neighbors with [ c-type != 5 ] / count neighbors ) ]
   if (vecindad = "VN")
     [ set total_1 count neighbors4 with [ c-type = 1 ]
       set total_2 count neighbors4 with [ c-type = 2 ]
       set total_3 count neighbors4 with [ c-type = 3 ]
       set total_4 count neighbors4 with [ c-type = 4 ]
       set total_5 count neighbors4 with [ c-type = 5 ]
       set u_1 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 1 ) [ 1 ] [ 0 ] ) + b * ( total_1 / count neighbors4 ) - c * ( count neighbors with [ c-type != 1 ] / count neighbors4 )
       set u_2 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 2 ) [ 1 ] [ 0 ] ) + b * ( total_2 / count neighbors4 ) - c * ( count neighbors with [ c-type != 2 ] / count neighbors4 )
       set u_3 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 3 ) [ 1 ] [ 0 ] ) + b * ( total_3 / count neighbors4 ) - c * ( count neighbors with [ c-type != 3 ] / count neighbors4 )
       set u_4 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 4 ) [ 1 ] [ 0 ] ) + b * ( total_4 / count neighbors4 ) - c * ( count neighbors with [ c-type != 4 ] / count neighbors4 )
       set u_5 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 5 ) [ 1 ] [ 0 ] ) + b * ( total_5 / count neighbors4 ) - c * ( count neighbors with [ c-type != 5 ] / count neighbors4 ) ]
]
  reset-ticks
end 

to go
; para guardar los valores anteriores

ask patches
[  set c-type_old c-type
   set cluster nobody
   if ( clus > 0 ) [ set dato_cluster clus ]
   set clus  0
]

; con las preferencias individuales (t-types) y los c-types

  ask patches
    [ set c-type ifelse-value (( u_1 > u_2 ) and (u_1 > u_3) and (u_1 > u_4) and (u_1 > u_5)) [ 1 ][
       ifelse-value ((u_2 > u_1) and (u_2 > u_3) and (u_2 > u_4) and (u_2 > u_5)) [ 2 ] [
        ifelse-value ((u_3 > u_1) and (u_3 > u_2) and (u_3 > u_4) and (u_3 > u_5))[ 3 ] [
         ifelse-value ((u_4 > u_1) and (u_4 > u_2) and (u_4 > u_3) and (u_4 > u_5)) [ 4 ] [
          ifelse-value ((u_5 > u_1) and (u_5 > u_2) and (u_5 > u_3) and (u_5 > u_4)) [ 5 ] [ 1 + random ct_opciones ]]]]]
     recolor-patch ]

; mutaciones (existe una probabilidad que ocurra un cambio en las elecciones del agente)

ask patches
 [ if ( random-float 1.000 <= prob_mut ) [ set c-type 1 + random ct_opciones ]
     recolor-patch ]

; Para exportar la pantalla o el gráfico

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

;      export-plot (word ticks ".png")

;      export-interface (word ticks ".png")


      tick

; ahora se calculan utilidades de cada opción, luego de la elección del producto

ask patches
[ if ( vecindad = "Moore" )
     [ set total_1 count neighbors with [ c-type = 1 ]
       set total_2 count neighbors with [ c-type = 2 ]
       set total_3 count neighbors with [ c-type = 3 ]
       set total_4 count neighbors with [ c-type = 4 ]
       set total_5 count neighbors with [ c-type = 5 ]
       set u_1 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 1 ) [ 1 ] [ 0 ] ) + b * ( total_1 / count neighbors ) - c * ( count neighbors with [ c-type != 1 ] / count neighbors )
       set u_2 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 2 ) [ 1 ] [ 0 ] ) + b * ( total_2 / count neighbors ) - c * ( count neighbors with [ c-type != 2 ] / count neighbors )
       set u_3 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 3 ) [ 1 ] [ 0 ] ) + b * ( total_3 / count neighbors ) - c * ( count neighbors with [ c-type != 3 ] / count neighbors )
       set u_4 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 4 ) [ 1 ] [ 0 ] ) + b * ( total_4 / count neighbors ) - c * ( count neighbors with [ c-type != 4 ] / count neighbors )
       set u_5 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 5 ) [ 1 ] [ 0 ] ) + b * ( total_5 / count neighbors ) - c * ( count neighbors with [ c-type != 5 ] / count neighbors ) ]
   if (vecindad = "VN")
     [ set total_1 count neighbors4 with [ c-type = 1 ]
       set total_2 count neighbors4 with [ c-type = 2 ]
       set total_3 count neighbors4 with [ c-type = 3 ]
       set total_4 count neighbors4 with [ c-type = 4 ]
       set total_5 count neighbors4 with [ c-type = 5 ]
       set u_1 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 1 ) [ 1 ] [ 0 ] ) + b * ( total_1 / count neighbors4 ) - c * ( count neighbors with [ c-type != 1 ] / count neighbors4 )
       set u_2 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 2 ) [ 1 ] [ 0 ] ) + b * ( total_2 / count neighbors4 ) - c * ( count neighbors with [ c-type != 2 ] / count neighbors4 )
       set u_3 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 3 ) [ 1 ] [ 0 ] ) + b * ( total_3 / count neighbors4 ) - c * ( count neighbors with [ c-type != 3 ] / count neighbors4 )
       set u_4 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 4 ) [ 1 ] [ 0 ] ) + b * ( total_4 / count neighbors4 ) - c * ( count neighbors with [ c-type != 4 ] / count neighbors4 )
       set u_5 a * ( 1 / ct_opciones ) * ( ifelse-value (t-type = 5 ) [ 1 ] [ 0 ] ) + b * ( total_5 / count neighbors4 ) - c * ( count neighbors with [ c-type != 5 ] / count neighbors4 ) ]
]

if (ticks = 1 or ticks = 5 or ticks = 10 or ticks = 15 or ticks = 20 or ticks = 25 or ticks = 30 or ticks = 35 or ticks = 40 or ticks = 45 or ticks = 50 or ticks = 55 or ticks = 60) [ find-clusters ]
end 

to go-global
; este caso sirve para mostrar el desarrollo del modelo cuando los individuos toman en cuenta la información de todos los agentes

; es igual que "GO" pero la vecindad es el conjunto de todos los individuos

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

ask patches
[  set c-type_old c-type ]
  ask patches
    [ set c-type ifelse-value (( u_1 > u_2 ) and (u_1 > u_3) and (u_1 > u_4) and (u_1 > u_5)) [ 1 ][
       ifelse-value ((u_2 > u_1) and (u_2 > u_3) and (u_2 > u_4) and (u_2 > u_5)) [ 2 ] [
        ifelse-value ((u_3 > u_1) and (u_3 > u_2) and (u_3 > u_4) and (u_3 > u_5))[ 3 ] [
         ifelse-value ((u_4 > u_1) and (u_4 > u_2) and (u_4 > u_3) and (u_4 > u_5)) [ 4 ] [
          ifelse-value ((u_5 > u_1) and (u_5 > u_2) and (u_5 > u_3) and (u_5 > u_4)) [ 5 ] [ 1 + random ct_opciones ]]]]]
     recolor-patch ]

; mutaciones

ask patches
 [ if ( random-float 1.000 <= prob_mut ) [ set c-type 1 + random ct_opciones ]
     recolor-patch ]

; Para exportar la pantalla

;      export-interface (word "frame_2" but-first (word (100000 + ticks)) ".png")

;      export-plot (word ticks ".png")



      tick


;      export-interface (word ticks ".png")

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

       ]
end 

to recolor-patch  ;; colores diferentes para cada c-type

  ifelse c-type = 1 [ set pcolor red + 1] [
   ifelse c-type = 2 [ set pcolor green + 1 ][
    ifelse c-type = 3 [ set pcolor blue ][
     ifelse c-type = 4 [ set pcolor yellow ] [ set pcolor magenta ]
   ]
  ]
 ]
end 

;;; para contar la cantidad de clusters


to find-clusters
  loop [
    ;; pick a random patch that isn't in a cluster yet

    let seed one-of patches with [cluster = nobody]
    ;; if we can't find one, then we're done!

    if seed = nobody
    [ show-clusters
      stop ]
    ;; otherwise, make the patch the "leader" of a new cluster

    ;; by assigning itself to its own cluster, then call

    ;; grow-cluster to find the rest of the cluster

    ask seed
    [ set cluster self
      grow-cluster ]
  ]
 display
end 

to grow-cluster  ;; patch procedure

  ask neighbors4 with [(cluster = nobody) and
    (pcolor = [pcolor] of myself)]
  [ set cluster [cluster] of myself
    grow-cluster ]
end 

;; once all the clusters have been found, this is called

;; to put numeric labels on them so the user can see

;; that the clusters were identified correctly


to show-clusters
  let counter 1
  loop
  [ ;; pick a random patch we haven't labeled yet

    let p one-of patches with [ clus = 0 ]
    if p = nobody
      [ stop ]
    ;; give all patches in the chosen patch's cluster

    ;; the same label

    ask p
    [ ask patches with [cluster = [cluster] of myself]
      [ set clus counter ] ]
    set counter counter + 1 ]
end 

There are 4 versions of this model.

Uploaded by When Description Download
Emiliano Alvarez about 8 years ago MEJORA EN INTERFAZ Download this version
Emiliano Alvarez about 8 years ago comentarios Download this version
Emiliano Alvarez about 8 years ago cambios en la interfaz gráfica 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.