# Assignment Problem Integer Linear Programming Matlab

This example shows how to set up and solve a mixed-integer linear programming problem. The problem is to find the optimal production and distribution levels among a set of factories, warehouses, and sales outlets. For the solver-based approach, see Factory, Warehouse, Sales Allocation Model: Solver-Based.

The example first generates random locations for factories, warehouses, and sales outlets. Feel free to modify the scaling parameter , which scales both the size of the grid in which the production and distribution facilities reside, but also scales the number of these facilities so that the density of facilities of each type per grid area is independent of .

### Facility Locations

For a given value of the scaling parameter , suppose that there are the following:

factories

warehouses

sales outlets

These facilities are on separate integer grid points between 1 and in the and directions. In order that the facilities have separate locations, you require that . In this example, take , , , and .

### Production and Distribution

There are products made by the factories. Take .

The demand for each product in a sales outlet is . The demand is the quantity that can be sold in a time interval. One constraint on the model is that the demand is met, meaning the system produces and distributes exactly the quantities in the demand.

There are capacity constraints on each factory and each warehouse.

Suppose that each sales outlet receives its supplies from just one warehouse. Part of the problem is to determine the cheapest mapping of sales outlets to warehouses.

### Costs

The cost of transporting products from factory to warehouse, and from warehouse to sales outlet, depends on the distance between the facilities, and on the particular product. If is the distance between facilities and , then the cost of shipping a product between these facilities is the distance times the transportation cost :

The distance in this example is the grid distance, also known as the distance. It is the sum of the absolute difference in coordinates and coordinates.

The cost of making a unit of product in factory is .

### Optimization Problem

Given a set of facility locations, and the demands and capacity constraints, find:

A production level of each product at each factory

A distribution schedule for products from factories to warehouses

A distribution schedule for products from warehouses to sales outlets

These quantities must ensure that demand is satisfied and total cost is minimized. Also, each sales outlet is required to receive all its products from exactly one warehouse.

### Variables and Equations for the Optimization Problem

The control variables, meaning the ones you can change in the optimization, are

The objective function to minimize is

The constraints are

(capacity of factory).

(demand is met).

(capacity of warehouse).

(each sales outlet associates to one warehouse).

(nonnegative production).

(binary ).

The variables and appear in the objective and constraint functions linearly. Because is restricted to integer values, the problem is a mixed-integer linear program (MILP).

### Generate a Random Problem: Facility Locations

Set the values of the , , , and parameters, and generate the facility locations.

Of course, it is not realistic to take random locations for facilities. This example is intended to show solution techniques, not how to generate good facility locations.

Plot the facilities. Facilities 1 through F are factories, F+1 through F+W are warehouses, and F+W+1 through F+W+S are sales outlets.

### Generate Random Capacities, Costs, and Demands

Generate random production costs, capacities, turnover rates, and demands.

These random demands and capacities can lead to infeasible problems. In other words, sometimes the demand exceeds the production and warehouse capacity constraints. If you alter some parameters and get an infeasible problem, during solution you will get an exitflag of -2.

### Generate Variables and Constraints

To begin specifying the problem, generate the distance arrays and .

Create variables for the optimization problem. represents the production, a continuous variable, with dimension -by--by-. represents the binary allocation of sales outlet to warehouse, an -by- variable.

Now create the constraints. The first constraint is a capacity constraint on production.

The next constraint is that the demand is met at each sales outlet.

There is a capacity constraint at each warehouse.

Finally, there is a requirement that each sales outlet connects to exactly one warehouse.

### Create Problem and Objective

Create an optimization problem.

The objective function has three parts. The first part is the sum of the production costs.

The second part is the sum of the transportation costs from factories to warehouses.

The third part is the sum of the transportation costs from warehouses to sales outlets.

The objective function to minimize is the sum of the three parts.

Include the constraints in the problem.

### Solve the Problem

Turn off iterative display so that you don't get hundreds of lines of output. Include a plot function to monitor the solution progress.

Call the solver to find the solution.

### Examine the Solution

Examine the exit flag and the infeasibility of the solution.

Round the portion of the solution to be exactly integer-valued. To understand why these variables might not be exactly integers, see the documentation.

How many sales outlets are associated with each warehouse? Notice that, in this case, some warehouses have 0 associated outlets, meaning the warehouses are not in use in the optimal solution.

Plot the connection between each sales outlet and its warehouse.

The black * with no green lines represent the unused warehouses.

### Office Assignment Problem

You want to assign six people, Marcelo, Rakesh, Peter, Tom, Marjorie, and Mary Ann, to seven offices. Each office can have no more than one person, and each person gets exactly one office. So there will be one empty office. People can give preferences for the offices, and their preferences are considered based on their seniority. The longer they have been at the MathWorks, the higher the seniority. Some offices have windows, some do not, and one window is smaller than others. Additionally, Peter and Tom often work together, so should be in adjacent offices. Marcelo and Rakesh often work together, and should be in adjacent offices.

### Office Layout

Offices 1, 2, 3, and 4 are inside offices (no windows). Offices 5, 6, and 7 have windows, but the window in office 5 is smaller than the other two. Here is how the offices are arranged.

### Problem Formulation

You need to formulate the problem mathematically. Create binary variables that indicate whether a person occupies an office. The list of people's names is

Create binary variables indexed by office number and name.

### Seniority

You want to weight the preferences based on seniority so that the longer you have been at MathWorks, the more your preferences count. The seniority is as follows: Mary Ann 9 years, Marjorie 10 years, Tom 5 years, Peter 3 years, Marcelo 1.5 years, and Rakesh 2 years. Create a normalized weight vector based on seniority.

### People's Office Preferences

Set up a preference matrix where the rows correspond to offices and the columns correspond to people. Ask each person to give values for each office so that the sum of all their choices, i.e., their column, sums to 100. A higher number means the person prefers the office. Each person's preferences are listed in a column vector.

The ith element of a person's preference vector is how highly they value the ith office. Thus, the combined preference matrix is as follows.

Weight the preferences matrix by to scale the columns by seniority.

### Objective Function

The objective is to maximize the satisfaction of the preferences weighted by seniority. This is the linear objective function .

Create an optimization problem and include the objective function.

### Constraints

The first set of constraints requires that each person gets exactly one office, that is for each person, the sum of the values corresponding to that person is exactly one.

The second set of constraints are inequalities. These constraints specify that each office has no more than one person in it.

You want Tom and Peter no more than one office away from each other, and the same with Marcelo and Rakesh.

Set constraints that Tom and Peter are not more than 1 away from each other.

Now create constraints that Marcelo and Rakesh are not more than 1 away from each other.

### Solve Assignment Problem

Call to solve the problem.

### View the Solution -- Who Got Each Office?

### Solution Quality

For this problem, the satisfaction of the preferences by seniority is maximized to the value of . = 1 tells you that converged to an optimal solution. The output structure gives information about the solution process, such as how many nodes were explored, and the gap between the lower and upper bounds in the branching calculation. In this case, no branch-and-bound nodes were generated, meaning the problem was solved without a branch-and-bound step. The gap is 0, meaning the solution is optimal, with no difference between the internally calculated lower and upper bounds on the objective function.

## 0 Replies to “Assignment Problem Integer Linear Programming Matlab”