import numpy as np import matplotlib.pyplot as plt from APMonitor.apm import * s = 'https://byu.apmonitor.com' a = 'cspline' model = ''' Objects c = cspline End Objects File c.csv x_data , y_data -1.0000000e+00 , 3.8461538e-02 -8.0000000e-01 , 5.8823529e-02 -5.0000000e-01 , 1.3793103e-01 -2.5000000e-01 , 3.9024390e-01 0.0000000e+00 , 1.0000000e+00 1.0000000e-01 , 8.0000000e-01 2.0000000e-01 , 5.0000000e-01 5.0000000e-01 , 1.3793103e-01 End File Connections x = c.x_data y = c.y_data End Connections Parameters End Parameters Variables x = -0.5 >= -1 <= 0.5 y End Variables Equations maximize y End Equations ''' # write file fid = open('model.apm','w') fid.write(model) fid.close() # clear prior, load new model apm(s,a,'clear all') apm_load(s,a,'model.apm') # set steady state optimiation and solve apm_option(s,a,'apm.imode',3) output = apm(s,a,'solve') print(output) # retrieve solution z = apm_sol(s,a) # print solution print('x: ' + str(z['x'])) print('y: ' + str(z['y']))