Search code examples
pythonoptimizationconstraintsoperationgekko

GEKKO - Indicator Variable for Columns of Variables as Constraints of Problem


Assume "I" is as follow: (indicator)

Columns represent charger 1 and charger 2.

Rows represent EV1, EV2, EV3.

The time stamp is equal to 6.

Each EV can be charged with only one charger. For instance for EV 1: at time 0, I = [0,1] and at time 1, I = [1,0], which is not a valid case. I want to implement it while the number of chargers is greater than 2.

What kind of constraints can satisfy this requirement?

I= [[[0.0], [1.0]],
    [[0.0], [1.0]],
    [[0.0], [1.0]]],

   [[[1.0], [0.0]],
    [[1.0], [0.0]],
    [[1.0], [0.0]]],

   [[[0.0], [0.0]],
    [[0.0], [0.0]],
    [[0.0], [0.0]]],

   [[[0.0], [0.0]],
    [[0.0], [0.0]],
    [[0.0], [0.0]]],

   [[[0.0], [0.0]],
    [[0.0], [0.0]],
    [[0.0], [0.0]]],

   [[[0.0], [0.0]],
    [[0.0], [0.0]],
    [[0.0], [0.0]]]], dtype=object)

Solution

  • A typical method for this type of problem is to create a variable array for the use of the charger such as I = m.Array(m.Var,(3,6),integer=True,lb=0,ub=1) for 3 EVs and 6 time periods. If there is only one charger then a constraint can be created with an equation for every time period such as:

    for i in range(6):
       m.Equation(m.sum(I[:,i])==1)
    

    The indicator variable I can only be one (charging) for one of the vehicles. There is additional information on how to form scheduling optimization problems with integer programming.