I am using cplex cpo model for optimisation problem in python. I am beginner and I am learning. I am facing an issue which is given below.
I have the following binary decision variables:
model.binary_var(name='gamma1')
model.binary_var(name='gamma2')
model.binary_var(name='gamma3')
model.binary_var(name='gamma4')`
I have another variable defined as:
d =
5gamma1 + 13gamma2 + 17gamma3 + 45gamma4 / sum(gamma1 +gamma2+gamma3)`
objective function = minmization problem depending on decision and many other values
When I solve the optmization problem, I can get the values of gamma by following
model.add(model.minimize(objectiveFunction))
solution = model.solve( )
all_variables = model.get_all_variables()
# Iterate over all variables
print("All Variables:")
for var in all_variables:
print(var.get_name(), "-", var.get_type(), "Variable", solution.get_value(var), "solution"
But I am unable to get value of "d ". Is there a way I can get this value from model? (not to recalculate like getting optimized gamma value and calling a function to calculate d)
I've tried
solution.get_var_solution(d)
solution.get_value(d)
You can use kpi for that.
See example at https://github.com/AlexFleischerParis/zoodocplex/blob/master/zookpicpo.py