better sym breaking
Some checks failed
Build and deploy the backend to staging / Build and push image (pull_request) Successful in 2m7s
Run linting on the backend code / Build (pull_request) Successful in 27s
Run testing on the backend code / Build (pull_request) Failing after 1m11s
Build and deploy the backend to staging / Deploy to staging (pull_request) Successful in 23s

This commit is contained in:
Helldragon67 2025-01-15 09:35:25 +01:00
parent dba988629d
commit 14385342cc
2 changed files with 9 additions and 8 deletions

View File

@ -35,6 +35,7 @@ def test_turckheim(client, request): # pylint: disable=redefined-outer-name
} }
) )
result = response.json() result = response.json()
print(result)
landmarks = load_trip_landmarks(client, result['first_landmark_uuid']) landmarks = load_trip_landmarks(client, result['first_landmark_uuid'])

View File

@ -35,7 +35,7 @@ class Optimizer:
""" """
Initialize the objective function coefficients and inequality constraints. Initialize the objective function coefficients and inequality constraints.
-> Adds 1 row of constraints -> Adds 1 row of constraints
-> Pre-allocates A_ub for the rest of the computations with 2*L rows -> Pre-allocates A_ub for the rest of the computations with L + (L*L-L)/2 rows
This function computes the distances between all landmarks and stores This function computes the distances between all landmarks and stores
their attractiveness to maximize sightseeing. The goal is to maximize their attractiveness to maximize sightseeing. The goal is to maximize
@ -55,8 +55,8 @@ class Optimizer:
c = np.zeros(L, dtype=np.int16) c = np.zeros(L, dtype=np.int16)
# Coefficients of inequality constraints (left-hand side) # Coefficients of inequality constraints (left-hand side)
A_ub = np.zeros((2*L, L*L), dtype=np.int16) A_ub = np.zeros((L + int((L*L-L)/2), L*L), dtype=np.int16)
b_ub = np.zeros(2*L, dtype=np.int16) b_ub = np.zeros(L + int((L*L-L)/2), dtype=np.int16)
# Fill in first row # Fill in first row
b_ub[0] = round(max_time*self.overshoot) b_ub[0] = round(max_time*self.overshoot)
@ -65,9 +65,9 @@ class Optimizer:
c[i] = -spot1.attractiveness c[i] = -spot1.attractiveness
for j in range(i+1, L) : for j in range(i+1, L) :
if i !=j : if i !=j :
t = get_time(spot1.location, landmarks[j].location) + spot1.duration t = get_time(spot1.location, landmarks[j].location)
A_ub[0, i*L + j] = t A_ub[0, i*L + j] = t + spot1.duration
A_ub[0, j*L + i] = t A_ub[0, j*L + i] = t + landmarks[j].duration
# Expand 'c' to L*L for every decision variable # Expand 'c' to L*L for every decision variable
c = np.tile(c, L) c = np.tile(c, L)
@ -120,7 +120,7 @@ class Optimizer:
Generate constraints to prevent simultaneous travel between two landmarks Generate constraints to prevent simultaneous travel between two landmarks
in both directions. Constraint to not have d14 and d41 simultaneously. in both directions. Constraint to not have d14 and d41 simultaneously.
Does not prevent cyclic paths with more elements Does not prevent cyclic paths with more elements
-> Adds L rows of constraints (some of which might be zero) -> Adds (L*L-L)/2 rows of constraints (some of which might be zero)
Args: Args:
L (int): Number of landmarks. L (int): Number of landmarks.
@ -136,7 +136,7 @@ class Optimizer:
# A = np.zeros((len(up_ind_x[1:]),L*L), dtype=np.int8) # A = np.zeros((len(up_ind_x[1:]),L*L), dtype=np.int8)
# Fill-in rows L to 2*L-1 # Fill-in rows L to 2*L-1
for i in range(L) : for i in range(int((L*L-L)/2)) :
if up_ind_x[i] != up_ind_y[i] : if up_ind_x[i] != up_ind_y[i] :
A[L+i, up_ind_x[i]*L + up_ind_y[i]] = 1 A[L+i, up_ind_x[i]*L + up_ind_y[i]] = 1
A[L+i, up_ind_y[i]*L + up_ind_x[i]] = 1 A[L+i, up_ind_y[i]*L + up_ind_x[i]] = 1