Set up linear programming optimization in R using LpSolve?
问题 I have this optimization problem where I am trying to maximize column z based on a unique value from column X, but also within a constraint that each of the unique values picked of X added up column of Y most be less than (in this example) 23. For example, I have this sample data: d=data.frame(x=c(1,1,1,2,2,2,3,3,3),y=c(9,7,5,9,7,5,9,7,5),z=c(25,20,5,20,10,5,10,5,3)) Which looks like this: X Y Z 1 1 9 25 2 1 7 20 3 1 5 5 4 2 9 20 5 2 7 10 6 2 5 5 7 3 9 10 8 3 7 5 9 3 5 5 The result should