Navigation Menu
Search code, repositories, users, issues, pull requests..., provide feedback.
We read every piece of feedback, and take your input very seriously.
Saved searches
Use saved searches to filter your results more quickly.
To see all available qualifiers, see our documentation .
- Notifications You must be signed in to change notification settings
Solved the Job Assignment Problem using a branch and bound algorithm
Valor-boop/Job-Assignment-Problem
Folders and files, repository files navigation, job-assignment-problem.
Solved the Job Assignment Problem using both brute force as well as branch and bound. The code contains 5 functions:
job_assignment(cost_matrix): Find an optimal solution to the job assignment problem using branch and bound. Input: an nxn matrix where a row represents a person and a column represents the cost each person takes to complete the jobs. Return: the minimal cost, an optimal solution, and the number of partial or full solutions evaluated.
get_csf(cost_matrix, partial_solution): Input: an nxn cost matrix and a partial solution. Return: the partial solution's Cost So Far (CSF). A partial solution is represented as a list of n elements, where an undecided element is denoted by a -1. For instance, a partial solution [2, -1, -1] represents assigning job 2 to person 0 and leaving the assignments of person 1 and person 2 undecided.
get_gfc(cost_matrix, partial_solution): Input: an nxn cost matrix and a partial solution. Return: the partial solution's Guaranteed Future Cost (GFC).
get_ffc(cost_matrix, partial_solution): Input: an nxn cost matrix and a partial solution. Return: the partial solution's Feasible Futre Cost (FFC)
brute_force(cost_matrix): This function finds an optimal solution for the job assignment problem using brute force. Input: an nxn cost matrix. Return: the minimal total cost, an optimal solution, and the number of full solutions investigated.
- Python 100.0%
- Data Science
- Trending Now
- Data Structures
- System Design
- Foundational Courses
- Practice Problem
- Machine Learning
- Data Science Using Python
- Web Development
- Web Browser
- Design Patterns
- Software Development
- Product Management
- Programming
Job assignment Problem | DSA Problem
Delve into the complexities of the job assignment problem and master an effective solution using the branch and bound technique with our detailed programming tutorial. This guide is essential for operations researchers, algorithm designers, and computer science students who are keen to understand and implement optimization algorithms in real-world scenarios.
In this tutorial, you'll learn:
- The fundamentals of the job assignment problem and its significance in operations research and resource management.
- An introduction to the branch and bound algorithm as a powerful tool for solving optimization problems by systematically enumerating candidate solutions.
- Step-by-step coding demonstrations that explain how to apply branch and bound to the job assignment problem, ensuring you grasp the methodology and can implement it effectively.
- Practical examples that illustrate the process and show the algorithm in action, helping you see the optimization in real-time.
- Optimization strategies and best practices to enhance the efficiency of your solutions, crucial for handling complex scenarios in professional environments.
By the end of this video, you’ll have a robust understanding of using branch and bound to solve optimization problems, equipping you with skills that are highly valued in industries like logistics, software development, and systems engineering.
For a deeper dive into this topic, including detailed code snippets and a more thorough discussion on branch and bound techniques, please visit our full article: https://www.geeksforgeeks.org/job-assignment-problem-using-branch-and-bound/
A Basic Branch and Bound Solver in Python using Cvxpy
Jun 13, 2019 • philzook58
Branch and bound is a useful problem solving technique. The idea is, if you have a minimization problem you want to solve, maybe there is a way to relax the constraints to an easier problem. If so, the solution of the easier problem is a lower bound on the possible solution of the hard problem. If the solution of the easier problem just so happens to also obey the more constrained hard problem, then it must also be the solution to the hard problem. You can also use the lower bound coming from a relaxed problem to prune your search tree for the hard problem. If even the relaxed problem doesn’t beat the current best found, don’t bother going down that branch.
A standard place this paradigm occurs is in mixed integer programming. The relaxation of a binary constraint (either 0 or 1) can be all the values in between (any number between 0 and 1). If this relaxed problem can be expressed in a form amenable to a solver like a linear programming solver, you can use that to power the branch and bound search, also using returned solutions for possible heuristics.
I built a basic version of this that uses cvxpy as the relaxed problem solver. Cvxpy already has much much faster mixed integer solvers baked in (which is useful to make sure mine is returning correct results), but it was an interesting exercise. The real reason I’m toying around is I kind of want the ability to add custom branching heuristics or inspect and maintain the branch and bound search tree, which you’d need to get into the more complicated guts of the solvers bound to cvxpy to get at. Julia might be a better choice.
A somewhat similar (and better) project is https://github.com/oxfordcontrol/miosqp which doesn’t use cvxpy explicitly, but does have the branch and bound control in the python layer of the solver. There are also other projects that can use fairly arbitrary solvers like Bonmin
As a toy problem I’m using a knapsack problem where we have objects of different sizes and different values. We want to maximize the value while keeping the total size under the capacity of the bag. This can be phrased linearly like so: $ \max v \cdot x$ s.t. $ \sum_i s_i x_i<= capacity $, $ x \in {0,1}$. The basic heuristic I’m using is to branch on variables that are either 0 or 1 in even the relaxed solution. The alternative branch hopefully gets pruned fast.
This is at least solving the problem fairly quickly. It needs better heuristics and to be sped up, which is possible in lots of ways. I was not trying to avoid all performance optimizations. It takes maybe 5 seconds, whereas the cvxpy solver is almost instantaneous.
Edit : I should investigate the Parameter functionality of cvxpy. That would make a make faster version than the one above based on deepcopy. If you made the upper and lower vectors on the binary variables parameters, you could restrict the interval to 0/1 without rebuilding the problem or copying everything.
IMAGES
VIDEO