Zakat Charity and Wealth Distribution An Agent-Based Computational Model

No preview image

1 collaborator

Download Muhammad Asif (Author)

Tags

zakat, wealth distribution 

Tagged by Muhammad Asif 10 months ago

Visible to everyone | Changeable by the author
Model was written in NetLogo 6.3.0 • Viewed 40 times • Downloaded 9 times • Run 0 times
Download the 'Zakat Charity and Wealth Distribution An Agent-Based Computational Model' 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-grain    ;; maximum amount any patch can hold set within model (below) as 50
  gini-index-reserve
  lorenz-points
  TotalZakat ;;Zakat total per cycle zakat pls and minus
            ;;Thru slider = percent-best-land, num-people, life-expectancy-max, life-expectancy-min
  Batch ;;just for data run control, each setup will be assigned a unique random number
  totalPoordied ;;tutles died because of wealth less than zero
]
patches-own
[
  grain-here      ; the current amount of grain on this patch
  max-grain-here  ; the maximum amount of grain this patch can hold
]
turtles-own
[
  age              ; how old a turtle is
  wealth           ; the amount of grain a turtle has
  life-expectancy  ; maximum age that a turtle can reach
  metabolism       ; how much grain a turtle eats each time
  vision           ; how many patches ahead a turtle can see
  zakat
]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

to setup
  clear-all
  ;; setting seed for random numbers
  if Run# = 1 [random-seed 1151]
  if Run# = 2 [random-seed 1251]
  if Run# = 3 [random-seed 1351]
  if Run# = 4 [random-seed 1451]
  if Run# = 5 [random-seed 1551]
  ;; set global variables to appropriate values
  set max-grain 150
  set Batch random 10000
  ;; call other procedures to set up various parts of the world
  setup-patches
  setup-turtles
  update-lorenz-and-gini
  reset-ticks
  fileheaders
end 

to setup-patches
  ;; set up the initial amounts of grain each patch has
  ;; give some patches the highest amount of grain possible --
  ;; these patches are the "best land"
  ask patches
    [ set max-grain-here 0
      if (random-float 100.0) <= percent-best-land
        [ set max-grain-here max-grain
          set grain-here max-grain-here ] ]
  ;; spread that grain around the window a little and put a little back
  ;; into the patches that are the "best land" found above
  repeat 5
    [ ask patches with [max-grain-here != 0]
        [ set grain-here max-grain-here ]
      diffuse grain-here 0.25 ]
  repeat 10
    [ diffuse grain-here 0.25 ]          ;; spread the grain around some more
  ask patches
    [ set grain-here floor grain-here    ;; round grain levels to whole numbers
      set max-grain-here grain-here      ;; initial grain level is also maximum
      recolor-patch ]
end 

to recolor-patch  ;; patch procedure -- use color to indicate grain level
  set pcolor scale-color white grain-here 0 max-grain
end 

to setup-turtles
  ;; set up the initial values for the turtle variables
  set-default-shape turtles "person"
  crt num-people
    [ move-to one-of patches  ;; put turtles on patch centers
      set size 1.5  ;; easier to see
      set-initial-turtle-vars
      set age random life-expectancy ]
  recolor-turtles
end 

to set-initial-turtle-vars
  set age 0
  face one-of neighbors4
  set life-expectancy life-expectancy-min + random (life-expectancy-max - life-expectancy-min + 1)
  set metabolism 1 + random metabolism-max
  set wealth metabolism + random 50
  set vision 1 + random max-vision
end 

to recolor-turtles
  ;; Set the class of the turtles -- if a turtle has less than a third
  ;; the wealth of the richest turtle, color it red.  If between one
  ;; and two thirds, color it green.  If over two thirds, color it blue.
  let max-wealth max [wealth] of turtles
  ask turtles
    [ ifelse (wealth <= max-wealth / 3)
        [ set color red ]
        [ ifelse (wealth <= (max-wealth * 2 / 3))
            [ set color green ]
            [ set color blue ] ] ]
end 

;;; GO AND HELPERS

to go
  Set TotalZakat 0
  ask turtles [ Set Zakat 0 turn-towards-grain ]  ;; choose direction holding most grain within the turtle's vision
  harvest
  ask turtles [move-eat-age-die ]
  recolor-turtles
  ;; grow grain every grain-growth-interval clock ticks
  if ticks mod grain-growth-interval = 0 [ ask patches [ grow-grain ] ]
  update-lorenz-and-gini
  FileEntries
  ;; set-current-directory "C:\\Users\\masif\\Desktop"
  show min [wealth] of turtles
  tick
  if ticks = MaxCycles [stop]
end 

to turn-towards-grain  ;; turtle procedure
  ;; determine the direction which is most profitable for each turtle in
  ;; the surrounding patches within the turtles' vision
  set heading 0
  let best-direction 0
  let best-amount grain-ahead
  set heading 90
  if (grain-ahead > best-amount) [ set best-direction 90 set best-amount grain-ahead ]
  set heading 180
  if (grain-ahead > best-amount) [ set best-direction 180 set best-amount grain-ahead ]
  set heading 270
  if (grain-ahead > best-amount) [ set best-direction 270 set best-amount grain-ahead ]
  set heading best-direction
end 

to-report grain-ahead  ;; turtle procedure
  let total 0
  let how-far 1
  repeat vision
    [ set total total + [grain-here] of patch-ahead how-far
      set how-far how-far + 1 ]
  report total
end 

to grow-grain  ;; patch procedure
  ;; if a patch does not have it's maximum amount of grain, add
  ;; num-grain-grown to its grain amount
  if (grain-here < max-grain-here)
    [ set grain-here grain-here + num-grain-grown
      ;; if the new amount of grain on a patch is over its maximum
      ;; capacity, set it to its maximum
      if (grain-here > max-grain-here)
        [ set grain-here max-grain-here ]
      recolor-patch ]
end 

to harvest
  ;; each turtle harvests the grain on its patch.  if there are multiple
  ;; turtles on a patch, divide the grain evenly among the turtles
  ;; have turtles harvest before any turtle sets the patch to 0
  ask turtles
    [ set wealth floor (wealth + (grain-here / (count turtles-here))) ]
  ;; now that the grain has been harvested, have the turtles make the
  ;; patches which they are on have no grain
  ask turtles
    [ set grain-here 0
      recolor-patch ]
end 

to move-eat-age-die  ;; turtle procedure
  fd 1
  ;; consume some grain according to metabolism
  set wealth (wealth - metabolism)
  ;; grow older
  set age (age + 1)
; zakat procedure
if zakat_status? = true
[ zakat_distribution]

  ;; check for death conditions: if you have no grain or
  ;; you're older than the life expectancy or if some random factor
  ;; holds, then you "die" and are "reborn" (in fact, your variables
  ;; are just reset to new random values)
  if (wealth < 0) [ set-initial-turtle-vars set totalpoordied (totalpoordied + 1) ]
  if (age >= life-expectancy) [ set-initial-turtle-vars ]
end 

to zakat_distribution

  if ( count turtles with [color = red] > 0 )
  [if random 100 < Prob_Giving
    [
      if (ZakatWealthLimit = ">Mean Wealth")           [if (wealth > mean [wealth] of turtles) [Update_Zakat_And_Wealth ]]
      if (ZakatWealthLimit = "Rich Class Only")        [if (color = blue) [Update_Zakat_And_Wealth ]]
      if (ZakatWealthLimit = "Middle and Rich Class")  [if (color = green or color = blue) [Update_Zakat_And_Wealth ]]
    ]
  ]
end 

to Update_Zakat_And_Wealth
  Let TempZakat 0
  set TempZakat wealth * 0.025
  set zakat TempZakat  ;;show wealth show zakat show TempZakat
  set wealth wealth - TempZakat ;;Show wealth
  if (ZakatTakers = "Random")
  [
    ask one-of turtles with [color = red ]
    [ set zakat zakat - TempZakat ;;show wealth show zakat show TempZakat
      set wealth wealth + TempZakat ;;show wealth
    ]
  ]
  if (ZakatTakers = "Extreme")
  [
    let minW min [wealth] of turtles
    ask one-of turtles with [wealth = minW]
    [ set zakat zakat - TempZakat ;;show wealth show zakat show TempZakat
      set wealth wealth + TempZakat ;;show wealth
    ]
  ]
  set TotalZakat TotalZakat + TempZakat
end 

to update-lorenz-and-gini
  ;; this procedure recomputes the value of gini-index-reserve
  ;; and the points in lorenz-points for the Lorenz and Gini-Index plots
  let sorted-wealths sort [wealth] of turtles
  let total-wealth sum sorted-wealths
  let wealth-sum-so-far 0
  let index 0
  set gini-index-reserve 0
  set lorenz-points []

  ;; now actually plot the Lorenz curve -- along the way, we also
  ;; calculate the Gini index.
  ;; (see the Info tab for a description of the curve and measure)
  repeat num-people [
    set wealth-sum-so-far (wealth-sum-so-far + item index sorted-wealths)
    set lorenz-points lput ((wealth-sum-so-far / total-wealth) * 100) lorenz-points
    set index (index + 1)
    set gini-index-reserve
    gini-index-reserve +
    (index / num-people) -
    (wealth-sum-so-far / total-wealth)
  ]
end 

to fileheaders
  file-close-all
  set-current-directory "C:\\Users\\masif\\Desktop"
  ;;carefully [file-delete  "zakaatdata.csv"] []
  file-open "zakaatdata.csv"
  file-type "zakat_status? ,"
  file-type "Batch Run ,"
  file-type "count turtles Lower class < MaxWealth x 1/3 (Red) ,"
  file-type "count turtles Middle Class B/w MaxWealth x 1/3 and MaxWealth x 2/3 (Green) ,"
  file-type "count turtles Upper Class > MaxWealth x 2/3 (blue) ,"
  file-type "sum [wealth] Lower class ," ;; of turtles with [color = red]
  file-type "sum [wealth] Middle Class ," ;; of turtles with [color = green]
  file-type "sum [wealth] Upper Class ," ;; of turtles with [color = blue]"
  file-type "Total wealth ," ;; sum [wealth] of turtles"
  file-type "gini-index-reserve ,"
  file-type "gini ,"
  ;;file-type "lorenz-points ,"
  file-type "num-people ,"
  file-type "max-vision ,"
  file-type "metabolism-max ,"
  file-type "percent-best-land ,"
  file-type "life-expectancy-max ,"
  file-type "life-expectancy-min ,"
  file-type "grain-growth-interval ,"
  file-type "num-grain-grown ,"
  file-type "run date-and-time ,"
  file-type "cycle # ,"
  file-type "wealt of random turtle 4 ,"
  file-type "max [wealth] of turtles ,"
  file-type "min [wealth] of turtles ,"
  file-type "sum zakat +ve givers ,"
  file-type "sum zakat -ve takers ,"
  file-type "count zakat givers ,"
  file-type "count zakat takers ,"
  file-type "TotalZakat ,"
  file-type "Prob_Giving ,"
  file-type "ZakatWealthLimit ,"
  file-type "ZakatTakers ,"
  file-type "totalpoordied ,"
  file-type "avgvision_poor ,"
  file-type "avgvision_middle ,"
  file-type "avgvision_rich ,"
  file-type "avgage_poor ,"
  file-type "avgage_middle ,"
  file-type "avgage_rich ,"
  file-print ","
  file-close-all
end 

to FileEntries
  file-open "zakaatdata.csv"
  file-type zakat_status?
  file-type ","
  file-type Batch
  file-type ","
  file-type   count turtles with [color = red]
  file-type ","
  file-type   count turtles with [color = green]
  file-type ","
  file-type    count turtles with [color = blue]
  file-type ","
  file-type sum [wealth] of turtles with [color = red]
  file-type ","
  file-type sum [wealth] of turtles with [color = green]
  file-type ","
  file-type sum [wealth] of turtles with [color = blue]
  file-type ","
  file-type sum [wealth] of turtles
  file-type ","
  file-type gini-index-reserve
  file-type ","
  file-type (gini-index-reserve / num-people) / 0.5
  file-type ","
  ;;file-type lorenz-points
  ;;file-type ","
  file-type num-people
  file-type ","
  file-type max-vision
  file-type ","
  file-type metabolism-max
  file-type ","
  file-type percent-best-land
  file-type ","
  file-type life-expectancy-max
  file-type ","
  file-type life-expectancy-min
  file-type ","
  file-type grain-growth-interval
  file-type ","
  file-type num-grain-grown
  file-type ","
  file-type date-and-time
  file-type ","
  file-type ticks
  file-type ","
  ask turtle 4 [file-write wealth]
  file-type ","
  file-type max [wealth] of turtles
  file-type ","
  file-type min [wealth] of turtles
  file-type ","
  file-type sum [zakat] of turtles with [zakat > 0]
  file-type ","
  file-type sum [zakat] of turtles with [zakat < 0]
  file-type ","
  file-type count turtles with [zakat > 0] ;;not exactly rich class , probably b/c some interactions before zakat procedure changes color
  file-type ","
  file-type count turtles with [zakat < 0] ;; same as above
  file-type ","
  file-type TotalZakat
  file-type ","
  file-type Prob_Giving
  file-type ","
  file-type ZakatWealthLimit
  file-type ","
  file-type ZakatTakers
  file-type ","
  file-type totalpoordied
  file-type ","
  file-type Mean [vision] of turtles with [color = red]
  file-type ","
  file-type Mean [vision] of turtles with [color = green]
  file-type ","
  file-type Mean [vision] of turtles with [color = blue]
  file-type ","
  file-type Mean [age] of turtles with [color = red]
  file-type ","
  file-type Mean [age] of turtles with [color = green]
  file-type ","
  file-type Mean [age] of turtles with [color = blue]
  file-print ","

  file-close
end 

; Copyright 1998 Uri Wilensky
; See Info tab for full copyright and license.

There are 2 versions of this model.

Uploaded by When Description Download
Muhammad Asif 10 months ago information updated Download this version
Muhammad Asif 10 months ago Initial upload Download this version

Attached files

File Type Description Last updated
published 340-Article Text-1094-1-10-20220824.pdf pdf Zakat Charity and Wealth Distribution An Agent-Based Computational Model 10 months ago, by Muhammad Asif Download
Published paper.pdf pdf 4TH INTERNATIONAL CONFERENCE OF ZAKAT PROCEEDINGS ISSN: 2655-6251 Can Zakat Charity Help Reduce Economic Inequality? An Agent Based Simulation 10 months ago, by Muhammad Asif Download

This model does not have any ancestors.

This model does not have any descendants.