@@ -94,15 +94,19 @@ def setUp(self):
9494 demand_grid = gpd .GeoDataFrame (
9595 demand_data , geometry = gpd .points_from_xy (demand_data .x , demand_data .y )
9696 )
97- demand_grid ["geometry" ] = demand_grid .buffer (0.5 )
97+ demand_grid ["geometry" ] = demand_grid .buffer (0.25 )
9898
9999 supply_data = pd .DataFrame ({"id" : [1 ], "x" : [0 ], "y" : [1 ], "value" : [1 ]})
100100 supply_grid = gpd .GeoDataFrame (
101101 supply_data , geometry = gpd .points_from_xy (supply_data .x , supply_data .y )
102102 )
103103
104- cost_matrix = pd .DataFrame (
105- {"origin" : [0 , 0 , 1 , 1 ], "dest" : [1 , 0 , 0 , 1 ], "cost" : [1 , 0 , 1 , 0 ]}
104+ point_cost_matrix = pd .DataFrame (
105+ {
106+ "origin" : [0 , 0 , 1 , 1 ],
107+ "dest" : [1 , 0 , 0 , 1 ],
108+ "ctr_expectation" : [1 , 0 , 1 , 0 ],
109+ }
106110 )
107111
108112 self .model = Access (
@@ -112,38 +116,57 @@ def setUp(self):
112116 supply_df = supply_grid ,
113117 supply_index = "id" ,
114118 supply_value = "value" ,
115- cost_df = cost_matrix ,
119+ cost_df = point_cost_matrix ,
116120 cost_origin = "origin" ,
117121 cost_dest = "dest" ,
118- cost_name = "expectation " ,
119- neighbor_cost_df = cost_matrix ,
122+ cost_name = "ctr_expectation " ,
123+ neighbor_cost_df = point_cost_matrix ,
120124 neighbor_cost_origin = "origin" ,
121125 neighbor_cost_dest = "dest" ,
122- neighbor_cost_name = "cost" ,
126+ neighbor_cost_name = "ctr_expectation" ,
127+ )
128+
129+ # The geometries are buffered by 0.25, so the circles are 0.5 apart.
130+ # Add these as a second set of costs
131+ buff_cost_matrix = pd .DataFrame (
132+ {
133+ "origin" : [0 , 0 , 1 , 1 ],
134+ "dest" : [1 , 0 , 0 , 1 ],
135+ "buf_expectation" : [0.5 , 0 , 0.5 , 0 ],
136+ }
137+ )
138+
139+ self .model .append_user_cost_neighbors (
140+ buff_cost_matrix , "origin" , "dest" , "buf_expectation"
123141 )
124142
125143 def test_euclidean_neighbors_centroids (self ):
126144 self .model .create_euclidean_distance_neighbors (
127145 name = "euclidean" , threshold = 2 , centroid = True
128146 )
129- self .assertEqual (
147+ self .assertLess (
130148 (
131149 self .model .neighbor_cost_df .euclidean
132- == self .model .neighbor_cost_df .expectation
133- ).all ()
150+ - self .model .neighbor_cost_df .ctr_expectation
151+ )
152+ .abs ()
153+ .max (),
154+ 1e-9 ,
134155 )
135156
136157 def test_euclidean_neighbors_poly (self ):
137158 self .model .create_euclidean_distance_neighbors (
138159 name = "euclidean" , threshold = 2 , centroid = False
139160 )
140161
141- # It doesn't actually care if centroid is passed or not, since these are just points.
142- self .assertEqual (
162+ self .assertLess (
143163 (
144164 self .model .neighbor_cost_df .euclidean
145- == self .model .neighbor_cost_df .expectation
146- ).all ()
165+ - self .model .neighbor_cost_df .buf_expectation
166+ )
167+ .abs ()
168+ .max (),
169+ 1e-9 ,
147170 )
148171
149172 def test_euclidean_neighbors_without_geopandas_demand_dataframe_raises_TypeError (
0 commit comments