Yu_Liu_FinalProject_V2

No preview image

1 collaborator

Img_3637 Yu Liu (Author)

Tags

(This model has yet to be categorized with any tags)
Model group MAM-2013 | Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.4 • Viewed 473 times • Downloaded 69 times • Run 0 times
Download the 'Yu_Liu_FinalProject_V2' 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?

This model shows how a given society's criminal activities are influenced by police policies(tax rate and police salary). The model allows user to set the parameters of a society, including living expense, job ratio, fair factor and tendency to change career. The user can observe the collective wealth, avreage wealth and career distribution of each kind of characters in society.This model explores three extensions.First is simulate the situation thief can escape from police, second is introduce catastrophe to societ and lastly is HubNet model.

HOW IT WORKS

If I am a worker: If my salary is enough for living, I will work here and get money, then I pay tax, otherwise I will search job, I keep moving until I find a patch without anyone else Rules to switch career/job: If my salary is lower than living expense, I will become a thief Otherwise I have 70% chance to change job and 30% to change career. If I choose to change career, first if my job salary lower than police pay, I will become police Otherwise if average worker wealth is lower than average thief wealth, I will become thief.

If I am a police: I first see if there is some thief around me, if so, punish him by taking half of his money Then I walk around Rules to switch career: Then I have chance to change my career: If I find a job with higher salary than police pay, I become a worker and work here. Otherwise I check average worker wealth and average thief wealth, I will become the higher one if it is also higher than police pay.

If I am a thief: I first see if there is some worker around me, if so, grab half of his money Then I walk around Rules to switch career: Then I have chance to change my career if my money is less than average wealth of worker of police. If I decide change career, I will become the one with higher average wealth.

Lastly, there is one rule for the society as a whole: when everyone dies, the system stops. Notice in case of user want to try HubNet with zero initial population, current the system is set to stop if population is zero after 150 ticks.This time is long enough for user join.

HOW TO USE IT

Setup:set up the initial population and job distributed GO: Starts and stops the model.

The input parameters of this model can be divided into two parts roughly: the setting of a society(initial population of each breed, job ratio, fair factor, people's tendency of changing career) and the policies of the society(police pay and tax rate).

Regarding of the setting of a society: 1.number-of-worker, number-of-thief-number-of-police As their name implies, they are the initial population of each character. These parameters have to be set before running "set up" procedure. Changing them after press "go" button has no effect. 2.job-ratio The higher this value, the more jobs in the world. 3.fair-factor The higher this value, the more fairly salary is distributed. 4.living expense The basic living expense that everyone needs to spend each tick. 5.career-change-tendency The probability for everyone to change their career.

Regarding of the policies 1.police-pay The salary police expects to get each tick. But police has no guarantee to get this salary unless government collects enough tax 2.tax-rate The ratio needs to take away from worker's salary. Tax rate is used for paying police.

Lastly, There is one rule for the society as a whole: when everyone dies, the system stops.

THINGS TO NOTICE

Run the model with the default settings.Watch the plots at the bottom. What kind of career distribution and wealth distribution you see and is this the same as you expected?

THINGS TO TRY

Change tax rate and police pay to different values and see what will happend. Is the effect the same as you expected? After familiar with the model, set police pay as 4 and tax rate 0.25 (other values are welcomed to try if interested), then try to change the slider to any you society you can find data in real life, and observe whether the result matches. Also mental expirements is highly recommended, user can set certain extreme society context or policies to see the result.

EXTENDING THE MODEL

There are other policies which can influence criminal polices, such as welfare. Also other features of society can be further explored.

NETLOGO FEATURES

Breeds are used to represent the two different kinds of agents. The turtles primitive is used to refer to both breeds together. Using HubNet to allow user get involved into the model.

RELATED MODELS

Did not find yet.

CREDITS AND REFERENCES

(a reference to the model's URL on the web if it has one, as well as any other necessary credits, citations, and links)

Comments and Questions

FinalProject V3

adding different salary and rules to changes career.

Posted over 12 years ago

Click to Run Model

breed [worker a-worker]
breed [thief a-cowboy]
breed [police a-police]
turtles-own
[
  money
  user-id
  step-size
  user-control?
]
patches-own[job-salary]
globals[tax]

to setup
  clear-patches
  clear-drawing
  clear-output
  
  ca
  set tax 0
  ask patches
  [                                                   ;;patches represent job, the salary of jobs obey maxwell-Boltzmann velocity distribution
    ifelse(random-float 100.00 < job-ratio)
    [
      let m 2.18e-25
      let k 1.38e-23
      let cons1  m / (2 * pi * k * fair-factor)
      set cons1 cons1 * cons1 * cons1
      set cons1 cons1 * 4 * pi
      let cons2 -1 * m / (2 * k * fair-factor * 100)
      let x random-float 1500.00
      let fv cons1 * x * x * exp(cons2 * x * x)
      set fv  fv * 1e6                               ;;magnify the result to reasonable range
      if(fair-factor > 1)
        [
          set fv fv * fair-factor                      ;;more fair society has lower collective wealth in Boltzmann, so here needs to add reward to fair society
        ]
      set job-salary ceiling fv      
    ]
    [
      set pcolor black                 ;;patch color initialized black 
    ]
  ]
  visualize-job-salary
  create-worker number-of-worker
  [
    set size 2;
    set money 100
    set shape "person"
    set color  blue                                   ;;worker colored blue
    setxy random-xcor random-ycor                     ;;random init position
    set user-control? false
  ]
  create-thief number-of-thief
  [
    set size 2;
    set money 100
    set shape "person"
    set color  red                                    ;;Thief colored red
    setxy random-xcor random-ycor                     ;;random init position
    set user-control? false
  ]
  create-police number-of-police
  [
    set size 2;
    set money 100
    set shape "person"
    set color  brown                                  ;;Police colored brown
    setxy random-xcor random-ycor                     ;;random init position
    set user-control? false
  ]
  reset-ticks
end 

to go
  show-money                                          ;;visualize each people's money
  visualize-job-salary                                ;;color patch to visualize salary
  listen-clients                                      ;;hubnet function, listen to user operation
  every 0.1
  [ 
    ask turtles
    [spend-living-expense]                            ;;everyone needs to spend basic living expense
    ask worker
    [ 
      set money money + job-salary
      pay-tax
      if user-control? = false                        ;;aotumatically action doesn not happen if user control the turtle, they same hold for other turtles
      [
        search-job
        worker-change-career
      ]
    ]
    pay-police                                        ;;pay police based on how many tax is collected
    ask police
    [
      punish-thief                                    ;;police in charge of punish thief 
      if user-control? = false
      [
        search                                        ;;walk around 
        police-change-career
      ]
    ]
    ask thief
    [
      grab-money
      if user-control? = false
      [
        search
        thief-change-career
        if(thief-escape-mode?)                      ;;thief will escape when police near by(in a certain range)
        [escape]
      ]
    ]
    catastrophe                                     ;;check whether catastrophe mode is on, and if so do introduce it.
    tick
  ]
  if ticks > 150
  [
    if count turtles = 0
    [stop]
  ]
end 

;;;;;;;;;turtle functions;;;;;;;;;;;;;;;;;;;;;
;;turtle spend basic living expense if not die

to spend-living-expense
  check-die                                         
  set money money - living-expense                  ;;;;updete the money left
end 

;;if any person(turtle) has 0 or less money, it will die 

to check-die                                       
  if(money <= 0)
  [die]
end 

;;choose a random direction and go

to search
  rt random 90
  lt random 90
  fd 0.5
end 

;;;;;;;;;;worker functions;;;;;;;;;;;;;;;;;;;;;

to search-job                                       ;;worker isn't allowed to take same job
  search
  while[any? other worker-here]                     ;;so if there is some other worker here, keep searching
  [search]
end 

to pay-tax
  let a-tax (job-salary * tax-rate)                 ;;calculate tax
  set money (money - a-tax)                         ;;take this money from worker
  set tax tax + a-tax                               ;;add this money to "government collective"
end 
;;this function follows the rules in info tab

to worker-change-career
  if (random-float 100.00 < career-change-tendency)
  [
    ifelse job-salary * (1 - tax-rate) < living-expense
    [
      set breed thief
      set color red
      set shape "person"
    ]
    [
      ifelse(random-float 100.00 >= 30)
      [ search-job]
      [
        let worker-expectation (ifelse-value (0 = count worker)  [0] [mean[money] of worker])   ;;calculate average wealth of worker and thief
        let thief-expectation  (ifelse-value (0 = count thief)  [0] [mean[money] of thief])
        ifelse (job-salary * (1 - tax-rate) < police-pay or worker-expectation < thief-expectation )  ;;trigure the condition of changing career
        [
          ifelse((job-salary * (1 - tax-rate)) < police-pay)                                          ;;choose which to become
          [
            set breed police
            set color brown
            set shape "person"
          ]
          [
            set breed thief
            set color red
            set shape "person"
          ]
        ]
        [search-job]
      ]
    ]
    
  ]
end 


;;;;;;;;;;;;;;;police functions;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;punish half of thief's money if there is any thief at the same patch with the police

to punish-thief                                          
  let money-from 0
  if any? thief
  [  
    ask one-of thief
    [
      set money-from money / 2                            ;;record how many money can punish
      set money money / 2
    ]
    set money money + money-from                        
  ]
end 

;;this function follows the rules in info tab

to police-change-career
  if (random-float 100.00 < career-change-tendency)
  [
    ifelse(job-salary * (1 - tax-rate) > (floor tax / count police) )
    [
      set breed worker
      set color blue
      set shape "person"
    ]
    [
      let worker-expectation (ifelse-value (0 = count worker)  [0] [mean[money] of worker])
      let thief-expectation  (ifelse-value (0 = count thief)  [0] [mean[money] of thief])
      if(money < worker-expectation or money < thief-expectation)
      [
        ifelse(thief-expectation > worker-expectation)
        [
          set breed thief
          set color red
          set shape "person"
        ]
        [
          set breed worker
          set color blue
          set shape "person"
        ]
      ]
    ]
  ]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;thief functions;;;;;;;;;;;;;;;;;;;;;
;;this function follows the rules in info tab

to thief-change-career
  if (random-float 100.00 < career-change-tendency)
  [
    let worker-expectation (ifelse-value (0 = count worker)  [0] [mean[money] of worker])
    let police-expectation (ifelse-value (0 = count police)  [0] [mean[money] of police])
    if(money < worker-expectation or money < police-expectation)
    [
      ifelse worker-expectation >= police-expectation
      [
        set breed worker
        set color blue
        set shape "person"
      ]
      [
        set breed police
        set color brown
        set shape "person"
      ]
    ]
  ]
end 
;;try to grab money from worker

to grab-money
  let money-from 0
  if any? worker-here 
  [                                                         ;;if there any worker nearby, then steal money
    ask one-of worker-here
    [
      set money-from  money / 2                             ;;get worker's money info(how much they have
      set money  money / 2
    ]
    set money money + money-from                            ;;successfully steal money, add this money to thief money
  ]
end 
;;try to escape from police

to escape
  let object one-of police in-radius thief-vision           ;I simply use in-radius rather than in-cone here because this is not a main parameter, so user do not need to bother set two parameters         
  if object != nobody                                                   
  [
    face object                                                              
    rt 180                                     
    fd 2
  ]  
end 


;;system functions
;;use the collective tax to pay for police

to pay-police
  ifelse (tax >= police-pay * (count police))                           ;;if the money is enough to pay all polices
  [
    ask police
    [
      set money money + police-pay                                      ;;give police their payment
    ]
    set tax tax - police-pay * (count police)                           ;;reduce remaining tax
  ]
  [
    ask n-of  (floor tax / police-pay)  police                          ;;if the money is only enough to pay some police, randomly choose whom to pay
    [
      set money money + police-pay
    ]
    set tax tax -  (floor tax / police-pay)  * police-pay               ;;reduce remaining tax
  ]
end 
;;whether to show money

to show-money
  ask turtles[
    ifelse show-money?
    [ set label floor money]
    [ set label ""]
  ]
end 
;;whether to show job salary, use scale of color to vidualize

to visualize-job-salary
  ask patches with [job-salary > 0]
  [
    ifelse(visualize-job-salary?)
    [ set pcolor scale-color green job-salary 0 50]
    [ set pcolor black]
  ]
end 
;;;;;introduce catastrophe to society

to catastrophe
  if catastrophe-mode?
  [
    if (random-float 100.00 < catastrophe-probability)              ;;if catastrophe happens
    [
      let x random-xcor
      let y random-ycor
      let r random-float 2                                          ;;randomly choose a circle
      ask patches with[pxcor < x + r and pxcor > x - r and pycor < y + r and pycor > y - r]      ;;destory jobs within this circle
      [
        set job-salary 0
        ifelse(visualize-job-salary?)
        [set pcolor yellow]                                           ;;use yellow to vidualize catastrophe
        [set pcolor black]
      ]
      ask turtles with[xcor < x + r and xcor > x - r and ycor < y + r and ycor > y - r]          ;;and kill people within this circle
      [die]
    ]
    if (random-float 100.00 < rebuild-probability)                   ;;society has chance to rebuid
    [
      ask one-of patches with[job-salary <= 0]                       ;;by creating some new jobs, and the salary also obey Boltmann distribution
      [
        let m 2.18e-25
        let k 1.38e-23
        let cons1  m / (2 * pi * k * fair-factor)
        set cons1 cons1 * cons1 * cons1
        set cons1 cons1 * 4 * pi
        let cons2 -1 * m / (2 * k * fair-factor * 100)
        let x random-float 1500.00
        let fv cons1 * x * x * exp(cons2 * x * x)
        set fv ceiling (fv * 1e6)
        set job-salary fv
        ifelse(visualize-job-salary?)
        [set pcolor scale-color green fv 0 50]
        [set pcolor black]
      ]
    ]
  ]
end 


;;
;; HubNet Procedures
;;


;; the STARTUP procedure runs only once at the beginning of the model
;; at this point you must initialize the system.

to startup
  hubnet-reset
end 

to listen-clients
  ;; as long as there are more messages from the clients
  ;; keep processing them.
  while [ hubnet-message-waiting? ]
  [
    ;; get the first message in the queue
    hubnet-fetch-message
    ifelse hubnet-enter-message? ;; when clients enter we get a special message
    [ create-new-student ]
    [
      ifelse hubnet-exit-message? ;; when clients exit we get a special message
      [ remove-student ]
      [ ask turtles with [user-id = hubnet-message-source]
        [ execute-command hubnet-message-tag ] ;; otherwise the message means that the user has
      ]                                        ;; done something in the interface hubnet-message-tag
                                               ;; is the name of the widget that was changed
    ]
  ]
end 

;; when a new user logs in create a student turtle
;; this turtle will store any state on the client
;; values of sliders, etc.

to create-new-student
  create-turtles 1
  [
    ;; store the message-source in user-id now
    ;; so when you get messages from this client
    ;; later you will know which turtle it affects
    set user-control? true
    set user-id hubnet-message-source
    set money 100
    set step-size 1
    set breed worker
    set size 2
    set shape "person"
    set color blue
    set xcor random-xcor
    set ycor random-ycor
    ;; update the clients with any information you have set
    send-info-to-clients
  ]
end 

to remove-student
  ask turtles with [user-id = hubnet-message-source]
  [ die ]
end 

to execute-command [command]
  if command = "step-size"
  [
    set step-size hubnet-message
    stop
  ]
  if command = "up"
  [ execute-move 0 stop ]
  if command = "down"
  [ execute-move 180 stop ]
  if command = "right"
  [ execute-move 90 stop ]
  if command = "left"
  [ execute-move 270 stop ]
  if command = "become-police"
  [ 
    set breed police
    set shape "person"
    set color brown 
  ]
  if command = "become-thief"
  [ 
    set breed thief
    set shape "person"
    set color red
  ]
  if command = "become-worker"
  [ 
    set breed worker
    set shape "person"
    set color blue
  ]
end 

;; whenever something in world changes that should be displayed in
;; a monitor on the client send the information back to the client

to send-info-to-clients ;; turtle procedure
  hubnet-send user-id "salary" job-salary
  hubnet-send user-id "tax-rate" tax-rate
  hubnet-send user-id "police-pay" police-pay
  hubnet-send user-id "worker-wealth" ceiling sum [money] of worker
  hubnet-send user-id "thief-wealth"  ceiling sum [money] of thief
  hubnet-send user-id "police-wealth" ceiling sum [money] of police
  if breed = police
  [hubnet-send user-id "career" "police"]
  if breed = worker
  [hubnet-send user-id "career" "worker"]
  if breed = thief
  [hubnet-send user-id "career" "thief"]
end 

to execute-move [new-heading]
  set heading new-heading
  fd step-size
  send-info-to-clients
end 


;;;;;;;;;;;;show output functions

to-report total-money-of-worker                    ;;report personal property(money) of worker
  report sum [money] of worker
end 

to-report total-money-of-thief                     ;;report personal property(money) of thief
  report sum [money] of thief
end 

to-report total-money-of-police                    ;;report personal property(money) of police
  report sum [money] of police
end 

to-report total-money                              ;;report personal property(money) of all person(turtles)
  report sum[money]of turtles
end 

to-report average-worker
  ifelse count worker = 0
  [report 0]
  [report mean[money]of worker]
end 

to-report average-thief
  ifelse count thief = 0
  [report 0]
  [report mean[money]of thief]
end 

to-report average-police
  ifelse count police = 0
  [report 0]
  [report mean[money]of police]
end 

to-report average-all
  ifelse count turtles = 0
  [report 0]
  [report mean[money]of turtles]
end 

There are 7 versions of this model.

Uploaded by When Description Download
Yu Liu about 12 years ago Final version Download this version
Yu Liu about 12 years ago Final version Download this version
Yu Liu about 12 years ago with disaster extension Download this version
Yu Liu about 12 years ago hubnet extension Download this version
Yu Liu about 12 years ago update project Download this version
Yu Liu over 12 years ago V3 Download this version
Yu Liu over 12 years ago Initial upload Download this version

Attached files

File Type Description Last updated
FinalProjectProposal.docx word Original final project proposal about 12 years ago, by Yu Liu Download
readme.txt word additional instructions about 12 years ago, by Yu Liu Download
Yu_Liu_FinalPaper.pdf pdf PDF version of final paper about 12 years ago, by Yu Liu Download
Yu_Liu_Slam.pptx word Poster slam PPT about 12 years ago, by Yu Liu Download
YuLiu_FinalProjectProposal feedback.docx word Final Proposal feedback about 12 years ago, by Yu Liu Download
YuLiu_June03.docx word Progress report over 12 years ago, by Yu Liu Download
YuLiu_May20.docx word Progress report over 12 years ago, by Yu Liu Download
YuLiu_May27.docx word Progress report over 12 years ago, by Yu Liu Download
YuLiu_May27.docx word next report, the part of what questions my model can answer over 12 years ago, by Yu Liu Download
yuliu_present.pdf pdf poster about 12 years ago, by Yu Liu Download

This model does not have any ancestors.

This model does not have any descendants.