backend/new-overpass #52
| @@ -41,7 +41,7 @@ class Optimizer: | |||||||
|             resx (list[float]): List of edge weights. |             resx (list[float]): List of edge weights. | ||||||
|  |  | ||||||
|         Returns: |         Returns: | ||||||
|             tuple[list[int], list[int]]: A tuple containing a new row for constraint matrix and new value for upper bound vector. |             tuple[list[int], list[int]]: A tuple containing a new row for A and new value for ub. | ||||||
|         """ |         """ | ||||||
|          |          | ||||||
|         for i, elem in enumerate(resx): |         for i, elem in enumerate(resx): | ||||||
| @@ -165,19 +165,21 @@ class Optimizer: | |||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     def init_ub_dist(self, landmarks: list[Landmark], max_time: int): |     def init_ub_time(self, landmarks: list[Landmark], max_time: int): | ||||||
|         """ |         """ | ||||||
|         Initialize the objective function coefficients and inequality constraints for the optimization problem. |         Initialize the objective function coefficients and inequality constraints. | ||||||
|  |  | ||||||
|         This function computes the distances between all landmarks and stores their attractiveness to maximize sightseeing.  |         This function computes the distances between all landmarks and stores | ||||||
|         The goal is to maximize the objective function subject to the constraints A*x < b and A_eq*x = b_eq. |         their attractiveness to maximize sightseeing. The goal is to maximize  | ||||||
|  |         the objective function subject to the constraints A*x < b and A_eq*x = b_eq. | ||||||
|  |  | ||||||
|         Args: |         Args: | ||||||
|             landmarks (list[Landmark]): List of landmarks. |             landmarks (list[Landmark]): List of landmarks. | ||||||
|             max_time (int): Maximum time of visit allowed. |             max_time (int): Maximum time of visit allowed. | ||||||
|  |  | ||||||
|         Returns: |         Returns: | ||||||
|             tuple[list[float], list[float], list[int]]: Objective function coefficients, inequality constraint coefficients, and the right-hand side of the inequality constraint. |             tuple[list[float], list[float], list[int]]: Objective function coefficients, inequality | ||||||
|  |             constraint coefficients, and the right-hand side of the inequality constraint. | ||||||
|         """ |         """ | ||||||
|          |          | ||||||
|         # Objective function coefficients. a*x1 + b*x2 + c*x3 + ... |         # Objective function coefficients. a*x1 + b*x2 + c*x3 + ... | ||||||
| @@ -191,7 +193,7 @@ class Optimizer: | |||||||
|             for j, spot2 in enumerate(landmarks) : |             for j, spot2 in enumerate(landmarks) : | ||||||
|                 t = get_time(spot1.location, spot2.location) + spot1.duration |                 t = get_time(spot1.location, spot2.location) + spot1.duration | ||||||
|                 dist_table[j] = t |                 dist_table[j] = t | ||||||
|             closest = sorted(dist_table)[:25] |             closest = sorted(dist_table)[:15] | ||||||
|             for i, dist in enumerate(dist_table) : |             for i, dist in enumerate(dist_table) : | ||||||
|                 if dist not in closest : |                 if dist not in closest : | ||||||
|                     dist_table[i] = 32700 |                     dist_table[i] = 32700 | ||||||
| @@ -452,7 +454,7 @@ class Optimizer: | |||||||
|         L = len(landmarks) |         L = len(landmarks) | ||||||
|  |  | ||||||
|         # SET CONSTRAINTS FOR INEQUALITY |         # SET CONSTRAINTS FOR INEQUALITY | ||||||
|         c, A_ub, b_ub = self.init_ub_dist(landmarks, max_time)          # Add the distances from each landmark to the other |         c, A_ub, b_ub = self.init_ub_time(landmarks, max_time)          # Add the distances from each landmark to the other | ||||||
|         A, b = self.respect_number(L, max_landmarks)                                   # Respect max number of visits (no more possible stops than landmarks).  |         A, b = self.respect_number(L, max_landmarks)                                   # Respect max number of visits (no more possible stops than landmarks).  | ||||||
|         A_ub = np.vstack((A_ub, A), dtype=np.int16) |         A_ub = np.vstack((A_ub, A), dtype=np.int16) | ||||||
|         b_ub += b |         b_ub += b | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user