{ "cells": [ { "cell_type": "markdown", "metadata": { "pycharm": {} }, "source": [ "\n", "*This notebook contains course material from [CBE40455](https://jckantor.github.io/CBE40455) by\n", "Jeffrey Kantor (jeff at nd.edu); the content is available [on Github](https://github.com/jckantor/CBE40455.git).\n", "The text is released under the [CC-BY-NC-ND-4.0 license](https://creativecommons.org/licenses/by-nc-nd/4.0/legalcode),\n", "and code is released under the [MIT license](https://opensource.org/licenses/MIT).*" ] }, { "cell_type": "markdown", "metadata": { "pycharm": {} }, "source": [ "\n", "< [Getting Started with CVXPY](http://nbviewer.jupyter.org/github/jckantor/CBE40455/blob/master/notebooks/01.01-Getting-Started-with-CVXPY.ipynb) | [Contents](toc.ipynb) | [Getting Started with GNU MathProg in Jupyter Notebooks](http://nbviewer.jupyter.org/github/jckantor/CBE40455/blob/master/notebooks/01.03-Getting-Started-with-GNU-MathProg.ipynb) >
"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {}
},
"source": [
"# Getting Started with Gurobi\n",
"\n",
"[Gurobi](http://www.gurobi.com) is a commercial, state-of-the-art mathematical programming engines used in a diverse array of industries. It is available under academic licensing terms that allow free use by faculty and students in accredited insitutions, and comes with a very complete Python interface. The purpose of this notebook is to help you get started using Gurobi via the Python interface.\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {}
},
"source": [
"## Simple Two-Variable LP"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false,
"pycharm": {}
},
"outputs": [
{
"data": {
"text/plain": [
"[2.4, 1.6]"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from gurobi import *\n",
"m = Model()\n",
"\n",
"v0 = m.addVar()\n",
"v1 = m.addVar()\n",
"m.update()\n",
"\n",
"m.getVars()\n",
"\n",
"m.addConstr(v0 - v1 <= 4)\n",
"m.addConstr(v0 + v1 <= 4)\n",
"m.addConstr(-0.25*v0 + v1 <= 1)\n",
"m.setObjective(v1, GRB.MAXIMIZE)\n",
"m.params.outputflag = 0\n",
"m.optimize()\n",
"[v0.x,v1.x]"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {}
},
"source": [
"## Assignment Problem"
]
},
{
"cell_type": "markdown",
"metadata": {
"pycharm": {}
},
"source": [
"### Problem Data"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false,
"pycharm": {}
},
"outputs": [
{
"data": {
"text/html": [
"
| \n", " | Atlanta | \n", "Boise | \n", "Charlotte | \n", "Dallas | \n", "Fresno | \n", "
|---|---|---|---|---|---|
| Austin | \n", "921 | \n", "1627 | \n", "1166 | \n", "196 | \n", "1594 | \n", "
| Boston | \n", "1078 | \n", "2661 | \n", "837 | \n", "1767 | \n", "3107 | \n", "
| Chicago | \n", "716 | \n", "1693 | \n", "756 | \n", "925 | \n", "2140 | \n", "
| Denver | \n", "1400 | \n", "815 | \n", "1561 | \n", "788 | \n", "1142 | \n", "
| Edmonton | \n", "3764 | \n", "1718 | \n", "3848 | \n", "3310 | \n", "2835 | \n", "
"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda root]",
"language": "python",
"name": "conda-root-py"
},
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}