Area Gradients Simulation

Area Gradients Simulation preview image

1 collaborator

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.2.0 • Viewed 337 times • Downloaded 29 times • Run 0 times
Download the 'Area Gradients Simulation' modelDownload this modelEmbed this model

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


WHAT IS IT?

Gradient Descent Simulation Modelization

HOW IT WORKS

Two types of turtles: originTurtle to indicate the basement (grad 0) and fieldTurtles to simulate the flood going down to the basement (grad 0) by choosing patches with smallest altitude value.

First the world (with 50 * 50 patches) is initialized with an area (one patch) altitude value (gradlevel patch-own variable) when setup button is clicked.

Next in setup, the total number of fieldTurtles selected is created with a random position.

When go button is pressed, fieldTurtles start running towards to origin point (basement with grad 0) and disappear. All can disappear or some can still bouncing at the basement level.

Each patch has a specific color based on the base color chosen

HOW TO USE IT

1- Set the counter speed to fast

2- Set the world (background basic color) 3- Set the base point (Grad 0) coordinates offset value

4- Set the total number of FieldTurtle needed

5- Set the tick counter limit value

6- Clic setup button (Wait till it pops up back)

7- Set Speed to it slower position before clicking in order to see fieldTurtles paths

7- Clic in final go button (wait for the simulation to finish or stop go to check figures and graphs before the end)

THINGS TO NOTICE

At the beginning if the speed button is set to slower position the setup process could last too long.

THINGS TO TRY

Try the simulation with different steps of speed, different base point position, different number of filedTurtles and diffrent background color base to experience diffrent type of mood

EXTENDING THE MODEL

Next step: Try and associate math function to the base point random positionning and for fieldTurtles move

NETLOGO FEATURES

Need: feature to code speed button by default

RELATED MODELS

NA

CREDITS AND REFERENCES

Constant Patrice KODJA ADJOVI pkodja@gmail.com Lomé TOGO

Comments and Questions

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

Click to Run Model

;;Title: Exam project
;; Student: Constant Patrice KODJA ADJOVI
;; S21
;; Model: This project goal is to implement the gradien paths based on the areas' elevation in altitude (gradlevel variable)
;; Please do reduce the ticks speed in order the experience slow move.

;;Notice: ;;Gradien_0_XPosition and Gradien_0_YPosition are values that provide an offset from min-pxcor and min-pycor.

breed [ originTurtles originTurtle ]  ;; Turtle to be placed at the most min point (area with lower gradien)
breed [ fieldTurtles fieldTurtle ]  ;; Turtles in the field which will run to grafien 0 (gradlevel 0)

globals[
  optPt-xcor optPt-ycor  ;; min point of gathering
  patchCurrXcor patchCurrYcor  ;; This is to keep track with the turtles move in relation with the area elevation.
  countrestfieldturtles ;; for counting non-dying fieldTurtles
  dyingTurtles ;; number of dead fieldTurtles
]

patches-own [
  gradlevel   ;; area geographicla elevation
]

turtles-own [
]

to setup
  clear-all
  set countrestfieldturtles 0 ;; set remaining fieldTurtles counter to 0

  create-originTurtles 1 [set xcor optPt-xcor
    set ycor optPt-ycor set hidden? true] ;; Turtle 0 creation for world origin identification
                                          ;; Gradien_0_XPosition and Gradien_0_YPosition
                                          ;; are values that provide an offset from min-pxcor and min-pycor.
                                          ;; originTurtle 0 is hidden in oorder to let the red patch appear.

  set patchCurrXcor 0  ;; turtle patch position initialization
  set patchCurrYcor 0

  post-setup ;; to create and point a turtle to the origin

  set optPt-xcor min-pxcor + Gradien_0_XPosition ;; select the origin point at the minimum point of the area elevation
  set optPt-ycor min-pycor + Gradien_0_YPosition

  ask patch optPt-xcor optPt-ycor [ask neighbors [ set pcolor white ] set gradlevel 0 set pcolor red] ;; color origin patch's turtle's
                                                                                      ;; neighbors in WHITE

  ;;post-setup ;; to create and point a turtle to the origin

  reset-ticks
end 

to post-setup
  patches-elevation  ;; To assign area elevation to each patch by feeling it local variable grad-level

  ask patch optPt-xcor optPt-ycor [set gradlevel 0]

  create-fieldTurtles TotTurtlesNum [
    set xcor random-pxcor
    set ycor random-pycor
    ;;set color yellow
    set size 2
    set shape "arrow"
    pen-down
    facexy optPt-xcor optPt-ycor
  ]
end 

to patches-elevation
  let totpatches (max-pxcor * max-pycor)

  ask patches [
    let elevation random totpatches
    let elev% ceiling ( (elevation / totpatches) * 100 )

    if elevation != 0 [
      set gradlevel elevation
      ;;set pcolor scale-color basefieldcolor 10 50 5 ;; is a color
      if ( (elev% >= 95) and (elev% <= 100) ) [set pcolor basefieldcolor + 1.17 ]
      if ( (elev% >= 75) and (elev% < 95) ) [set pcolor (basefieldcolor + 1.2) ]
      if ( (elev% >= 50) and (elev% < 75) ) [set pcolor (basefieldcolor + 1.3) ]
      if ( (elev% >= 20) and (elev% < 50) ) [set pcolor (basefieldcolor + 1.4) ]
      if ( (elev% > 00) and (elev% < 20) ) [set pcolor (basefieldcolor + 1.5) ]
      ;;if (elev% = 00) [set pcolor white ]

      show gradlevel
      show elev%
    ]
]
end 

to go

  ;;setup ;; to force running setup procedure first

  set countrestfieldturtles count fieldTurtles  ;; fieldTurtles counting
  set dyingTurtles TotTurtlesNum - countrestfieldturtles

  ask fieldTurtles [

    ask patch optPt-xcor optPt-ycor [ask neighbors [ set pcolor white ]
     set gradlevel 0 set pcolor red] ;; color origin patch's turtle's neighbors in WHITE

    savePatchXY  ;; to save the current turtle position
                 ;; in order to compare it to the next position
                 ;; and see if the turtle will come back to it
                 ;; if the min elevation <= the same

    show "Below former pxcor and pycor"
    show patchCurrXcor show patchCurrYcor ;; for checking

    move-to min-one-of neighbors [gradlevel]  ;; Move the turtle onto
                                              ;; the lowest elevation within its close patches

    savePatchXY  ;; To save the new coordinates after "min-one-of neighbors"

    ask neighbors [set pcolor green] ;; color the turtle close patches

    show "Below after move pxcor and pycor"
    show pxcor show pycor ;; for checking

    show "Area (patch) altitude value (area elevation)"
    show gradlevel

    minPointNeigborhood ;; procedure for turtle's death if the most min point (area) is reached

    facexy optPt-xcor optPt-ycor  ;; To allow the turtle to always point to
                                            ;; the general min point (2,2)
    if (patchCurrXcor = pxcor and patchCurrYcor = pycor)
      [ fd 3 minPointNeigborhood ] ;; move to 3 steps away in order to avoid having the former low elevation
             ;; within it close patches if by the that value would ne lower than the next one
             ;; and will force the turtle to come back to it's former position

    ;;ask patch optPt-xcor optPt-ycor [ask neighbors [ set pcolor white ] set gradlevel 0 set pcolor red] ;; color origin patch's turtle's
                                                                                      ;; neighbors in WHITE

  ]
  ask patch optPt-xcor optPt-ycor [ask neighbors [ set pcolor white ]
    set gradlevel 0 set pcolor red] ;; color origin patch's turtle's neighbors in WHITE

  tick
  if ticks = Stop_ticks_Num [ beep stop ] ;; Stops the steps counter and emits a sound to indicate the simulation end
end 

to savePatchXY
  set patchCurrXcor pxcor ;; update the global variables with the current turtle position
  set patchCurrYcor pycor
end 


;; to check if the turtle's patch is within the close patch's neighbors of the most min point (area)
;;and if so, turtle can die

to minPointNeigborhood
  if ( (pxcor = optPt-xcor and pycor = optPt-ycor) or gradlevel = 0 )
      [ show "The most min point is reached (-grad)"
         die ] ;; If general min point (area) is reached
                                                           ;;or area's altitude is 0, the turtle die
  ask originTurtle 0
  [if ( member? [pxcor] of fieldTurtles [pxcor] of neighbors ) [ die ]] ;; if a turtle arrives in origin neighborhood, it dies
end 

There is only one version of this model, created almost 4 years ago by Constant Patrice KODJA ADJOVI.

Attached files

File Type Description Last updated
Area Gradients Simulation.png preview Preview for 'Area Gradients Simulation' almost 4 years ago, by Constant Patrice KODJA ADJOVI Download

This model does not have any ancestors.

This model does not have any descendants.