from APMonitor.apm import * # pip install APMonitor import numpy as np A = np.random.random((3,4)) n = np.size(A,0) # rows m = np.size(A,1) # columns # write model.apm fid = open('model.apm','w') fid.write('Constants \n') fid.write(' n ='+str(n)+' \n') fid.write(' m ='+str(m)+' \n') fid.write(' \n') fid.write('Parameters \n') fid.write(' p[1:n][1::m] \n') fid.write(' \n') fid.write('Variables \n') fid.write(' x \n') fid.write('Equations \n') fid.write(' x=p[1][1] \n') fid.close() # write data.csv fid = open('data.csv','w') for i in range(n): for j in range(m): fid.write(' p['+str(i+1)+']['+str(j+1)+'], '+str(A[i,j])+' \n') fid.close() # load model, data file, and solve s = 'https://byu.apmonitor.com' a = 'matrix_write' apm(s,a,'clear all') apm_load(s,a,'model.apm') csv_load(s,a,'data.csv') apm(s,a,'solve') # retrieve solution apm_web_var(s,a)