Hello Tim,
I hope you are doing well.
What do you mean by matrix?
If you are going to import some input data, you can directly use the pandas library through Pyomo. For example, the first code below imports the data for the generating units' parameters. If you are importing the matrix, say,
A=[1 2 3;4 5 6;7 8 9], you can use numpy library as the second example, as well.
#----------------------------------------First Example---------------------------------------------------
# Load the Excel file into a pandas DataFrame --> Generators' Input Data
excel_file = 'your_excel_file.xlsx' # Replace with the path to your Excel file
df = pd.read_excel(excel_file, sheet_name='your_sheet_name', index_col=0)
# Strip any extra spaces from the index
df.index = df.index.str.strip()
# Extract parameters from the DataFrame
data = {
'A' : df['A'].to_dict(),
'B' : df['B'].to_dict(),
'C' : df['C'].to_dict(),
'costSD' : df['costSD'].to_dict(),
'costST' : df['costST'].to_dict(),
'RU' : df['RU'].to_dict(),
'RD' : df['RD'].to_dict(),
'UT' : df['UT'].to_dict(),
'DT' : df['DT'].to_dict(),
'Pmin' : df['Pmin'].to_dict(),
'Pmax' : df['Pmax'].to_dict(),
'Uini' : df['Uini'].to_dict(),
'FP' : df['FP'].to_dict()
}
mp.A = Param(mp.I, initialize=data['A'])
mp.B = Param(mp.I, initialize=data['B'])
mp.C = Param(mp.I, initialize=data['C'])
mp.costSD = Param(mp.I, initialize=data['costSD'])
mp.costST = Param(mp.I, initialize=data['costST'])
mp.RU = Param(mp.I, initialize=data['RU'])
mp.RD = Param(mp.I, initialize=data['RD'])
mp.UT = Param(mp.I, initialize=data['UT'])
mp.DT = Param(mp.I, initialize=data['DT'])
mp.Pmin = Param(mp.I, initialize=data['Pmin'])
mp.Pmax = Param(mp.I, initialize=data['Pmax'])
mp.Uini = Param(mp.I, initialize=data['Uini'])
mp.FP = Param(mp.I, initialize=data['FP'])
#---------------------------------Second Example --------------------------------------------
import numpy as np
from pyomo.environ import *
# Your matrix
A = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
model = ConcreteModel()
# Define index sets for rows and columns
model.I = RangeSet(A.shape[0])
model.J = RangeSet(A.shape[1])
# Import matrix into a Pyomo Param
model.A = Param(model.I, model.J, initialize=lambda model, i, j: A[i-1, j-1])
model.A.pprint()