0

Here is the objective I would like to maximize in R:

AX1+BX2+CX3+DX4

The following constraints exists

0 >= S2 >= 8

0 >= S3 >= 8

0 >= S4 >= 8

0 >= S5 >= 8

Where

S2 = X1 + V

S3 = X2 + X1 + V

S4 = X3 + X2 + X1 + V

S5 = X4 + X3 + X2 + X1 + V

Basically, the constraints reference the objective.

As an example, if V = 4, X1 = 2, then S2 = 6. (therefore the constraint, 0 >= S2 >= is not violated.

How do I reference the objective (I used L_Objective function) in the constraint function?

Thanks in Advance

Florian
  • 597
  • 3
  • 9
Doptima
  • 171
  • 1
  • 1
  • 10
  • 1
    How do the constraints reference the objective function? Also what is V? – Noah Dec 11 '18 at 02:08
  • Hi Noah, I made some edits and added some examples. Does that help? – Doptima Dec 11 '18 at 02:35
  • I still don't see how this differs from a regular optimization problem. Just replace the Ss with the values you set for them and this is totally standard linear programming optimization problem with linear inequality constraints. – Noah Dec 11 '18 at 02:52
  • Thanks for the answer, I'll try it and follow up. My apologies for the confusion. There is a constraint for X4 and I added it. I tried to simplify the premise to focus on my exact problem but I think it might have left out key details. To give context, I am trying to optimize the charging and discharge of a battery over 24 hours. There is a limit to the amount of charge the battery can hold, so it can't discharge once it reaches its minimum stored charge and can't charge once it reaches its maximum charge. – Doptima Dec 11 '18 at 16:37
  • 1
    Only the last constraint (S5) matters. The others are automatically satisfied if S5 is satisfied. – Noah Dec 12 '18 at 05:58
  • But what is V? Nowhere have you defined V. Is it the objective function `V = AX1+BX2+CX3+DX4`, or is it some other scalar constraint? – smci Dec 13 '18 at 07:44

1 Answers1

0

Does the following not work?

library(ROI)

obj <- L_objective(c(A, B, C, D)

const.mat <- matrix(c(1, 0, 0, 0,
                      1, 1, 0, 0,
                      1, 1, 1, 0,
                      1, 1, 1, 1),
                    nrow = 4)
const <- L_constraint(rbind(const.mat, constmat),
                      dir = c(rep(">=", 4), rep("<=", 4)),
                      rhs = c(rep(0-V, 4),    rep(8-V, 4)))
op <- op(obj, const, maximum = TRUE)
out <- ROI_solve(op)

Of course, filling in the correct values for A, B, C, D, and V, which I assume you have. If the last constraint is satisfied, the others will be automatically, so it's the only one that matters.

smci
  • 32,567
  • 20
  • 113
  • 146
Noah
  • 3,437
  • 1
  • 11
  • 27