Skip to content

Commit

Permalink
bug fix + min R
Browse files Browse the repository at this point in the history
bug fix + better way to find min R

removed print statement
  • Loading branch information
ngomezve committed Jul 16, 2024
1 parent edbf835 commit 348e47d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/structures/size_cabin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function find_floor_angles(fdoubledecker::Bool, Rfuse::Float64, dRfuse::Float64;
if dRfuse > 0.0
θ1 = -asin(dRfuse / (2*Rfuse))
if fdoubledecker
θ2 = asin((h_seat + d_floor - dRfuse/2) / Rfuse)
θ2 = asin((d_floor - dRfuse/2) / Rfuse)
return θ1, θ2
else
return θ1
Expand All @@ -186,7 +186,7 @@ function find_floor_angles(fdoubledecker::Bool, Rfuse::Float64, dRfuse::Float64;
θ1 = -asin(h_seat / (2*Rfuse)) #This angle maximizes the cabin width
return θ1
else #If it is a double decker with no lower bubble, the main cabin could be anywhere => Use provided angle
θ2 = asin((h_seat + d_floor) / Rfuse)
θ2 = asin((Rfuse * sin(θ1) + d_floor) / Rfuse)
return θ1, θ2
end
end
Expand All @@ -208,7 +208,6 @@ passengers on each deck.
- `maxl::Float64`: required cabin length (m)
"""
function find_double_decker_cabin_length(x::Vector{Float64}, parg, parm)

seat_pitch = parg[igseatpitch]
seat_width = parg[igseatwidth]
aisle_halfwidth = parg[igaislehalfwidth]
Expand Down Expand Up @@ -243,10 +242,9 @@ function find_double_decker_cabin_length(x::Vector{Float64}, parg, parm)
l2, _, _ = place_cabin_seats(paxtop, w2, seat_pitch, seat_width, aisle_halfwidth)

maxl = max(l1, l2) #Required length

return maxl, pax_per_row_main
catch
return 1e6
return 1e6, 1e6
end
end

Expand Down Expand Up @@ -351,7 +349,7 @@ function MinCabinHeightConst(x, parg, minheight = 2.0)

_, θ2 = find_floor_angles(true, Rfuse, dRfuse, θ1 = θ1, h_seat= 0.0, d_floor = d_floor) #The seat height does not need to be included

hcabin = Rfuse * (1 - sin(θ2))
hcabin = Rfuse * (1 - sin(θ2)) + dRfuse #Add dRfuse as it shifts the lower bubble down

constraint = minheight/hcabin - 1.0 #Constraint has to be negative if hcabin > minheight

Expand Down
13 changes: 7 additions & 6 deletions src/structures/update_fuse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,21 @@ This function calculates the minimum radius required to have a desired number of
"""
function find_minimum_radius_for_seats_per_row(seats_per_row, ac_base)
ac = deepcopy(ac_base) #Copy input ac to avoid modifying it
obj(x, grad) = x[1] #Objective function is just the radius itself
obj(x, grad) = x[1] + 1e3 * abs(check_seats_per_row_diff(seats_per_row, x, ac)) #Objective function is the radius plus a big penalty if constraint is not met

initial_x = [4.0]
initial_dx = [0.5]
opt = Opt(:LN_COBYLA, length(initial_x)) #Use a local optimizer that can handle equality constraints
opt = Opt(:GN_DIRECT, length(initial_x)) #Use a global optimizer that can handle equality constraints
opt.lower_bounds = [0.0]
opt.upper_bounds = [5.0]
opt.ftol_rel = 1e-4 # Set the tolerance
opt.maxeval = 100 # Set the max number of evaluations

# opt_local = Opt(:GN_DIRECT, length(initial_x))
opt.maxeval = 500 # Set the max number of evaluations
# opt.local_optimizer = opt_local

opt.min_objective = obj

#Apply the equality constraint that ensures that the number of seats per row is the desired one
equality_constraint!(opt, (x, grad) -> check_seats_per_row_diff(seats_per_row, x, ac), 1e-5)
#equality_constraint!(opt, (x, grad) -> check_seats_per_row_diff(seats_per_row, x, ac), 1e-5)

(minf,xopt,ret) = NLopt.optimize(opt, initial_x) #Solve optimization problem
R = xopt[1]
Expand Down

0 comments on commit 348e47d

Please sign in to comment.