eren darici


Lab 2 - Mathematical Programming Examples

1. Introduction

This lab introduces additional mathematical programming examples and demonstrates how optimization models can be formulated in both open form (explicit equations) and closed form (set-based notation).

Topics covered include:


2. Cake Production Problem

A bakery produces two types of cakes:

Available resources:

The objective is to determine the production quantities that maximize the total number of cakes produced.

ResourceAvailable
Flour5000 g
Fat1000 g
Cake TypeFlour (g)Fat (g)
Plain20025
Chocolate10050

Mathematical Model

Let:

Objective

Maximize total cakes produced:

$$ \max Z = x_1 + x_2 $$
Subject to
$$ 200x_1 + 100x_2 \le 5000 $$$$ 25x_1 + 50x_2 \le 1000 $$$$ x_1, x_2 \ge 0 $$$$ x_1, x_2 \in \mathbb{Z}_{\ge 0} $$

3. Diet Problem

A diet must satisfy minimum daily nutritional requirements at the lowest possible cost.

Available foods:

Food ItemCost
Brownie$0.50
Chocolate Ice Cream$0.20
Juice$0.30
Pineapple Cheesecake$0.80

Daily requirements:


Nutritional Data

ItemCaloriesChocolate (oz)Sugar (oz)Fat (oz)
Brownie400322
Chocolate Ice Cream200224
Juice250041
Pineapple Cheesecake500045

Closed Form Model

Sets
$$ J = \{1,2,3,4\} $$

Food items

$$ I = \{1,2,3,4\} $$

Nutritional requirements


Decision Variables
$$ x_j = \text{amount of food item } j $$$$ x_j \ge 0 \quad \forall j \in J $$
Parameters

Objective Function
$$ \min Z = \sum_{j \in J} c_j x_j $$
Constraints
$$ \sum_{j \in J} a_{ij}x_j \ge b_i \quad \forall i \in I $$$$ x_j \ge 0 \quad \forall j \in J $$

Matrix Representation

Cost vector:

$$ \mathbf{c}= \begin{bmatrix} 0.50 & 0.20 & 0.30 & 0.80 \end{bmatrix} $$

Requirement vector:

$$ \mathbf{b}= \begin{bmatrix} 500\\ 6\\ 10\\ 8 \end{bmatrix} $$

Coefficient matrix:

$$ \mathbf{A}= \begin{bmatrix} 400 & 200 & 250 & 500\\ 3 & 2 & 0 & 0\\ 2 & 2 & 4 & 4\\ 2 & 4 & 1 & 5 \end{bmatrix} $$

4. PuLP Indexed Variables

When models contain sets of variables, PuLP allows variables to be created using LpVariable.dicts().

Example

import pulp

foods = [1, 2, 3, 4]

x = pulp.LpVariable.dicts(
    "x",
    foods,
    lowBound=0,
    cat="Continuous"
)

This creates:

$$ x_1,\;x_2,\;x_3,\;x_4 \ge 0 $$

Variables can then be referenced using indexing:

x[j]

5. PuLP Summations with lpSum

Optimization models frequently use summation notation.

Mathematically:

$$ \min Z = \sum_{j \in J} c_jx_j $$

In PuLP:

model += pulp.lpSum(
    c[j] * x[j]
    for j in foods
)

Benefits of lpSum:


6. Dorian Auto Advertising Problem

Dorian Auto is planning a television advertising campaign.

Advertising options:

Commercial TypeWomen Reached (millions)Men Reached (millions)Cost
Comedy Show72$50,000
Football Game212$100,000

Requirements:

Objective:

Minimize advertising cost.


Open Form Model

Let:

Objective
$$ \min Z = 50,000x_1 + 100,000x_2 $$
Subject to
$$ 7x_1 + 2x_2 \ge 28 $$$$ 2x_1 + 12x_2 \ge 24 $$$$ x_1,x_2 \ge 0 $$

Closed Form Model

Sets
$$ J = \{1,2\} $$

Advertising options

$$ I = \{1,2\} $$

Audience groups


Decision Variables
$$ x_j = \text{number of advertisements of type } j $$$$ x_j \ge 0 \quad \forall j \in J $$
Parameters

Mathematical Formulation
$$ \min Z = \sum_{j \in J} c_j x_j $$$$ \sum_{j \in J} a_{ij}x_j \ge b_i \quad \forall i \in I $$$$ x_j \ge 0 \quad \forall j \in J $$

Matrix Representation

Cost vector:

$$ \mathbf{c}= \begin{bmatrix} 50,000 & 100,000 \end{bmatrix} $$

Requirement vector:

$$ \mathbf{b}= \begin{bmatrix} 28\\ 24 \end{bmatrix} $$

Coefficient matrix:

$$ \mathbf{A}= \begin{bmatrix} 7 & 2\\ 2 & 12 \end{bmatrix} $$

View Slides


Materials


References


← Back to Course Home: