How to calculate normal distribution CDF where the mean and variance is linear combination of decision variables?
AnsweredHi,
I wanted to express a constraint where the reward is calculated as a normal distribution CDF, and the upper bound, mean, and variance are linear expressions of some decision variables.
 1) PDF = normal distribution's probability density function
 2) CDF = the integration of the defined PDF, the lower bound is inf, the upper bound, mean, and variance are linear expressions of decision vars.
Please see the following code:
def PDF (x, mu, sigma):
return 1/(sigma * (2.0 * math.pi)**(1/2))* math.exp(1/2*((xmu)/sigma)**2)
def CDF(ub, mu, sigma):
lb =  math.inf
value = integrate.quad(PDF, lb, ub, args=(mu, sigma))
return value
when I try to implement
CDF(0.95*R_ML0[0], P[0,0]*(y2_ML0[0]+(1alpha)*y1_ML0[0]), 100),
where R_ML[0], y2_ML0[0], y1_ML0[0] are decision vars, it gave me:
gurobipy.LinExpr.__richcmp__
NotImplementedError
Really appreciate if anyone can help me!!!
Best,
Ye

Hi Ye,
Gurobi variables cannot be directly used in arbitrary math functions, you have to use general constraints to deal with nonlinear/nonquadratic terms. You might need to reformulate your function and/or introduce helper variables to be able to use the general constraints.
Note that complex function constraints are approximated by piecewise linear functions.Best regards,
Mario0 
Thanks Mario for you reply!
Did you know by any chance the approximation of normal distribution? I have been looking it up and found all of them involve division. Since Gurobi cannot divide decision variables, I guess there is no way to formulate the model..
Also, did you know if Gurobi can control the number of violated constraints? For example, I have 100 constraints, I want to optimize as long as any 99 of the constraints are satisfied.
Thanks,
Ye
0 
Hi Ye,
Sorry, I am not too much into the theory of normal distributions.
Regarding modeling divisions: Sometimes, the divisions can be reformulated such that they can be handled in Gurobi. For example, by introducing an artificial variable z and an according equation: a / b = z. This can be reformulated to a = z * b.
What you could do is to use the feasibility relaxation, but it is not obvious how to control the number of violated constraints with this. Alternatively, you can model this manually, e.g., by introducing a slack variable for each of the constraints modeling the amount of violation. Then, you create an SOS1 constraint with those slack variables, stating that at most 1 of those variables is allowed to be nonzero.
Best regards,
Mario0
Please sign in to leave a comment.
Comments
3 comments