BYU-PRISM / GEKKO

GEKKO Python for Machine Learning and Dynamic Optimization
https://machinelearning.byu.edu
Other
573 stars 102 forks source link

Unexpected results using GEKKO MILP #119

Closed quynhtran29 closed 2 years ago

quynhtran29 commented 3 years ago

I'm working on a cost minimization problem. I tried many times but still get this error:

    Exception:  @error: Equation Definition
     Equation without an equality (=) or inequality (>,<)
     1((((5.84-v34)+((6)*(int_v2))))*(31.7))
     STOPPING...

Here is my code:

    import pandas as pd
    import numpy as np
    from gekko import GEKKO
    m = GEKKO() # Initialize gekko
    Sadd=pd.read_csv("Sadd.csv")
    X2= m.Array(m.Var,len(Sadd),value=0,lb=-1,ub=1,integer=True)
    SOC2= m.Array(m.Var,len(Sadd),value=100,lb=0,ub=100)
    m.Equation(SOC2[0]==100)
    for i in range(1,3):
         m.Equation(SOC2[i]-SOC2[i-1] == 5*X2[i-1])
    for i in range(3,11): 
            m.Equation(X2[i]==0)
            m.Equation(SOC2[i]==0)
    for i in range(12,16):
        m.Equation(SOC2[i]-SOC2[i-1] == 5*X2[i-1])
    m.Equation(SOC2[11]==SOC2[2]-55)
    TOU=Sadd['TOU']
    PV=m.Array(m.Var,len(Sadd),value=5)
    for i in range(0,len(Sadd)):
        m.Equation(PV[i]>= 0)
        m.Equation(PV[i]<= Sadd['PV'].iloc[i])
        m.Equation(Sadd['Load'].iloc[i]-PV[i]+6*X2[i]>=0)
    m.Obj((Sadd['Load']-PV+6*X2)*TOU) 
    m.options.SOLVER=1
    m.solve()

How can I fix it? Thanks

Here is my Sadd.csv in case you wanna check it. Thanks a lot.

        Date/Time       C2  SC2 SOC2PV  Load    TOU
    0   11/25/2020 6:00 0   0   0   0   5.82    31.7
    1   11/25/2020 6:15 0   0   0   0   5.84    31.7
    2   11/25/2020 6:30 0   55  0   0   7       31.7
    3   11/25/2020 6:45 1   0   0   0   7.16    31.7
    4   11/25/2020 7:00 1   0   0   0   8.41    31.7
    5   11/25/2020 7:15 1   0   0   0   10.95   31.7
    6   11/25/2020 7:30 1   0   0   1   11.79   31.7
    7   11/25/2020 7:45 1   0   0   2.75    14.77   31.7
    8   11/25/2020 8:00 1   0   0   4.35    12.24   31.7
    9   11/25/2020 8:15 1   0   0   5.975   17.58   31.7
    10  11/25/2020 8:30 1   0   0   7.65    16.79   31.7
    11  11/25/2020 8:45 0   0   0   8.625   19.04   31.7
    12  11/25/2020 9:00 0   0   0   8.8     20.66   31.7
    13  11/25/2020 9:15 0   0   0   9.575   18.57   11
    14  11/25/2020 9:30 0   0   0   10.5    19.66   11
    15  11/25/2020 9:45 0   0   0   10.625  19.76   11
APMonitor commented 2 years ago

Code and solution are posted to https://stackoverflow.com/questions/68232974/how-to-fix-error-equation-definition-gekko/68316597