library(lpSolve) f.obj <- c(1,1,0,0,0,0,0,0,0) # x12 x13 x24 x25 x34 x36 x47 x57 x67 f.con <- matrix(c(-1,0,1,1,0,0,0,0,0, 0,-1,0,0,1,1,0,0,0, 0,0,-1,0,-1,0,1,0,0, 0,0,0,-1,0,0,0,1,0, 0,0,0,0,0,-1,0,0,1, 1,0,0,0,0,0,0,0,0, 0,1,0,0,0,0,0,0,0, 0,0,1,0,0,0,0,0,0, 0,0,0,1,0,0,0,0,0, 0,0,0,0,1,0,0,0,0, 0,0,0,0,0,1,0,0,0, 0,0,0,0,0,0,1,0,0, 0,0,0,0,0,0,0,1,0, 0,0,0,0,0,0,0,0,1), ncol=9, byrow=T) f.rhs <- c(0,0,0,0,0, 3,5,2,2,3,3,2,3,4) f.dir <- c("=", "=", "=", "=","=", "<=", "<=", "<=", "<=", "<=", "<=", "<=", "<=", "<=") res <- lp("max", f.obj, f.con, f.dir, f.rhs)