Firstly, I have a basic understanding of linear programming and may not know the correct terminology. I think what I need is a breadth-first solver.
I have two tables of probabilities, which I would like to to use as constraints. My objective function is for all of the parameters to add up to 1.
Using R and lpSolveApi, I find that only some of the parameters I wish to optimise are given any values. I have also tried adding a constraint to say that every parameter should be > 2 or some other value
, but this seems wrong.
A minimal example of my code is:
objective_coefficients = c(1,1,1,1,1,1,1,1,1,1,1,1,1) #One for each parameter
lp_model = make.lp(0,13)
lp.control(lp_model, sense="max")
set.objfn(lp_model, objective_coefficients)
#Constraints for probability table 1
add.constraint(lp_model, c(1,0,1,1,1,0,0,0,0,0,0,0,0), "<=", 0.4)
add.constraint(lp_model, c(0,0,0,0,0,0,0,0,0,1,0,0,0), "<=", 0.1)
add.constraint(lp_model, c(0,1,0,0,0,0,0,0,0,0,0,0,0), "<=", 0.2)
add.constraint(lp_model, c(0,0,0,0,0,0,0,0,1,0,0,0,1), "<=", 0.1)
add.constraint(lp_model, c(0,0,0,0,0,1,1,1,0,0,1,1,0), "<=", 0.2)
#Constraints for probability table 2
add.constraint(lp_model, c(1,1,0,0,0,0,0,0,0,0,0,0,0), "<=", 0.2)
add.constraint(lp_model, c(0,0,1,1,1,1,0,0,0,0,0,0,0), "<=", 0.35)
add.constraint(lp_model, c(0,0,0,0,0,0,1,1,0,0,0,0,0), "<=", 0.25)
add.constraint(lp_model, c(0,0,0,0,0,0,0,0,1,1,1,1,0), "<=", 0.17)
add.constraint(lp_model, c(0,0,0,0,0,0,0,0,0,0,0,0,1), "<=", 0.03)
The result is that some parameters have large values attached, and others none at all:
0.05 0.15 0.35 0.00 0.00 0.00 0.20 0.00 0.07 0.10 0.00 0.00 0.03
If I set a minimum for all parameters, I can see it's feasible to have all of them > 0.02.
I have tried:
lp.control(lp_model, basis.crash="mostfeasible", sense="max")
lp.control(lp_model, basis.crash="leastdegenerate", sense="max")
lp.control(lp_model, bb.rule=c("first", "breadthfirst"), sense="max")
lp.control(lp_model, bb.rule=c("gap", "breadthfirst"), sense="max")
These all give the same result.
I think what's happening is the solver is using depthfirst, but I want it to solve breadthfirst, and I can't understand how to do this.