{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2595a3a1-1834-4acc-b70a-3e11f538091e",
   "metadata": {},
   "source": [
    "**Example 3.6.** Reconsider the family farm problem of Example 3.4. The family\n",
    "has 625 acres available for planting. There are 5 plots of 120 acres each and\n",
    "another plot of 25 acres. The family wants to plant each plot with only one\n",
    "crop: corn, wheat, or oats. As before, 1,000 acre–ft of water will be available\n",
    "for irrigation, and the farmers will be able to devote 300 hours of labor per\n",
    "week. Additional data are presented in Table 3.2. Find the crop that should be\n",
    "planted in each plot for maximum proﬁt."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e3a43366-9901-4305-9cd3-8136d4504da5",
   "metadata": {},
   "source": [
    "**Table 3.2.**\n",
    "\n",
    "|Requirements|Corn|Wheat|Oats|\n",
    "|-|-|-|-|\n",
    "|Irrigation (acre-ft)|3.0|1.0|1.5|\n",
    "|Labor (person-hrs/week)|0.8|0.2|0.3|\n",
    "|Yield ($)|400|200|250|"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2038a56f-f1ac-41ee-8786-ed533fb17a30",
   "metadata": {},
   "source": [
    "$x_1 = {}$number of 120 acre plots of corn planted\\\n",
    "$x_2 = {}$number of 120–acre plots of wheat planted\\\n",
    "$x_3 = {}$number of 120–acre plots of oats planted\\\n",
    "$x_4 = {}$number of 25–acre plots of corn planted\\\n",
    "$x_5 = {}$number of 25–acre plots of wheat planted\\\n",
    "$x_6 = {}$number of 25–acre plots of oats planted\\\n",
    "$w = {}$irrigation required (acre–ft)\\\n",
    "$l = {}$labor required (person–hrs/wk)\\\n",
    "$t = {}$total acreage planted\\\n",
    "$y = {}$total yield (\\$)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1d2c456f-00e8-4732-8018-242a6555f4d3",
   "metadata": {},
   "outputs": [],
   "source": [
    "using JuMP,HiGHS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "b293b593-60b8-44e3-be4d-34f3135b2ebc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "A JuMP Model\n",
       "├ solver: HiGHS\n",
       "├ objective_sense: FEASIBILITY_SENSE\n",
       "├ num_variables: 0\n",
       "├ num_constraints: 0\n",
       "└ Names registered in the model: none"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model=Model(HiGHS.Optimizer)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "be75fef0-822e-4657-b329-3ae66a485a8a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6-element Vector{VariableRef}:\n",
       " x[1]\n",
       " x[2]\n",
       " x[3]\n",
       " x[4]\n",
       " x[5]\n",
       " x[6]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "@variable(model,x[1:6].>=0,Int)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "426d6c72-0c4c-4646-b56b-774b921d8773",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$$ \\begin{aligned}\n",
       "\\text{feasibility}\\\\\n",
       "\\text{Subject to} \\quad & x_{1} \\geq 0\\\\\n",
       " & x_{2} \\geq 0\\\\\n",
       " & x_{3} \\geq 0\\\\\n",
       " & x_{4} \\geq 0\\\\\n",
       " & x_{5} \\geq 0\\\\\n",
       " & x_{6} \\geq 0\\\\\n",
       " & x_{1} \\in \\mathbb{Z}\\\\\n",
       " & x_{2} \\in \\mathbb{Z}\\\\\n",
       " & x_{3} \\in \\mathbb{Z}\\\\\n",
       " & x_{4} \\in \\mathbb{Z}\\\\\n",
       " & x_{5} \\in \\mathbb{Z}\\\\\n",
       " & x_{6} \\in \\mathbb{Z}\\\\\n",
       "\\end{aligned} $$"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "print(model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6571d363-a129-4c14-934a-c4e5b3d5dbd5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "y (generic function with 1 method)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Note the function definitions that extend over two lines extend\n",
    "# to the next line by placing the + at the end of the first line. \n",
    "w(x)=120*(3.0*x[1]+1.0*x[2]+1.5*x[3])+\n",
    "      25*(3.0*x[4]+1.0*x[5]+1.5*x[6])\n",
    "l(x)=120*(0.8*x[1]+0.2*x[2]+0.3*x[3])+\n",
    "      25*(0.8*x[4]+0.2*x[5]+0.3*x[6])\n",
    "t(x)=120*(x[1]+x[2]+x[3])+25*(x[4]+x[5]+x[6])\n",
    "y(x)=120*(400*x[1]+200*x[2]+250*x[3])+\n",
    "     25*(400*x[4]+200*x[5]+250*x[6])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8db6b5d8-f221-43f1-82b7-849ba8e399aa",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Will continue this next time..."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Julia 1.10",
   "language": "julia",
   "name": "julia-1.10"
  },
  "language_info": {
   "file_extension": ".jl",
   "mimetype": "application/julia",
   "name": "julia",
   "version": "1.10.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
