pythongekko

Is there any way to make GEKKO create a csv file that's more readable?


The results.csv file is hard to read since the variables, intermediates etc. are shown in a format like "i1000" which probably means "intermediate number 1000". Is there any way to make the results show the proper symbols/characters that I used in the variable declaration?

I've used the m.Array function to declare variables, I'm not sure if I can assign names to them with indexes such as Temperature[1,2,3]


Solution

  • Use a list comprehension to define custom names for an array of variables. Here is an example:

    from gekko import GEKKO
    
    m = GEKKO(remote=False)
    
    # Create an array of variables
    #t = m.Array(m.Var,3,lb=-1000,ub=1000)
    t = [m.Var(lb=-1000,ub=1000,name=f'T{i+1}') for i in range(3)]
    
    # Create intermediate variables
    i1 = m.Intermediate(t[0] + 10, name='T4')
    i2 = m.Intermediate(t[2] / 100, name='T5')
    
    # Example equations
    m.Equation(t[0]+t[1]==10)
    m.Equation(t[1]+2*t[2]==50)
    m.Equation(t[0]-6*t[2]==10)
    
    m.solve()
    
    m.open_folder()
    

    The results.csv file is now more readable with:

    t4,  -5.5000000000E+01
    t5,  -1.2500000000E-01
    t1,  -6.5000000000E+01
    t2,   7.5000000000E+01
    t3,  -1.2500000000E+01
    

    APMonitor solution engine converts all variable names to lowercase. One other suggestion is to avoid starting names with reserved function names such as abs, sin, cos, and tan.