Help translate mathematic model / optimization to Python
AnsweredI am looking to translate the following mathematic model to Python, this is a model that takes in subjobs (each one has a start and end time tracked as integer that is the minute in the day, and the days it runs Boolean by day of week) also takes in a machines (the machine numbers and the subjob assigned to each machine). The goal of the optimization is to increase utilization of machines and minimize number of machines in this resource allocation problem. The mathematic problem posted in the photo:
-
Hi Nizar,
Check out our Jupyter Notebook Modeling Example for an Intro to Mathematical Optimization Modeling.
This will provide a good foundation for converting your mathematical formulation into python code using gurobipy.
For handling overlaps note that for two jobs, k and p, they do not overlap if either start(p) >= end(k) or if start(k) >= end(p) - you should draw diagrams if it helps convince you. Therefore (using De Morgan's Laws) they overlap if start(p) < end(k) and start(k) < end(p). You can apply this condition to each pair of jobs before even starting to construct your model to create a list of incompatible pairs, or you could create a function which takes two jobs and returns whether they overlap and use that while constructing your model. While it is not wrong to have both \(x_{k,m} + x_{p,m} \leq 1\) and \(x_{p,m} + x_{k,m} \leq 1\) it would not be helpful either, so make sure what when you calculating incompatible jobs you only consider unique pairs.- Riley
0
Please sign in to leave a comment.
Comments
1 comment