-
Notifications
You must be signed in to change notification settings - Fork 5
/
cohort_match.py
77 lines (63 loc) · 2.52 KB
/
cohort_match.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Project: SF BARF
# Goal: Create a matching function for renters and houses
# Description: For every agent that enters the model, match them to a house that satisfies their requirements
# Created on: 6/6/15
# Created by: Jean-Ezra Yeung
# Outline
# 1. Objects - Generate 2 lists: renters, houses
# 2. Emergence - Match renters and houses based on price and niceness (quality for acceptance)
# 3. Complexity
# Agent flow:
# 1. Cohort of agents enters a market with a set of houses
# 2. Agents choose a house of interest
# 2a. Whoever loops first gets the house
# 3. Agents re-bid based on new market
import pandas as pd
from pandas import Series, DataFrame
# 1. Objects - Generate 2 lists: renters, houses
class Renters:
def __init__(self, cohort, match_score, demand):
self.cohort = 1
self.features = list(DataFrame(np.random.randint(match_score, size= (demand,1)))[0])
class Houses:
def __init__(self, cohort, match_score, supply):
self.cohort = 1
self.features = list((DataFrame(np.random.randint(match_score, size= (supply,1))))[0])
# 2. Emergence - Match renters and houses based on a set of features
def match(time,match_score,demand,supply):
r = Renters(cohort,match_score,demand)
h = Houses(cohort,match_score,supply)
renter = r.features
print renter
house = h.features
print house
match_r = []
match_h = []
no_match_r = []
no_match_h = []
for t in time:
for i in renter:
for j in house:
if i == j:
match_r.append(i)
match_h.append(j)
elif i != j:
no_match_r.append(i)
no_match_h.append(j)
print 'Cycle:', t
print 'Renter match:', '\n', 'renter |', 'matches', '\n', match_r, '\n', (Series(match_r)).value_counts(ascending=True)
print 'House match:', '\n', 'house |', 'matches', '\n', match_h, '\n', (Series(match_h)).value_counts(ascending=True)
print 'No renter match:', '\n', 'renter |', 'no matches', '\n', no_match_r, '\n', (Series(no_match_r)).value_counts(ascending=True)
print 'No house match:', '\n', 'house |', 'no matches', '\n', no_match_h, '\n', (Series(no_match_h)).value_counts(ascending=True)
# Add new renters and houses for each cycle
# renters.append(range(11,20))
# houses.append(range(11,20))
# if __name__ == "__main__":
# Parameters
time = list(range(1,2))
cohort = 'A'
match_score = 10
demand = 11
supply = 11
# Run
match(time,match_score,demand,supply)