Incorporating machine learning model results as a variable in optimization model
AnsweredHello, I have a problem at hand. I want to incorporate a machine learning model result as the variable value n the model.
Suppose
Vp is a continuous variable. I want to change a few variable values that are in the model and based on the value changes I want to predict the value of Vp by a prediction model and assign the value to the variable.
Ex. Say Rl, RH = denote the residential percentage of low and highrise building.
Vp denotes vulnerability which is a dependent of Rl and Rh values. As the Rl and RH value changes, I predict Vp.
Now I have to Minimize a cost where,
Vp< a value
Rh+Rl < a value
How to develop this in gurobi python
Regards,
Vaibhav
-
Hi Vaibhav
If you have a linear model, then is easy, you just need to get the linear regression coefficients into the model i.e.
Vp=L(x1,...xn) which for linear models will be just a vector, i.e. Vp = a * x
If you have a function of one variable, then you can use a piece-wise linear approximation of any function. The scheme can be generalized even for two variables, but more (although possible) dimensions starts to get harder. There is a nice paper on how to do it in general from http://www.optimization-online.org/DB_FILE/2008/09/2104.pdf
Best,
Daniel0 -
Hi Daniel,
Thank you for the document and your comment. I am new to the field of computer optimization and algorithms. So it will take some time for me to understand the paper. I will try to search and learn what it details. I want t know how to code down the variable:
I guess below is the syntax to define a variable.
Vp = m.addVar(vtype=GRB.CONTINUOUS, name="Vp")
How do I incorporate :Vp=a1X1+a2X2+Const
Has it to be defined like this:
Vp = m.addVar(a1X1+a2X2+Const, vtype=GRB.CONTINUOUS, name="Vp").Also, I have a query related to the solver. Is there any way to find out the list of values for a variable that solver used during optimization. Ex. Suppose R is a continuous variable and I want to know what were the values solver took during optimization. My purpose of asking this is because in my problem:
I have a square area grids. each grid has a vulnerability value associated with and the details of residential commercial etc (built up percentage) area. I want to combine a prediction model and the optimisation model to yield optimal results. My Model has variables: R: residential area, C: commercial area, I: Industrial area. These variables are continuous. I have a trained model on a set of data where I predict Vulnerability(Vp) as a function of (R,C,I). Now, My model is trained I can predict the vulnerability by changing R, C, and I values. I want to optimize the vulerability value by changing the composition of R, C,I.
So the objective: Minimise (Vulne predicted (Vp))
constraints 1: R+C+I < a threshold value (comth)
Constraint 2: Vp <= 0.80 * existing vulnerability (Vc)
1. How do I model this problem?
2. When the solver will start selecting values for R, C,I as they are continuous how to extract these values and apply the prediction model to calculated Vp variable. This is one of the main issues that I am not able to solve.
Thanks,
Vaibhav0 -
Hi Vaibhav,
If you are new to optimization, then I strongly suggest to look at our online examples:
https://www.gurobi.com/documentation/8.1/examples/example_tour.html
0 -
Hi Daniel,
Thanks for the document. I have read it. I was unable to figure out how to initialize a variable value. Consider X is a variable whose lower bound (lb) can be 0 (Means it can take min values to zero: This is what I understood from the document) and upper bound (ub) can be 100. I want to initialize the variable to 50 during the start of the execution. Can you help me with this?
Regards,
Vaibhav
0 -
Adding to the previous comment. My problem is LP. I used
PStart
attribute but it didn't work.Regards,
Vaibhav
0 -
Hi Vaibhav,
bound on variables describe where the algorithm could set them while looking for an optimal solution, i.e. you are describing the complete set of possible feasible values, and letting the algorithm find the best value for each variable within that set.... so, no, you should not set a fixed value for a variable (unless, that is its only valid value).
Now, you can share guesses, feasible solutions, and partial feasible solutions using mip-starts and hints, and for LP's, you can set a PStart/DStart... but they should describe a completely feasible basic point, otherwise, it will not be used
Best,
Daniel0 -
Dear Daniel,
Thanks for the reply
I don't want to fix the variable value. The variable I am defining has the property that its value can go to zero or till a max number. However, the optimization must start from the current value and then it can choose to go till lower or any other value based on objective and constraints.
The actual scenario is: My Variables (RL,Cl) are residential and commercial percentage buildings in an area. My fire vulnerability has linear relationship (vul=a1 RL+a2Cl). I want to design an optimal concentration of RL and Cl which can provide a less vulnerable area. So I want to start the optimization from the existing values. Now, what I think at an optimal state some of the RL might convert to Cl or vice-versa can be possible. That's why I want to initialize the variable values and as I can specify lower and upper bound I can decide what can be min and max concentration of variable values.
Regards,
Vaibhav
0 -
Hi Vaibhav
I think there is a misunderstanding on what does on behind the scenes when Gurobi solves a problem. Gurobi does not do a local search to find better solutions, it relies on a global point view, and uses one of three algorithms (for purely continuous problems): Primal Simplex, Dual Simplex, and Barrier or interior point. The first two might see a benefit when providing a "close to optimal starting basis", whereas for Barrier, the knowledge of some (close to) feasible solution can not be incorporated into the algorithm. So, a starting point __might__ be helpful for simplex, but not any point will be helpful nor used (it has to has a certain structure).
Now, it might be that you are describing a different use case: namely, you do have a running system, and some (feasible) solution being used, and now with your model, you want to find a better operating point (new solution), but you may also want it to be "close" to the current solution. This is called a multi-objective optimization problem, and Gurobi does support it... there is a whole section describing how to do it, and different ways in which to model multi-objective problems.
Hope this helps,
Daniel0 -
Hi Vaibhav,
Did you find a way to do this in Gurobi? I am really really interested to learn how we can incorporate machine learning prediction into the Gurobi model. Please let me know if you find a way. I appreciate it.
0
Please sign in to leave a comment.
Comments
9 comments