Hi guys,

I am not totally new to optimization usage but I am struggeling with the usage within node.js and the GLPK.js implementation.

I do have a problem, where I basically want to introduce constraints, which allows only a set of variables in the subject or a constraint to be non-zero, while others then need to be zero. So either-or.

To be more specific, imagine the following subject:

x1 * 2 - x2 * 1 + x3 * 3 - x4 * 1.5 → maximize

constraints:

0 <= x1 - x2 <= 1000

0 <= x1 - x2 + x3 - x4 <= 1000

0 <= x1 <= 32000

0 <= x2 <= 32000

0 <= x3 <= 32000

0 <= x4 <= 32000

The physicallity behind this is a battery, which can either draw energy from the net or feed energy in. The two prices to draw energy are 1 and 1.5 and the variable for the power to be drawn are x2 and x4.

The infeed prices are 2 and 3 (so higher that the price to draw energy) and the corresponding variables are x1 and x3.

If nothing else is introduced, the optimizer with put all variables to maximum. But this is physically not possible at the same power-meter. Either can energy be drawn ot fed-in and only the net balance for each step shoud get honored with the price of the direction. So only one variable of each tuple x1,x2 and x3,x4 is allowed to be non-zero. Not x1,x2 or x3,x4 at the same time…

How can I achieve this?

I read something about “Sets” for CPLEX files, but is something similar possible with GLPK.js or node in combination with GLPK?

Hope you have a hint for me!

KR

SEB