{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Continuous Optimization" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "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": {}, "outputs": [], "source": [ "import pandas as pd\n", "import pyomo.environ as pyo" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Linear Programs: Student Diet Example" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Reference: https://docs.mosek.com/modeling-cookbook/linear.html" ] }, { "cell_type": "markdown", "metadata": {}, "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": {}, "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", "
Activity
\n", " Check the Pyomo model. Specifically, are the input (parameter) data correct? Do the equations match our model written on paper?\n", "Activity
\n", " Does your degree of freedom analysis match Ipopt?\n", "Activity
\n", " Identify the sets, parameters, variables, and constraints.\n", "Activity
\n", " Perform degree of freedom analysis.\n", "Activity
\n", " Compare the initial values for x and y with and without initialization. What is the default initial value in Pyomo?\n", "Activity
\n", " Reinitialize the model, plot the initial point, resolve, and plot the solution. Is there more than one solution?\n", "