{ "cells": [ { "cell_type": "markdown", "id": "4181fd90", "metadata": {}, "source": [ "\n", "*This notebook contains material from [CBE60499](https://ndcbe.github.io/CBE60499);\n", "content is available [on Github](git@github.com:ndcbe/CBE60499.git).*\n" ] }, { "cell_type": "markdown", "id": "761d951d", "metadata": {}, "source": [ "\n", "< [2.0 Optimization Modeling with Applications](https://ndcbe.github.io/CBE60499/02.00-Optimization-Modeling.html) | [Contents](toc.html) | [Tag Index](tag_index.html) | [2.2 Integer Programs](https://ndcbe.github.io/CBE60499/02.02-IP.html) >
"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6b20a3d3",
"metadata": {},
"outputs": [],
"source": [
"# IMPORT DATA FILES USED BY THIS NOTEBOOK\n",
"import os, requests\n",
"\n",
"file_links = [(\"data/student_diet.csv\", \"https://ndcbe.github.io/CBE60499/data/student_diet.csv\")]\n",
"\n",
"# This cell has been added by nbpages. Run this cell to download data files required for this notebook.\n",
"\n",
"for filepath, fileurl in file_links:\n",
" stem, filename = os.path.split(filepath)\n",
" if stem:\n",
" if not os.path.exists(stem):\n",
" os.mkdir(stem)\n",
" if not os.path.isfile(filepath):\n",
" with open(filepath, 'wb') as f:\n",
" response = requests.get(fileurl)\n",
" f.write(response.content)\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 1,
"link": "[2.1 Continuous Optimization](https://ndcbe.github.io/CBE60499/02.01-LP-NLP.html#2.1-Continuous-Optimization)",
"section": "2.1 Continuous Optimization"
}
},
"source": [
"# 2.1 Continuous Optimization"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"nbpages": {
"level": 1,
"link": "[2.1 Continuous Optimization](https://ndcbe.github.io/CBE60499/02.01-LP-NLP.html#2.1-Continuous-Optimization)",
"section": "2.1 Continuous Optimization"
}
},
"outputs": [],
"source": [
"# This code cell installs packages on Colab\n",
"\n",
"import sys\n",
"if \"google.colab\" in sys.modules:\n",
" !wget \"https://raw.githubusercontent.com/ndcbe/CBE60499/main/notebooks/helper.py\"\n",
" import helper\n",
" helper.install_idaes()\n",
" helper.install_ipopt()\n",
" helper.install_glpk()\n",
" helper.download_data(['student_diet.csv'])\n",
" helper.download_figures(['pack1.png','pack2.png','pack3.png'])"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"nbpages": {
"level": 1,
"link": "[2.1 Continuous Optimization](https://ndcbe.github.io/CBE60499/02.01-LP-NLP.html#2.1-Continuous-Optimization)",
"section": "2.1 Continuous Optimization"
}
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import pyomo.environ as pyo"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 2,
"link": "[2.1.1 Linear Programs: Student Diet Example](https://ndcbe.github.io/CBE60499/02.01-LP-NLP.html#2.1.1-Linear-Programs:-Student-Diet-Example)",
"section": "2.1.1 Linear Programs: Student Diet Example"
}
},
"source": [
"## 2.1.1 Linear Programs: Student Diet Example"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 2,
"link": "[2.1.1 Linear Programs: Student Diet Example](https://ndcbe.github.io/CBE60499/02.01-LP-NLP.html#2.1.1-Linear-Programs:-Student-Diet-Example)",
"section": "2.1.1 Linear Programs: Student Diet Example"
}
},
"source": [
"Reference: https://docs.mosek.com/modeling-cookbook/linear.html"
]
},
{
"cell_type": "markdown",
"metadata": {
"nbpages": {
"level": 2,
"link": "[2.1.1 Linear Programs: Student Diet Example](https://ndcbe.github.io/CBE60499/02.01-LP-NLP.html#2.1.1-Linear-Programs:-Student-Diet-Example)",
"section": "2.1.1 Linear Programs: Student Diet Example"
}
},
"source": [
"You want to save money eating while remaining healthy. A healthy diet requires at least P=6 units of protein, C=15 units of carbohydrates, F=5 units of fats and V=7 units of vitamins. Due to compounding factors (blizzard during Lent), our campus only has these options:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"nbpages": {
"level": 2,
"link": "[2.1.1 Linear Programs: Student Diet Example](https://ndcbe.github.io/CBE60499/02.01-LP-NLP.html#2.1.1-Linear-Programs:-Student-Diet-Example)",
"section": "2.1.1 Linear Programs: Student Diet Example"
}
},
"outputs": [
{
"data": {
"text/html": [
"
\n", " | P | \n", "C | \n", "F | \n", "V | \n", "price | \n", "
---|---|---|---|---|---|
takeaway | \n", "3.0 | \n", "3 | \n", "2 | \n", "1 | \n", "5 | \n", "
vegtables | \n", "1.0 | \n", "2 | \n", "0 | \n", "4 | \n", "1 | \n", "
bread | \n", "0.5 | \n", "4 | \n", "1 | \n", "0 | \n", "2 | \n", "
"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}