Unable to optimize using a trained neural network as a surrogate model
AnsweredHello Gurobi Community,
I am solving a single-source facility location problem with stochastic demands. There are two tasks: 1. selecting facilities to operate to fulfill customers' demands, from a list of facilities with varying capacities and operational costs 2. assigning customers with stochastic demands, to the selected facilities. Locations of the facilities and customers are given. The objective is to minimize the expected overall cost (operational cost + travel cost by distance).
The problem can be efficiently solved by using a set of scenarios sampled from the stochastic demands. In each scenario, the demand values are fixed, allowing optimization through direct constraints, such as the total demands assigned to a facility cannot exceed its capacity and each customer is assigned to one facility only. Since the computing time increases exponentially when more scenarios are included, we tried Gurobi Machine Learning using Surrogate Models.
In the two tasks of the problem, only the second is influenced by the increasing number of scenarios. A neural network is trained as a surrogate model for Task two: Given a list of facilities to operate as input, the network predicts the expected travel cost (calculated on a sufficiently large set of scenarios) for the optimal assignment. This trained network is then applied to the original problem, which determines the optimal solution for which facilities to operate (task one).
The test instances have approximately 20 operable facilities and 50 customers. The network predicts well, with R2 score about 0.8 and average predicting error around 3-5%. However, optimization for the surrogate model fails.
Results indicate "Optimal solution found (tolerance 1.00e-01)" with an objective function value that is far from expectation and no facility is included in the solution. It is technically impossible since no demands are met, making it impossible to be optimal.
For debugging, I manually introduce additional constraints that force specific facilities to open, it resolves the issue. As a matter of fact, even adding a single constraint, such as requiring facility 1 to be open, a reasonably good solution can be found by the model. But it doesn't explain why the model fails without such an artificial constraint.
I also tried to reduce the size of the neural network while maintaining precision to minimize the number of constraints generated by the predictor. Sometimes the following warnings appear but the issue remains the same:
"Optimal solution found (tolerance 1.00e-01)
Warning: max constraint violation (6.0338e-06) exceeds tolerance
Warning: max general constraint violation (6.0338e-06) exceeds tolerance"
For other settings, I took directly from the official example for Surrogate Models:
model.Params.MIPGap = 0.1
model.Params.NonConvex = 2
Thank you for your time. I would greatly appreciate any suggestions.
-
Hi!
Interesting problem. If you don't have too many scenarios, you could consider testing multi-scenario feature in Gurobi. Regarding the surrogate model approach - if I understand correctly, the surrogate model only predicts travel time given a set of facilities to open; it assumes that all demand is fulfilled? What constraints in the remaining MIP ensure that demand is fulfilled?
Kind regards,
Ronald0 -
Hi Ronald,
Thank you for the suggestions.
The surrogate model predicts the evaluation value of a given set of facilities based on travel costs with added penalties to account for unfulfilled demands. It aims to predict solution quality across various scenarios. The training dataset is generated by solving the assignment problem for the open facilities.
You are right that then there is no constraints on fulfilling the demands in the remaining MIP, it should be the cause of the issue. As the constraints on demands depend entirely on the surrogate model, insufficient data on rare solutions with few or no open facilities in the training set could be another contributing factor.
Thank you once more for making it clear. I'll tackle the issue by addressing these two aspects.
Best regards,
Xiaochen0
Please sign in to leave a comment.
Comments
2 comments