250 likes | 257 Views
Find the closest living location within your budget that maximizes proximity to work and amenities when relocating to a new city for work.
E N D
Location optimization Monica Metro Joren Mcsorley
Situation Suppose you are relocating to a new city for work. You already know where you will be working and what rent price you can afford but are unfamiliar with the new city. You know how important being close to work and local amenities are to you. These algorithms will show you the closest living location within your budget, and consider your importance of proximity to work and amenities.
Informal Problem statement Given an individual’s minimum and maximum acceptable rent price, work location, and importance of amenities; find the living location that minimizes the distance between an individual’s home, place of work, and desirable amenities. The user will select the importance of distance to work and amenities. Amenities are based on the apartment location.
Formulization • Given: • Set H of apartments / houses with comparable mortgages • N = the total number of apartments/houses • Exclusive price range and maximum inclusive distance from work • Weights for importance of constraints to user • q = weight for work distance • r = weight for price • t = weight for distance from amenities • All weights are integers such that 1 ≤ weight ≤ 10 • 10 for highest importance • 1 for least importance • There can be repeats
Best option is the minimum of the ranking functions: • a= unique apartment from set T • ais the optimal apartment given that f(a) is the smallest solution value (global minimum) • f(a) = q*w(a) + r*p(a) + t*z(a) • w(a) is the function that ranks according to distance from work • p(a) is the function that ranks according to apartment/house price • z(a) is the function that ranks according to distance from amenities
w(a) • Given N total number of apartments/houses and maximum wanted work distance wd: • Calculate the Pythagorean distance between the work location and ai • straight-line distance between two points • If Pythagorean distance ≤ wd, keep the apartment/house • Else, filter out • Sort apartments/houses from shortest to largest distance • w(a) = k + 1 integer value such that 0 ≤ k ≤ N-1 • Where k is the position of the apartment/house in the sorted array
p(a) • Given Nr number of apartments/houses and a wanted price range • (N-reduced), the number of apartments/houses after the work function filtered some out • First, check if apartments/houses are in given price range • If in price range, keep • Else, filter out • Sort apartments/houses from least to greatest price • p(a) = k + 1 integer value such that 0 ≤ k ≤ Nr - 1 • Where k is the position of the apartment/house in the sorted array
Why start at 1? • Both the weights and ranking function values cannot be < 1 • Weight * Rank = Weighted Value • Low importance, Low rank: 0*N-1 = 0 • Weight of 0 for low importance • N-1 ranking makes it the worst option • High importance, High rank: 10*0 = 0 • Weight of 10 for high importance • 0 ranking makes it the best option • Importance and ranking would not matter
z(a) • Given n number of apartments/houses • For testing purposes N = n, (no filtering) • Calculate total Pythagoreandistance from one amenity to the next • Grocery stores, gym, movies… • Uses the minimum distance from apartment/house for each group • Does not give bonus points for how many are close by • Sort apartments/houses from least to greatest ‘A-value’ • Amenities are also weighted: • A-value = e*d1 + f*d2 + g*d3 … • Where e, f, and g are the respective weights for that amenity group • All weights are integers such that 1 ≤ weight ≤ 10 • d1 = grocery stores, d2 = gyms, etc. • z(a) = k + 1 integer value such that 0 ≤ k ≤ n-1 • Where k is the position of the apartment/house in the sorted array
Example Map 0 1 2 3 4 0 $900 $700 $700 $1000 $600 5x5 example map with a work location, amenities locations, and housing locations with rent prices. 1 AMEN $600 $900 $1000 WORK 2 $1200 $1000 $1100 AMEN AMEN 3 $1200 $1000 $1400 $1800 $1100 4 $1500 $1100 $1300 $1600 $1200
Brute Force • The most straightforward way to find global optimum • Exhaustively searches all the apartment/houses • O(n2) • Work function, w(a) for N apartments O(Nlog(N)) • Price function, p(a) for Nrapartments O(Nr log(Nr)) • Amenity function, z(a) for n apartments O(n2)worst case • Solve for final solution value for each apartment O(n) • Sort apartments from least to greatest to find optimums O(nlog(n))
Backtracking • Find a set of solutions by computing a partial solution • If partial solution is not a valid solution, abandon candidate • Usually faster than brute force without sacrificing accuracy
Backtracking pseudocode • Work function, w(a) for N apartments O(Nlog(N)) • Price function, p(a) for Nrapartments O(Nr log(Nr)) • Amenity function, z(a) for n apartments O(n) times each below • Calculate partial solutions for first 20 apartments • For each apartment while apartment count > 20 • For each amenity group, calculate a partial z(a) (amenity ranking) O(N) and use it to find f(a) • If f(a) > f(20th) , abandon apartment a • If apartment was never abandoned, compare partial solution ( f(a) ranking ) to the 20th • If it’s better, replace the 20th apartment and re-sort solution set 20log(20) • Else, abandon • Worst case O(N2 ) like brute force, but saves time on sorting with 20log(20) and reduces O(N) count in calculating partial z(a)
Simulated annealing • Used to find global optimum by escaping local optimums via an acceptance probability • e-∆E / T where ∆E = old solution – new solution • Probability decreases as temperature decreases • If p(acceptance) ≥ random[0, 1), accept solution • Good for finding approximate global optimums quickly
Simulated Annealing Pseudocode • Work function, w(a) for N apartments O(Nlog(N)) • Price function, p(a) for Nrapartments O(Nr log(Nr)) • Amenity function, z(a) for n apartments Set iteration count • oldApt = a random apartment • While current temp > 1.0 • newApt = get neighbor • run amenity function and calculate partial solution ( f(a) ranking ) O(n) • if the new solution is better, keep newApt • else, run acceptance function • current temperature * cooling rate • Ends up being slow with all the sorting
Rankings • Solution value: A total value taking into account the distances between work, home, amenities, and their respective ranking values. The lower the solution value, the more ideal the location.