import pandas as pd
import numpy as np
import re
import cvxpy as cvx
data = pd.read_excel('Optimality_V3.xlsx', encoding='latin-1')
As u can see I just imported a csv file as a dataframe. Now I want to solve a maximixation function using the CVXPY library to identify the optimal values of row data['D'] such that the sum of values of data['B'] is maximum.
My objective function is quadratic as my decision variable data['D'] and the function is something like this:
data['B'] = data['C'] * data['D']**2 / data['E'].
The constraints I want to assign to every row of data['D']:
data['D'] * 0.8 <= data['D'] <= data['D'] * 1.2
decision_variables = []
variable_constraints = []
for rownum, row in data.iterrows():
var_ind = str('x' + str(rownum))
var_ind = cvx.Variable()
con_ind = var_ind * 0.8 <= var_ind <= var_ind * 1.2
decision_variables.append(str(var_ind))
variable_constraints.append(str(con_ind))
The above code is my attempt at doing this. I am new to CVXPY and trying to figure out how I can create variables named var_ind with constraints con_ind.