首页
网站开发
桌面应用
管理软件
微信开发
App开发
嵌入式软件
工具软件
数据采集与分析
其他
首页
>
> 详细
辅导Program语言程序、讲解Java编程、Java程序辅导 讲解留学生Processing|辅导Database
项目预算:
开发周期:
发布时间:
要求地区:
Program 3
Due Mar 16 by 11:59pm Points 100
Program 3: Schelling's Model of Segregation
It is an Honor Code violation to resubmit prior work from an earlier semester in this course.
It is an Honor Code violation to submit work authored by someone else as your own.
You must include the following Virginia Tech Honor Code pledge at the very top of each Java file you write
(separate from the class Javadoc comment). Include your name and PID as shown, to serve as your
signature:
// Virginia Tech Honor Code Pledge:
//
// As a Hokie, I will conduct myself with honor and integrity at all times.
// I will not lie, cheat, or steal, nor will I accept the actions of those
// who do.
// -- Your Name (pid)
Goal
Racial segregation has always been a pernicious social problem in the United States. Although much effort has
been extended to desegregate our schools, churches, and neighborhoods, the US continues to remain
segregated (https://tcf.org/content/commentary/racial-segregation-is-still-a-problem/) by race and economic
lines. The New York Times has an interesting interactive map
(http://projects.nytimes.com/census/2010/explorer?ref=censusbureau) showing the distribution of racial and ethnic
groups in cities and states around the country as recorded during the 2010 census. Why is segregation such a
difficult problem to eradicate?
The forces that lead people to select where they live are complex and it is unlikely that any simple model can
truly answer the questions of how such segregation arises and why it persists. However, it is still possible to ask
simple questions that may shed some light on the situation.
In 1971, the American economist Thomas Schelling (http://en.wikipedia.org/wiki/Thomas_Schelling) created an
agent-based model that might help explain why segregation is so difficult to combat. He was trying to answer a
simple question: is it possible that even if a group of individuals would prefer to live in integrated neighborhoods,
might they still end up in segregated neighborhoods as the result of their collective choices?
2021/3/3 Program 3
https://canvas.vt.edu/courses/125115/assignments/1087638 2/6
His simple model of segregation showed that even when individuals (or "agents") didn't mind being surrounded
or living by agents of a different race, they would still choose to segregate themselves from other agents over
time! Although the model is quite simple, it gives a fascinating look at how individuals might self-segregate, even
when they have no explicit desire to do so. In this assignment, students will create a simulation of Schelling's
model, and see how it operates.
How the Model Works
We will work with a slight simplification of Schelling's model. To explain the model, suppose there are two types
of agents: X and O. For this assignment, these two types of agents will represent: those who prefer their iced tea
sweetened, and those who prefer their iced tea unsweetened. We'll use separate visual representations for these
individuals so it is easier to see how agents move. Green elephants are sweet tea drinkers, , while orange
monkeys prefer unsweetened tea, , instead.
Two populations of the two agent types are initially placed into random locations of a neighborhood represented
by a grid. After placing all the agents in the grid, each cell is either occupied by an agent or is empty as shown
below.
Now we must determine if each agent is satisfied with its current location. A satisfied agent is one that is
surrounded by at least t percent of agents that are like itself. That means each agent is perfectly happy to live in
an integrated neighborhood where 1 - t percent of its neighbors have the opposite tea preference. We'll call t the
agent's satisfaction threshold. Note that the higher the threshold, the higher the likelihood the agents will not be
satisfied with their current location.
For example, if t = 30%, agent X is satisfied if at least 30% of its neighbors are also X, meaning up to 70% of its
neighbors can be O's. If fewer than 30% are X, then the agent is not satisfied and it will want to change its
location in the grid. For the remainder of this explanation, let's assume a threshold t of 30%. This means every
agent is fine with being in the minority as long as there are at least 30% of similar agents in adjacent cells.
The picture below (left) shows a satisfied agent because 50% of X's neighbors are also X (50% > t). The next X
(right) is not satisfied because only 25% of its neighbors are X (25% < t). Notice that empty cells are not
counted when calculating satisfaction.
2021/3/3 Program 3
https://canvas.vt.edu/courses/125115/assignments/1087638 3/6
When an agent is not satisfied, it can move to any vacant location in the grid where it would be satisfied.
In the image below, all dissatisfied agents have an asterisk next to them. These are the agents that would
choose to move when it is their turn, although they will only move to a different cell if that cell is empty, and if they
would be satisfied after the move. Note that such a move may cause some agents that were previously satisfied
to become dissatisfied!
Design Exercise 1
In our implementation, on every call to act() an Agent will either move or stay put. You'll have to write the logic
to determine whether it will move or not, and to where. Recall that the World provides a getOneObjectAt()
method that takes an (x, y) location and returns the object, if any, that is located there (if multiple objects are
located there, it just returns one of them at random).
Before you read any further in this assignment, take a piece of paper and outline which method(s) you would
create for your Agent class to implement this choice. What logic would you use to decide whether you are
satisfied? What logic would you use to decide where to move?
Outline your logic now, and the methods you would use to implement it. Then proceed to read the rest of the
assignment.
Do NOT read below until you have finished your Agent class method design. The preliminary design should
contain for each method a descriptive name and parameter types.
__________________________________________________________________________________________
Starting Materials
Download the scenario for this assignment, which contains all the classes you need to start.: program3.zip.
The starting scenario does not contain any starting classes--you'll have to create all the classes yourself from
scratch. The starting scenario only contains the necessary images for the green elephants and the orange
monkeys.
Classes You Create
2021/3/3 Program 3
https://canvas.vt.edu/courses/125115/assignments/1087638 4/6
You will create two classes: one to represent the world, and one to represent the "agents" (that is, residents) who
live in and move around in the world. For this simulation, we will divide our population into two groups of agents:
those who prefer their iced tea sweetened, and those who prefer their iced tea unsweetened. We'll use separate
visual representations for these individuals so it is easier to see how agents move. Green elephants, , are
sweet tea drinkers, while orange monkeys, , prefer unsweetened tea instead.
A City Class
Create a subclass of World called City that represents a single rectangular region where your agents will live.
You can use any image background you wish for your city.
Your City class must provide a constructor that takes its width and height as parameters. Grid cells in your city
should be 24 pixels square. Each City should be initially empty (that is, no agents).
Your City class must also define a populate() method that takes three double parameters between 0.0 - 1.0.
The first parameter represents the percentage of elephants in the city, and the second represents the percentage
of monkeys. The third parameter represents the satisfaction threshold for the agents. For example, consider this
call:
city.populate(0.3, 0.4, 0.3);
This call indicates that approximately 30% of the cells in the city should be filled with elephants, and
approximately 40% of the cells should be filled with monkeys, which will leave approximately 30% of the cells
unoccupied or empty. All of the agents will use 0.3 (30%) as their satisfaction threshold, according to the third
parameter.
You can implement populate using a pair of loops:
For each possible X coordinate ...
And for each possible Y coordinate ...
Generate one random number between 0.0 - 1.0 for the cell at (x, y).
If that random number is less than or equal to the "elephant" parameter, then place an elephant at (x, y), or
If that random number is less than or equal to the sum of the "elephant" and "monkey" parameters, then put a
monkey at (x, y), or
Otherwise, leave that cell empty.
Note that you must limit yourself to just a single random number per cell. For example, for a 10x10 city, you
should make exactly 100 calls to generate random numbers, no more, no less. Use the same random value for
all tests you perform to determine the contents of a single cell location in the city.
Finally, your City class must also provide a default constructor that initializes the city to a size of your choice
(something that looks good on your screen), and then calls populate() with population ratios and a threshold
that you pick. You should implement your default constructor by using this to call the City constructor that
takes the width and height as parameters instead of using super() .
An Agent Class
Create a subclass of Actor called Agent that represents a single agent.
2021/3/3 Program 3
https://canvas.vt.edu/courses/125115/assignments/1087638 5/6
Your Agent should provide a constructor that takes two parameters: a String indicating the kind of animal, and
a double value between 0.0 - 1.0 indicating its satisfaction threshold.
Note that while we are describing this scenario in terms of elephants and monkeys (i.e., the kind of animal might
be "elephant" or "monkey"), you may not assume these are the only kinds of agents. Your code should work
for any kind specified, without assuming only these two values might be provided.
Your constructor should set the image used for the Agent using the animal name. For example, the elephants
use the "elephant.png" image, while the monkeys use the "monkey.png" image (and rabbits use the "rabbit.png"
image, and kangaroos use the "kangaroo.png" image, etc.).
Your Agent must also provide the following methods:
getKind()
A getter method that returns the kind of agent, as a string (such as "elephant", for example).
getThreshold()
A getter method that returns the agent's satisfaction threshold, as a double value.
isSameKindAs(agent)
A boolean method that returns true if this agent is the same kind of agent as the one provided.
isSatisfiedAt(x, y)
A boolean method that returns true if this agent would be satisfied at the specified location, or not. Remember
to watch out for out of bounds errors when an agent is on an edge or corner of the city.
isSatisfied()
A boolean method that returns true if this agent is satisfied at its current location. Note: you may not simply
repeat the code from isSatisfiedAt(). Your implementation here should be a single line (no more). Be careful
with how you compare this agent with its neighbors to count up the number of neighbors of the same kind.
relocate()
A method that moves the Agent to a new location in the grid where it will be satisfied, if there is one. You may
use a pair of nested loops to examine each (x, y) location to find the first empty location where this agent will
be satisfied, then move there. (The x loop must be the outer loop.) Remember that if there are no empty spaces
where this agent will be satisfied, it should stay put. You can use the agent's setGridLocation() method (which
is a combination of setGridX() and setGridY()) to move it to a new location.
act()
Executes one "turn" for this agent, which means determining if the agent is satisfied, and relocating if it is not.
Design Exercise 2
Go back to the outline you made of your program logic and your methods earlier (from Design Exercise 1).
Compare your method breakdown with the breakdown given above.
2021/3/3 Program 3
https://canvas.vt.edu/courses/125115/assignments/1087638 6/6
Does the method breakdown given above help simplify the problem? Does it make it easier to outline the logic of
the act() method?
Identify the key differences in your own outline and the method breakdown shown above for what is required. Try
to determine why those differences are present, and look for the reasons behind the methods specified above.
Comments on Design
As in other assignments, you will be graded in part on the design and readability of your solution using the
posted grading criteria, so consider these factors when devising and naming your methods. The Program
Grading Rubric (same as on Programs 1 and 2) describes the grading criteria. Note that a portion of your grade
will be based on your approach to testing your solution.
For testing, remember that you can create very small, completely empty cities (even as small as 1x2, 2x2, or
3x3), and place exactly the agents you want at exactly the positions you want in order to test behaviors. All of the
methods for cities can be tested without calling act(). Constructing simple, tiny situations to test out your
behaviors is much cleaner and easier than trying to "run" a big simulation with a large population of elephants
and monkeys spread around.
Submitting Your Solution
All program assignments are submitted to Web-CAT. Use the Controls->Submit... menu command to submit your
work.
© 2020 Virginia Tech University, All rights reserved.
http://www.copyright.gov (http://www.copyright.gov/title17/92chap5.html#501)
软件开发、广告设计客服
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-23:00
微信:codinghelp
热点项目
更多
代写infosys 110 digital syst...
2024-12-28
代写fbe 506 quantitative met...
2024-12-28
代做part i: (crazy eddie htm...
2024-12-28
代写infosys 110 digital syst...
2024-12-28
代做stats 769 statistics sec...
2024-12-28
代写ece3700j introduction to...
2024-12-28
代做tcm2301 biochemistry代做...
2024-12-28
代做ece5550: applied kalman ...
2024-12-28
代写mth205 introduction to s...
2024-12-28
代写scicomp project 3 week 4...
2024-12-28
代做business operations anal...
2024-12-28
代写mth205 introduction to s...
2024-12-28
代写socs0100 computational t...
2024-12-28
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 9951568
© 2021
www.rj363.com
软件定制开发网!