eren darici


Lab 3 - Assignment and Transportation Problems

1. Introduction

This lab introduces transportation and assignment problems, two important classes of optimization models.

Topics covered include:


2. Recap: Transportation and Assignment Problems

The Assignment Problem is a special case of the Transportation Problem.

Key characteristics:


3. Transportation Problem: Closed Form Model

Decision Variables

$$ x_{ij} = \text{amount shipped from source } i \text{ to destination } j $$

Parameters


Objective Function

$$ \min \sum_i \sum_j c_{ij}x_{ij} $$

Constraints

Supply Constraints
$$ \sum_j x_{ij} \le s_i \qquad \forall i $$
Demand Constraints
$$ \sum_i x_{ij} \ge d_j \qquad \forall j $$
Non-negativity
$$ x_{ij} \ge 0 \qquad \forall i,j $$

4. Powerco Transportation Problem

Powerco operates three electric power plants that supply electricity to four cities.

Plant Capacities (Million kWh)

PlantSupply
Plant 135
Plant 250
Plant 340

City Demands (Million kWh)

CityDemand
City 145
City 220
City 330
City 430

The objective is to determine the amount of electricity shipped from each plant to each city while minimizing transmission costs.


Transportation Tableau

PlantCity 1City 2City 3City 4Supply
Plant 1$8$6$10$935
Plant 2$9$12$13$750
Plant 3$14$9$16$540
Demand45203030125

All costs are per one million kWh.


5. Open Form Linear Programming Model

Decision Variables

$$ x_{ij}

\text{amount shipped from Plant } i \text{ to City } j $$

Objective Function

$$ \begin{aligned} \min Z = &8x_{11}+6x_{12}+10x_{13}+9x_{14}\\ &+9x_{21}+12x_{22}+13x_{23}+7x_{24}\\ &+14x_{31}+9x_{32}+16x_{33}+5x_{34} \end{aligned} $$

Supply Constraints

$$ x_{11}+x_{12}+x_{13}+x_{14}\le35 $$$$ x_{21}+x_{22}+x_{23}+x_{24}\le50 $$$$ x_{31}+x_{32}+x_{33}+x_{34}\le40 $$

Demand Constraints

$$ x_{11}+x_{21}+x_{31}\ge45 $$$$ x_{12}+x_{22}+x_{32}\ge20 $$$$ x_{13}+x_{23}+x_{33}\ge30 $$$$ x_{14}+x_{24}+x_{34}\ge30 $$

Non-negativity

$$ x_{ij}\ge0 \qquad \forall i,j $$

6. PuLP: LpVariable.dicts

In transportation problems, a decision variable is needed for every source-destination pair.

Instead of creating variables individually, PuLP allows variables to be created using indexed dictionaries.

Example

import pulp

plants = [1, 2, 3]
cities = [1, 2, 3, 4]

x = pulp.LpVariable.dicts(
    "ship",
    [(i, j) for i in plants for j in cities],
    lowBound=0,
    cat="Continuous"
)

This creates variables such as:

$$ x_{11}, x_{12}, x_{13}, \ldots, x_{34} $$

which can be referenced as:

x[(i, j)]

Benefits:


7. Pandas Concepts for Data Handling

Optimization models often use external datasets stored in CSV files.

CSV Files

A CSV (Comma-Separated Values) file:

Example:

Plant,City,Cost
1,1,8
1,2,6
2,1,9

DataFrames

A Pandas DataFrame is a two-dimensional table structure.

Features:

Example:

import pandas as pd

df = pd.read_csv("transportation_costs.csv")

Index-Based Selection with iloc

The iloc function selects rows and columns by position.

Example:

df.iloc[0]

Returns the first row.

df.iloc[0, 2]

Returns the value in row 1, column 3.

This is useful when optimization data is stored in matrix form and positions are known.


View Slides


Materials


References


← Back to Course Home