0

i have three input matrices: profits: 5x4 matrix. column names plane types 1:4 and for route names rows routes 1:5, profit per route per plane type block hour per plane available: 1x4 matrix. column names plane types 1:4, available block hour per plane type is rows 1. this constraint is a maximum, sum of hours plane is used cannot be bigger than this block hour per route: 5x1 matrix. row names are routes 1:5 with one column. this is a binding constraint, the number of block hours flown for each route must be equal to this.

i want to optimise allocation of plane types to routes, maximising profit whilst keeping constraints in r

profits is what i want to maximise. i want to allocate plane types to routes, where block_hours_per_route is binding as a constraint and block_hours_available cannot be less than the sum of the plane being used in hours

I have an issue with the lp function:

# Input matrices
profits <- matrix(c(10, 15, 20, 25, 30,
                    12, 16, 18, 22, 28,
                    8, 12, 16, 20, 24,
                    9, 11, 13, 15, 19), ncol = 4, byrow = TRUE,
                  dimnames = list(paste0("Route", 1:5), paste0("Plane", 1:4)))

block_hours_available <- matrix(c(50, 40, 60, 45), nrow = 1, ncol = 4)
colnames(block_hours_available) <- paste0("Plane", 1:4)

block_hours_per_route <- matrix(c(20, 30, 25, 35, 15), nrow = 5, ncol = 1)
rownames(block_hours_per_route) <- paste0("Route", 1:5)

# Number of routes and planes
n_routes <- nrow(profits)
n_planes <- ncol(profits)

lprec <- lp(direction = "max",
            objective.in = as.vector(profits),
            const.mat = rbind(block_hours_available, profits),
            const.dir = c(rep("<=", n_planes), rep("==", n_routes)),
            const.rhs = c(block_hours_available, block_hours_per_route),
            all.bin = TRUE)


# Solve the LP problem
sol <- solve(lprec)

# Print the optimal solution
sol$solution

Problem is here:

lprec <- lp(direction = "max",
            objective.in = as.vector(profits),
            const.mat = rbind(block_hours_available, profits),
            const.dir = c(rep("<=", n_planes), rep("==", n_routes)),
            const.rhs = c(block_hours_available, block_hours_per_route),
            all.bin = TRUE)

jpsmith
  • 11,023
  • 5
  • 15
  • 36
Sarah
  • 1
  • 2
  • I'm unsure how to interpret your description of the optimization task. Is the expected solution the number of flights per plane and route? Aren't the _block_hours_per_route_ constant parameters which define _the number of block hours flown for each route_? If so, why should and how could one construct a constraint for this predetermined, invariable identity? – Armali May 05 '23 at 06:39
  • Now I saw you specified that all variables should be binary; I don't understand how this can model that a plane can fly a route multiple times - or is this disallowed? – Armali May 05 '23 at 08:23
  • Showing an expected output would help a lot. – Armali May 05 '23 at 09:05

0 Answers0