Yu_Liu_FinalProject_V2
No preview image
Model was written in NetLogo 5.0.4
•
Viewed 283 times
•
Downloaded 38 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Comments and Questions
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.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
FinalProjectProposal.docx | word | Original final project proposal | over 11 years ago, by Yu Liu | Download |
readme.txt | word | additional instructions | over 11 years ago, by Yu Liu | Download |
Yu_Liu_FinalPaper.pdf | PDF version of final paper | over 11 years ago, by Yu Liu | Download | |
Yu_Liu_Slam.pptx | word | Poster slam PPT | over 11 years ago, by Yu Liu | Download |
YuLiu_FinalProjectProposal feedback.docx | word | Final Proposal feedback | over 11 years ago, by Yu Liu | Download |
YuLiu_June03.docx | word | Progress report | over 11 years ago, by Yu Liu | Download |
YuLiu_May20.docx | word | Progress report | over 11 years ago, by Yu Liu | Download |
YuLiu_May27.docx | word | Progress report | over 11 years ago, by Yu Liu | Download |
YuLiu_May27.docx | word | next report, the part of what questions my model can answer | over 11 years ago, by Yu Liu | Download |
yuliu_present.pdf | poster | over 11 years ago, by Yu Liu | Download |
This model does not have any ancestors.
This model does not have any descendants.
Yu Liu
FinalProject V3
adding different salary and rules to changes career.
Posted over 11 years ago