PREY HUNTER 2

PREY HUNTER 2 preview image

3 collaborators

Maria Fernanda Avila Bedoya (Author)
Jonathan Tautiva Cely (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.1.1 • Viewed 110 times • Downloaded 14 times • Run 0 times
Download the 'PREY HUNTER 2' modelDownload this modelEmbed this model

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


Comments and Questions

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

Click to Run Model

globals [ max-submarinos hunting aleatorio Coordenadax Coordenaday PromedioX PromedioY obstacle-color space-color border-color
puntos-dataset mapa2-dataset mapa3-dataset i ex long-C lat-C Capturas CapturasGlobal j listapr Rango Victorias Energia path-end Tiempo yFreq ListaFreq P-latitud P-longitud]

Breed [Destinos destino] ;; Punto de despliegue de la operación en altamar
breed [ bots bot ]       ;; bots use a*nodes to search the space
breed [ a*nodes a*node ] ;; each a*node occupies a place on the grid, contains the cost to get there
breed [ indicators indicator ]
extensions [gis]
breed [ puntos-labels puntos-label]
breed [ mapa2-labels mapa2-label]
breed [ mapa3-labels mapa3-label]
breed [ cazadores cazador ]
breed [hijos hijo]; la otra raza de tortugas, lobos
Breed [presas presa]
Breed[dummies dummy]
;; SUbmarinos que aparecen en el mapa como "presas"
a*nodes-own
[ owner  ;; the bot that owns this node
  parent ;; the node that is the parent (that comes earlier in the path) of this node
  child  ;; the node that is the child (comes later in the path) of this node (not standard a*)
  g-score  ;; stores the cummulative cost of arriving at this point from the start
  h-score  ;; stores the estimated cost of getting from this point to the goal/target
  f-score  ;; the sum of g and h
  location ;; the patch that contains this node (duplicates "patch-here" when the node is on the path, but can be used in an -of expression, unlike patch-here)
  closed?  ;; node are open (0), or closed (1). Nodes start out open
  ; target   ;; copy of the PATCH that is the target patch
  ; start    ;; copy of the PATCH that is the start patch
  on-path? ;; is this node on the final route (or route-so-far, if needed) of the path to the target
]
bots-own
[ start     ;; the patch that the search starts from, may not be the current patch
  target    ;; the patch that is the goal / target of the search
  owner     ;; the owner of the search---always the bot itself... exists so it can be inherited by the a*nodes
  child     ;; the child of this bot is the first a*node of the path.. the a*node on the start
  g-score   ;; the bots own g-score is 0, unless the bot moves along its own path... then it might change...
;  path-end  ;; the a*node at the end of the path... is nobody until the goal/target is reached.            ;; the path-end node is the only node that can construct the entire path back to the start
  done?     ;; boolean that indicates the search is over--may mean that no path can be found
  current   ;; the current a*node being examined or expanding the search
  o-current ;; the node that was previously current
  d-mode    ;; directions mode, either 4 or 8
  heuristic ;; heuristic-mode used by this bot
]

to setup
  ca
   set Energia Combustible
   set Tiempo 0
  set yFreq 0
  set ListaFreq []
  while [ (length ListaFreq) < 10000]
  [set yFreq yFreq + round ((0.71822 + 7.02756 * ( - ln (1 - random-float 1))^(1 / 0.84907)))
   set ListaFreq lput yFreq ListaFreq]
  ;
;;------------------------------------------------------------------- INICIO: Cargar sistemas de mapas--------------------------------------------------------------
     ;;Establecimiento del sístema geografico, por medio de archivos de arcGIS

  gis:load-coordinate-system (word "POLIGONO3.prj")
  set puntos-dataset gis:load-dataset "POLI_FRON.shp"
  set mapa2-dataset gis:load-dataset "polig_tierr_colom.shp"
  set mapa3-dataset gis:load-dataset "POLIGONO3.shp"
  gis:set-world-envelope (gis:envelope-union-of(gis:envelope-of puntos-dataset)
                                               (gis:envelope-of puntos-dataset)
                                               (gis:envelope-of puntos-dataset))
;;----------------------------------------------------------------------FIN: Cargar sistemas de mapas-----------------------------------------------------------------------------

;;-------------------------------------------------------------INICIO: Crear y Cargar ubicación de las presas y cazadores-----------------------------------------------------------------

    ;; Generación de presas de acuerdo una distribución dada

  ;(-163.92711 + (28.044352 *  (exp ylong - exp (- ylong) ) / 2))
  ;(49.75698 + (14.99748 *  (exp ylat - exp (- ylat) ) / 2))

    ;create-presas 1 [set shape Forma-presa set xcor random-normal (0) 1 set ycor 50 + random 50 set size 12]
  create-dummies 50 [set shape "square"  set xcor (-163.92711 + (28.044352 *  ((exp ((random-normal 0 1) - 0.05372 )/  0.75355) - exp (((- random-normal 0 1) - 0.05372)/  0.75355)) / 2))
  set ycor (49.75698 + (14.99748 *  (((exp ((random-normal 0 1) + 2.21844)/ (0.92444))  - exp (((- random-normal 0 1) + 2.21844 )/ (0.92444) ) ) / 2)))   set color red set size 12 set heading 250 + random 100
  set Coordenadax (sum [xcor] of dummies)
  set Coordenaday (sum [ycor] of dummies)
  set PromedioX round (Coordenadax / count dummies)
  set PromedioY round (Coordenaday / count dummies)]
 ; ask dummies[die]
  ;; Generación del punto de despliegue objetivo por medio de un centroide

   ;; Puntos de inicio y final del algoritmo a*, convertidos desde latitud y longitud a coordenadas de Netlogo

   set P-latitud (((latitud - 1) * 104.1714186) + 13)
   set P-longitud ((longitud - (-76.916666666666667)) * 88.0733945)

  ;;Establecimiento inicio y destino del predador

  let setup-start patch P-longitud P-latitud
  let setup-target patch PromedioX PromedioY

create-bot setup-start setup-target extract-heuristic

   set-default-shape indicators "X"

   create-cazadores 1
  [
    set color blue
    set size 20
    set xcor P-longitud set ycor P-latitud
    set shape Forma-manada
  ]

;;--------------------------------------------------------FIN: Crear y Cargar ubicación inicial de predadores y presas-----------------------------------------------------------------------

;;----------------------------------------------------------------- INICIO: Crear indicadores de  predadores y presas------------------------------------------------------------------------
  ask setup-start
   [ sprout-indicators 1
     [ set color orange
       set size 10
       set heading 180
     ]
   ]
    ask setup-target
   [ sprout-indicators 1
     [ set color orange
       set size 10
       set heading 0
     ]
   ]
;;-------------------------------------------------- -----------------FIN: Crear indicadores de predadores y presas---------------------------------------------------------------------------

;;-----------------------------------------------------------------INICIO: Cargar sistemas de colores en el mapa------------------------------------------------------------------------------
    ;; Colores respectivos para cada tipo de zona en el mapa
   set obstacle-color blue
   set border-color pink
   set space-color black
   let bread-crumb-color red


    fill-patches space-color
     do-terrain
     border
     clear-around setup-start
     clear-around setup-target





;;------------------------------------------------------------------FIN: Cargar sistemas de colores en el mapa--------------------------------------------------------
;;-----------------------------------------------------------------INICIO: Definir zonas de interes de caceria--------------------------------------------------------
  set i 0
 set ex [ [ -95.41284404 276.9009225 ]
[ -91.4348621 623.2708834 ]
[ -180.7706425 79.23565915 ]
[ -69.51486239 623.4028339 ]
[ -218.7155963 148.4228418 ]
[ -432.3425081 218.8253577 ]
[ -186.6422016 105.1048944 ]
[ -163.336758 87.19609162 ]
[ -1275.261407 -6.908315199 ]
[ -487.5596331 132.5367008 ]
[ -64.19571905 635.2505963 ]
[ -135.1192658 169.4307443 ]
[ -141.8470946 127.1545109 ]
[ -63.31058143 635.5897322 ]
[ -125.3162082 170.2178171 ]
[ -183.6036694 80.2686924 ]
[ -78.65443406 653.7699593 ]
[ -166.0110089 57.55932354 ]
[ -119.4152907 168.6870761 ]
[ -111.8409788 644.7041525 ]
[ -396.7951067 294.2628254 ]
[ -82.39755333 659.1521492 ]
[ -149.4556574 85.97497114 ]
[ -165.0275232 59.30419477 ]
[ -138.5443423 173.5107914 ]
[ -219.0825691 136.8193035 ]
[ -238.7522936 156.4961266 ]
[ -75.22935751 649.6928058 ]
[ -198.1896021 82.3029287 ]
[ -189.5045869 75.76327862 ]
[ -124.7706419 190.6122656 ]
[ -204.036697 70.29427924 ]
[ -138.6422015 113.8205695 ]
[ -138.6422015 113.8205695 ]
[ -93.94495384 238.7047364 ]
[ -193.9885011 68.10089224 ]
[ -64.88073365 257.6292104 ]
[ -69.65137615 643.9604842 ]
[ -201.2017122 79.20672272 ]
[ -142.44159 135.6242258 ]
[ -152.8073398 174.6971881 ]
[ -126.2189604 153.8600111 ]
[ -54.55657483 605.0408854 ]
[ -149.7247709 172.7295057 ]
[ -200.7828747 188.8760753 ]
[ -62.23853182 270.158717 ]
[ -189.4556577 61.84481989 ]
[ -155.8899086 154.0133746 ]
[ -190.5321101 63.87037517 ]
[ -159.9999997 134.5333196 ]
[ -187.8899083 78.97523061 ]
[ -175.2748627 66.90870819 ]
[ -164.6238529 172.8163153 ]
[ -68.99082569 628.3347717 ]
[ -111.6430585 220.4996239 ]
[ -67.18042775 632.7909934 ]
[ -187.8899083 63.34951809 ]
[ -222.4880731 60.71050889 ]
[ -235.8899083 64.53591479 ]
[ -210.9754131 64.91729791 ]
[ -182.4587153 94.2537051 ]
[ -173.9696634 70.35302036 ]
[ -174.5810399 71.68525704 ]
[ -226.2409782 115.5214573 ]
[ -199.9779817 116.8502216 ]
[ -179.0581038 62.56823246 ]
[ -54.35522936 237.9856643 ]
[ -195.0336391 60.57161371 ]
[ -162.71315 97.67284247 ]
[ -127.6183489 162.8853068 ]
[ -55.38348624 215.8130676 ]
[ -173.7017741 92.95214117 ]
[ -163.2097861 97.37884761 ]
[ -296.4844037 123.1439113 ]
[ -200.3772474 115.3345275 ]
[ -149.7247709 184.9117742 ]
[ -179.412844 74.47849785 ]
[ -163.1510702 97.04607785 ]
[ -131.7920493 175.6810293 ]
[ -132.4330272 179.7958002 ]
[ -130.0892964 169.9863251 ]
[ -170.8623856 97.89970469 ]
[ -220.6727827 181.4104572 ]
[ -162.6275232 97.85919357 ]
[ -168.1467887 115.9560836 ]
[ -181.5486239 63.14117525 ]
[ -388.9908254 334.1952018 ]
[ -175.0752294 63.0196419 ]
[ -167.8077061 105.5597762 ]
[ -264.2446479 193.5927256 ]
[ -131.1314989 201.6660104 ]
[ -166.0183489 138.9953286 ]
[ -182.5321104 76.13945317 ]
[ -185.8348627 62.13418496 ]
[ -77.21100888 267.3518761 ]
[ -144.5871557 197.5570268 ]
[ -133.5662385 207.6304028 ]
[ -167.5351683 142.6355409 ]
[ -140.5944954 192.1632623 ]
[ -120.3840981 167.1621223 ]
[ -149.3088681 148.2781593 ]
[ -180.9981651 90.10421037 ]
[ -205.707156 96.22138743 ]
[ -183.3125384 80.227892 ]
[ -243.5229361 192.23271 ]
[ -187.0091743 97.72608563 ]
[ -149.4311924 216.8287389 ]
[ -170.4220187 111.7197793 ]
[ -156.085627 131.4371136 ]
[ -189.2354742 102.963593 ]
[ -199.8042816 225.3071348 ]
[ -176.6194493 133.6669607 ]
[ -694.7278286 274.9621767 ]
[ -175.7724774 71.13343792 ]
[ -129.2917434 192.348456 ]
[ -181.5681955 81.22649066 ]
[ -183.9310092 79.27559159 ]
[ -124.7094802 180.7073001 ]
[ -349.7247707 387.5251799 ]
[ -64.44036668 258.8445436 ]
[ -165.3602443 65.6152464 ]
[ -126.4014679 200.8609968 ]
[ -171.5963303 222.2109287 ]
[ -157.2305811 98.09647294 ]
[ -167.363914 139.6261445 ]
[ -143.305199 80.46546064 ]
[ -238.0183489 130.6268915 ]
[ -77.19388389 653.2722514 ]
[ -143.3859323 80.48860982 ]
[ -393.5412844 210.0575968 ]
[ -176 141.3044617 ]
[ -170.1284401 130.0192248 ]
[ -157.0886852 225.5096903 ]
[ -176.440367 211.1571839 ]
[ -155.3027523 187.9732565 ]
[ -88.80733945 244.7814024 ]
[ -182.502752 80.97184946 ]
[ -301.0152901 122.9587178 ]
[ -154.1039756 182.0759968 ]
[ -224.8513765 64.02663229 ]
[ -230.6055046 140.1585761 ]
[ -82.59327178 742.1999176 ]
[ -225.4385318 174.1531818 ]

 ]
 print ex

   foreach ex
      [
      [ xy_coords ] ->
      ask patches with [ pxcor = (round item 0 xy_coords) and pycor = ( round item 1  xy_coords) ] [
      ask patches in-radius 10 [
            set pcolor black]]
      ]
set j 0
  set listapr []
print listapr
  reset-ticks
end 

to fill-patches [ #color ]
  ask puntos-labels [ die ]
  ask patches gis:intersecting puntos-dataset [set pcolor space-color]
  ask patches gis:intersecting mapa2-dataset [set pcolor obstacle-color]
  ask patches gis:intersecting mapa3-dataset [set pcolor obstacle-color]

 ask mapa2-labels [ die ]
  gis:set-drawing-color green
  gis:fill mapa2-dataset 2

  ask mapa3-labels [ die ]
  gis:set-drawing-color cyan
  gis:fill mapa3-dataset 2
end 

to go
 ifelse Tiempo <= Horizonte [
   ask presas [mover-presas]
   ask bots
   [ go-bot
     ifelse is-turtle? path-end
    [ show-path-nodes get-path yellow
      ask bots [ foreach get-path [ [ coord_pr ] -> ask coord_pr [set listapr lput (list (xcor) (ycor)) listapr]]]
    ]

      []
  ]

  if show-path-in-progress? [  ]
   if not any? bots with [ done? = false ]
   [ ask bots
   [ ifelse is-turtle? path-end
      [ask center-patch [ set plabel  "Path Solved."   ] ]
       [ ask center-patch [ set plabel  "No Path." ] ]
  ]]
if member? ticks ListaFreq [create-presas 1 [set shape Forma-presa set xcor (-163.92711 + (28.044352 *  ((exp ((random-normal 0 1) - 0.05372 )/  0.75355) - exp (((- random-normal 0 1) - 0.05372)/  0.75355)) / 2))
      set ycor (49.75698 + (14.99748 *  (((exp ((random-normal 0 1) + 2.21844)/ (0.92444))  - exp (((- random-normal 0 1) + 2.21844 )/ (0.92444) ) ) / 2)))   set color red set size 12 set heading 250 + random 100]]

    tick
  ifelse (Capturas > 0) or (Energia <= 0) [Devolverse ][ operar]

  ask cazadores [if (Capturas > 0) or (Energia <= 0) and  round xcor = P-longitud and round ycor = P-latitud [
      ask a*nodes [die] ask bots [die]
      set Capturas 0 set listapr []
      set Energia Combustible
      set Coordenadax (sum [xcor] of presas)
      set Coordenaday (sum [ycor] of presas)
      set Promediox round (Coordenadax / count presas)
      set Promedioy round (Coordenaday / count presas)

      let setup-start patch P-longitud P-latitud let setup-target patch PromedioX PromedioY create-bot2 setup-start setup-target extract-heuristic
      ask setup-target   [ sprout-dummies 1     [ set color Green       set size 10       set shape "square"     ]   ]
      ]
    ]

  ;let setup-start patch xstart ystart let setup-target patch xtarget ytarget setup-start setup-target extract-heuristic]]

  ]  [stop]
; (Energia <= 0) and
  ;ask a*nodes [die] ask bots [die] set Capturas 0 set listapr [] (Capturas > 0) or (Energia <= 0) and
 ; let setup-start patch xstart ystart let setup-target patch xtarget ytarget create-bot setup-start setup-target extract-heuristic
end 

to operar
   ask hijos [cazar]
  ask presas [if [pcolor] of patch-ahead 6 = blue [set Victorias Victorias + 1]]
  ask presas [if [pcolor] of patch-ahead 6 = blue [die]]
  ask hijos [if [pcolor] of patch-ahead 6 = blue [set heading heading - 150]]
  foreach listapr [[caminar] -> ask cazadores with [xcor != PromedioX and ycor != PromedioY][set xcor (item 0 caminar) set ycor (item 1 caminar)] ]
  ask cazadores [cazar]
  ask cazadores [if xcor = PromedioX and ycor = PromedioY [if count hijos != manada [hatch-hijos manada [set color red set size 20 set xcor PromedioX set ycor PromedioY set shape Forma-cazador set Energia Combustible]
      ]
  ask hijos [mover-cazadores cazar set Energia Energia - 1]
  ]]

  ask hijos [if not any? cazadores in-radius despliegue [set heading heading - 150]]

   ; [ cazar wait 5 ]

 ;if not any? presas [stop]
  set Tiempo Tiempo + 1
end 

to Devolverse
    ask hijos [die]
    ask cazadores [facexy P-longitud P-latitud fd 1]
    ask presas [if [pcolor] of patch-ahead 6 = blue [set Victorias Victorias + 1]]
    ask presas [if [pcolor] of patch-ahead 6 = blue [die]]
    set Tiempo Tiempo + 1
end 

to mover-cazadores
  rt random 5
  lt random 5
  fd 1
end 

to mover-presas
  rt random 5
  lt random 5
  fd 10
end 

to go-bot
   ;;
   ;; when path-end is not nobody, that means the target has been reached.
   ;; and path-end contains the a*node that lies on the target.
   ;; path-end can then be used to trace the path back to the start
   ;;
   ;; when done? is true, that means that no more locations
   ;; need to be searched.
   ;;
   ;; if path-end is nobody when done? is true, that means there is
   ;; NO path from the start to the target.
   ;;
   if path-end = nobody
     [ ;;
     ;; collect the nodes that are this bots nodes
       ;; (if netlogo had mutable lists, or mutable agentsets, this could be made faster!)
       ;;
       let my-nodes  a*nodes with [ owner = myself ]
       ;;
       ;; are any of the nodes open?
       ;;
       ifelse any? my-nodes with [ closed? = 0 ]
       [ ;;
         ;; yes. do the path search
         ;;
         set current a*build-path
         ;;
         ;; having done that, was the target found?
         ;;
         if [location] of current = target
         [ set path-end current
           set done? true
         ]
       ]
       [ ;;
         ;; no more open nodes means no where left to search, so we are done.
         ;;
         set done? true
       ]
     ]
end 

to border
   ;;
   ;; colors the edge of the world to prevent searches and maze-making from leaking
   ;;
   ask patches with [ pxcor = min-pxcor or pxcor = max-pxcor or pycor = min-pycor or pycor = max-pycor ]
   [ set pcolor border-color ]
end 

to do-terrain
;; Mas negro = Mas facil pasar
;; Mas blanco = Mas dificil pasar
;; El algoritmo busca el balance entre distancia al objetivo y elevación del terreno

          ask patches gis:intersecting puntos-dataset [set pcolor gray
         ; [ set pcolor 140 - ((distancexy-nowrap PromedioX PromedioY ) / (world-width) * 140) ]
         ; repeat 3 [ diffuse pcolor .5]
         ;   ask patches gis:intersecting puntos-dataset [ set pcolor scale-color gray pcolor 0 140 ]
  ]
end 

to clear-around [ agent ]
   ;; Limpia los alrededores de origenes y destinos para poder inicializar el algoritmo
  ask agent [ ask neighbors [ set pcolor space-color ] set pcolor space-color ]
end 

to-report same-patch [ a b ]
   ;;
   ;; reports true if both agent a and b, whether turtles or patches, are on the same patch
   ;;
   report ([pxcor] of a = [pxcor] of b and [pycor] of a = [pycor] of b )
end 

to highlight-path [ path-color ]
   ;;
   ;; recursive routine that colors the nodes, tracing back up through the node parents
   ;; until the start node is reached
   ;;
   set on-path? true
   set color path-color
   if color = yellow [ ifelse heading mod 90 = 0 [set shape "path" ] [ set shape "path-long" ] ]
   if is-turtle? parent
   [ set heading towards-nowrap parent
     ask parent
     [ highlight-path path-color
     ]
   ]
end 

to-report get-path
   let n path-end
   if not is-turtle? n
   [ set n current ]
   if not is-turtle? n
   [ report false ]

   let p (list n )
   while [ [location] of n != start ]
   [ set n [parent] of n
     set p fput n p
   ]
   report p
end 

to show-path-nodes [ p hue ]
   ask (turtle-set p)
   [ set color hue
     if color = yellow [ ifelse heading mod 90 = 0 [set shape "line" ] [ set shape "line" ] ]
   ]
   ; ask a*nodes with [ member? self p ] [ set color hue ]
   display
   ;;   foreach p
   ;;   [ set color hue
   ;;     if color = yellow [ ifelse heading mod 90 = 0 [set shape "path" ] [ set shape "path-long" ] ]
   ;;   ]
end 

to color-path-patches [ p ]
   ;;
   ;; non-recursive routine that,
   ;; given the path-end, increments the pcolor of the patches covered by the path,
   ;; tracing back to the start
   ;;
   foreach p
   [ if pcolor = 0 [ set pcolor 2 ]
     if pcolor < 9.5 [ set pcolor pcolor + .5 ]
   ]
end 

to create-bot2 [ starting-patch target-patch #heuristic ]
    hatch-bots 1
   [ set color gray
     set start starting-patch
     set target target-patch
     set owner self
     set path-end nobody
     set g-score 0
     setxy [pxcor] of start [pycor] of start
     set shape "circle"
     set done? false
     set current nobody
     set o-current self
     set child nobody
     set heuristic #heuristic
     expand-into self start
     ask child [ set closed? 0 set shape "x" set parent nobody set on-path? true ]
   ]
end 

to create-bot [ starting-patch target-patch #heuristic ]
   ;;
   ;; creates a search bot
   ;; and the first a*node for that bot.
   ;; so: a bot always has at least one a*node, and that first node is
   ;; the child of the bot
   ;; the first node, however, does not have any "parent"...
   ;; that is, its parent is always "nobody"
   ;; this is how a trace-back routine can know that it has reached
   ;; the begining of a path: when there is no more parents to trace-back to...
   ;;
   create-bots 1
   [ set color gray
     set start starting-patch
     set target target-patch
     set owner self
     set path-end nobody
     set g-score 0
     setxy [pxcor] of start [pycor] of start
     set shape "circle"
     set done? false
     set current nobody
     set o-current self
     set child nobody
     set heuristic #heuristic
     expand-into self start
     ask child [ set closed? 0 set shape "x" set parent nobody set on-path? true ]
   ]
end 

to expand-into [ parent-agent location-agent ]
   ;;
   ;; causes the given parent agent to
   ;; expand into the given location (patch)
   ;;
   ;; this means that nodes are created in the given patch, and the parent
   ;; of these nodes is the given parent agent.
   ;;
   ask parent-agent
   [ hatch-a*nodes 1
     [ set location location-agent
       setxy [pxcor] of location [pycor] of location
       ;; first thing--is this a dead end? if so, don't
       ;; bother to add it to any list... just die.
       let my-owner owner
       ifelse location = [ target ] of owner or any? neighbors with [ shade-of? pcolor space-color and not any? a*nodes-here with [ owner = my-owner ] ]
       [ set breed a*nodes
         set shape "x"
         set size 1.01
         set color green
         set parent parent-agent
         set owner [owner] of parent-agent
         ask parent-agent [set child myself]
         set child nobody



         face parent

         ;; target is inherited
         set g-score calculate-g parent-agent
         set h-score calculate-h
         set f-score calculate-f
         set closed? -1 ;; new... neither open or closed
         set on-path? false
       ]
       [ die ]
     ]
   ]
end 

to-report calculate-f
  ;;
  ;; calculates the f score for this s*node
  ;;

  ifelse location = [ target ] of owner
  [ report -999999 ]
  [ report g-score + h-score  ]
end 

to-report calculate-g [ candidate ]
  ;;
  ;; calculates the g score relative to the candidate for this s*node
  ;;

   let g [g-score] of candidate + distance-nowrap candidate
   if terrain? [ set g g + pcolor * 10]
   report g
end 

to-report calculate-h
   let result 0
   if [ heuristic ] of owner = 0  ;; euclidian distance to target
   [ set result distance-nowrap [ target ] of owner ]

   if [ heuristic ] of owner = 1 ;; manhattan distance
   [ let xdiff abs(pxcor - [pxcor] of [ target ] of owner)
     let ydiff abs(pycor - [pycor] of [ target ] of owner)
     set result ( xdiff + ydiff )
   ]

  if [ heuristic ] of owner = 2 ;; diagonal distance
   [

     let D  1
     let D2 1.414214
     let xdiff abs(pxcor - [pxcor] of [ target ] of owner)
     let ydiff abs(pycor - [pycor] of [ target ] of owner)
     let h_diagonal min (list xdiff ydiff)
     let h_straight xdiff + ydiff
     set result D2 * h_diagonal + D * ( h_straight - 2 * h_diagonal )
   ]

   if [ heuristic ] of owner = 3 ;; diagonal distance + tie-breaker
   [

     let D  1
     let D2 1.414214
     let xdiff abs(pxcor - [ [pxcor] of target ] of owner)
     let ydiff abs(pycor - [ [pycor] of target ] of owner)
     let h_diagonal min (list xdiff ydiff)
     let h_straight xdiff + ydiff
     set result D2 * h_diagonal + D * ( h_straight - 2 * h_diagonal )
     ;; tie-breaker: nudge H up by a small amount
     let h-scale (1 + (16 / 8 / world-width * world-height))
     set result result * h-scale
   ]
   if [ heuristic ] of owner = 4  ;; euclidian distance to target with tie-breaker
   [ set result distance-nowrap [ target ] of owner
     let h-scale (1 + (16 / 8 / world-width + world-height))
     set result result * h-scale
   ]
   report result
end 

to-report a*build-path
   let o-c o-current
   set current min-one-of a*nodes with [ owner = myself and closed? = 0 ] [ f-score ] ; + distance-nowrap o-c ]
   set o-current current
   let cc current
   if is-turtle? cc
   [ ask cc
     [ set closed? 1
       set color magenta

       if not same-patch location [ target ] of owner
       [ let me owner
         let paths nobody
         ifelse 8 = 8
         [ set paths neighbors with [ shade-of? pcolor space-color ] ]
         [ set paths neighbors4 with [ shade-of? pcolor space-color ] ]

         let new-paths (paths with [ not any? a*nodes-here with [ owner = me ] ] )
         if any? new-paths [ ask  new-paths [ expand-into cc self ] ]

         set new-paths  (a*nodes-on paths ) with [ owner = me and closed? < 1 ]
         ; if any? new-paths [ set new-paths min-one-of new-paths [ f-score ] ]
         ask  new-paths
         [ ifelse closed? = 0 ;; already open
           [ ;; see if g from current is better than prior g
             let new-g calculate-g cc
             set f-score calculate-f
             if new-g < g-score
             [ ;; if it is, then change path to go from this point
               ;; set parent of this node to current
               set parent cc
               set shape "x"
               face parent
               ask parent [ set child myself ]
               set g-score new-g
               set f-score calculate-f
             ]
           ]
           [ ;; must be new (not yet open, not previously closed.
             set closed? 0 ;; open it
               set parent cc
           ]
         ]
       ]
     ]
   ]
   report current
end 

to-report extract-heuristic
   report first choose-heuristic
end 

to reset-bots
   ask a*nodes [ die ]
   ask bots [ die ]
   let setup-start patch (P-longitud) (P-latitud)
   let setup-target patch (PromedioX) (PromedioY )
   create-bot setup-start setup-target extract-heuristic
end 

to-report center-patch
   report patch (int (min-pxcor + world-width * .5)) (int (min-pycor + world-height * .5))
end 

to cazar  ; wolf procedure
  let prey one-of presas in-radius rango-caceria
  set long-C  round xcor
  set lat-C  round ycor
   if prey != nobody  [                          ; did we get one? if so,
  print long-C
  print lat-C

      if i < 143
      [
      ask patches gis:intersecting puntos-dataset [set pcolor gray]
      set ex replace-item i ex (list long-C lat-C)
      set i (i + 1)
      if i > 143 [
      set i 0
      ask patches gis:intersecting puntos-dataset [set pcolor gray]
      set ex replace-item i ex (list long-C lat-C)
      ]
    ]
      print ex
    ask prey [ die ]
    set Capturas Capturas + 1
    set CapturasGlobal CapturasGlobal + Capturas
     ; kill it, and...
    ; get energy from eating
      foreach ex
      [
      [ xy_coords ] ->
      ask patches with [ pxcor = (round item 0 xy_coords) and pycor = ( round item 1  xy_coords) ] [
      ask patches in-radius 10 [
            set pcolor black]]
      ]
  ]
end 
   ;;  1) Add the starting square (or node) to the open list.
   ;;  2) Repeat the following:
   ;;     a) Look for the lowest F cost square on the open list. We refer to this as the current square.
   ;;     b) Switch it to the closed list.
   ;;     c) For each of the 8 squares adjacent to this current square �
   ;;
   ;;        * If it is not walkable or if it is on the closed list, ignore it.
   ;;          Otherwise do the following.
   ;;      * If it is on the open list already...
   ;;          Check to see if this path to that square is better,
   ;;          using G cost as the measure.
   ;;          A lower G cost means that this is a better path.
   ;;          If so, change the parent of the square to the current square,
   ;;          and recalculate the G and F scores of the square.
   ;;          If you are keeping your open list sorted by F score,
   ;;          you may need to resort the list to account for the change.
   ;;        * If it isn�t on the open list...
   ;;            Add it to the open list.
   ;;            Make the current square the parent of this square.
   ;;            Record the F, G, and H costs of the square.
  ;;
   ;;  d) Stop when you:
   ;;
   ;;      * Add the target square to the closed list, in which case the path has been found (see note below), or
   ;;      * Fail to find the target square, and the open list is empty. In this case, there is no path.
   ;;
   ;;  3) Save the path. Working backwards from the target square, go from each square to its parent square until you reach the starting square. That is your path.

There is only one version of this model, created almost 4 years ago by DIANA MARCELA GARNICA CORTES.

Attached files

File Type Description Last updated
POLI_FRON.cpg extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLI_FRON.dbf extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLI_FRON.prj extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLI_FRON.sbn extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLI_FRON.sbx extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLI_FRON.shp extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLI_FRON.shp.xml extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLI_FRON.shx extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
polig_tierr_colom.cpg extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
polig_tierr_colom.dbf extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
polig_tierr_colom.prj extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
polig_tierr_colom.sbn extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
polig_tierr_colom.sbx extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
polig_tierr_colom.shp extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
polig_tierr_colom.shp.xml extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
polig_tierr_colom.shx extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLIGONO3.cpg extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLIGONO3.dbf extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLIGONO3.prj extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLIGONO3.sbn extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLIGONO3.sbx extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLIGONO3.shp extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLIGONO3.shp.xml extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
POLIGONO3.shx extension PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
PREY HUNTER 2.png preview PREY HUNTER 2 almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download
PREY HUNTER 2.png preview Preview for 'PREY HUNTER 2' almost 4 years ago, by DIANA MARCELA GARNICA CORTES Download

This model does not have any ancestors.

This model does not have any descendants.