I apologize for the confusion. The problem is to optimize for power output given a nuclearcraft reactor, fuel, and cells allowed as well as the coolant available. The code is still incomplete, but here is my progress so far.
Anyway, I’m changing this back to optimization.
As for the reference, here is the specification. Fission Reactor - Official Feed The Beast Wiki
using JuMP
using HiGHS
function nuclearcraftoptimize(base_energy, base_heat,reactor_width, reactor_length, reactor_height, reactor_cell_limit = 1024; )
model = Model(HiGHS.Optimizer)
@variable(model,reactor_cells[1:reactor_width,1:reactor_length,1:reactor_height],Bin)
@constraint(model,sum(reactor_cells)<=reactor_cell_limit)
@variable(model,moderators[1:reactor_width,1:reactor_length,1:reactor_height],Bin)
#Left and right (mandatory) boosting.
#Left booster ranges.
@variable(model,left_boosted_reactor[1:reactor_width,1:reactor_length,1:reactor_height],Bin)
@variable(model,left_boosted_reactor_range_0[2:reactor_width,1:reactor_length,1:reactor_height],Bin)
@variable(model,left_boosted_reactor_range_1[3:reactor_width,1:reactor_length,1:reactor_height],Bin)
@variable(model,left_boosted_reactor_range_2[4:reactor_width,1:reactor_length,1:reactor_height],Bin)
@variable(model,left_boosted_reactor_range_3[5:reactor_width,1:reactor_length,1:reactor_height],Bin)
@variable(model,left_boosted_reactor_range_4[6:reactor_width,1:reactor_length,1:reactor_height],Bin)
#Left booster ranges sum up.
@constraint(model, left_boosted_reactor[1,:,:] .== 0)
if reactor_width >= 2
@constraint(model, left_boosted_reactor[2,:,:] .== left_boosted_reactor_range_0[2,:,:])
end
if reactor_width >= 3
@constraint(model, left_boosted_reactor[3,:,:] .== left_boosted_reactor_range_0[3,:,:] .+ left_boosted_reactor_range_1[3,:,:])
end
if reactor_width >= 4
@constraint(model, left_boosted_reactor[4,:,:] .== left_boosted_reactor_range_0[4,:,:] .+ left_boosted_reactor_range_1[4,:,:] .+ left_boosted_reactor_range_2[4,:,:])
end
if reactor_width >= 5
@constraint(model, left_boosted_reactor[5,:,:] .== left_boosted_reactor_range_0[5,:,:] .+ left_boosted_reactor_range_1[5,:,:] .+ left_boosted_reactor_range_2[5,:,:] .+ left_boosted_reactor_range_3[5,:,:])
end
@constraint(model, left_boosted_reactor[6:end,:,:] .== left_boosted_reactor_range_0[6:end,:,:] .+ left_boosted_reactor_range_1[6:end,:,:] .+ left_boosted_reactor_range_2[6:end,:,:] .+ left_boosted_reactor_range_3[6:end,:,:] .+ left_boosted_reactor_range_4[6:end,:,:])
#Left booster ranges constraints.
@constraint(model,reactor_cells[2:end,:,:] .+ reactor_cells[1:end-1,:,:] .- 1 .<= left_boosted_reactor_range_0[2:end,:,:])
@constraint(model,reactor_cells[2:end,:,:] .+ reactor_cells[1:end-1,:,:] .>= 2*left_boosted_reactor_range_0[2:end,:,:])
@constraint(model,reactor_cells[3:end,:,:] .+ moderators[2:end-1,:,:] .+ reactor_cells[1:end-2,:,:] .- 2 .<= left_boosted_reactor_range_1[3:end,:,:])
@constraint(model,reactor_cells[3:end,:,:] .+ moderators[2:end-1,:,:] .+ reactor_cells[1:end-2,:,:] .>= 3*left_boosted_reactor_range_1[3:end,:,:])
@constraint(model,reactor_cells[4:end,:,:] .+ moderators[3:end-1,:,:] .+ moderators[2:end-2,:,:] .+ reactor_cells[1:end-3,:,:] .- 3 .<= left_boosted_reactor_range_2[4:end,:,:])
@constraint(model,reactor_cells[4:end,:,:] .+ moderators[3:end-1,:,:] .+ moderators[2:end-2,:,:] .+ reactor_cells[1:end-3,:,:] .>= 4*left_boosted_reactor_range_2[4:end,:,:])
@constraint(model,reactor_cells[5:end,:,:] .+ moderators[4:end-1,:,:] .+ moderators[3:end-2,:,:] .+ moderators[2:end-3,:,:] .+ reactor_cells[1:end-4,:,:] .- 4 .<= left_boosted_reactor_range_3[5:end,:,:])
@constraint(model,reactor_cells[5:end,:,:] .+ moderators[4:end-1,:,:] .+ moderators[3:end-2,:,:] .+ moderators[2:end-3,:,:] .+ reactor_cells[1:end-4,:,:] .>= 5*left_boosted_reactor_range_3[5:end,:,:])
@constraint(model,reactor_cells[6:end,:,:] .+ moderators[5:end-1,:,:] .+ moderators[4:end-2,:,:] .+ moderators[3:end-3,:,:] .+ moderators[2:end-4,:,:] .+ reactor_cells[1:end-5,:,:] .- 5 .<= left_boosted_reactor_range_4[6:end,:,:])
@constraint(model,reactor_cells[6:end,:,:] .+ moderators[5:end-1,:,:] .+ moderators[4:end-2,:,:] .+ moderators[3:end-3,:,:] .+ moderators[2:end-4,:,:] .+ reactor_cells[1:end-5,:,:] .>= 6*left_boosted_reactor_range_4[6:end,:,:])
#Right booster ranges.
@variable(model,right_boosted_reactor[1:reactor_width,1:reactor_length,1:reactor_height],Bin)
@variable(model,right_boosted_reactor_range_0[1:reactor_width-1,1:reactor_length,1:reactor_height],Bin)
@variable(model,right_boosted_reactor_range_1[1:reactor_width-2,1:reactor_length,1:reactor_height],Bin)
@variable(model,right_boosted_reactor_range_2[1:reactor_width-3,1:reactor_length,1:reactor_height],Bin)
@variable(model,right_boosted_reactor_range_3[1:reactor_width-4,1:reactor_length,1:reactor_height],Bin)
@variable(model,right_boosted_reactor_range_4[1:reactor_width-5,1:reactor_length,1:reactor_height],Bin)
#Right booster ranges sum up.
@constraint(model,right_boosted_reactor[reactor_width,:,:] .== 0)
if reactor_width >=2
@constraint(model,right_boosted_reactor[reactor_width-1,:,:] .== right_boosted_reactor_range_0[reactor_width-1,:,:])
end
if reactor_width >=3
@constraint(model,right_boosted_reactor[reactor_width-2,:,:] .== right_boosted_reactor_range_0[reactor_width-2,:,:] .+ right_boosted_reactor_range_1[reactor_width-2,:,:])
end
if reactor_width >=4
@constraint(model,right_boosted_reactor[reactor_width-3,:,:] .== right_boosted_reactor_range_0[reactor_width-3,:,:] .+ right_boosted_reactor_range_1[reactor_width-3,:,:] .+ right_boosted_reactor_range_2[reactor_width-3,:,:])
end
if reactor_width >=5
@constraint(model,right_boosted_reactor[reactor_width-4,:,:] .== right_boosted_reactor_range_0[reactor_width-4,:,:] .+ right_boosted_reactor_range_1[reactor_width-4,:,:] .+ right_boosted_reactor_range_2[reactor_width-4,:,:] .+ right_boosted_reactor_range_3[reactor_width-4,:,:])
end
@constraint(model,right_boosted_reactor[1:reactor_width-5,:,:] .== right_boosted_reactor_range_0[1:reactor_width-5,:,:] .+ right_boosted_reactor_range_1[1:reactor_width-5,:,:] .+ right_boosted_reactor_range_2[1:reactor_width-5,:,:] .+ right_boosted_reactor_range_3[1:reactor_width-5,:,:] .+ right_boosted_reactor_range_4[1:reactor_width-5,:,:])
#Constraints of right_boosted_reactors
@constraint(model,reactor_cells[1:reactor_width-1,:,:] .+ reactor_cells[2:reactor_width,:,:] .- 1 .<= right_boosted_reactor_range_0[1:reactor_width-1,:,:])
@constraint(model,reactor_cells[1:reactor_width-1,:,:] .+ reactor_cells[2:reactor_width,:,:] .>= 2*right_boosted_reactor_range_0[1:reactor_width-1,:,:])
@constraint(model,reactor_cells[1:reactor_width-2,:,:] .+ moderators[2:reactor_width-1,:,:] .+ reactor_cells[3:reactor_width,:,:] .- 2 .<= right_boosted_reactor_range_1[1:reactor_width-2,:,:])
@constraint(model,reactor_cells[1:reactor_width-2,:,:] .+ moderators[2:reactor_width-1,:,:] .+ reactor_cells[3:reactor_width,:,:] .>= 3*right_boosted_reactor_range_1[1:reactor_width-2,:,:])
@constraint(model,reactor_cells[1:reactor_width-3,:,:] .+ moderators[2:reactor_width-2,:,:] .+ moderators[3:reactor_width-1,:,:] .+ reactor_cells[4:reactor_width,:,:] .- 3 .<= right_boosted_reactor_range_2[1:reactor_width-3,:,:])
@constraint(model,reactor_cells[1:reactor_width-3,:,:] .+ moderators[2:reactor_width-2,:,:] .+ moderators[3:reactor_width-1,:,:] .+ reactor_cells[4:reactor_width,:,:] .>= 4*right_boosted_reactor_range_2[1:reactor_width-3,:,:])
@constraint(model,reactor_cells[1:reactor_width-4,:,:] .+ moderators[2:reactor_width-3,:,:] .+ moderators[3:reactor_width-2,:,:] .+ moderators[4:reactor_width-1,:,:] .+ reactor_cells[5:reactor_width,:,:] .- 4 .<= right_boosted_reactor_range_3[1:reactor_width-4,:,:])
@constraint(model,reactor_cells[1:reactor_width-4,:,:] .+ moderators[2:reactor_width-3,:,:] .+ moderators[3:reactor_width-2,:,:] .+ moderators[4:reactor_width-1,:,:] .+ reactor_cells[5:reactor_width,:,:] .>= 5*right_boosted_reactor_range_3[1:reactor_width-4,:,:])
@constraint(model,reactor_cells[1:reactor_width-5,:,:] .+ moderators[2:reactor_width-4,:,:] .+ moderators[3:reactor_width-3,:,:] .+ moderators[4:reactor_width-2,:,:] .+ moderators[5:reactor_width-1,:,:] .+ reactor_cells[6:reactor_width,:,:] .- 5 .<= right_boosted_reactor_range_4[1:reactor_width-5,:,:])
@constraint(model,reactor_cells[1:reactor_width-5,:,:] .+ moderators[2:reactor_width-4,:,:] .+ moderators[3:reactor_width-3,:,:] .+ moderators[4:reactor_width-2,:,:] .+ moderators[5:reactor_width-1,:,:] .+ reactor_cells[6:reactor_width,:,:] .>= 6*right_boosted_reactor_range_4[1:reactor_width-5,:,:])
#Forward and backward (mandatory) boosting.
#Forward booster ranges.
@variable(model,forward_boosted_reactor[1:reactor_width,1:reactor_length,1:reactor_height],Bin)
@variable(model,forward_boosted_reactor_range_0[1:reactor_width,2:reactor_length,1:reactor_height],Bin)
@variable(model,forward_boosted_reactor_range_1[1:reactor_width,3:reactor_length,1:reactor_height],Bin)
@variable(model,forward_boosted_reactor_range_2[1:reactor_width,4:reactor_length,1:reactor_height],Bin)
@variable(model,forward_boosted_reactor_range_3[1:reactor_width,5:reactor_length,1:reactor_height],Bin)
@variable(model,forward_boosted_reactor_range_4[1:reactor_width,6:reactor_length,1:reactor_height],Bin)
#Forward booster ranges sum up.
@constraint(model, forward_boosted_reactor[:,1,:] .== 0)
if reactor_length >=2
@constraint(model, forward_boosted_reactor[:,2,:] .== forward_boosted_reactor_range_0[:,2,:])
end
if reactor_length >= 3
@constraint(model, forward_boosted_reactor[:,3,:] .== forward_boosted_reactor_range_0[:,3,:] .+ forward_boosted_reactor_range_1[:,3,:])
end
if reactor_length >= 4
@constraint(model, forward_boosted_reactor[:,4,:] .== forward_boosted_reactor_range_0[:,4,:] .+ forward_boosted_reactor_range_1[:,4,:] .+ forward_boosted_reactor_range_2[:,4,:])
end
if reactor_length >= 5
@constraint(model, forward_boosted_reactor[:,5,:] .== forward_boosted_reactor_range_0[:,5,:] .+ forward_boosted_reactor_range_1[:,5,:] .+ forward_boosted_reactor_range_2[:,5,:] .+ forward_boosted_reactor_range_3[:,5,:])
end
@constraint(model, forward_boosted_reactor[:,6:end,:] .== forward_boosted_reactor_range_0[:,6:end,:] .+ forward_boosted_reactor_range_1[:,6:end,:] .+ forward_boosted_reactor_range_2[:,6:end,:] .+ forward_boosted_reactor_range_3[:,6:end,:] .+ forward_boosted_reactor_range_4[:,6:end,:])
#Forward booster ranges constraints.
@constraint(model,reactor_cells[:,2:end,:] .+ reactor_cells[:,1:end-1,:] .- 1 .<= forward_boosted_reactor_range_0[:,2:end,:])
@constraint(model,reactor_cells[:,2:end,:] .+ reactor_cells[:,1:end-1,:] .>= 2*forward_boosted_reactor_range_0[:,2:end,:])
@constraint(model,reactor_cells[:,3:end,:] .+ moderators[:,2:end-1,:] .+ reactor_cells[:,1:end-2,:] .- 2 .<= forward_boosted_reactor_range_1[:,3:end,:])
@constraint(model,reactor_cells[:,3:end,:] .+ moderators[:,2:end-1,:] .+ reactor_cells[:,1:end-2,:] .>= 3*forward_boosted_reactor_range_1[:,3:end,:])
@constraint(model,reactor_cells[:,4:end,:] .+ moderators[:,3:end-1,:] .+ moderators[:,2:end-2,:] .+ reactor_cells[:,1:end-3,:] .- 3 .<= forward_boosted_reactor_range_2[:,4:end,:])
@constraint(model,reactor_cells[:,4:end,:] .+ moderators[:,3:end-1,:] .+ moderators[:,2:end-2,:] .+ reactor_cells[:,1:end-3,:] .>= 4*forward_boosted_reactor_range_2[:,4:end,:])
@constraint(model,reactor_cells[:,5:end,:] .+ moderators[:,4:end-1,:] .+ moderators[:,3:end-2,:] .+ moderators[:,2:end-3,:] .+ reactor_cells[:,1:end-4,:] .- 4 .<= forward_boosted_reactor_range_3[:,5:end,:])
@constraint(model,reactor_cells[:,5:end,:] .+ moderators[:,4:end-1,:] .+ moderators[:,3:end-2,:] .+ moderators[:,2:end-3,:] .+ reactor_cells[:,1:end-4,:] .>= 5*forward_boosted_reactor_range_3[:,5:end,:])
@constraint(model,reactor_cells[:,6:end,:] .+ moderators[:,5:end-1,:] .+ moderators[:,4:end-2,:] .+ moderators[:,3:end-3,:] .+ moderators[:,2:end-4,:] .+ reactor_cells[:,1:end-5,:] .- 5 .<= forward_boosted_reactor_range_4[:,6:end,:])
@constraint(model,reactor_cells[:,6:end,:] .+ moderators[:,5:end-1,:] .+ moderators[:,4:end-2,:] .+ moderators[:,3:end-3,:] .+ moderators[:,2:end-4,:] .+ reactor_cells[:,1:end-5,:] .>= 6*forward_boosted_reactor_range_4[:,6:end,:])
#Backward booster ranges.
@variable(model,backward_boosted_reactor[1:reactor_width,1:reactor_length,1:reactor_height],Bin)
@variable(model,backward_boosted_reactor_range_0[1:reactor_width,1:reactor_length-1,1:reactor_height],Bin)
@variable(model,backward_boosted_reactor_range_1[1:reactor_width,1:reactor_length-2,1:reactor_height],Bin)
@variable(model,backward_boosted_reactor_range_2[1:reactor_width,1:reactor_length-3,1:reactor_height],Bin)
@variable(model,backward_boosted_reactor_range_3[1:reactor_width,1:reactor_length-4,1:reactor_height],Bin)
@variable(model,backward_boosted_reactor_range_4[1:reactor_width,1:reactor_length-5,1:reactor_height],Bin)
#Backward booster ranges sum up.
@constraint(model,backward_boosted_reactor[:,reactor_length,:] .== 0)
if reactor_length >= 2
@constraint(model,backward_boosted_reactor[:,reactor_length-1,:] .== backward_boosted_reactor_range_0[:,reactor_length-1,:])
end
if reactor_length >= 3
@constraint(model,backward_boosted_reactor[:,reactor_length-2,:] .== backward_boosted_reactor_range_0[:,reactor_length-2,:] .+ backward_boosted_reactor_range_1[:,reactor_length-2,:])
end
if reactor_length >= 4
@constraint(model,backward_boosted_reactor[:,reactor_length-3,:] .== backward_boosted_reactor_range_0[:,reactor_length-3,:] .+ backward_boosted_reactor_range_1[:,reactor_length-3,:] .+ backward_boosted_reactor_range_2[:,reactor_length-3,:])
end
if reactor_length >= 5
@constraint(model,backward_boosted_reactor[:,reactor_length-4,:] .== backward_boosted_reactor_range_0[:,reactor_length-4,:] .+ backward_boosted_reactor_range_1[:,reactor_length-4,:] .+ backward_boosted_reactor_range_2[:,reactor_length-4,:] .+ backward_boosted_reactor_range_3[:,reactor_length-4,:])
end
@constraint(model,backward_boosted_reactor[:,1:reactor_length-5,:] .== backward_boosted_reactor_range_0[:,1:reactor_length-5,:] .+ backward_boosted_reactor_range_1[:,1:reactor_length-5,:] .+ backward_boosted_reactor_range_2[:,1:reactor_length-5,:] .+ backward_boosted_reactor_range_3[:,1:reactor_length-5,:] .+ backward_boosted_reactor_range_4[:,1:reactor_length-5,:])
#constraints of backward_boosted_reactors
@constraint(model,reactor_cells[:,1:reactor_length-1,:] .+ reactor_cells[:,2:reactor_length,:] .- 1 .<= backward_boosted_reactor_range_0[:,1:reactor_length-1,:])
@constraint(model,reactor_cells[:,1:reactor_length-1,:] .+ reactor_cells[:,2:reactor_length,:] .>= 2*backward_boosted_reactor_range_0[:,1:reactor_length-1,:])
@constraint(model,reactor_cells[:,1:reactor_length-2,:] .+ moderators[:,2:reactor_length-1,:] .+ reactor_cells[:,3:reactor_length,:] .- 2 .<= backward_boosted_reactor_range_1[:,1:reactor_length-2,:])
@constraint(model,reactor_cells[:,1:reactor_length-2,:] .+ moderators[:,2:reactor_length-1,:] .+ reactor_cells[:,3:reactor_length,:] .>= 3*backward_boosted_reactor_range_1[:,1:reactor_length-2,:])
@constraint(model,reactor_cells[:,1:reactor_length-3,:] .+ moderators[:,2:reactor_length-2,:] .+ moderators[:,3:reactor_length-1,:] .+ reactor_cells[:,4:reactor_length,:] .- 3 .<= backward_boosted_reactor_range_2[:,1:reactor_length-3,:])
@constraint(model,reactor_cells[:,1:reactor_length-3,:] .+ moderators[:,2:reactor_length-2,:] .+ moderators[:,3:reactor_length-1,:] .+ reactor_cells[:,4:reactor_length,:] .>= 4*backward_boosted_reactor_range_2[:,1:reactor_length-3,:])
@constraint(model,reactor_cells[:,1:reactor_length-4,:] .+ moderators[:,2:reactor_length-3,:] .+ moderators[:,3:reactor_length-2,:] .+ moderators[:,4:reactor_length-1,:] .+ reactor_cells[:,5:reactor_length,:] .- 4 .<= backward_boosted_reactor_range_3[:,1:reactor_length-4,:])
@constraint(model,reactor_cells[:,1:reactor_length-4,:] .+ moderators[:,2:reactor_length-3,:] .+ moderators[:,3:reactor_length-2,:] .+ moderators[:,4:reactor_length-1,:] .+ reactor_cells[:,5:reactor_length,:] .>= 5*backward_boosted_reactor_range_3[:,1:reactor_length-4,:])
@constraint(model,reactor_cells[:,1:reactor_length-5,:] .+ moderators[:,2:reactor_length-4,:] .+ moderators[:,3:reactor_length-3,:] .+ moderators[:,4:reactor_length-2,:] .+ moderators[:,5:reactor_length-1,:] .+ reactor_cells[:,6:reactor_length,:] .- 5 .<= backward_boosted_reactor_range_4[:,1:reactor_length-5,:])
@constraint(model,reactor_cells[:,1:reactor_length-5,:] .+ moderators[:,2:reactor_length-4,:] .+ moderators[:,3:reactor_length-3,:] .+ moderators[:,4:reactor_length-2,:] .+ moderators[:,5:reactor_length-1,:] .+ reactor_cells[:,6:reactor_length,:] .>= 6*backward_boosted_reactor_range_4[:,1:reactor_length-5,:])
# Downward and upward boosting
#Downward booster ranges
@variable(model,downward_boosted_reactor[1:reactor_width,1:reactor_length,1:reactor_height],Bin)
@variable(model,downward_boosted_reactor_range_0[1:reactor_width,1:reactor_length,2:reactor_height],Bin)
@variable(model,downward_boosted_reactor_range_1[1:reactor_width,1:reactor_length,3:reactor_height],Bin)
@variable(model,downward_boosted_reactor_range_2[1:reactor_width,1:reactor_length,4:reactor_height],Bin)
@variable(model,downward_boosted_reactor_range_3[1:reactor_width,1:reactor_length,5:reactor_height],Bin)
@variable(model,downward_boosted_reactor_range_4[1:reactor_width,1:reactor_length,6:reactor_height],Bin)
#Downward booster ranges sum up.
@constraint(model, downward_boosted_reactor[:,:,1] .== 0)
if reactor_height >= 2
@constraint(model, downward_boosted_reactor[:,:,2] .== downward_boosted_reactor_range_0[:,:,2])
end
if reactor_height >=3
@constraint(model, downward_boosted_reactor[:,:,3] .== downward_boosted_reactor_range_0[:,:,3] .+ downward_boosted_reactor_range_1[:,:,3])
end
if reactor_height >= 4
@constraint(model, downward_boosted_reactor[:,:,4] .== downward_boosted_reactor_range_0[:,:,4] .+ downward_boosted_reactor_range_1[:,:,4] .+ downward_boosted_reactor_range_2[:,:,4])
end
if reactor_height >= 5
@constraint(model, downward_boosted_reactor[:,:,5] .== downward_boosted_reactor_range_0[:,:,5] .+ downward_boosted_reactor_range_1[:,:,5] .+ downward_boosted_reactor_range_2[:,:,5] .+ downward_boosted_reactor_range_3[:,:,5])
end
@constraint(model, downward_boosted_reactor[:,:,6:end] .== downward_boosted_reactor_range_0[:,:,6:end] .+ downward_boosted_reactor_range_1[:,:,6:end] .+ downward_boosted_reactor_range_2[:,:,6:end] .+ downward_boosted_reactor_range_3[:,:,6:end] .+ downward_boosted_reactor_range_4[:,:,6:end])
#Downward booster ranges constraints
@constraint(model,reactor_cells[:,:,2:end] .+ reactor_cells[:,:,1:end-1] .- 1 .<= downward_boosted_reactor_range_0[:,:,2:end])
@constraint(model,reactor_cells[:,:,2:end] .+ reactor_cells[:,:,1:end-1] .>= 2*downward_boosted_reactor_range_0[:,:,2:end])
@constraint(model,reactor_cells[:,:,3:end] .+ moderators[:,:,2:end-1] .+ reactor_cells[:,:,1:end-2] .- 2 .<= downward_boosted_reactor_range_1[:,:,3:end])
@constraint(model,reactor_cells[:,:,3:end] .+ moderators[:,:,2:end-1] .+ reactor_cells[:,:,1:end-2] .>= 3*downward_boosted_reactor_range_1[:,:,3:end])
@constraint(model,reactor_cells[:,:,4:end] .+ moderators[:,:,3:end-1] .+ moderators[:,:,2:end-2] .+ reactor_cells[:,:,1:end-3] .- 3 .<= downward_boosted_reactor_range_2[:,:,4:end])
@constraint(model,reactor_cells[:,:,4:end] .+ moderators[:,:,3:end-1] .+ moderators[:,:,2:end-2] .+ reactor_cells[:,:,1:end-3] .>= 4*downward_boosted_reactor_range_2[:,:,4:end])
@constraint(model,reactor_cells[:,:,5:end] .+ moderators[:,:,4:end-1] .+ moderators[:,:,3:end-2] .+ moderators[:,:,2:end-3] .+ reactor_cells[:,:,1:end-4] .- 4 .<= downward_boosted_reactor_range_3[:,:,5:end])
@constraint(model,reactor_cells[:,:,5:end] .+ moderators[:,:,4:end-1] .+ moderators[:,:,3:end-2] .+ moderators[:,:,2:end-3] .+ reactor_cells[:,:,1:end-4] .>= 5*downward_boosted_reactor_range_3[:,:,5:end])
@constraint(model,reactor_cells[:,:,6:end] .+ moderators[:,:,5:end-1] .+ moderators[:,:,4:end-2] .+ moderators[:,:,3:end-3] .+ moderators[:,:,2:end-4] .+ reactor_cells[:,:,1:end-5] .- 5 .<= downward_boosted_reactor_range_4[:,:,6:end])
@constraint(model,reactor_cells[:,:,6:end] .+ moderators[:,:,5:end-1] .+ moderators[:,:,4:end-2] .+ moderators[:,:,3:end-3] .+ moderators[:,:,2:end-4] .+ reactor_cells[:,:,1:end-5] .>= 6*downward_boosted_reactor_range_4[:,:,6:end])
#Upward booster ranges
@variable(model,upward_boosted_reactor[1:reactor_width,1:reactor_length,1:reactor_height],Bin)
@variable(model,upward_boosted_reactor_range_0[1:reactor_width,1:reactor_length,1:reactor_height-1],Bin)
@variable(model,upward_boosted_reactor_range_1[1:reactor_width,1:reactor_length,1:reactor_height-2],Bin)
@variable(model,upward_boosted_reactor_range_2[1:reactor_width,1:reactor_length,1:reactor_height-3],Bin)
@variable(model,upward_boosted_reactor_range_3[1:reactor_width,1:reactor_length,1:reactor_height-4],Bin)
@variable(model,upward_boosted_reactor_range_4[1:reactor_width,1:reactor_length,1:reactor_height-5],Bin)
#Upward booster ranges sum up.
@constraint(model,upward_boosted_reactor[:,:,reactor_height] .== 0)
if reactor_height >= 2
@constraint(model,upward_boosted_reactor[:,:,reactor_height-1] .== upward_boosted_reactor_range_0[:,:,reactor_height-1])
end
if reactor_height >= 3
@constraint(model,upward_boosted_reactor[:,:,reactor_height-2] .== upward_boosted_reactor_range_0[:,:,reactor_height-2] .+ upward_boosted_reactor_range_1[:,:,reactor_height-2])
end
if reactor_height >= 4
@constraint(model,upward_boosted_reactor[:,:,reactor_height-3] .== upward_boosted_reactor_range_0[:,:,reactor_height-3] .+ upward_boosted_reactor_range_1[:,:,reactor_height-3] .+ upward_boosted_reactor_range_2[:,:,reactor_height-3])
end
if reactor_height >= 5
@constraint(model,upward_boosted_reactor[:,:,reactor_height-4] .== upward_boosted_reactor_range_0[:,:,reactor_height-4] .+ upward_boosted_reactor_range_1[:,:,reactor_height-4] .+ upward_boosted_reactor_range_2[:,:,reactor_height-4] .+ upward_boosted_reactor_range_3[:,:,reactor_height-4])
end
@constraint(model,upward_boosted_reactor[:,:,1:reactor_height-5] .== upward_boosted_reactor_range_0[:,:,1:reactor_height-5] .+ upward_boosted_reactor_range_1[:,:,1:reactor_height-5] .+ upward_boosted_reactor_range_2[:,:,1:reactor_height-5] .+ upward_boosted_reactor_range_3[:,:,1:reactor_height-5] .+ upward_boosted_reactor_range_4[:,:,1:reactor_height-5])
#Upward booster ranges constraints.
@constraint(model,reactor_cells[:,:,1:reactor_height-1] .+ reactor_cells[:,:,2:reactor_height] .- 1 .<= upward_boosted_reactor_range_0[:,:,1:reactor_height-1])
@constraint(model,reactor_cells[:,:,1:reactor_height-1] .+ reactor_cells[:,:,2:reactor_height] .>= 2*upward_boosted_reactor_range_0[:,:,1:reactor_height-1])
@constraint(model,reactor_cells[:,:,1:reactor_height-2] .+ moderators[:,:,2:reactor_height-1] .+ reactor_cells[:,:,3:reactor_height] .- 2 .<= upward_boosted_reactor_range_1[:,:,1:reactor_height-2])
@constraint(model,reactor_cells[:,:,1:reactor_height-2] .+ moderators[:,:,2:reactor_height-1] .+ reactor_cells[:,:,3:reactor_height] .>= 3*upward_boosted_reactor_range_1[:,:,1:reactor_height-2])
@constraint(model,reactor_cells[:,:,1:reactor_height-3] .+ moderators[:,:,2:reactor_height-2] .+ moderators[:,:,3:reactor_height-1] .+ reactor_cells[:,:,4:reactor_height] .- 3 .<= upward_boosted_reactor_range_2[:,:,1:reactor_height-3])
@constraint(model,reactor_cells[:,:,1:reactor_height-3] .+ moderators[:,:,2:reactor_height-2] .+ moderators[:,:,3:reactor_height-1] .+ reactor_cells[:,:,4:reactor_height] .>= 4*upward_boosted_reactor_range_2[:,:,1:reactor_height-3])
@constraint(model,reactor_cells[:,:,1:reactor_height-4] .+ moderators[:,:,2:reactor_height-3] .+ moderators[:,:,3:reactor_height-2] .+ moderators[:,:,4:reactor_height-1] .+ reactor_cells[:,:,5:reactor_height] .- 4 .<= upward_boosted_reactor_range_3[:,:,1:reactor_height-4])
@constraint(model,reactor_cells[:,:,1:reactor_height-4] .+ moderators[:,:,2:reactor_height-3] .+ moderators[:,:,3:reactor_height-2] .+ moderators[:,:,4:reactor_height-1] .+ reactor_cells[:,:,5:reactor_height] .>= 5*upward_boosted_reactor_range_3[:,:,1:reactor_height-4])
@constraint(model,reactor_cells[:,:,1:reactor_height-5] .+ moderators[:,:,2:reactor_height-4] .+ moderators[:,:,3:reactor_height-3] .+ moderators[:,:,4:reactor_height-2] .+ moderators[:,:,5:reactor_height-1] .+ reactor_cells[:,:,6:reactor_height] .- 5 .<= upward_boosted_reactor_range_4[:,:,1:reactor_height-5])
@constraint(model,reactor_cells[:,:,1:reactor_height-5] .+ moderators[:,:,2:reactor_height-4] .+ moderators[:,:,3:reactor_height-3] .+ moderators[:,:,4:reactor_height-2] .+ moderators[:,:,5:reactor_height-1] .+ reactor_cells[:,:,6:reactor_height] .>= 6*upward_boosted_reactor_range_4[:,:,1:reactor_height-5])
#=
if reactor_width >= 5
@constraint(model, 16 .* reactor_cells[5,:,:] .+ 15 .* reactor_cells[4,:,:] .+ 8 .* moderators[4,:,:] .+ 7 .* reactor_cells[3,:,:] .+ 4 .* moderators[3,:,:]
.+ 3 .* reactor_cells[2,:,:] .+ 2 .* moderators[2,:,:] .+ reactor_cells[1,:,:] .- 31 .<= 64*left_boosted_reactor[5,:,:])
@constraint(model, 16 .* reactor_cells[5,:,:] .+ 15 .* reactor_cells[4,:,:] .+ 8 .* moderators[4,:,:] .+ 7 .* reactor_cells[3,:,:] .+ 4 .* moderators[3,:,:]
.+ 3 .* reactor_cells[2,:,:] .+ 2 .* moderators[2,:,:] .+ reactor_cells[1,:,:] .- 31 .+ 1 .>= left_boosted_reactor[5,:,:])
end
if reactor_width >= 4
@constraint(model,8 .* reactor_cells[4,:,:] .+ 7 .* reactor_cells[3,:,:] .+ 4 .* moderators[3,:,:]
.+ 3 .* reactor_cells[2,:,:] .+ 2 .* moderators[2,:,:] .+ reactor_cells[1,:,:] .- 15 .<= 64*left_boosted_reactor[4,:,:])
@constraint(model,8 .* reactor_cells[4,:,:] .+ 7 .* reactor_cells[3,:,:] .+ 4 .* moderators[3,:,:]
.+ 3 .* reactor_cells[2,:,:] .+ 2 .* moderators[2,:,:] .+ reactor_cells[1,:,:] .- 15 .+ 1 .>= left_boosted_reactor[4,:,:])
end
if reactor_width >= 3
@constraint(model,4 .* reactor_cells[3,:,:] .+ 3 .* reactor_cells[2,:,:] .+ 2 .* moderators[2,:,:] .+ reactor_cells[1,:,:] .- 7 .<= 64*left_boosted_reactor[3,:,:])
@constraint(model,4 .* reactor_cells[3,:,:] .+ 3 .* reactor_cells[2,:,:] .+ 2 .* moderators[2,:,:] .+ reactor_cells[1,:,:] .- 7 .+ 1 .>= left_boosted_reactor[3,:,:])
end
if reactor_width >= 2
@constraint(model,2 .*reactor_cells[2,:,:] .+ reactor_cells[1,:,:] .- 3 .<= 64*left_boosted_reactor[2,:,:])
@constraint(model,2 .*reactor_cells[2,:,:] .+ reactor_cells[1,:,:] .- 3 .+ 1 .>= left_boosted_reactor[2,:,:])
end
=#
println(model)
#optimize!(model)
end
nuclearcraftoptimize(200,80,5,5,5)