Skip to content

Commit

Permalink
Update HiGHS solver import (up to ch 4 included) and facility locatio…
Browse files Browse the repository at this point in the history
…n notebook
  • Loading branch information
alessandrozocca committed Oct 18, 2023
1 parent 0df7b9d commit 926d37e
Show file tree
Hide file tree
Showing 27 changed files with 8,578 additions and 2,305 deletions.
4 changes: 2 additions & 2 deletions notebooks/01/production-planning-advanced.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/01/production-planning-basic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/02/L1-regression-wine-quality.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/02/bim-dual.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/02/bim-fractional.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/02/bim-maxmin.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/02/bim-rawmaterialplanning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/02/bim.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else: \n",
" from pyomo.environ import SolverFactory\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/02/lad-regression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/02/mad-portfolio-optimization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/02/multiproductionfaciliity_worstcase.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/03/bim-perturbed.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/03/bim-production-revisited.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down
47 changes: 33 additions & 14 deletions notebooks/03/cryptarithms.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
" !pip install pyomo >/dev/null 2>/dev/null\n",
" !pip install highspy >/dev/null 2>/dev/null\n",
"\n",
" from pyomo.contrib import appsi\n",
" SOLVER = appsi.solvers.Highs(only_child_vars=False)\n",
" from pyomo.environ import SolverFactory\n",
" SOLVER = SolverFactory('appsi_highs')\n",
" \n",
"else:\n",
" from pyomo.environ import SolverFactory\n",
Expand Down Expand Up @@ -134,41 +134,60 @@
"\n",
"m = pyo.ConcreteModel()\n",
"\n",
"m.LETTERS = pyo.Set(initialize=['S', 'E', 'N', 'D', 'M', 'O', 'R', 'Y'])\n",
"m.PAIRS = pyo.Set(initialize=m.LETTERS * m.LETTERS, filter = lambda m, a, b: a < b)\n",
"m.LETTERS = pyo.Set(initialize=[\"S\", \"E\", \"N\", \"D\", \"M\", \"O\", \"R\", \"Y\"])\n",
"m.PAIRS = pyo.Set(initialize=m.LETTERS * m.LETTERS, filter=lambda m, a, b: a < b)\n",
"m.n = pyo.Var(m.LETTERS, domain=pyo.Integers, bounds=(0, 9))\n",
"\n",
"\n",
"@m.Constraint()\n",
"def message(m):\n",
" return 1000*m.n['S'] + 100*m.n['E'] + 10*m.n['N'] + m.n['D'] \\\n",
" + 1000*m.n['M'] + 100*m.n['O'] + 10*m.n['R'] + m.n['E'] \\\n",
" == 10000*m.n['M'] + 1000*m.n['O'] + 100*m.n['N'] + 10*m.n['E'] + m.n['Y']\n",
" return (\n",
" 1000 * m.n[\"S\"]\n",
" + 100 * m.n[\"E\"]\n",
" + 10 * m.n[\"N\"]\n",
" + m.n[\"D\"]\n",
" + 1000 * m.n[\"M\"]\n",
" + 100 * m.n[\"O\"]\n",
" + 10 * m.n[\"R\"]\n",
" + m.n[\"E\"]\n",
" == 10000 * m.n[\"M\"]\n",
" + 1000 * m.n[\"O\"]\n",
" + 100 * m.n[\"N\"]\n",
" + 10 * m.n[\"E\"]\n",
" + m.n[\"Y\"]\n",
" )\n",
"\n",
"\n",
"# leading digit must be non-zero\n",
"@m.Constraint()\n",
"def leading_digit_nonzero(m):\n",
" return m.n['M'] >= 1\n",
" return m.n[\"M\"] >= 1\n",
"\n",
"\n",
"# assign a different number to each letter\n",
"@m.Disjunction(m.PAIRS)\n",
"def unique_assignment(m, a, b):\n",
" return [m.n[a] >= m.n[b] + 1, m.n[b] >= m.n[a] + 1]\n",
"\n",
"\n",
"# assign a \"dummy\" objective to avoid solver errors\n",
"@m.Objective()\n",
"def dummy_objective(m):\n",
" return m.n['M']\n",
" return m.n[\"M\"]\n",
"\n",
"\n",
"pyo.TransformationFactory('gdp.bigm').apply_to(m)\n",
"pyo.TransformationFactory(\"gdp.bigm\").apply_to(m)\n",
"SOLVER.solve(m)\n",
"\n",
"\n",
"def letters2num(s):\n",
" return ' '.join(map(lambda s: f\"{int(m.n[s]())}\", list(s)))\n",
" return \" \".join(map(lambda s: f\"{int(m.n[s]())}\", list(s)))\n",
"\n",
"\n",
"print(\" \", letters2num('SEND'))\n",
"print(\" + \", letters2num('MORE'))\n",
"print(\" \", letters2num(\"SEND\"))\n",
"print(\" + \", letters2num(\"MORE\"))\n",
"print(\" ----------\")\n",
"print(\"= \", letters2num('MONEY'))"
"print(\"= \", letters2num(\"MONEY\"))"
]
},
{
Expand Down
Loading

0 comments on commit 926d37e

Please sign in to comment.