Net Mod 1: Linear Assignment and Transportation Problems

Packages Used: No new packages are used in this notebook.

Many problems can be modeled as networks, where the nodes of the network represent entities and the arcs represent either flows or relationships, for example. All of the network models that we will be covering can be solved as linear programs. In the past, modeling a problem as a network allowed network-specific procedures to be used that were more efficient than solving a general linear programming formulation of the problem, but now even large-scale linear programs can be solved efficiently, and the use of network-specific procedures are not necessary for many problems.

1. Linear Assignment Problem (LAP)

The linear assignment problem can be modeled as a complete bipartite network, which is a network consisting of two sets of nodes with all arcs from one set to the other. The first set of "supply" nodes represent an entity that can be assigned to one of the second set of "demand" nodes. Each arc represents the cost of making the assignment, and the problem is solved by determining the least-cost assignment. Although the Hungarian method is a specialized procedure for the LAP, modeling the LAP as a network flow problem and then solving it as an LP works is also effective and easier to implement.

Ex 1: Unter's Passenger-to-Car Assignment

An example of the linear assignment problem would be its use by a ride-hailing service to assign available cars to passengers wanting a ride. One way of doing the assignment is to make the assignment based on which car is closest to any of the passengers and then continue until all the assignments are complete. Unfortunately, this simple greedy procedure does not, in general, provide an optimal assignment; instead, an optimal assignment can be determined modeled as a network flow problem, where one unit of supply provided by a car can be used to satisfy one unit of demand required for each passenger, where the arc connecting each card to each passenger represents the cost (distance) of the car from the passenger.

image.png

This procedure can be made into a function to allow it to be easily reused:

What if the number of cars does not equal the number of passengers?

The LAP can be modeled as a network flow problem and then solving as an LP:

Linear Assignment Problem (LAP):

$ \begin{eqnarray*} \quad \mbox{Minimize} \quad \sum_{i \in Cars} \sum_{j \in Pass} c_{ij} x_{i,j} \\ \quad \mbox{subject to} \quad \sum_{j \in Pass} x_{ij} &\le& 1\mbox{,} &\quad i \in Cars\mbox{,}\quad\mbox{: each car is assigned up to one passenger}\\ \sum_{i \in Cars} x_{ij} &=& 1\mbox{,} &\quad j \in Pass\mbox{,}\quad\mbox{: each passenger is assigned a car}\\ x_i &\ge& 0 \mbox{,} \end{eqnarray*} $

Ex 2: Distance as Cost for Ex 1

Given the (x, y) coordinates of each car and passenger, determine the assignment based on minimizing the total Euclidean distance of the cars from their passengers.

Side Issue: Combining Vector Outputs into a Matrix

Using the splat operator ... to pass each element as a separate input to the vertical concatenation function vcat converts the vectors into a matrix:

Distance Matrix

What if the number of cars does not equal the number of passengers?

Ex 3: Ten Random Cars and Passengers

2. Transportation Problem

The transportation problem is a generalization of the linear assignment problem (LAP). As in the LAP, nodes are separated into supply and demand nodes with arcs representing the associated cost per unit of flow, connecting each supply node to all of the demand nodes. Unlike the LAP, in which each supply node can provide only one unit and each demand node can require only one unit, the transportation problem supply nodes can provide multiple units, and the demand nodes can require multiple units.

The transportation problem can be modeled as a network flow problem and then solving as an LP:

Transportation Problem:

$ \begin{eqnarray*} \quad \mbox{Minimize} \quad \sum_{i \in S} \sum_{j \in D} c_{i,j} x_{i,j} \\ \quad \mbox{subject to} \quad \sum_{j \in D} x_{i,j} &\le& s_i\mbox{,} &\quad i \in S\\ \sum_{i \in S} x_{i,j} &=& d_j\mbox{,} &\quad j \in D\\ x_i &\ge& 0 \mbox{,} \end{eqnarray*} $

Ex 4: Transportation Problem with Excess Supply

image.png

What if the total supply is less than the total demand?

Can add a check inside trans to detect supply being less than demand so that an error is thrown and nothing returned instead of having to check the solver message to determine that an erroneous solution is being returned when using trans0:

Ex 5: Vaccine Supply

Tomorrow, 130, 82, 215, and 175 doses of vaccine will be needed at clinics located at coordinates (3,2), (2,3), (4,2), and (3,4), respectively, and 180, 300, and 250 doses are available for shipment overnight from distribution centers located at coordinates (2,2), (1,1), and (2,4), respectively. Assuming the cost of supplying each clinic from a distribution center is proportional to the Euclidean distance between them, determine how much each distribution center should send to each clinic.