%% Assign Flights with Minimal Cost
% Assign salespeople to flights such that the total cost of transportation is minimized.
% A company has four salespeople who need to travel to key cities around the country. The company must book their flights, and wants to spend as little money as possible. These salespeople are based in different parts of the country, so the cost for them to fly to each city varies.
% This table shows the cost for each salesperson to fly to each key city.
% $$\begin{array}{|c|c|c|c|}
% \hline & \mbox{Dallas} & \mbox{Chicago} & \mbox{New York City} & \mbox{St. Louis}\\
% \hline \mbox{Fred} & \$600 & \$670 & \$960 & \$560\\
% \hline \mbox{Beth} & \$900 & \$280& \$970 & \$540\\
% \hline \mbox{Sue} & \$310 & \$350 & \$950& \$820\\
% \hline \mbox{Greg} & \$325 & \$290 & \$600 & \$540\\ \hline \end{array}$$
% Each city represents a sales opportunity. If a city is missed, then the company loses out on an average revenue gain of $2,000.
%
% Create a cost matrix to represent the cost of each salesperson flying to each city.

C = [600 670 960 560
     900 280 970 540
     310 350 950 820
     325 290 600 540];

%
% Use matchpairs to assign the salespeople to the cities with minimal cost. Specify the cost of unassignment as 1000, since the cost of unassignment is counted twice if a row and a column remain unmatched.

M = matchpairs(C,1000)

% matchpairs calculates the least expensive way to get a salesperson to each city.
% $$\begin{array}{|c|c|c|c|}
% \hline & \mbox{Dallas} & \mbox{Chicago} & \mbox{New York City} & \mbox{St. Louis}\\
% \hline \mbox{Fred} & \$600 & \$670 & \$960 & \textbf{\$560}\\
% \hline \mbox{Beth} & \$900 & \textbf{\$280} & \$970 & \$540\\
% \hline \mbox{Sue} & \textbf{\$310} & \$350 & \$950& \$820\\
% \hline \mbox{Greg} & \$325 & \$290 & \textbf{\$600} & \$540\\ \hline \end{array}$$
%
% Copyright 2018 The MathWorks, Inc.