Buffy_Final_City_Reportv2

advertisement
Lucia Wang
Kevin(Zixi) Xu
10/26/2012
ORF467
My City: Buffy Report
1. Land Use Characteristics
Character of Buffy
The City of Buffy (population 250,000) is loosely based on the city of Buffalo, New York
(population: 261,025). This city, built along Erie River, is completely self-sufficient and
functions independently of the rest of the world. Residents live around the city center that
houses most office spaces as well as the large public lakes and parks in the city.
Buffy is divided into 68 mostly rectangular shaped TAZ, inclusive of both open space and
water. Commercially/industrially designated areas include medical, retail, restaurant,
recreational, professional office, light industrial, heavy industrial, public buildings, and
educational. The residential areas of Buffy are divided into light, medium, and heavy
density areas. Approximately 28.7 square miles (29.39%) of land are undeveloped which
includes open space (19.53%) and water (9.86%).
Color Key
Land Use
Water
Educational
Medical
Retail
Restaurant
Recreational
Professional Office
Open Space
Light Residential (5k/sqmi)
Medium Residential (8k/sqmi)
Heavy Residential (20k/sqmi)
Stadiums
Light Industrial
Heavy Industrial
Public Buildings
Public Parks
#Cells
101
37
12
85
44
30
81
200
104
153
42
12
14
36
10
63
1024
Area(sqmi)
10.1
3.7
1.2
8.5
4.4
3
8.1
20
10.4
15.3
4.2
1.2
1.4
3.6
1
6.3
102.4
% of Land
9.86%
3.61%
1.17%
8.30%
4.30%
2.93%
7.91%
19.53%
10.16%
14.94%
4.10%
1.17%
1.37%
3.52%
0.98%
6.15%
100.00%
With all developed lands to the east of the river, it is not necessary at this time for bridges
to be built crossing into the undeveloped land past the Erie River. Typically, residents
travel to heart of the city for work and have all necessary daily needs distributed
throughout the many residential districts. These needs include retail, restaurants,
recreational space, schools, and parks. Both industrial districts (heavy and light) lie at the
furthest east points (one on the south and one on the north) of the city to minimize the
pollution and disturbance to the city’s residents. Along with the open space, a large area of
lake and park/forests isolates the heavy industrial district from the residential areas. There
is also a recreational area nearby where the worker can go exercise or relax right after
work. Furthermore, we have five school districts surrounded by residential areas. We
believe that proximity to school is one of the key attributes of great education quality,
hence we want to provide the students in Buffy as easy an access to schools as possible so
that they can minimize the time spent on route to/from school as well as the number of
traffic accidents associated with it. The professional offices are mostly concentrated right in
the center of Buffy, while the restaurants and retail districts are scattered around. We
would imagine that employees in the professional offices all head to the center of the city in
the morning and disperse to different places in the city after work. There are two medical
centers, one on the northwest, the other on the southeast, so that people living in either
side of the city all have an equally easy access to health services. Lastly, we have a long
vertical stripe of riverside parks along the river on the west side of Buffy, where we hope
our residents can take a walk after work/school/dinner.
Demographics
1. Population Breakdown:
Pulling data from the 2010 census, we got the distribution in age in percentages for Buffalo,
NY. Adjusting for Buffy’s population difference, we applied the percentages to get our city’s
population age distribution. Similarly, we also applied the gender distribution of Buffalo,
NY to get the female to male ratio for Buffy. To further break down the population into
workers, unemployed, elderly, and students, we took the 8.8% unemployment rate from
the Bureau of Labor statistics and applied it to our population of 250,000. We then took the
average number of students per grade and multiplied it by four for the number of students
at our community college.
Population
under 5
5-18
over 65
18-65
Sex Ratio
Female
Male
Population Breakdown
Children under 5
K-12 Students
College Students
Workers
Unemployed
Elderly
Total
250,000
16,750
422,50
28,500
162,500
13,025
11,975
16,750
42,250
10,560
138,941
12,999
28,500
250,000
2. Student Breakdown:
For student breakdown, we took the average number of students and multiplied it by the
number of grades in each category of schools (e.g. elementary, middle). We also assumed
that 2/3s of the students would go to public school while 1/3 of the students would go to
public school. In addition, from the Department of Education, we found that approximately
550 students attended every single elementary school, giving us the number of elementary
schools in buffalo. As for high schools, middle schools, and private schools, we made
estimates off of the elementary schools.
Student Breakdown
Elementary
Middle
High
Private
Community College
Total
15,167
4,333
8,667
14,083
10,560
52,810
Number of schools
28
4
6
4
1
43
3. Residential Breakdown:
Loosely following the information given, we set light residential areas to have about 5,000
people/square mile, medium residential areas to have about 8,000 people/square mile, and
heavy residential areas to have about 20,000 people/square mile.
Residential
Light residential
Medium residential
Heavy residential
Population/Square Mile
4,600
7,750
19,900
# of Square Miles
10.4
15.3
4.2
Total Population
47,845
118,575
83,580
4. Employment Breakdown:
We believe that Buffy is a very well developed city. Therefore, most workers are employed
by either heavy industrial companies (auto and aerospace manufacturers, etc) or
professional offices (IT, commerce, financial services, consulting, etc.) There are also a
large proportion of people working in education: we believe a high faculty-student ratio
will contribute to the high overall education quality at Buffy. We value the work-life
balance of the people living in our city, so we have a very large number of retail stores and
restaurants, which employ a significant number of people as well.
Employment
Employees
Population/Square Mile
Light Industrial
14,000
10,000
Heavy Industrial
75,600
21,000
Restaurants
2,464
560
Retail
5,015
590
Medical
780
650
Public Offices
450
450
5,550
1,500
33,210
4,100
420
350
1,200
400
252
40
Educational
Professional Office
Stadium
Recreational
Park
Total
138,941
Quality of Life
As mentioned earlier, we care about both the physical and mental well-beings of the people
living in Buffy, which is precisely why we placed the residential areas, school districts,
medical centers, parks, and industrial districts where they are. Additionally, Buffy people
love sports, so we have a huge stadium and entertainment complex on the east side of the
city for the people to watch games during the weekends. Furthermore, they also enjoy
movies and music, therefore we have 6 movie theatres, 2 classical concert halls, 1 opera
house, 1 ballet theatre, and 5 musical theatres (please refer to the TAZ tab in the attached
excel file.) We also have a large number of gyms and sports facilities distributed across the
recreational areas so people can have easy access to sports during their leisure time. In
short, we want the people at Buffy to work hard and play hard, just as we do here at
Princeton.
2. Trip Generation
Overall, when constructing the production and attraction vectors, we followed the general
guidelines such as the number of trips produced in or attracted by different TAZ’s is
proportion to its area and density. We also checked and made sure that the sum of the
attraction vectors is the same as the sum of the production vectors for each of the trip type
as well as the fact that everybody will get home by the end of the day -- we don’t really
want people to wander around our city in the middle of the night.
Description of Production and Attraction Vector Types
Home-School
This trip type includes all the trips that students go from home to school in the morning
each day. We assume there is no boarding student (e.g. community college,) so every
student has to make this trip.
Home-Work
This trip type includes all the trips that workers go from home to work each morning.
Home-Other1
This trip type includes all the trips that people who are neither students nor workers go
directly from home to shopping/restaurants/recreations each day.
School-Other
This trip type includes all the trips that students (20% of total) go directly from school to
other places (bars, restaurants, etc) after school.
Work-Other
This trip type includes all the trips that workers (20% of total) go directly from work to
other places after work.
School-Home
This trip type includes all the trips that students (80% of total) go directly from school to
home.
Work-Home
This trip type includes all the trips that workers (80% of total) go directly from work to
home.
Other-Other
This trip type includes all the trips that people go from other places to other places. They
could be going to restaurants after gym or visiting theatres after dinner, etc. We would
imagine that most Buffy people (who enjoy life) have more than 1 activity after
school/work thus we have a fair number of Other-Other trips.
HB-Other2
This trip type includes all the trips that people who went home after school/work first and
then go out again to other places.
Other-Home
By the end of the day, like it or not, everyone has to go home.
Generation of Production and Attraction Vectors
Home-School
To generate the production vector in this case, we multiplied the area of the TAZ with the
population density of the residential area and the proportion of students in the city based
on the values in the Calculations sheet. To generate the attraction vector, we multiplied the
area of the TAZ with the student population per square mile.
Home-Work
To generate the production vector in this case, we multiplied the area of the TAZ with the
population density of the residential area and the proportion of workers in the city based
on the values in the Calculations sheet. To generate the attraction vector, we multiplied the
area of the TAZ with the corresponding number of workers per square mile based on the
type designation of the TAZ.
Home-Other1
To generate the production vector in this case, we multiplied the area of the TAZ with the
population density of the residential area and the remaining proportion of people in the
city based on the values in the Calculations sheet. To generate the attraction vector, we
multiplied the area of the TAZ with the population per square mile of people who would
visit these areas.
School-Other
To generate the production vector in this case, we multiplied the attraction vector of the
Home-School case by 20% since 80% of students go straight home after school. To
generate the attraction vector in this case, we first multiplied the area of the TAZ with the
population per square mile of people who would visit these areas. Then using these
proportions we scaled this to make the total vector sum equivalent to the number of people
produced.
Work-Other
To generate the production vector, we multiplied the attraction vector of the Home-Work
case by 20% since 80% of work go straight home after school. To generate the attraction
vector, we first multiplied the area of the TAZ with the population per square mile of
people who would visit these areas. Then using these proportions, we also scaled this
vector to make the total vector sum equivalent to the number of people produced.
Other-Other
To generate the attraction vector, we first took the attraction vector of the Home-Other1
vector. Using this vector, we scaled it to include the people who went out again after
returning from home or work. Ultimately, this allows our average number of trips to be
four. Because these vectors are other-other trips, it makes sense for the production and the
attraction vectors to be equivalent.
HB-Other2
To generate the production vector, we took approximately 50% of the total people who did
home-school and home-work travels to be the total number of people leaving home again
for an other trip. To generate the actual numbers, we scaled the TAZ area multiplied by the
population density so that the sum the productive vector was approximately the 50%
number we calculated before. To generate the attraction vector, we scaled the TAZ area
multiplied by the population density for the other TAZ’s to have the sum of the attraction
vector equivalent to the sum of the production vector.
Other-Home
To generate the production vector, we calculated the number of people who left and did not
return home from the TAZ’s. Then for calculating the attraction vector, we scaled the
population density *TAZ area so that the sum of the production to be equivalent to the
attraction vector.
Summary Trip Production and Attraction Tables
Please refer to the P&A tab of the attached excel file for the Trip Production and Attraction
Vectors.
3. Trip Distribution
Overview of Trip Array Generating Process
We applied the gravity model to generate trip distributions. According to the gravity model,
the trips produced in a TAZ i will be distributed to other TAZ’s based on the relative
attractiveness as well as the relative accessibility of those TAZ’s. For each trip type, the
relative attractiveness of a TAZ j is measured by the attraction of this TAZ divided by the
sum of attractions across all TAZ’s. The rational is that if there are many attractions in one
TAZ (such as movie theatres, retails stores, restaurants,) people are more likely to go there
because they have more choices and they can do multiple things without the trouble of
making another trip. The relative accessibility is measured by the disutility of the distance
travelled from current TAZ i to another TAZ j divided by the sum of these disutilities across
all potential TAZ j’s. The rationale is, the farther away a TAZ is from where the people are,
the less likely they are going to travel to that TAZ due to money and time constraints. After
some calculations and rearrangements, we have arrived at our formula, Tij = [Pi / j=1,n Fij *
Kij * Aj] * Aj * Kij * Fij. Here, Tij is the number of trips from TAZ i to TAZ j; Pi is the number of
trips produced at TAZ I; Fij is the disutility of travelling from i to j, calculated from the
distance matrix; Kij is the optional social-economical adjustment factor, which is taken to be
the identity matrix here; Aj is the number of trips attracted to TAZ j.
For each trip type, we take the Production and Attraction vectors from above. Now we only
need to calculate the Distance matrix and F matrix, which are the same across all trip types.
Regarding the Distance matrix, Dij is calculated as the 1.2 times the Euclidean distance
between TAZ i and TAZ j for i  j (which takes into account of the circuitry and actual
distance travelled on the road from point i to j,) and the square root of the zone area for i  j
(a good estimate of intra-zone travel distance.) Fij is simply 1/Dij2. The calculations of D and
F are first done through Excel and verified by our R codes.
Excel Iterations
In excel, we first take the Production and Attraction vectors for one trip type, multiply the F
matrix by the A vector to obtain vector Sum where Sumi = j=1,n Fij * Kij * Aj. Then we divide
the P vector by Sum to obtain vector P/Sum where [Pi / j=1,n Fij * Kij * Aj] . Lastly, we
multiply P/Sum by AT to obtain P/Sum * AT, and then multiply the results by F to obtain our
trip distribution array. Noticeably, the column sums of our trip distribution array, Aoutput do
not equal to the initial A vector we have, Adesired – which is an issue here because we want
the column sums to be exactly equal to our initial Attraction vector (AT). Hence we use
different adjusted Ainput vectors through multiple iterations until the Aoutput vector is within
1% of the Adesired vector. To run the iterations on excel, we followed the steps specified in
the SimpleTripDistF10 excel file. Formulas such as MMULT and TRANSPOSE are used for
manipulation and calculation purposes in excel.
We went through this process in Excel and generated trip distribution arrays for all ten of
the trip types specified above. The average number of iterations it takes to reach Adesired for
a trip type is around 5. We have attached an example of trip distribution array in later
sections. Please refer to the attached excel file for the comprehensive data of trip
distribution arrays.
Coding
In addition to manual iterations, we also wrote up code in R to compute and verified the
trip array matrix following the algorithm as explained above (please refer to Appendix A
for code & more in-depth documentation.) The following functions are:









Distance: The function Distance computes the Euclidean distance between different
TAZ’s. For interzonal distances, the distance is calculated as the squareroot of the
area of the TAZ
PA: The function PA computes the matrix multiplication between P and A
Fmat: The function Fmat computes the F matrix which is 1/D^2. It is disutility of
traveling between TAZ’s
Sum: The function Sum computes the matrix multiplication between A and F
PdivSum: The function PdivSum computes the vector that is P divided by the sum
vector
PdivSumA: The function PdivSum takes the matrix multiplication between the
Pdivsum and A
Trip: The function Trip generates the trip array by matrix multiplying F and
PdivsumA
Iter: The function Iter keeps iterating to generate a closer A vector until max error is
less than the errorlim threshold set
GraphHelper: The function GraphHelper creates a matrix that is the sorted trip
distances matched up with the corresponded number of trips. It also includes the
cumulative sum of the number of trips for each distance.
In order to generate trip arrays, the Iter function was the one that we ran to ultimately get
the results. This function not only returns the calculated trip array, but it also returns the
corresponding adjusted attraction vector as well as the number of iterations necessary for
Aoutput to be under the error threshold. This count of the number of iterations allowed us to
run a sensitivity analysis on the number of iterations necessary for Aoutput to be within the
specified error threshold of Adesired.
Trip Array Example
Here is an example of the generated trip distribution array for Home-Other1:
Trip Demand and Length Analysis
While we have produced trip distribution charts and cumulative trip distribution charts for
all the trip types, we will limit our discussion and analysis to 7 trip types: Home-School,
Home-Work, Home-Other1, School-Other, Work-Other, Other-Other, and Other-Home for
the following reasons. The School-Home and Work-Home trip arrays are simply the
transposes of Home-School and Home-Work (adjusted by a factor of 0.8,) and thus have
identical distributions (adjusted by a factor of 0.8 for the number of trips,) respectively.
Home-Other 1 and Home-Other 2 also have identical distributions (with an adjustment
factor for the number of trips.) If interested, please refer to the attached Excel file for all the
charts. We wrote code in R to extract and write out the relevant data, and used Excel to
manipulate and graph the charts. Please refer to Appendix A for the R code.
Home-School
As indicated by the above chart, most Home-School trips are concentrated on the 0 to 2
miles per trip, thanks to our design of the city that schools are surrounded by residential
districts. Although the trip distribution is heavily skewed to the right with a global
maximum (peak) centered around 1 mile per trip, we observe that there is another local
peak centered around 5.5 miles per trip. We believe this is caused by the
light/medium/heavy residential districts on the northeast part of the city (please refer to
the map above.) Although there is a school district nearby, there is a capacity issues here.
Once the students enrolled in the nearby schools reach the maximum numbers, residents in
those regions have to send their children to schools that still have spots available but are
relatively further away.
Home-Work
The Home-Work trips have a multi-modal distribution, which is not surprising. We
designed the city such that the professional offices are mostly centered in the middle,
resulting in the global peak at around 2 miles per trip. The light and heavy industrial
districts, however, are placed on the far east side, resulting in the two local peaks centered
around 6.5 miles per trip and 9.5 miles per trip. There are other employers such as schools,
retail stores, and restaurants, which are all pretty well dispersed across different regions of
the city, resulting in the other local peaks we saw in between the shorter and longer trips.
Home-Other1
The Home-Other1 trips have a right-skewed distribution. Most people choose to go to
places next to their homes for fun. Overall, most trips are distributed in the less than 4
miles per trip interval. Noticeably, one often has to travel a bit further to get to where
he/she actually wants to go, ad indicated by the global peak centered around 3 miles per
trip rather than the local peak centered around 1 mile per trip. If one wants to watch a
sports game, however, one has to go all the way to the far east side of the city no matter
where he/she lives. There are these special attractions such as the stadium-complex
district that people have to go with no other alternatives, which resulted in another local
peak centered around 6.5 mile per trip as well as the tail region of 9 to 12 miles per trip.
School-Other
The locations of the schools are quite concentrated -- we only have 4 school districts in our
city. Consequently, the students who choose to go somewhere else rather than home
usually have to travel rather far in order to reach where they want to go (in other words,
the schools’ locations are relative remote compared to the other attractions.) This is
indicated by the two large peaks between 4 to 6 miles per trip and the two small peaks
between 7 to 9 miles per trip of the School-Other trip distribution. If there actually exist
interesting places nearby, the students would certainly love to go hang out near their
schools, as reflected by the 0 to 3.5 mile interval of the trip distribution.
Work-Other
Contrary to the schools, the locations of the workplaces are relatively spread out, and most
of the workplaces are surrounded by other attractions such as restaurants, retail, and
recreational districts. Admittedly, the industrial districts are relative far way – but they also
have restaurants and shops nearby. Therefore, most workers do not have to travel too far
to get to other attractions after work. There is a global peek centered around 4.5 miles per
trip with the rest of the trip distances evenly dispersed throughout the entire distance
interval.
Other-Other
When people are already at the restaurants/shops/movie theatres, etc, they are very
unwilling to travel very far to get to another entertainment attraction (unless they really
want to do something special, watching a sports game for instance. Therefore, we have one
global pick centered around 2 miles per trip -- we infer that those are mostly intra-zone
trips from one attraction to another, with the rest of trip distances evenly spread out.
Other-Home
The distribution of Other-Home trips is also heavily skewed to the right, indicating that
most people end up somewhere not too far away from home by the end of the day. There is
a global peak centered around 2 miles per trip. Although most people do not have to travel
more than 6 miles to get home, there are a significant number of people who do have to
travel a bit more than that, which corresponds to the fact that no matter where one end up
at night, one has to go home.
Overall
The overall trip distribution has a global peak centered around 2 miles per trip, suggesting
that most people do not travel very far from home for their activities. Interestingly, the
second largest peak is centered at around 1 mile per trip -- a significant number of people
hardly ever travel more than 1 mile per trip. Furthermore, as the miles per trip increases,
the number of trips gradually decreases, which is an excellent indication of the gravity
model at work. Overall, the people at Buffy do not have to travel to far to do whatever they
need and want to do.
Cumulative Trip Distribution Example: Other-Other
Cumulative Trip Distribution
120.0000
number of trips
100.0000
80.0000
60.0000
40.0000
20.0000
0.0000
0
2
4
6
8
Distance (miles)
10
12
14
Above is one example of the cumulative trip distribution chart, and we have picked OtherOther as an interesting illustration. It is not difficult to observe that there is a sharp jump in
terms of the number of trips from 20,000 to over 100,000 between the interval of about 1.5
miles per trip and 2.5 miles per trip. Since most of our “Other” TAZ’s have multiple
attractions, most people will initiate intra-zone trips from one attraction to another
attraction rather than going to other TAZ’s.
Cumulative Trip Distribution (%) Comparisons
We have graphed the cumulative distributions of all 10 of our trip types above. Again,
Other-Other stands out for reasons explained earlier. Work-Other has an interesting jump
at around 4.5 miles per trip, and we inferred earlier that this may be caused by the
relatively large dispersion of work locations. School-Other also has a jump at around 6
miles per trip. This number is greater than 4.5 miles per trip from Work-Other because the
locations of the schools are relatively concentrated and students often need to go quite far
to do anything at all after school. The rest of the lines are relatively smooth. The line that is
on top of the others, Home-School, for example, indicates that there are relatively more
shorter trips than longer trips in this cumulative trip distribution. The line that is below the
others, Work-Home, for example, indicate that there are relatively more longer trips than
shorter this in this cumulative trip distribution.
Sensitivity Analysis of the Number of Iterations
error
homeschool
home work
number of iterations to reach error threshold
home school
workotherhomeother1
- other
other
other
other2
otherhome
average
1%
0.5%
0.25%
0.1%
0.01%
5
6
7
8
12
5
6
7
8
12
5
5
6
7
8
5
6
7
8
10
4.875
5.5
6.375
7.25
9.625
4
5
5
6
7
4
4
5
5
7
6
7
8
9
12
5
5
6
7
9
Using the R code, we are able to conduct a sensitivity analysis on the number of iterations
required for the Aoutput vector to be within the error threshold of the Adesired vector. As
indicated by the table above, on average, it takes slightly fewer than 5 iterations for Aoutput
to be within 1% error of Adesired. We only need, on average, 0.625 additional iteration to
reduce the error threshold by half, and again another iteration 0.875 iteration to further
reduce the error threshold by half to 0.25%. We need on average 7.25 iterations to be
within a 0.1% error threshold, which we believe is a small enough boundary for the error.
Therefore, the algorithm we are applying here to adjust the Ainput vector is a very efficient
one. In all cases, we are able to get extremely close to the Adesired vector within a few
iterations.
Summary of the Average Miles per Trip and Number of Trips by Trip Type
Here is a table summarizing the average miles per trip and the number of trips by each trip
type.
Home - School
School - Home
Other - Other
Other - Home
Home - Other2
Home - Other1
Work - Other
School - Other
Home - Work
Work -Home
Total
Average Trip Length
2.99
2.99
3.00
3.71
4.13
4.13
4.67
4.76
5.32
5.32
3.89
Number Trips
158,035.54
10,562.00
139,294.75
202,220.18
105,620.04
58,249.02
27,788.20
10,562.00
138,941.05
27,788.60
879,061.39
Total Miles
472,925.99
31,607.11
418,405.95
750,800.20
436,240.48
240,584.85
129,707.56
50,229.47
739,764.74
147,958.32
3,418,224.67
We have arranged the table in the order of ascending “Average Trip Length” by trip type.
The trips with shortest average trip length are home-based school, coinciding with our
original intents when designing the city. Other-Other trips comes close to have the second
shortest average trip length due to the heavy intra-zone trips. The home-based work trips
have the longest average trip length for reasons such as people have to go to work no
matter where their work locations are, and the fact that our light and heavy industrial
districts are placed on the far east side of Buffy.
The overall average trip length in our city is 3.89 miles per trip.
There are a total of 879,061.39 trips covering 3,418,224.67 miles.
*** Please refer to the attached Excel file for any additional information.
Works Cited
Bureau of Labor Statistics. “Local Area Unemployment Statistics: Unemployment Rates for
Large Metropolitan Areas.” Web. 26 October 2012.
<http://www.bls.gov/web/metro/laulrgma.htm>.
Kornhauser, Alain. “Class # 8, Part 2: Planning and Analysis Tools of Transportation
Demand and Investment.” Web. 26 October 2012.
Kornhauser, Alain. “SimpleTripDistF10.xls.” Web. 26 October 2012.
National Center for Education Statistics. “Table 95. Public elementary schools, by grade
span, average school size, and state or jurisdiction: 2005-06.” Web. 26 October 2012.
<http://nces.ed.gov/programs/digest/d07/tables/dt07_095.asp>.
United States Census Bureau. “State & County QuickFacts: Buffalo (city), New York.” Web.
26 October 2012. <http://quickfacts.census.gov/qfd/states/36/3611000.html>.
Appendix A
Code and Documentation Used

Distance:
o Parameters:
 DEBUG: if True, debugs with the sample values from the given excel
spreadsheet (4 valued vector example)
 Xfilename: takes a string for csv file that has the x values of centroid
for TAZ
 Yfilename: takes a string for csv file that has the y values of centroid
for TAZ
 Area: takes a string for csv file that has the areas of the TAZ
o The function Distance computes the Euclidean distance between different
TAZ’s. For interzonal distances, the distance is calculated as the squareroot of
the area of the TAZ
Distance <- function(DEBUG = FALSE, xfilename = "x.csv", yfilename =
"y.csv", area = "area.csv") {
if (DEBUG == TRUE) {
D = matrix(c(1.1,2,3,5,2,1.2,4,6,3,4,1.3,7,5,6,7,1.4),4,4)
}
else {
x = as.matrix(read.csv(xfilename))
y = as.matrix(read.csv(yfilename))
area = as.matrix(read.csv(area))
D = matrix(rep(0, dim(x)[1]^2), dim(x)[1], dim(x)[1])
for (i in 1:dim(x)[1]) {
for (j in 1:dim(x)[1]) {
if (i!=j) {
D[i,j] = 1.2*sqrt((x[i]-x[j])^2 + (y[i]-y[j])^2)
}
if (i==j) {
D[i,j] = sqrt(area[i])
}
}
}
}
write.csv(D, "d.csv")
D
}

PA
o Parameters
 Pfilename: takes a string for the csv file that has the production vector
Afilename: takes string for csv file that has the attraction vector;
overrides a vector
 A: takes a vector that is the attraction vector
o The function PA computes the matrix multiplication between P and A

PA <- function(afilename=NULL,pfilename="p.csv",a = NULL) {
if (!is.null(afilename)) {
a = as.matrix(read.csv(afilename, header = FALSE))
class(a) <- "numeric"
}
else a = a
p = as.matrix(read.csv(pfilename, header = FALSE))
a = t(a)
p%*%a
}

Fmat
o Parameters
 Dfilename: takes a string for csv file that has the distance matrix for
TAZ’s
o The function Fmat computes the F matrix which is 1/D^2. It is disutility of
traveling between TAZ’s
Fmat <- function(dfilename="d.csv") {
d = as.matrix(read.csv(dfilename))[,-1]
f = 1/d^2
write.csv(f, "f.csv")
f
}

Sum
o Parameters:
 Afilename: takes string for csv file that has the attraction vector;
overrides a vector
 F: F matrix as computed from Fmat function
 A: takes a vector that is the attraction vector
o The function Sum computes the matrix multiplication between A and F
Sum <- function(afilename=NULL, f, a= NULL) {
if (!is.null(afilename)) {
a = as.matrix(read.csv(afilename, header = FALSE))
}
else a = a
a = t(a)
a%*%f
}

PdivSum
o Parameters:
 S: sum vector as computed by the Sum function
 Pfilename: takes a string for the csv file that has the production vector
o The function PdivSum computes the vector that is P divided by the sum
vector
PdivSum <- function(s, pfilename="p.csv") {
p = t(as.matrix(read.csv(pfilename, header = FALSE)))
class(p) <- "numeric"
p/s
}

PdivSumA
o Parameters
 Afilename: takes string for csv file that has the attraction vector;
overrides a vector
 A: takes a vector that is the attraction vector
 Pdivsum: vector PdivSum as computed by PdivSum function
o The function PdivSum takes the matrix multiplication between the Pdivsum
and A
PdivSumA <- function(afilename=NULL, pdivSum, a= NULL) {
if (!is.null(afilename)) {
a = as.matrix(read.csv(afilename, header = FALSE))
class(a) <- "numeric"
}
else a = a
a = t(a)
t(pdivSum)%*%a
}

Trip
o Parameters
 F: F matrix as computed from Fmat function
 PdivsumA: matrix as computed by the PdivSumA function
o The function Trip generates the trip array by matrix multiplying F and
PdivsumA
Trip <- function(f, pdivSumA) {
c = matrix(rep(0, dim(f)[1]*dim(f)[2]), dim(f)[1], dim(f)[2])
for (i in 1:dim(f)[1]) {
for (j in 1:dim(f)[1]) {
c[i,j] = f[i,j]*pdivSumA[i,j]
}
}
c
}

Iter
o Parameters
 Afilename: takes string for csv file that has the attraction vector
 Pfilename: takes string for the csv file that has the production vector
 DEBUG: if True, uses debug mode which is based off the spreadsheet
example
 Errorlim: numeric value that is the error threshold
o The function Iter keeps iterating to generate a closer A vector until max error
is less than the errorlim threshold set
Iter <- function(afilename = "a.csv", pfilename = "p.csv", DEBUG =
FALSE, errorlim = .01) {
initiala = as.matrix(read.csv(afilename, header = FALSE))
count = 1
#first iteration
d = Distance(DEBUG = DEBUG)
f = Fmat()
sum = Sum(f=f, afilename=afilename)
PdivSum = PdivSum(s=sum)
PdivSumA = PdivSumA(pdivSum = PdivSum, afilename=afilename)
Trip = Trip(f=f, pdivSumA=PdivSumA)
Aoutput = colSums(Trip)
error = (initiala-Aoutput)/initiala
error[is.nan(error)] <-0
Aoutputold = Aoutput
iterA = initiala*initiala/Aoutputold
iterA[is.nan(iterA)] <- 0
while (max(abs(error)) > errorlim) {
count = count + 1
sum = Sum(a = iterA, f=f)
PdivSum = PdivSum(s=sum)
PdivSumA = PdivSumA(a=iterA, pdivSum=PdivSum)
Trip = Trip(f=f, pdivSumA=PdivSumA)
Aoutput = colSums(Trip)
error = (initiala-Aoutput)/initiala
error[is.nan(error)] <-0
if (max(abs(error)) < errorlim) {
break
}
Aoutputold = Aoutput
iterA = initiala*iterA/Aoutputold
iterA[is.nan(iterA)] <- 0
}
list(triparray = Trip, finala = iterA, count = count)
}

GraphHelper:
o Parameters:
 Csvname: takes string of csv file that includes the trip matrix
o The function GraphHelper creates a matrix that is the sorted trip distances
matched up with the corresponded number of trips. It also includes the
cumulative sum of the number of trips for each distance.
GraphHelper <- function(csvname) {
trip = read.csv(csvname, header = FALSE)
d = Distance()
data = matrix(rep(1,3),1,3)
for (i in 1:dim(trip)[1]) {
for (j in 1:dim(trip)[2]) {
if (trip[i,j] != 0 ) {
data = rbind(data, c(d[i,j], trip[i,j], 0))
}
}
}
data=data[-1,]
data = data[sort.list(data[,1]),]
data[,3] = cumsum(data[,2])
data[,1] = data[,1]/sqrt(10)
data
}
Download