I am trying to formulate and solve an optimization problem using IBM CPLEX framework using python API.
My objective function is as follows:
where and
are my integer variables. I define the variables as follows in my code:
function f is as follows:
def f(p,n):
if p==4 and n ==4:
return 0.8
elif p==4 and n ==8:
return 0.9
elif p==6. and n==4:
return 0.88
.
.
.
My problem:
The problem that I have is about calling function f and using the variable n in that function. Nore specifically, I can not compare this variable to a number suhc as 4 or 8 or I can not use this varibale as the index of a dictionary. The error I get is:
I tried to implement function f as bellow:
def f (p,n):
my_dictionary = {4:{4:0.8,8:0.9},6:{4:0.88,8:0.92}
return my_dictionary[p][n]
I get the error of "keyerror exception" meaning that there is no key as n in my dictionary.
How can I pass the value of my variable to a function and use that value there?