Update 0.3 docs

This commit is contained in:
2023-06-08 09:18:49 -05:00
parent 3d4a6a87a8
commit d9d44ce4b2
45 changed files with 7925 additions and 3158 deletions

View File

@@ -38,8 +38,8 @@
},
{
"cell_type": "code",
"execution_count": 1,
"id": "3d9cc182",
"execution_count": 3,
"id": "6d342a4e",
"metadata": {
"collapsed": false
},
@@ -103,7 +103,7 @@
},
{
"cell_type": "markdown",
"id": "e7175752",
"id": "8a46bb8a",
"metadata": {
"collapsed": false
},
@@ -111,7 +111,7 @@
},
{
"cell_type": "markdown",
"id": "e993aa6f",
"id": "d8699092",
"metadata": {
"collapsed": false
},
@@ -131,7 +131,7 @@
},
{
"cell_type": "markdown",
"id": "711639bd",
"id": "99a122dc",
"metadata": {
"collapsed": false
},
@@ -172,7 +172,7 @@
},
{
"cell_type": "markdown",
"id": "9b35d7f7",
"id": "7fe76973",
"metadata": {
"collapsed": false
},
@@ -184,25 +184,16 @@
},
{
"cell_type": "code",
"execution_count": 2,
"id": "7ea6b715",
"execution_count": 4,
"id": "425717fe",
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/axavier/Software/anaconda3/envs/miplearn/lib/python3.8/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Removing empty/corrupted h5 file: data/tsp/00000.h5\n",
"lp_obj_value = 2909.0\n",
"mip_obj_value = 2921.0\n"
]
@@ -218,7 +209,7 @@
" TravelingSalesmanGenerator,\n",
" build_tsp_model,\n",
")\n",
"from miplearn.io import save\n",
"from miplearn.io import write_pkl_gz\n",
"from miplearn.h5 import H5File\n",
"from miplearn.collectors.basic import BasicCollector\n",
"\n",
@@ -237,11 +228,11 @@
").generate(10)\n",
"\n",
"# Save instance data to data/tsp/00000.pkl.gz, data/tsp/00001.pkl.gz, ...\n",
"save(data, \"data/tsp\")\n",
"write_pkl_gz(data, \"data/tsp\")\n",
"\n",
"# Solve all instances and collect basic solution information. Process at most four\n",
"# instances in parallel, with a per-instance time limit of one hour.\n",
"bc = BasicCollector(time_limit_sec=3600)\n",
"# Solve all instances and collect basic solution information.\n",
"# Process at most four instances in parallel.\n",
"bc = BasicCollector()\n",
"bc.collect(glob(\"data/tsp/*.pkl.gz\"), build_tsp_model, n_jobs=4)\n",
"\n",
"# Read and print some training data for the first instance.\n",
@@ -252,8 +243,8 @@
},
{
"cell_type": "code",
"execution_count": 2,
"id": "97ac9136",
"execution_count": null,
"id": "30023d2b",
"metadata": {
"collapsed": false
},
@@ -277,7 +268,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.9.12"
}
},
"nbformat": 4,

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>2. Training Data Collectors &#8212; MIPLearn 0.3</title>
<title>5. Training Data Collectors &#8212; MIPLearn 0.3</title>
<link href="../../_static/css/theme.css" rel="stylesheet" />
<link href="../../_static/css/index.c5995385ac14fb8791e8eb36b4908be2.css" rel="stylesheet" />
@@ -24,6 +24,7 @@
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sphinx-book-theme.acff12b8f9c144ce68a297486a2fa670.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/custom.css" />
<link rel="preload" as="script" href="../../_static/js/index.1c5a1a01449ed65a7b51.js">
@@ -38,8 +39,8 @@
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]], "processRefs": false, "processEnvironments": false}})</script>
<link rel="index" title="Index" href="../../genindex/" />
<link rel="search" title="Search" href="../../search/" />
<link rel="next" title="3. Feature Extractors" href="../features/" />
<link rel="prev" title="1. Benchmark Problems" href="../problems/" />
<link rel="next" title="6. Feature Extractors" href="../features/" />
<link rel="prev" title="4. Benchmark Problems" href="../problems/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
@@ -68,6 +69,28 @@
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
<div class="bd-toc-item active">
<p class="caption">
<span class="caption-text">
Tutorials
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-pyomo/">
1. Getting started (Pyomo)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-gurobipy/">
2. Getting started (Gurobipy)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-jump/">
3. Getting started (JuMP)
</a>
</li>
</ul>
<p class="caption">
<span class="caption-text">
User Guide
</span>
@@ -75,59 +98,59 @@
<ul class="current nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../problems/">
1. Benchmark Problems
4. Benchmark Problems
</a>
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
2. Training Data Collectors
5. Training Data Collectors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../features/">
3. Feature Extractors
6. Feature Extractors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../primal/">
4. Primal Components
7. Primal Components
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../solvers/">
5. Solvers
8. Solvers
</a>
</li>
</ul>
<p class="caption">
<span class="caption-text">
API Reference
Python API Reference
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../../api/problems/">
6. Benchmark Problems
9. Benchmark Problems
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/collectors/">
7. Collectors &amp; Extractors
10. Collectors &amp; Extractors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/components/">
8. Components
11. Components
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/solvers/">
9. Solvers
12. Solvers
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/helpers/">
10. Helpers
13. Helpers
</a>
</li>
</ul>
@@ -199,12 +222,12 @@
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Overview">
2.1. Overview
5.1. Overview
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#HDF5-Format">
2.2. HDF5 Format
5.2. HDF5 Format
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -216,7 +239,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Basic-collector">
2.3. Basic collector
5.3. Basic collector
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -242,279 +265,22 @@
<div>
<style>
/* CSS for nbsphinx extension */
/* remove conflicting styling from Sphinx themes */
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt *,
div.nbinput.container div.input_area pre,
div.nboutput.container div.output_area pre,
div.nbinput.container div.input_area .highlight,
div.nboutput.container div.output_area .highlight {
border: none;
padding: 0;
margin: 0;
box-shadow: none;
}
div.nbinput.container > div[class*=highlight],
div.nboutput.container > div[class*=highlight] {
margin: 0;
}
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt * {
background: none;
}
div.nboutput.container div.output_area .highlight,
div.nboutput.container div.output_area pre {
background: unset;
}
div.nboutput.container div.output_area div.highlight {
color: unset; /* override Pygments text color */
}
/* avoid gaps between output lines */
div.nboutput.container div[class*=highlight] pre {
line-height: normal;
}
/* input/output containers */
div.nbinput.container,
div.nboutput.container {
display: -webkit-flex;
display: flex;
align-items: flex-start;
margin: 0;
width: 100%;
}
@media (max-width: 540px) {
div.nbinput.container,
div.nboutput.container {
flex-direction: column;
}
}
/* input container */
div.nbinput.container {
padding-top: 5px;
}
/* last container */
div.nblast.container {
padding-bottom: 5px;
}
/* input prompt */
div.nbinput.container div.prompt pre {
color: #307FC1;
}
/* output prompt */
div.nboutput.container div.prompt pre {
color: #BF5B3D;
}
/* all prompts */
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: 4.5ex;
padding-top: 5px;
position: relative;
user-select: none;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: absolute;
right: 0;
margin-right: 0.3ex;
}
@media (max-width: 540px) {
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: unset;
text-align: left;
padding: 0.4em;
}
div.nboutput.container div.prompt.empty {
padding: 0;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: unset;
}
}
/* disable scrollbars and line breaks on prompts */
div.nbinput.container div.prompt pre,
div.nboutput.container div.prompt pre {
overflow: hidden;
white-space: pre;
}
/* input/output area */
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
-webkit-flex: 1;
flex: 1;
overflow: auto;
}
@media (max-width: 540px) {
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
width: 100%;
}
}
/* input area */
div.nbinput.container div.input_area {
border: 1px solid #e0e0e0;
border-radius: 2px;
/*background: #f5f5f5;*/
}
/* override MathJax center alignment in output cells */
div.nboutput.container div[class*=MathJax] {
text-align: left !important;
}
/* override sphinx.ext.imgmath center alignment in output cells */
div.nboutput.container div.math p {
text-align: left;
}
/* standard error */
div.nboutput.container div.output_area.stderr {
background: #fdd;
}
/* ANSI colors */
.ansi-black-fg { color: #3E424D; }
.ansi-black-bg { background-color: #3E424D; }
.ansi-black-intense-fg { color: #282C36; }
.ansi-black-intense-bg { background-color: #282C36; }
.ansi-red-fg { color: #E75C58; }
.ansi-red-bg { background-color: #E75C58; }
.ansi-red-intense-fg { color: #B22B31; }
.ansi-red-intense-bg { background-color: #B22B31; }
.ansi-green-fg { color: #00A250; }
.ansi-green-bg { background-color: #00A250; }
.ansi-green-intense-fg { color: #007427; }
.ansi-green-intense-bg { background-color: #007427; }
.ansi-yellow-fg { color: #DDB62B; }
.ansi-yellow-bg { background-color: #DDB62B; }
.ansi-yellow-intense-fg { color: #B27D12; }
.ansi-yellow-intense-bg { background-color: #B27D12; }
.ansi-blue-fg { color: #208FFB; }
.ansi-blue-bg { background-color: #208FFB; }
.ansi-blue-intense-fg { color: #0065CA; }
.ansi-blue-intense-bg { background-color: #0065CA; }
.ansi-magenta-fg { color: #D160C4; }
.ansi-magenta-bg { background-color: #D160C4; }
.ansi-magenta-intense-fg { color: #A03196; }
.ansi-magenta-intense-bg { background-color: #A03196; }
.ansi-cyan-fg { color: #60C6C8; }
.ansi-cyan-bg { background-color: #60C6C8; }
.ansi-cyan-intense-fg { color: #258F8F; }
.ansi-cyan-intense-bg { background-color: #258F8F; }
.ansi-white-fg { color: #C5C1B4; }
.ansi-white-bg { background-color: #C5C1B4; }
.ansi-white-intense-fg { color: #A1A6B2; }
.ansi-white-intense-bg { background-color: #A1A6B2; }
.ansi-default-inverse-fg { color: #FFFFFF; }
.ansi-default-inverse-bg { background-color: #000000; }
.ansi-bold { font-weight: bold; }
.ansi-underline { text-decoration: underline; }
div.nbinput.container div.input_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight].math,
div.nboutput.container div.output_area.rendered_html,
div.nboutput.container div.output_area > div.output_javascript,
div.nboutput.container div.output_area:not(.rendered_html) > img{
padding: 5px;
margin: 0;
}
/* fix copybtn overflow problem in chromium (needed for 'sphinx_copybutton') */
div.nbinput.container div.input_area > div[class^='highlight'],
div.nboutput.container div.output_area > div[class^='highlight']{
overflow-y: hidden;
}
/* hide copybtn icon on prompts (needed for 'sphinx_copybutton') */
.prompt .copybtn {
display: none;
}
/* Some additional styling taken form the Jupyter notebook CSS */
.jp-RenderedHTMLCommon table,
div.rendered_html table {
border: none;
border-collapse: collapse;
border-spacing: 0;
color: black;
font-size: 12px;
table-layout: fixed;
}
.jp-RenderedHTMLCommon thead,
div.rendered_html thead {
border-bottom: 1px solid black;
vertical-align: bottom;
}
.jp-RenderedHTMLCommon tr,
.jp-RenderedHTMLCommon th,
.jp-RenderedHTMLCommon td,
div.rendered_html tr,
div.rendered_html th,
div.rendered_html td {
text-align: right;
vertical-align: middle;
padding: 0.5em 0.5em;
line-height: normal;
white-space: normal;
max-width: none;
border: none;
}
.jp-RenderedHTMLCommon th,
div.rendered_html th {
font-weight: bold;
}
.jp-RenderedHTMLCommon tbody tr:nth-child(odd),
div.rendered_html tbody tr:nth-child(odd) {
background: #f5f5f5;
}
.jp-RenderedHTMLCommon tbody tr:hover,
div.rendered_html tbody tr:hover {
background: rgba(66, 165, 245, 0.2);
}
</style>
<div class="section" id="Training-Data-Collectors">
<h1><span class="section-number">2. </span>Training Data Collectors<a class="headerlink" href="#Training-Data-Collectors" title="Permalink to this headline"></a></h1>
<div class="section" id="Training-Data-Collectors">
<h1><span class="section-number">5. </span>Training Data Collectors<a class="headerlink" href="#Training-Data-Collectors" title="Permalink to this headline"></a></h1>
<p>The first step in solving mixed-integer optimization problems with the assistance of supervised machine learning methods is solving a large set of training instances and collecting the raw training data. In this section, we describe the various training data collectors included in MIPLearn. Additionally, the framework follows the convention of storing all training data in files with a specific data format (namely, HDF5). In this section, we briefly describe this format and the rationale for
choosing it.</p>
<div class="section" id="Overview">
<h2><span class="section-number">2.1. </span>Overview<a class="headerlink" href="#Overview" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">5.1. </span>Overview<a class="headerlink" href="#Overview" title="Permalink to this headline"></a></h2>
<p>In MIPLearn, a <strong>collector</strong> is a class that solves or analyzes the problem and collects raw data which may be later useful for machine learning methods. Collectors, by convention, take as input: (i) a list of problem data filenames, in gzipped pickle format, ending with <code class="docutils literal notranslate"><span class="pre">.pkl.gz</span></code>; (ii) a function that builds the optimization model, such as <code class="docutils literal notranslate"><span class="pre">build_tsp_model</span></code>. After processing is done, collectors store the training data in a HDF5 file located alongside with the problem data. For example, if
the problem data is stored in file <code class="docutils literal notranslate"><span class="pre">problem.pkl.gz</span></code>, then the collector writes to <code class="docutils literal notranslate"><span class="pre">problem.h5</span></code>. Collectors are, in general, very time consuming, as they may need to solve the problem to optimality, potentially multiple times.</p>
</div>
<div class="section" id="HDF5-Format">
<h2><span class="section-number">2.2. </span>HDF5 Format<a class="headerlink" href="#HDF5-Format" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">5.2. </span>HDF5 Format<a class="headerlink" href="#HDF5-Format" title="Permalink to this headline"></a></h2>
<p>MIPLearn stores all training data in <a class="reference external" href="HDF5">HDF5</a> (Hierarchical Data Format, Version 5) files. The HDF format was originally developed by the <a class="reference external" href="https://en.wikipedia.org/wiki/National_Center_for_Supercomputing_Applications">National Center for Supercomputing Applications</a> (NCSA) for storing and organizing large amounts of data, and supports a variety of data types, including integers, floating-point numbers, strings, and arrays. Compared to other formats, such as CSV, JSON or SQLite, the
HDF5 format provides several advantages for MIPLearn, including:</p>
<ul class="simple">
<li><p><em>Storage of multiple scalars, vectors and matrices in a single file</em> — This allows MIPLearn to store all training data related to a given problem instance in a single file, which makes training data easier to store, organize and transfer.</p></li>
<li><p><em>High-performance partial I/O</em> — Partial I/O allows MIPLearn to read a single element from the training data (e.g. value of the optimal solution) without loading the entire file to memory or reading it from beginning to end, which dramatically improves performance and reduces memory requirements. This is especially important when processing a large number of training data files.</p></li>
<li><p><em>High-performance partial I/O</em> — Partial I/O allows MIPLearn to read a single element from the training data (e.g. value of the optimal solution) without loading the entire file to memory or reading it from beginning to end, which dramatically improves performance and reduces memory requirements. This is especially important when processing a large number of training data files.</p></li>
<li><p><em>On-the-fly compression</em> — HDF5 files can be transparently compressed, using the gzip method, which reduces storage requirements and accelerates network transfers.</p></li>
<li><p><em>Stable, portable and well-supported data format</em> — Training data files are typically expensive to generate. Having a stable and well supported data format ensures that these files remain usable in the future, potentially even by other non-Python MIP/ML frameworks.</p></li>
</ul>
@@ -524,7 +290,7 @@ automatically perform type-checking and gzip compression. The example below show
<div class="section" id="Example">
<h3>Example<a class="headerlink" href="#Example" title="Permalink to this headline"></a></h3>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[1]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[3]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
@@ -587,7 +353,7 @@ x5 = (2, 3) 0.68030757
</div>
</div>
<div class="section" id="Basic-collector">
<h2><span class="section-number">2.3. </span>Basic collector<a class="headerlink" href="#Basic-collector" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">5.3. </span>Basic collector<a class="headerlink" href="#Basic-collector" title="Permalink to this headline"></a></h2>
<p><a class="reference external" href="../../api/collectors/#miplearn.collectors.basic.BasicCollector">BasicCollector</a> is the most fundamental collector, and performs the following steps:</p>
<ol class="arabic simple">
<li><p>Extracts all model data, such as objective function and constraint right-hand sides into numpy arrays, which can later be easily and efficiently accessed without rebuilding the model or invoking the solver;</p></li>
@@ -729,7 +495,7 @@ x5 = (2, 3) 0.68030757
<h3>Example<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h3>
<p>The example below shows how to generate a few random instances of the traveling salesman problem, store its problem data, run the collector and print some of the training data to screen.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[2]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[4]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">random</span>
@@ -741,7 +507,7 @@ x5 = (2, 3) 0.68030757
<span class="n">TravelingSalesmanGenerator</span><span class="p">,</span>
<span class="n">build_tsp_model</span><span class="p">,</span>
<span class="p">)</span>
<span class="kn">from</span> <span class="nn">miplearn.io</span> <span class="kn">import</span> <span class="n">save</span>
<span class="kn">from</span> <span class="nn">miplearn.io</span> <span class="kn">import</span> <span class="n">write_pkl_gz</span>
<span class="kn">from</span> <span class="nn">miplearn.h5</span> <span class="kn">import</span> <span class="n">H5File</span>
<span class="kn">from</span> <span class="nn">miplearn.collectors.basic</span> <span class="kn">import</span> <span class="n">BasicCollector</span>
@@ -760,11 +526,11 @@ x5 = (2, 3) 0.68030757
<span class="p">)</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
<span class="c1"># Save instance data to data/tsp/00000.pkl.gz, data/tsp/00001.pkl.gz, ...</span>
<span class="n">save</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="s2">&quot;data/tsp&quot;</span><span class="p">)</span>
<span class="n">write_pkl_gz</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="s2">&quot;data/tsp&quot;</span><span class="p">)</span>
<span class="c1"># Solve all instances and collect basic solution information. Process at most four</span>
<span class="c1"># instances in parallel, with a per-instance time limit of one hour.</span>
<span class="n">bc</span> <span class="o">=</span> <span class="n">BasicCollector</span><span class="p">(</span><span class="n">time_limit_sec</span><span class="o">=</span><span class="mi">3600</span><span class="p">)</span>
<span class="c1"># Solve all instances and collect basic solution information.</span>
<span class="c1"># Process at most four instances in parallel.</span>
<span class="n">bc</span> <span class="o">=</span> <span class="n">BasicCollector</span><span class="p">()</span>
<span class="n">bc</span><span class="o">.</span><span class="n">collect</span><span class="p">(</span><span class="n">glob</span><span class="p">(</span><span class="s2">&quot;data/tsp/*.pkl.gz&quot;</span><span class="p">),</span> <span class="n">build_tsp_model</span><span class="p">,</span> <span class="n">n_jobs</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
<span class="c1"># Read and print some training data for the first instance.</span>
@@ -774,27 +540,17 @@ x5 = (2, 3) 0.68030757
</pre></div>
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area stderr docutils container">
<div class="highlight"><pre>
/home/axavier/Software/anaconda3/envs/miplearn/lib/python3.8/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
</pre></div></div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
Removing empty/corrupted h5 file: data/tsp/00000.h5
lp_obj_value = 2909.0
mip_obj_value = 2921.0
</pre></div></div>
</div>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[2]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[ ]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>
@@ -811,8 +567,8 @@ mip_obj_value = 2921.0
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="../problems/" title="previous page"><span class="section-number">1. </span>Benchmark Problems</a>
<a class='right-next' id="next-link" href="../features/" title="next page"><span class="section-number">3. </span>Feature Extractors</a>
<a class='left-prev' id="prev-link" href="../problems/" title="previous page"><span class="section-number">4. </span>Benchmark Problems</a>
<a class='right-next' id="next-link" href="../features/" title="next page"><span class="section-number">6. </span>Feature Extractors</a>
</div>
@@ -822,7 +578,7 @@ mip_obj_value = 2921.0
<div class="container">
<p>
&copy; Copyright 2020-2022, UChicago Argonne, LLC.<br/>
&copy; Copyright 2020-2023, UChicago Argonne, LLC.<br/>
</p>
</div>
</footer>

View File

@@ -12,7 +12,7 @@
},
{
"cell_type": "markdown",
"id": "599ac2f7",
"id": "94df359d",
"metadata": {
"collapsed": false
},
@@ -32,7 +32,7 @@
},
{
"cell_type": "markdown",
"id": "60efe8f5",
"id": "d450370d",
"metadata": {
"collapsed": false
},
@@ -45,7 +45,7 @@
},
{
"cell_type": "markdown",
"id": "dfc32e59",
"id": "b0e96d25",
"metadata": {
"collapsed": false
},
@@ -57,8 +57,8 @@
},
{
"cell_type": "code",
"execution_count": 1,
"id": "ed2f5006",
"execution_count": 5,
"id": "82609250",
"metadata": {
"collapsed": false
},
@@ -99,12 +99,12 @@
"from scipy.stats import uniform, randint\n",
"\n",
"from miplearn.collectors.basic import BasicCollector\n",
"from miplearn.features.fields import H5FieldsExtractor\n",
"from miplearn.extractors.fields import H5FieldsExtractor\n",
"from miplearn.h5 import H5File\n",
"from miplearn.io import save\n",
"from miplearn.io import write_pkl_gz\n",
"from miplearn.problems.multiknapsack import (\n",
" MultiKnapsackGenerator,\n",
" build_multiknapsack_model\n",
" build_multiknapsack_model,\n",
")\n",
"\n",
"# Set random seed to make example reproducible\n",
@@ -112,7 +112,7 @@
"\n",
"# Generate some random multiknapsack instances\n",
"rmtree(\"data/multiknapsack/\", ignore_errors=True)\n",
"save(\n",
"write_pkl_gz(\n",
" MultiKnapsackGenerator(\n",
" n=randint(low=10, high=11),\n",
" m=randint(low=5, high=6),\n",
@@ -124,7 +124,7 @@
" p_jitter=uniform(loc=0.75, scale=0.5),\n",
" fix_w=True,\n",
" ).generate(10),\n",
" \"data/multiknapsack\"\n",
" \"data/multiknapsack\",\n",
")\n",
"\n",
"# Run the basic collector\n",
@@ -155,7 +155,7 @@
" \"static_constr_rhs\",\n",
" \"lp_constr_dual_values\",\n",
" \"lp_constr_slacks\",\n",
" ]\n",
" ],\n",
")\n",
"\n",
"with H5File(\"data/multiknapsack/00000.h5\") as h5:\n",
@@ -174,7 +174,7 @@
},
{
"cell_type": "markdown",
"id": "35dc7ce3",
"id": "b6912b56",
"metadata": {
"collapsed": false
},
@@ -185,7 +185,7 @@
},
{
"cell_type": "markdown",
"id": "cc32efd6",
"id": "81fd1d27",
"metadata": {
"collapsed": false
},
@@ -199,7 +199,7 @@
},
{
"cell_type": "markdown",
"id": "2e3ba4fe",
"id": "fdbf5674",
"metadata": {
"collapsed": false
},
@@ -213,8 +213,8 @@
},
{
"cell_type": "code",
"execution_count": 5,
"id": "4944a4a4",
"execution_count": 6,
"id": "85ef526d",
"metadata": {
"collapsed": false
},
@@ -288,7 +288,7 @@
}
],
"source": [
"from miplearn.features.AlvLouWeh2017 import AlvLouWeh2017Extractor\n",
"from miplearn.extractors.AlvLouWeh2017 import AlvLouWeh2017Extractor\n",
"from miplearn.h5 import H5File\n",
"\n",
"# Build the extractor\n",
@@ -296,7 +296,6 @@
"\n",
"# Open previously-created multiknapsack training data\n",
"with H5File(\"data/multiknapsack/00000.h5\") as h5:\n",
"\n",
" # Extract and print variable features\n",
" x1 = ext.get_var_features(h5)\n",
" print(\"x1\", x1.shape, \"\\n\", x1.round(1))"
@@ -304,7 +303,7 @@
},
{
"cell_type": "markdown",
"id": "04eab813",
"id": "3e17c5f8",
"metadata": {
"collapsed": false
},
@@ -335,7 +334,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.9.12"
}
},
"nbformat": 4,

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>3. Feature Extractors &#8212; MIPLearn 0.3</title>
<title>6. Feature Extractors &#8212; MIPLearn 0.3</title>
<link href="../../_static/css/theme.css" rel="stylesheet" />
<link href="../../_static/css/index.c5995385ac14fb8791e8eb36b4908be2.css" rel="stylesheet" />
@@ -24,6 +24,8 @@
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sphinx-book-theme.acff12b8f9c144ce68a297486a2fa670.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/custom.css" />
<link rel="preload" as="script" href="../../_static/js/index.1c5a1a01449ed65a7b51.js">
@@ -38,8 +40,8 @@
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]], "processRefs": false, "processEnvironments": false}})</script>
<link rel="index" title="Index" href="../../genindex/" />
<link rel="search" title="Search" href="../../search/" />
<link rel="next" title="4. Primal Components" href="../primal/" />
<link rel="prev" title="2. Training Data Collectors" href="../collectors/" />
<link rel="next" title="7. Primal Components" href="../primal/" />
<link rel="prev" title="5. Training Data Collectors" href="../collectors/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
@@ -68,6 +70,28 @@
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
<div class="bd-toc-item active">
<p class="caption">
<span class="caption-text">
Tutorials
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-pyomo/">
1. Getting started (Pyomo)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-gurobipy/">
2. Getting started (Gurobipy)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-jump/">
3. Getting started (JuMP)
</a>
</li>
</ul>
<p class="caption">
<span class="caption-text">
User Guide
</span>
@@ -75,59 +99,59 @@
<ul class="current nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../problems/">
1. Benchmark Problems
4. Benchmark Problems
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../collectors/">
2. Training Data Collectors
5. Training Data Collectors
</a>
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
3. Feature Extractors
6. Feature Extractors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../primal/">
4. Primal Components
7. Primal Components
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../solvers/">
5. Solvers
8. Solvers
</a>
</li>
</ul>
<p class="caption">
<span class="caption-text">
API Reference
Python API Reference
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../../api/problems/">
6. Benchmark Problems
9. Benchmark Problems
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/collectors/">
7. Collectors &amp; Extractors
10. Collectors &amp; Extractors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/components/">
8. Components
11. Components
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/solvers/">
9. Solvers
12. Solvers
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/helpers/">
10. Helpers
13. Helpers
</a>
</li>
</ul>
@@ -199,12 +223,12 @@
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Overview">
3.1. Overview
6.1. Overview
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#H5FieldsExtractor">
3.2. H5FieldsExtractor
6.2. H5FieldsExtractor
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -216,7 +240,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#AlvLouWeh2017Extractor">
3.3. AlvLouWeh2017Extractor
6.3. AlvLouWeh2017Extractor
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -237,268 +261,11 @@
<div>
<style>
/* CSS for nbsphinx extension */
/* remove conflicting styling from Sphinx themes */
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt *,
div.nbinput.container div.input_area pre,
div.nboutput.container div.output_area pre,
div.nbinput.container div.input_area .highlight,
div.nboutput.container div.output_area .highlight {
border: none;
padding: 0;
margin: 0;
box-shadow: none;
}
div.nbinput.container > div[class*=highlight],
div.nboutput.container > div[class*=highlight] {
margin: 0;
}
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt * {
background: none;
}
div.nboutput.container div.output_area .highlight,
div.nboutput.container div.output_area pre {
background: unset;
}
div.nboutput.container div.output_area div.highlight {
color: unset; /* override Pygments text color */
}
/* avoid gaps between output lines */
div.nboutput.container div[class*=highlight] pre {
line-height: normal;
}
/* input/output containers */
div.nbinput.container,
div.nboutput.container {
display: -webkit-flex;
display: flex;
align-items: flex-start;
margin: 0;
width: 100%;
}
@media (max-width: 540px) {
div.nbinput.container,
div.nboutput.container {
flex-direction: column;
}
}
/* input container */
div.nbinput.container {
padding-top: 5px;
}
/* last container */
div.nblast.container {
padding-bottom: 5px;
}
/* input prompt */
div.nbinput.container div.prompt pre {
color: #307FC1;
}
/* output prompt */
div.nboutput.container div.prompt pre {
color: #BF5B3D;
}
/* all prompts */
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: 4.5ex;
padding-top: 5px;
position: relative;
user-select: none;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: absolute;
right: 0;
margin-right: 0.3ex;
}
@media (max-width: 540px) {
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: unset;
text-align: left;
padding: 0.4em;
}
div.nboutput.container div.prompt.empty {
padding: 0;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: unset;
}
}
/* disable scrollbars and line breaks on prompts */
div.nbinput.container div.prompt pre,
div.nboutput.container div.prompt pre {
overflow: hidden;
white-space: pre;
}
/* input/output area */
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
-webkit-flex: 1;
flex: 1;
overflow: auto;
}
@media (max-width: 540px) {
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
width: 100%;
}
}
/* input area */
div.nbinput.container div.input_area {
border: 1px solid #e0e0e0;
border-radius: 2px;
/*background: #f5f5f5;*/
}
/* override MathJax center alignment in output cells */
div.nboutput.container div[class*=MathJax] {
text-align: left !important;
}
/* override sphinx.ext.imgmath center alignment in output cells */
div.nboutput.container div.math p {
text-align: left;
}
/* standard error */
div.nboutput.container div.output_area.stderr {
background: #fdd;
}
/* ANSI colors */
.ansi-black-fg { color: #3E424D; }
.ansi-black-bg { background-color: #3E424D; }
.ansi-black-intense-fg { color: #282C36; }
.ansi-black-intense-bg { background-color: #282C36; }
.ansi-red-fg { color: #E75C58; }
.ansi-red-bg { background-color: #E75C58; }
.ansi-red-intense-fg { color: #B22B31; }
.ansi-red-intense-bg { background-color: #B22B31; }
.ansi-green-fg { color: #00A250; }
.ansi-green-bg { background-color: #00A250; }
.ansi-green-intense-fg { color: #007427; }
.ansi-green-intense-bg { background-color: #007427; }
.ansi-yellow-fg { color: #DDB62B; }
.ansi-yellow-bg { background-color: #DDB62B; }
.ansi-yellow-intense-fg { color: #B27D12; }
.ansi-yellow-intense-bg { background-color: #B27D12; }
.ansi-blue-fg { color: #208FFB; }
.ansi-blue-bg { background-color: #208FFB; }
.ansi-blue-intense-fg { color: #0065CA; }
.ansi-blue-intense-bg { background-color: #0065CA; }
.ansi-magenta-fg { color: #D160C4; }
.ansi-magenta-bg { background-color: #D160C4; }
.ansi-magenta-intense-fg { color: #A03196; }
.ansi-magenta-intense-bg { background-color: #A03196; }
.ansi-cyan-fg { color: #60C6C8; }
.ansi-cyan-bg { background-color: #60C6C8; }
.ansi-cyan-intense-fg { color: #258F8F; }
.ansi-cyan-intense-bg { background-color: #258F8F; }
.ansi-white-fg { color: #C5C1B4; }
.ansi-white-bg { background-color: #C5C1B4; }
.ansi-white-intense-fg { color: #A1A6B2; }
.ansi-white-intense-bg { background-color: #A1A6B2; }
.ansi-default-inverse-fg { color: #FFFFFF; }
.ansi-default-inverse-bg { background-color: #000000; }
.ansi-bold { font-weight: bold; }
.ansi-underline { text-decoration: underline; }
div.nbinput.container div.input_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight].math,
div.nboutput.container div.output_area.rendered_html,
div.nboutput.container div.output_area > div.output_javascript,
div.nboutput.container div.output_area:not(.rendered_html) > img{
padding: 5px;
margin: 0;
}
/* fix copybtn overflow problem in chromium (needed for 'sphinx_copybutton') */
div.nbinput.container div.input_area > div[class^='highlight'],
div.nboutput.container div.output_area > div[class^='highlight']{
overflow-y: hidden;
}
/* hide copybtn icon on prompts (needed for 'sphinx_copybutton') */
.prompt .copybtn {
display: none;
}
/* Some additional styling taken form the Jupyter notebook CSS */
.jp-RenderedHTMLCommon table,
div.rendered_html table {
border: none;
border-collapse: collapse;
border-spacing: 0;
color: black;
font-size: 12px;
table-layout: fixed;
}
.jp-RenderedHTMLCommon thead,
div.rendered_html thead {
border-bottom: 1px solid black;
vertical-align: bottom;
}
.jp-RenderedHTMLCommon tr,
.jp-RenderedHTMLCommon th,
.jp-RenderedHTMLCommon td,
div.rendered_html tr,
div.rendered_html th,
div.rendered_html td {
text-align: right;
vertical-align: middle;
padding: 0.5em 0.5em;
line-height: normal;
white-space: normal;
max-width: none;
border: none;
}
.jp-RenderedHTMLCommon th,
div.rendered_html th {
font-weight: bold;
}
.jp-RenderedHTMLCommon tbody tr:nth-child(odd),
div.rendered_html tbody tr:nth-child(odd) {
background: #f5f5f5;
}
.jp-RenderedHTMLCommon tbody tr:hover,
div.rendered_html tbody tr:hover {
background: rgba(66, 165, 245, 0.2);
}
</style>
<div class="section" id="Feature-Extractors">
<h1><span class="section-number">3. </span>Feature Extractors<a class="headerlink" href="#Feature-Extractors" title="Permalink to this headline"></a></h1>
<div class="section" id="Feature-Extractors">
<h1><span class="section-number">6. </span>Feature Extractors<a class="headerlink" href="#Feature-Extractors" title="Permalink to this headline"></a></h1>
<p>In the previous page, we introduced <em>training data collectors</em>, which solve the optimization problem and collect raw training data, such as the optimal solution. In this page, we introduce <strong>feature extractors</strong>, which take the raw training data, stored in HDF5 files, and extract relevant information in order to train a machine learning model. We describe the extractors readily available in MIPLearn.</p>
<div class="section" id="Overview">
<h2><span class="section-number">3.1. </span>Overview<a class="headerlink" href="#Overview" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">6.1. </span>Overview<a class="headerlink" href="#Overview" title="Permalink to this headline"></a></h2>
<p>Feature extraction is an important step of the process of building a machine learning model because it helps to reduce the complexity of the data and convert it into a format that is more easily processed. Previous research has proposed converting absolute variable coefficients, for example, into relative values which are invariant to various transformations, such as problem scaling, making them more amenable to learning. Various other transformations have also been described.</p>
<p>In the framework, we treat data collection and feature extraction as two separate steps to accelerate the model development cycle. Specifically, collectors are typically time-consuming, as they often need to solve the problem to optimality, and therefore focus on collecting and storing all data that may or may not be relevant, in its raw format. Feature extractors, on the other hand, focus entirely on filtering the data and improving its representation, and are therefore much faster to run.
Experimenting with new data representations, therefore, can be done without resolving the instances.</p>
@@ -506,13 +273,13 @@ Experimenting with new data representations, therefore, can be done without reso
subset of these methods, if it is known that it will not be used with a machine learning component that requires the other types of features.</p>
</div>
<div class="section" id="H5FieldsExtractor">
<h2><span class="section-number">3.2. </span>H5FieldsExtractor<a class="headerlink" href="#H5FieldsExtractor" title="Permalink to this headline"></a></h2>
<p><a class="reference external" href="#h5fieldsextractor">H5FieldsExtractor</a>, the most simple extractor in MIPLearn, simple extracts data that is already available in the HDF5 file, assembles it into a matrix and returns it as-is. The fields used to build instance, variable and constraint features are user-specified. The class also performs checks to ensure that the shapes of the returned matrices make sense.</p>
<h2><span class="section-number">6.2. </span>H5FieldsExtractor<a class="headerlink" href="#H5FieldsExtractor" title="Permalink to this headline"></a></h2>
<p><a class="reference internal" href="#H5FieldsExtractor"><span class="std std-ref">H5FieldsExtractor</span></a>, the most simple extractor in MIPLearn, simple extracts data that is already available in the HDF5 file, assembles it into a matrix and returns it as-is. The fields used to build instance, variable and constraint features are user-specified. The class also performs checks to ensure that the shapes of the returned matrices make sense.</p>
<div class="section" id="Example">
<h3>Example<a class="headerlink" href="#Example" title="Permalink to this headline"></a></h3>
<p>The example below demonstrates the usage of H5FieldsExtractor in a randomly generated instance of the multi-dimensional knapsack problem.</p>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[1]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[5]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">glob</span> <span class="kn">import</span> <span class="n">glob</span>
@@ -522,12 +289,12 @@ subset of these methods, if it is known that it will not be used with a machine
<span class="kn">from</span> <span class="nn">scipy.stats</span> <span class="kn">import</span> <span class="n">uniform</span><span class="p">,</span> <span class="n">randint</span>
<span class="kn">from</span> <span class="nn">miplearn.collectors.basic</span> <span class="kn">import</span> <span class="n">BasicCollector</span>
<span class="kn">from</span> <span class="nn">miplearn.features.fields</span> <span class="kn">import</span> <span class="n">H5FieldsExtractor</span>
<span class="kn">from</span> <span class="nn">miplearn.extractors.fields</span> <span class="kn">import</span> <span class="n">H5FieldsExtractor</span>
<span class="kn">from</span> <span class="nn">miplearn.h5</span> <span class="kn">import</span> <span class="n">H5File</span>
<span class="kn">from</span> <span class="nn">miplearn.io</span> <span class="kn">import</span> <span class="n">save</span>
<span class="kn">from</span> <span class="nn">miplearn.io</span> <span class="kn">import</span> <span class="n">write_pkl_gz</span>
<span class="kn">from</span> <span class="nn">miplearn.problems.multiknapsack</span> <span class="kn">import</span> <span class="p">(</span>
<span class="n">MultiKnapsackGenerator</span><span class="p">,</span>
<span class="n">build_multiknapsack_model</span>
<span class="n">build_multiknapsack_model</span><span class="p">,</span>
<span class="p">)</span>
<span class="c1"># Set random seed to make example reproducible</span>
@@ -535,7 +302,7 @@ subset of these methods, if it is known that it will not be used with a machine
<span class="c1"># Generate some random multiknapsack instances</span>
<span class="n">rmtree</span><span class="p">(</span><span class="s2">&quot;data/multiknapsack/&quot;</span><span class="p">,</span> <span class="n">ignore_errors</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
<span class="n">save</span><span class="p">(</span>
<span class="n">write_pkl_gz</span><span class="p">(</span>
<span class="n">MultiKnapsackGenerator</span><span class="p">(</span>
<span class="n">n</span><span class="o">=</span><span class="n">randint</span><span class="p">(</span><span class="n">low</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">high</span><span class="o">=</span><span class="mi">11</span><span class="p">),</span>
<span class="n">m</span><span class="o">=</span><span class="n">randint</span><span class="p">(</span><span class="n">low</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span> <span class="n">high</span><span class="o">=</span><span class="mi">6</span><span class="p">),</span>
@@ -547,7 +314,7 @@ subset of these methods, if it is known that it will not be used with a machine
<span class="n">p_jitter</span><span class="o">=</span><span class="n">uniform</span><span class="p">(</span><span class="n">loc</span><span class="o">=</span><span class="mf">0.75</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="mf">0.5</span><span class="p">),</span>
<span class="n">fix_w</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
<span class="p">)</span><span class="o">.</span><span class="n">generate</span><span class="p">(</span><span class="mi">10</span><span class="p">),</span>
<span class="s2">&quot;data/multiknapsack&quot;</span>
<span class="s2">&quot;data/multiknapsack&quot;</span><span class="p">,</span>
<span class="p">)</span>
<span class="c1"># Run the basic collector</span>
@@ -578,7 +345,7 @@ subset of these methods, if it is known that it will not be used with a machine
<span class="s2">&quot;static_constr_rhs&quot;</span><span class="p">,</span>
<span class="s2">&quot;lp_constr_dual_values&quot;</span><span class="p">,</span>
<span class="s2">&quot;lp_constr_slacks&quot;</span><span class="p">,</span>
<span class="p">]</span>
<span class="p">],</span>
<span class="p">)</span>
<span class="k">with</span> <span class="n">H5File</span><span class="p">(</span><span class="s2">&quot;data/multiknapsack/00000.h5&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">h5</span><span class="p">:</span>
@@ -631,16 +398,16 @@ constraint features (5, 3)
</div>
</div>
<div class="section" id="AlvLouWeh2017Extractor">
<h2><span class="section-number">3.3. </span>AlvLouWeh2017Extractor<a class="headerlink" href="#AlvLouWeh2017Extractor" title="Permalink to this headline"></a></h2>
<p>Alvarez, Louveaux and Wehenkel (2017) proposed a set features to describe a particular decision variable in a given node of the branch-and-bound tree, and applied it to the problem of mimicking strong branching decisions. The class <a class="reference external" href="#alvlouweh2017extractor">AlvLouWeh2017Extractor</a> implements a subset of these features (40 out of 64), which are available outside of the branch-and-bound tree. Some features are derived from the static defintion of the problem (i.e. from objective function and
<h2><span class="section-number">6.3. </span>AlvLouWeh2017Extractor<a class="headerlink" href="#AlvLouWeh2017Extractor" title="Permalink to this headline"></a></h2>
<p>Alvarez, Louveaux and Wehenkel (2017) proposed a set features to describe a particular decision variable in a given node of the branch-and-bound tree, and applied it to the problem of mimicking strong branching decisions. The class <a class="reference internal" href="#AlvLouWeh2017Extractor"><span class="std std-ref">AlvLouWeh2017Extractor</span></a> implements a subset of these features (40 out of 64), which are available outside of the branch-and-bound tree. Some features are derived from the static defintion of the problem (i.e. from objective function and
constraint data), while some features are derived from the solution to the LP relaxation. The features have been designed to be: (i) independent of the size of the problem; (ii) invariant with respect to irrelevant problem transformations, such as row and column permutation; and (iii) independent of the scale of the problem. We refer to the paper for a more complete description.</p>
<div class="section" id="id1">
<h3>Example<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h3>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[5]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[6]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">miplearn.features.AlvLouWeh2017</span> <span class="kn">import</span> <span class="n">AlvLouWeh2017Extractor</span>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">miplearn.extractors.AlvLouWeh2017</span> <span class="kn">import</span> <span class="n">AlvLouWeh2017Extractor</span>
<span class="kn">from</span> <span class="nn">miplearn.h5</span> <span class="kn">import</span> <span class="n">H5File</span>
<span class="c1"># Build the extractor</span>
@@ -648,7 +415,6 @@ constraint data), while some features are derived from the solution to the LP re
<span class="c1"># Open previously-created multiknapsack training data</span>
<span class="k">with</span> <span class="n">H5File</span><span class="p">(</span><span class="s2">&quot;data/multiknapsack/00000.h5&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">h5</span><span class="p">:</span>
<span class="c1"># Extract and print variable features</span>
<span class="n">x1</span> <span class="o">=</span> <span class="n">ext</span><span class="o">.</span><span class="n">get_var_features</span><span class="p">(</span><span class="n">h5</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;x1&quot;</span><span class="p">,</span> <span class="n">x1</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span> <span class="s2">&quot;</span><span class="se">\n</span><span class="s2">&quot;</span><span class="p">,</span> <span class="n">x1</span><span class="o">.</span><span class="n">round</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
@@ -740,8 +506,8 @@ x1 (10, 40)
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="../collectors/" title="previous page"><span class="section-number">2. </span>Training Data Collectors</a>
<a class='right-next' id="next-link" href="../primal/" title="next page"><span class="section-number">4. </span>Primal Components</a>
<a class='left-prev' id="prev-link" href="../collectors/" title="previous page"><span class="section-number">5. </span>Training Data Collectors</a>
<a class='right-next' id="next-link" href="../primal/" title="next page"><span class="section-number">7. </span>Primal Components</a>
</div>
@@ -751,7 +517,7 @@ x1 (10, 40)
<div class="container">
<p>
&copy; Copyright 2020-2022, UChicago Argonne, LLC.<br/>
&copy; Copyright 2020-2023, UChicago Argonne, LLC.<br/>
</p>
</div>
</footer>

View File

@@ -60,14 +60,16 @@
},
{
"cell_type": "code",
"execution_count": 3,
"id": "94907996",
"execution_count": 1,
"id": "253adbf4",
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
"\n",
"from sklearn.dummy import DummyClassifier\n",
"from sklearn.neighbors import KNeighborsClassifier\n",
"\n",
@@ -118,15 +120,13 @@
" extractor=H5FieldsExtractor(instance_fields=[\"static_var_obj_coeffs\"]),\n",
" constructor=MergeTopSolutions(k=3, thresholds=[0.25, 0.75]),\n",
" action=EnforceProximity(3),\n",
")"
")\n"
]
},
{
"cell_type": "markdown",
"id": "6b854305",
"metadata": {
"collapsed": false
},
"id": "f194a793",
"metadata": {},
"source": [
"## Independent vars primal component\n",
"\n",
@@ -145,10 +145,13 @@
},
{
"cell_type": "code",
"execution_count": 4,
"id": "f5024983",
"execution_count": 2,
"id": "3fc0b5d1",
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
@@ -157,7 +160,6 @@
"from miplearn.classifiers.singleclass import SingleClassFix\n",
"from miplearn.components.primal.indep import IndependentVarsPrimalComponent\n",
"from miplearn.extractors.AlvLouWeh2017 import AlvLouWeh2017Extractor\n",
"from miplearn.solvers.learning import LearningSolver\n",
"from miplearn.components.primal.actions import SetWarmStart\n",
"\n",
"# Configures a primal component that independently predicts the value of each\n",
@@ -173,15 +175,13 @@
" ),\n",
" extractor=AlvLouWeh2017Extractor(),\n",
" action=SetWarmStart(),\n",
")"
")\n"
]
},
{
"cell_type": "markdown",
"id": "dcb10079",
"metadata": {
"collapsed": false
},
"id": "45107a0c",
"metadata": {},
"source": [
"## Joint vars primal component\n",
"In the previous subsection, we used multiple machine learning models to independently predict the values of the binary decision variables. When these values are correlated, an alternative approach is to jointly predict the values of all binary variables using a single machine learning model. This strategy is implemented by `JointVarsPrimalComponent`. Compared to the previous ones, this component is much more straightforwad. It simply extracts instance features, using the user-provided feature extractor, then directly trains the user-provided binary classifier (using the `fit` method), without making any copies. The trained classifier is then used to predict entire solutions (using the `predict` method), which are given to the solver using one of the previously discussed methods. In the example below, we illustrate the usage of this component with a simple feed-forward neural network.\n",
@@ -193,10 +193,13 @@
},
{
"cell_type": "code",
"execution_count": 5,
"id": "c98f7eb8",
"execution_count": 3,
"id": "cf9b52dd",
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
@@ -204,7 +207,6 @@
"from sklearn.neural_network import MLPClassifier\n",
"from miplearn.components.primal.joint import JointVarsPrimalComponent\n",
"from miplearn.extractors.fields import H5FieldsExtractor\n",
"from miplearn.solvers.learning import LearningSolver\n",
"from miplearn.components.primal.actions import SetWarmStart\n",
"\n",
"# Configures a primal component that uses a feedforward neural network\n",
@@ -214,7 +216,7 @@
"comp = JointVarsPrimalComponent(\n",
" clf=MLPClassifier(),\n",
" extractor=H5FieldsExtractor(\n",
" instance_fields=['static_var_obj_coeffs'],\n",
" instance_fields=[\"static_var_obj_coeffs\"],\n",
" ),\n",
" action=SetWarmStart(),\n",
")\n",
@@ -225,18 +227,16 @@
"comp = JointVarsPrimalComponent(\n",
" clf=ClassifierChain(SingleClassFix(LogisticRegression())),\n",
" extractor=H5FieldsExtractor(\n",
" instance_fields=['static_var_obj_coeffs'],\n",
" instance_fields=[\"static_var_obj_coeffs\"],\n",
" ),\n",
" action=SetWarmStart(),\n",
")"
")\n"
]
},
{
"cell_type": "markdown",
"id": "92461394",
"metadata": {
"collapsed": false
},
"id": "dddf7be4",
"metadata": {},
"source": [
"## Expert primal component\n",
"\n",
@@ -248,9 +248,12 @@
{
"cell_type": "code",
"execution_count": 4,
"id": "fb7dbdd0",
"id": "9e2e81b9",
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"source": [
@@ -260,15 +263,13 @@
"# Configures an expert primal component, which reads a pre-computed\n",
"# optimal solution from the HDF5 file and provides it to the solver\n",
"# as warm start.\n",
"comp = ExpertPrimalComponent(\n",
" action=SetWarmStart()\n",
")"
"comp = ExpertPrimalComponent(action=SetWarmStart())\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -282,7 +283,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.9.12"
}
},
"nbformat": 4,

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>4. Primal Components &#8212; MIPLearn 0.3</title>
<title>7. Primal Components &#8212; MIPLearn 0.3</title>
<link href="../../_static/css/theme.css" rel="stylesheet" />
<link href="../../_static/css/index.c5995385ac14fb8791e8eb36b4908be2.css" rel="stylesheet" />
@@ -24,6 +24,9 @@
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sphinx-book-theme.acff12b8f9c144ce68a297486a2fa670.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/custom.css" />
<link rel="preload" as="script" href="../../_static/js/index.1c5a1a01449ed65a7b51.js">
@@ -38,8 +41,8 @@
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]], "processRefs": false, "processEnvironments": false}})</script>
<link rel="index" title="Index" href="../../genindex/" />
<link rel="search" title="Search" href="../../search/" />
<link rel="next" title="5. Solvers" href="../solvers/" />
<link rel="prev" title="3. Feature Extractors" href="../features/" />
<link rel="next" title="8. Solvers" href="../solvers/" />
<link rel="prev" title="6. Feature Extractors" href="../features/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
@@ -68,6 +71,28 @@
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
<div class="bd-toc-item active">
<p class="caption">
<span class="caption-text">
Tutorials
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-pyomo/">
1. Getting started (Pyomo)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-gurobipy/">
2. Getting started (Gurobipy)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-jump/">
3. Getting started (JuMP)
</a>
</li>
</ul>
<p class="caption">
<span class="caption-text">
User Guide
</span>
@@ -75,59 +100,59 @@
<ul class="current nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../problems/">
1. Benchmark Problems
4. Benchmark Problems
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../collectors/">
2. Training Data Collectors
5. Training Data Collectors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../features/">
3. Feature Extractors
6. Feature Extractors
</a>
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
4. Primal Components
7. Primal Components
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../solvers/">
5. Solvers
8. Solvers
</a>
</li>
</ul>
<p class="caption">
<span class="caption-text">
API Reference
Python API Reference
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../../api/problems/">
6. Benchmark Problems
9. Benchmark Problems
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/collectors/">
7. Collectors &amp; Extractors
10. Collectors &amp; Extractors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/components/">
8. Components
11. Components
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/solvers/">
9. Solvers
12. Solvers
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/helpers/">
10. Helpers
13. Helpers
</a>
</li>
</ul>
@@ -199,12 +224,12 @@
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Primal-component-actions">
4.1. Primal component actions
7.1. Primal component actions
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Memorizing-primal-component">
4.2. Memorizing primal component
7.2. Memorizing primal component
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -216,7 +241,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Independent-vars-primal-component">
4.3. Independent vars primal component
7.3. Independent vars primal component
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -228,7 +253,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Joint-vars-primal-component">
4.4. Joint vars primal component
7.4. Joint vars primal component
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -240,7 +265,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Expert-primal-component">
4.5. Expert primal component
7.5. Expert primal component
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -261,270 +286,13 @@
<div>
<style>
/* CSS for nbsphinx extension */
/* remove conflicting styling from Sphinx themes */
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt *,
div.nbinput.container div.input_area pre,
div.nboutput.container div.output_area pre,
div.nbinput.container div.input_area .highlight,
div.nboutput.container div.output_area .highlight {
border: none;
padding: 0;
margin: 0;
box-shadow: none;
}
div.nbinput.container > div[class*=highlight],
div.nboutput.container > div[class*=highlight] {
margin: 0;
}
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt * {
background: none;
}
div.nboutput.container div.output_area .highlight,
div.nboutput.container div.output_area pre {
background: unset;
}
div.nboutput.container div.output_area div.highlight {
color: unset; /* override Pygments text color */
}
/* avoid gaps between output lines */
div.nboutput.container div[class*=highlight] pre {
line-height: normal;
}
/* input/output containers */
div.nbinput.container,
div.nboutput.container {
display: -webkit-flex;
display: flex;
align-items: flex-start;
margin: 0;
width: 100%;
}
@media (max-width: 540px) {
div.nbinput.container,
div.nboutput.container {
flex-direction: column;
}
}
/* input container */
div.nbinput.container {
padding-top: 5px;
}
/* last container */
div.nblast.container {
padding-bottom: 5px;
}
/* input prompt */
div.nbinput.container div.prompt pre {
color: #307FC1;
}
/* output prompt */
div.nboutput.container div.prompt pre {
color: #BF5B3D;
}
/* all prompts */
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: 4.5ex;
padding-top: 5px;
position: relative;
user-select: none;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: absolute;
right: 0;
margin-right: 0.3ex;
}
@media (max-width: 540px) {
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: unset;
text-align: left;
padding: 0.4em;
}
div.nboutput.container div.prompt.empty {
padding: 0;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: unset;
}
}
/* disable scrollbars and line breaks on prompts */
div.nbinput.container div.prompt pre,
div.nboutput.container div.prompt pre {
overflow: hidden;
white-space: pre;
}
/* input/output area */
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
-webkit-flex: 1;
flex: 1;
overflow: auto;
}
@media (max-width: 540px) {
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
width: 100%;
}
}
/* input area */
div.nbinput.container div.input_area {
border: 1px solid #e0e0e0;
border-radius: 2px;
/*background: #f5f5f5;*/
}
/* override MathJax center alignment in output cells */
div.nboutput.container div[class*=MathJax] {
text-align: left !important;
}
/* override sphinx.ext.imgmath center alignment in output cells */
div.nboutput.container div.math p {
text-align: left;
}
/* standard error */
div.nboutput.container div.output_area.stderr {
background: #fdd;
}
/* ANSI colors */
.ansi-black-fg { color: #3E424D; }
.ansi-black-bg { background-color: #3E424D; }
.ansi-black-intense-fg { color: #282C36; }
.ansi-black-intense-bg { background-color: #282C36; }
.ansi-red-fg { color: #E75C58; }
.ansi-red-bg { background-color: #E75C58; }
.ansi-red-intense-fg { color: #B22B31; }
.ansi-red-intense-bg { background-color: #B22B31; }
.ansi-green-fg { color: #00A250; }
.ansi-green-bg { background-color: #00A250; }
.ansi-green-intense-fg { color: #007427; }
.ansi-green-intense-bg { background-color: #007427; }
.ansi-yellow-fg { color: #DDB62B; }
.ansi-yellow-bg { background-color: #DDB62B; }
.ansi-yellow-intense-fg { color: #B27D12; }
.ansi-yellow-intense-bg { background-color: #B27D12; }
.ansi-blue-fg { color: #208FFB; }
.ansi-blue-bg { background-color: #208FFB; }
.ansi-blue-intense-fg { color: #0065CA; }
.ansi-blue-intense-bg { background-color: #0065CA; }
.ansi-magenta-fg { color: #D160C4; }
.ansi-magenta-bg { background-color: #D160C4; }
.ansi-magenta-intense-fg { color: #A03196; }
.ansi-magenta-intense-bg { background-color: #A03196; }
.ansi-cyan-fg { color: #60C6C8; }
.ansi-cyan-bg { background-color: #60C6C8; }
.ansi-cyan-intense-fg { color: #258F8F; }
.ansi-cyan-intense-bg { background-color: #258F8F; }
.ansi-white-fg { color: #C5C1B4; }
.ansi-white-bg { background-color: #C5C1B4; }
.ansi-white-intense-fg { color: #A1A6B2; }
.ansi-white-intense-bg { background-color: #A1A6B2; }
.ansi-default-inverse-fg { color: #FFFFFF; }
.ansi-default-inverse-bg { background-color: #000000; }
.ansi-bold { font-weight: bold; }
.ansi-underline { text-decoration: underline; }
div.nbinput.container div.input_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight].math,
div.nboutput.container div.output_area.rendered_html,
div.nboutput.container div.output_area > div.output_javascript,
div.nboutput.container div.output_area:not(.rendered_html) > img{
padding: 5px;
margin: 0;
}
/* fix copybtn overflow problem in chromium (needed for 'sphinx_copybutton') */
div.nbinput.container div.input_area > div[class^='highlight'],
div.nboutput.container div.output_area > div[class^='highlight']{
overflow-y: hidden;
}
/* hide copybtn icon on prompts (needed for 'sphinx_copybutton') */
.prompt .copybtn {
display: none;
}
/* Some additional styling taken form the Jupyter notebook CSS */
.jp-RenderedHTMLCommon table,
div.rendered_html table {
border: none;
border-collapse: collapse;
border-spacing: 0;
color: black;
font-size: 12px;
table-layout: fixed;
}
.jp-RenderedHTMLCommon thead,
div.rendered_html thead {
border-bottom: 1px solid black;
vertical-align: bottom;
}
.jp-RenderedHTMLCommon tr,
.jp-RenderedHTMLCommon th,
.jp-RenderedHTMLCommon td,
div.rendered_html tr,
div.rendered_html th,
div.rendered_html td {
text-align: right;
vertical-align: middle;
padding: 0.5em 0.5em;
line-height: normal;
white-space: normal;
max-width: none;
border: none;
}
.jp-RenderedHTMLCommon th,
div.rendered_html th {
font-weight: bold;
}
.jp-RenderedHTMLCommon tbody tr:nth-child(odd),
div.rendered_html tbody tr:nth-child(odd) {
background: #f5f5f5;
}
.jp-RenderedHTMLCommon tbody tr:hover,
div.rendered_html tbody tr:hover {
background: rgba(66, 165, 245, 0.2);
}
</style>
<div class="section" id="Primal-Components">
<h1><span class="section-number">4. </span>Primal Components<a class="headerlink" href="#Primal-Components" title="Permalink to this headline"></a></h1>
<div class="section" id="Primal-Components">
<h1><span class="section-number">7. </span>Primal Components<a class="headerlink" href="#Primal-Components" title="Permalink to this headline"></a></h1>
<p>In MIPLearn, a <strong>primal component</strong> is class that uses machine learning to predict a (potentially partial) assignment of values to the decision variables of the problem. Predicting high-quality primal solutions may be beneficial, as they allow the MIP solver to prune potentially large portions of the search space. Alternatively, if proof of optimality is not required, the MIP solver can be used to complete the partial solution generated by the machine learning model and and double-check its
feasibility. MIPLearn allows both of these usage patterns.</p>
<p>In this page, we describe the four primal components currently included in MIPLearn, which employ machine learning in different ways. Each component is highly configurable, and accepts an user-provided machine learning model, which it uses for all predictions. Each component can also be configured to provide the solution to the solver in multiple ways, depending on whether proof of optimality is required.</p>
<div class="section" id="Primal-component-actions">
<h2><span class="section-number">4.1. </span>Primal component actions<a class="headerlink" href="#Primal-component-actions" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">7.1. </span>Primal component actions<a class="headerlink" href="#Primal-component-actions" title="Permalink to this headline"></a></h2>
<p>Before presenting the primal components themselves, we briefly discuss the three ways a solution may be provided to the solver. Each approach has benefits and limitations, which we also discuss in this section. All primal components can be configured to use any of the following approaches.</p>
<p>The first approach is to provide the solution to the solver as a <strong>warm start</strong>. This is implemented by the class <a class="reference external" href="SetWarmStart">SetWarmStart</a>. The main advantage is that this method maintains all optimality and feasibility guarantees of the MIP solver, while still providing significant performance benefits for various classes of problems. If the machine learning model is able to predict multiple solutions, it is also possible to set multiple warm starts. In this case, the solver evaluates
each warm start, discards the infeasible ones, then proceeds with the one that has the best objective value. The main disadvantage of this approach, compared to the next two, is that it provides relatively modest speedups for most problem classes, and no speedup at all for many others, even when the machine learning predictions are 100% accurate.</p>
@@ -536,7 +304,7 @@ scratch. The main disadvantage of this approach is that it loses optimality guar
<p>to the problem, where <span class="math notranslate nohighlight">\(k\)</span> is a user-defined parameter, which indicates how many of the predicted variables are allowed to deviate from the machine learning suggestion. The main advantage of this approach, compared to fixing variables, is its tolerance to lower-quality machine learning predictions. Its main disadvantage is that it typically leads to smaller speedups, especially for larger values of <span class="math notranslate nohighlight">\(k\)</span>. This approach also loses optimality guarantees.</p>
</div>
<div class="section" id="Memorizing-primal-component">
<h2><span class="section-number">4.2. </span>Memorizing primal component<a class="headerlink" href="#Memorizing-primal-component" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">7.2. </span>Memorizing primal component<a class="headerlink" href="#Memorizing-primal-component" title="Permalink to this headline"></a></h2>
<p>A simple machine learning strategy for the prediction of primal solutions is to memorize all distinct solutions seen during training, then try to predict, during inference time, which of those memorized solutions are most likely to be feasible and to provide a good objective value for the current instance. The most promising solutions may alternatively be combined into a single partial solution, which is then provided to the MIP solver. Both variations of this strategy are implemented by the
<code class="docutils literal notranslate"><span class="pre">MemorizingPrimalComponent</span></code> class. Note that it is only applicable if the problem size, and in fact if the meaning of the decision variables, remains the same across problem instances.</p>
<p>More precisely, let <span class="math notranslate nohighlight">\(I_1,\ldots,I_n\)</span> be the training instances, and let <span class="math notranslate nohighlight">\(\bar{x}^1,\ldots,\bar{x}^n\)</span> be their respective optimal solutions. Given a new instance <span class="math notranslate nohighlight">\(I_{n+1}\)</span>, <code class="docutils literal notranslate"><span class="pre">MemorizingPrimalComponent</span></code> expects a user-provided binary classifier that assigns (through the <code class="docutils literal notranslate"><span class="pre">predict_proba</span></code> method, following scikit-learns conventions) a score <span class="math notranslate nohighlight">\(\delta_i\)</span> to each solution <span class="math notranslate nohighlight">\(\bar{x}^i\)</span>, such that solutions with higher score are more likely to be good solutions for
@@ -558,15 +326,15 @@ Then it computes, for each binary decision variable <span class="math notranslat
</li>
</ol>
<p>The above specification of <code class="docutils literal notranslate"><span class="pre">MemorizingPrimalComponent</span></code> is meant to be as general as possible. Simpler strategies can be implemented by configuring this component in specific ways. For example, a simpler approach employed in the literature is to collect all optimal solutions, then provide the entire list of solutions to the solver as warm starts, without any filtering or post-processing. This strategy can be implemented with <code class="docutils literal notranslate"><span class="pre">MemorizingPrimalComponent</span></code> by using a model that returns a constant
value for all solutions (e.g. <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.dummy.DummyClassifier.html">scikit-learns DummyClassifier</a>), then selecting the top <span class="math notranslate nohighlight">\(n\)</span> (instead of <span class="math notranslate nohighlight">\(k\)</span>) solutions. See example below. Another simple approach is taking the solution to the most similar instance, and using it, by itself, as a warm start. This can be implemented by using a model that computes distances between the current instance and the training ones (e.g. <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html">scikit-learns
value for all solutions (e.g. <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.dummy.DummyClassifier.html">scikit-learns DummyClassifier</a>), then selecting the top <span class="math notranslate nohighlight">\(n\)</span> (instead of <span class="math notranslate nohighlight">\(k\)</span>) solutions. See example below. Another simple approach is taking the solution to the most similar instance, and using it, by itself, as a warm start. This can be implemented by using a model that computes distances between the current instance and the training ones (e.g. <a class="reference external" href="https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.KNeighborsClassifier.html">scikit-learns
KNeighborsClassifier</a>), then select the solution to the nearest one. See also example below. More complex strategies, of course, can also be configured.</p>
<div class="section" id="Examples">
<h3>Examples<a class="headerlink" href="#Examples" title="Permalink to this headline"></a></h3>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[3]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[1]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><br/><span></span><span class="kn">from</span> <span class="nn">sklearn.dummy</span> <span class="kn">import</span> <span class="n">DummyClassifier</span>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">sklearn.dummy</span> <span class="kn">import</span> <span class="n">DummyClassifier</span>
<span class="kn">from</span> <span class="nn">sklearn.neighbors</span> <span class="kn">import</span> <span class="n">KNeighborsClassifier</span>
<span class="kn">from</span> <span class="nn">miplearn.components.primal.actions</span> <span class="kn">import</span> <span class="p">(</span>
@@ -617,13 +385,13 @@ KNeighborsClassifier</a>), then select the solution to the nearest one. See also
<span class="n">constructor</span><span class="o">=</span><span class="n">MergeTopSolutions</span><span class="p">(</span><span class="n">k</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">thresholds</span><span class="o">=</span><span class="p">[</span><span class="mf">0.25</span><span class="p">,</span> <span class="mf">0.75</span><span class="p">]),</span>
<span class="n">action</span><span class="o">=</span><span class="n">EnforceProximity</span><span class="p">(</span><span class="mi">3</span><span class="p">),</span>
<span class="p">)</span>
</pre></div>
<br/></pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="Independent-vars-primal-component">
<h2><span class="section-number">4.3. </span>Independent vars primal component<a class="headerlink" href="#Independent-vars-primal-component" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">7.3. </span>Independent vars primal component<a class="headerlink" href="#Independent-vars-primal-component" title="Permalink to this headline"></a></h2>
<p>Instead of memorizing previously-seen primal solutions, it is also natural to use machine learning models to directly predict the values of the decision variables, constructing a solution from scratch. This approach has the benefit of potentially constructing novel high-quality solutions, never observed in the training data. Two variations of this strategy are supported by MIPLearn: (i) predicting the values of the decision variables independently, using multiple ML models; or (ii) predicting
the values jointly, with a single model. We describe the first variation in this section, and the second variation in the next section.</p>
<p>Let <span class="math notranslate nohighlight">\(I_1,\ldots,I_n\)</span> be the training instances, and let <span class="math notranslate nohighlight">\(\bar{x}^1,\ldots,\bar{x}^n\)</span> be their respective optimal solutions. For each binary decision variable <span class="math notranslate nohighlight">\(x_j\)</span>, the component <code class="docutils literal notranslate"><span class="pre">IndependentVarsPrimalComponent</span></code> creates a copy of a user-provided binary classifier and trains it to predict the optimal value of <span class="math notranslate nohighlight">\(x_j\)</span>, given <span class="math notranslate nohighlight">\(\bar{x}^1_j,\ldots,\bar{x}^n_j\)</span> as training labels. The features provided to the model are the variable features computed by an user-provided
@@ -638,7 +406,7 @@ probability of the value being zero or one (using the <code class="docutils lite
<div class="section" id="id1">
<h3>Examples<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h3>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[4]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[2]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">sklearn.linear_model</span> <span class="kn">import</span> <span class="n">LogisticRegression</span>
@@ -646,7 +414,6 @@ probability of the value being zero or one (using the <code class="docutils lite
<span class="kn">from</span> <span class="nn">miplearn.classifiers.singleclass</span> <span class="kn">import</span> <span class="n">SingleClassFix</span>
<span class="kn">from</span> <span class="nn">miplearn.components.primal.indep</span> <span class="kn">import</span> <span class="n">IndependentVarsPrimalComponent</span>
<span class="kn">from</span> <span class="nn">miplearn.extractors.AlvLouWeh2017</span> <span class="kn">import</span> <span class="n">AlvLouWeh2017Extractor</span>
<span class="kn">from</span> <span class="nn">miplearn.solvers.learning</span> <span class="kn">import</span> <span class="n">LearningSolver</span>
<span class="kn">from</span> <span class="nn">miplearn.components.primal.actions</span> <span class="kn">import</span> <span class="n">SetWarmStart</span>
<span class="c1"># Configures a primal component that independently predicts the value of each</span>
@@ -663,13 +430,13 @@ probability of the value being zero or one (using the <code class="docutils lite
<span class="n">extractor</span><span class="o">=</span><span class="n">AlvLouWeh2017Extractor</span><span class="p">(),</span>
<span class="n">action</span><span class="o">=</span><span class="n">SetWarmStart</span><span class="p">(),</span>
<span class="p">)</span>
</pre></div>
<br/></pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="Joint-vars-primal-component">
<h2><span class="section-number">4.4. </span>Joint vars primal component<a class="headerlink" href="#Joint-vars-primal-component" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">7.4. </span>Joint vars primal component<a class="headerlink" href="#Joint-vars-primal-component" title="Permalink to this headline"></a></h2>
<p>In the previous subsection, we used multiple machine learning models to independently predict the values of the binary decision variables. When these values are correlated, an alternative approach is to jointly predict the values of all binary variables using a single machine learning model. This strategy is implemented by <code class="docutils literal notranslate"><span class="pre">JointVarsPrimalComponent</span></code>. Compared to the previous ones, this component is much more straightforwad. It simply extracts instance features, using the user-provided feature
extractor, then directly trains the user-provided binary classifier (using the <code class="docutils literal notranslate"><span class="pre">fit</span></code> method), without making any copies. The trained classifier is then used to predict entire solutions (using the <code class="docutils literal notranslate"><span class="pre">predict</span></code> method), which are given to the solver using one of the previously discussed methods. In the example below, we illustrate the usage of this component with a simple feed-forward neural network.</p>
<p><code class="docutils literal notranslate"><span class="pre">JointVarsPrimalComponent</span></code> can also be used to implement strategies that use multiple machine learning models, but not indepedently. For example, a common strategy in multioutput prediction is building a <em>classifier chain</em>. In this approach, the first decision variable is predicted using the instance features alone; but the <span class="math notranslate nohighlight">\(n\)</span>-th decision variable is predicted using the instance features plus the predicted values of the <span class="math notranslate nohighlight">\(n-1\)</span> previous variables. This can be easily implemented
@@ -677,14 +444,13 @@ using scikit-learns <code class="docutils literal notranslate"><span class="p
<div class="section" id="id2">
<h3>Examples<a class="headerlink" href="#id2" title="Permalink to this headline"></a></h3>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[5]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[3]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">sklearn.multioutput</span> <span class="kn">import</span> <span class="n">ClassifierChain</span>
<span class="kn">from</span> <span class="nn">sklearn.neural_network</span> <span class="kn">import</span> <span class="n">MLPClassifier</span>
<span class="kn">from</span> <span class="nn">miplearn.components.primal.joint</span> <span class="kn">import</span> <span class="n">JointVarsPrimalComponent</span>
<span class="kn">from</span> <span class="nn">miplearn.extractors.fields</span> <span class="kn">import</span> <span class="n">H5FieldsExtractor</span>
<span class="kn">from</span> <span class="nn">miplearn.solvers.learning</span> <span class="kn">import</span> <span class="n">LearningSolver</span>
<span class="kn">from</span> <span class="nn">miplearn.components.primal.actions</span> <span class="kn">import</span> <span class="n">SetWarmStart</span>
<span class="c1"># Configures a primal component that uses a feedforward neural network</span>
@@ -694,7 +460,7 @@ using scikit-learns <code class="docutils literal notranslate"><span class="p
<span class="n">comp</span> <span class="o">=</span> <span class="n">JointVarsPrimalComponent</span><span class="p">(</span>
<span class="n">clf</span><span class="o">=</span><span class="n">MLPClassifier</span><span class="p">(),</span>
<span class="n">extractor</span><span class="o">=</span><span class="n">H5FieldsExtractor</span><span class="p">(</span>
<span class="n">instance_fields</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;static_var_obj_coeffs&#39;</span><span class="p">],</span>
<span class="n">instance_fields</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;static_var_obj_coeffs&quot;</span><span class="p">],</span>
<span class="p">),</span>
<span class="n">action</span><span class="o">=</span><span class="n">SetWarmStart</span><span class="p">(),</span>
<span class="p">)</span>
@@ -705,17 +471,17 @@ using scikit-learns <code class="docutils literal notranslate"><span class="p
<span class="n">comp</span> <span class="o">=</span> <span class="n">JointVarsPrimalComponent</span><span class="p">(</span>
<span class="n">clf</span><span class="o">=</span><span class="n">ClassifierChain</span><span class="p">(</span><span class="n">SingleClassFix</span><span class="p">(</span><span class="n">LogisticRegression</span><span class="p">())),</span>
<span class="n">extractor</span><span class="o">=</span><span class="n">H5FieldsExtractor</span><span class="p">(</span>
<span class="n">instance_fields</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;static_var_obj_coeffs&#39;</span><span class="p">],</span>
<span class="n">instance_fields</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;static_var_obj_coeffs&quot;</span><span class="p">],</span>
<span class="p">),</span>
<span class="n">action</span><span class="o">=</span><span class="n">SetWarmStart</span><span class="p">(),</span>
<span class="p">)</span>
</pre></div>
<br/></pre></div>
</div>
</div>
</div>
</div>
<div class="section" id="Expert-primal-component">
<h2><span class="section-number">4.5. </span>Expert primal component<a class="headerlink" href="#Expert-primal-component" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">7.5. </span>Expert primal component<a class="headerlink" href="#Expert-primal-component" title="Permalink to this headline"></a></h2>
<p>Before spending time and effort choosing a machine learning strategy and tweaking its parameters, it is usually a good idea to evaluate what would be the performance impact of the model if its predictions were 100% accurate. This is especially important for the prediction of warm starts, since they are not always very beneficial. To simplify this task, MIPLearn provides <code class="docutils literal notranslate"><span class="pre">ExpertPrimalComponent</span></code>, a component which simply loads the optimal solution from the HDF5 file, assuming that it has already
been computed, then directly provides it to the solver using one of the available methods. This component is useful in benchmarks, to evaluate how close to the best theoretical performance the machine learning components are.</p>
<div class="section" id="Example">
@@ -730,10 +496,8 @@ been computed, then directly provides it to the solver using one of the availabl
<span class="c1"># Configures an expert primal component, which reads a pre-computed</span>
<span class="c1"># optimal solution from the HDF5 file and provides it to the solver</span>
<span class="c1"># as warm start.</span>
<span class="n">comp</span> <span class="o">=</span> <span class="n">ExpertPrimalComponent</span><span class="p">(</span>
<span class="n">action</span><span class="o">=</span><span class="n">SetWarmStart</span><span class="p">()</span>
<span class="p">)</span>
</pre></div>
<span class="n">comp</span> <span class="o">=</span> <span class="n">ExpertPrimalComponent</span><span class="p">(</span><span class="n">action</span><span class="o">=</span><span class="n">SetWarmStart</span><span class="p">())</span>
<br/></pre></div>
</div>
</div>
</div>
@@ -746,8 +510,8 @@ been computed, then directly provides it to the solver using one of the availabl
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="../features/" title="previous page"><span class="section-number">3. </span>Feature Extractors</a>
<a class='right-next' id="next-link" href="../solvers/" title="next page"><span class="section-number">5. </span>Solvers</a>
<a class='left-prev' id="prev-link" href="../features/" title="previous page"><span class="section-number">6. </span>Feature Extractors</a>
<a class='right-next' id="next-link" href="../solvers/" title="next page"><span class="section-number">8. </span>Solvers</a>
</div>
@@ -757,7 +521,7 @@ been computed, then directly provides it to the solver using one of the availabl
<div class="container">
<p>
&copy; Copyright 2020-2022, UChicago Argonne, LLC.<br/>
&copy; Copyright 2020-2023, UChicago Argonne, LLC.<br/>
</p>
</div>
</footer>

View File

@@ -18,7 +18,7 @@
},
{
"cell_type": "markdown",
"id": "fbfe86db",
"id": "1ba30e52",
"metadata": {
"collapsed": false
},
@@ -64,7 +64,7 @@
},
{
"cell_type": "markdown",
"id": "0dcc6210",
"id": "218add9f",
"metadata": {
"collapsed": false
},
@@ -85,7 +85,7 @@
},
{
"cell_type": "markdown",
"id": "3e09abef",
"id": "3ffe5c46",
"metadata": {
"collapsed": false
},
@@ -103,7 +103,7 @@
},
{
"cell_type": "markdown",
"id": "c48da99f",
"id": "fd6cb059",
"metadata": {
"collapsed": false
},
@@ -134,9 +134,11 @@
"8 [ 8.47 21.9 16.58 15.37 3.76 3.91 1.57 20.57 14.76 18.61] 94.58\n",
"9 [ 8.57 22.77 17.06 16.25 4.14 4. 1.56 22.97 14.09 19.09] 100.79\n",
"\n",
"Restricted license - for non-production use only - expires 2023-10-25\n",
"Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)\n",
"Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)\n",
"\n",
"CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]\n",
"Thread count: 16 physical cores, 32 logical processors, using up to 32 threads\n",
"\n",
"Optimize a model with 20 rows, 110 columns and 210 nonzeros\n",
"Model fingerprint: 0x1ff9913f\n",
"Variable types: 0 continuous, 110 integer (110 binary)\n",
@@ -160,7 +162,7 @@
"H 0 0 2.0000000 1.27484 36.3% - 0s\n",
" 0 0 1.27484 0 4 2.00000 1.27484 36.3% - 0s\n",
"\n",
"Explored 1 nodes (38 simplex iterations) in 0.00 seconds (0.00 work units)\n",
"Explored 1 nodes (38 simplex iterations) in 0.01 seconds (0.00 work units)\n",
"Thread count was 32 (of 32 available processors)\n",
"\n",
"Solution count 3: 2 4 5 \n",
@@ -168,6 +170,14 @@
"Optimal solution found (tolerance 1.00e-04)\n",
"Best objective 2.000000000000e+00, best bound 2.000000000000e+00, gap 0.0000%\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/axavier/.conda/envs/miplearn2/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
"source": [
@@ -195,7 +205,7 @@
"\n",
"# Optimize first instance\n",
"model = build_binpack_model(data[0])\n",
"model.optimize()"
"model.optimize()\n"
]
},
{
@@ -224,7 +234,7 @@
},
{
"cell_type": "markdown",
"id": "021bbcef",
"id": "307ab9bf",
"metadata": {
"collapsed": false
},
@@ -294,7 +304,7 @@
},
{
"cell_type": "markdown",
"id": "bfcb9910",
"id": "5caf77ba",
"metadata": {
"collapsed": false
},
@@ -323,8 +333,11 @@
"capacities\n",
" [1310. 988. 1004. 1269. 1007.]\n",
"\n",
"Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)\n",
"Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)\n",
"\n",
"CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]\n",
"Thread count: 16 physical cores, 32 logical processors, using up to 32 threads\n",
"\n",
"Optimize a model with 5 rows, 10 columns and 50 nonzeros\n",
"Model fingerprint: 0xaf3ac15e\n",
"Variable types: 0 continuous, 10 integer (10 binary)\n",
@@ -350,7 +363,7 @@
"Cutting planes:\n",
" Cover: 1\n",
"\n",
"Explored 1 nodes (4 simplex iterations) in 0.00 seconds (0.00 work units)\n",
"Explored 1 nodes (4 simplex iterations) in 0.01 seconds (0.00 work units)\n",
"Thread count was 32 (of 32 available processors)\n",
"\n",
"Solution count 2: -1279 -804 \n",
@@ -394,7 +407,7 @@
"\n",
"# Build model and optimize\n",
"model = build_multiknapsack_model(data[0])\n",
"model.optimize()"
"model.optimize()\n"
]
},
{
@@ -459,7 +472,7 @@
},
{
"cell_type": "markdown",
"id": "f58d88e5",
"id": "838ef9d8",
"metadata": {
"collapsed": false
},
@@ -492,8 +505,11 @@
"demands = [6.12 1.39 2.92 3.66 4.56 7.85 2. 5.14 5.92 0.46]\n",
"capacities = [151.89 42.63 16.26 237.22 241.41 202.1 76.15 24.42 171.06 110.04]\n",
"\n",
"Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)\n",
"Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)\n",
"\n",
"CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]\n",
"Thread count: 16 physical cores, 32 logical processors, using up to 32 threads\n",
"\n",
"Optimize a model with 21 rows, 110 columns and 220 nonzeros\n",
"Model fingerprint: 0x8d8d9346\n",
"Variable types: 0 continuous, 110 integer (110 binary)\n",
@@ -526,7 +542,7 @@
" 0 0 86.06884 0 15 93.92000 86.06884 8.36% - 0s\n",
"* 0 0 0 91.2300000 91.23000 0.00% - 0s\n",
"\n",
"Explored 1 nodes (60 simplex iterations) in 0.01 seconds (0.00 work units)\n",
"Explored 1 nodes (70 simplex iterations) in 0.02 seconds (0.00 work units)\n",
"Thread count was 32 (of 32 available processors)\n",
"\n",
"Solution count 10: 91.23 93.92 93.98 ... 368.79\n",
@@ -568,7 +584,7 @@
"\n",
"# Build and optimize model\n",
"model = build_pmedian_model(data[0])\n",
"model.optimize()"
"model.optimize()\n"
]
},
{
@@ -583,7 +599,7 @@
},
{
"cell_type": "markdown",
"id": "5e02b717",
"id": "96a26e2d",
"metadata": {
"collapsed": false
},
@@ -658,8 +674,11 @@
"costs [1044.58 850.13 1014.5 944.83 697.9 971.87 213.49 220.98 70.23\n",
" 425.33]\n",
"\n",
"Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)\n",
"Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)\n",
"\n",
"CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]\n",
"Thread count: 16 physical cores, 32 logical processors, using up to 32 threads\n",
"\n",
"Optimize a model with 5 rows, 10 columns and 28 nonzeros\n",
"Model fingerprint: 0xe5c2d4fa\n",
"Variable types: 0 continuous, 10 integer (10 binary)\n",
@@ -686,7 +705,7 @@
"source": [
"import numpy as np\n",
"from scipy.stats import uniform, randint\n",
"from miplearn.problems.setcover import SetCoverGenerator, build_setcover_model\n",
"from miplearn.problems.setcover import SetCoverGenerator, build_setcover_model_gurobipy\n",
"\n",
"# Set random seed, to make example reproducible\n",
"np.random.seed(42)\n",
@@ -710,8 +729,8 @@
"print()\n",
"\n",
"# Build and optimize model\n",
"model = build_setcover_model(data[0])\n",
"model.optimize()"
"model = build_setcover_model_gurobipy(data[0])\n",
"model.optimize()\n"
]
},
{
@@ -726,7 +745,7 @@
},
{
"cell_type": "markdown",
"id": "fe2d24e5",
"id": "7c5d228d",
"metadata": {
"collapsed": false
},
@@ -738,7 +757,7 @@
},
{
"cell_type": "markdown",
"id": "679ae3f5",
"id": "7361cea0",
"metadata": {
"collapsed": false
},
@@ -757,7 +776,7 @@
},
{
"cell_type": "markdown",
"id": "66306263",
"id": "c32306f4",
"metadata": {
"collapsed": false
},
@@ -775,7 +794,7 @@
{
"cell_type": "code",
"execution_count": 5,
"id": "9d0ee846",
"id": "4607dbda",
"metadata": {
"collapsed": false
},
@@ -793,8 +812,11 @@
"costs [1044.58 850.13 1014.5 944.83 697.9 971.87 213.49 220.98 70.23\n",
" 425.33]\n",
"\n",
"Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)\n",
"Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)\n",
"\n",
"CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]\n",
"Thread count: 16 physical cores, 32 logical processors, using up to 32 threads\n",
"\n",
"Optimize a model with 5 rows, 10 columns and 28 nonzeros\n",
"Model fingerprint: 0x4ee91388\n",
"Variable types: 0 continuous, 10 integer (10 binary)\n",
@@ -847,7 +869,7 @@
"\n",
"# Build and optimize model\n",
"model = build_setpack_model(data[0])\n",
"model.optimize()"
"model.optimize()\n"
]
},
{
@@ -866,7 +888,7 @@
},
{
"cell_type": "markdown",
"id": "31bc4be9",
"id": "93235cdd",
"metadata": {
"collapsed": false
},
@@ -883,7 +905,7 @@
},
{
"cell_type": "markdown",
"id": "135f311f",
"id": "90b9e623",
"metadata": {
"collapsed": false
},
@@ -902,7 +924,7 @@
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 6,
"id": "0f996e99-0ec9-472b-be8a-30c9b8556931",
"metadata": {},
"outputs": [
@@ -914,8 +936,11 @@
"weights[0] [37.45 95.07 73.2 59.87 15.6 15.6 5.81 86.62 60.11 70.81]\n",
"weights[1] [ 2.06 96.99 83.24 21.23 18.18 18.34 30.42 52.48 43.19 29.12]\n",
"\n",
"Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)\n",
"Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)\n",
"\n",
"CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]\n",
"Thread count: 16 physical cores, 32 logical processors, using up to 32 threads\n",
"\n",
"Optimize a model with 10 rows, 10 columns and 24 nonzeros\n",
"Model fingerprint: 0xf4c21689\n",
"Variable types: 0 continuous, 10 integer (10 binary)\n",
@@ -937,7 +962,7 @@
"\n",
" 0 0 infeasible 0 -219.14000 -219.14000 0.00% - 0s\n",
"\n",
"Explored 1 nodes (4 simplex iterations) in 0.00 seconds (0.00 work units)\n",
"Explored 1 nodes (4 simplex iterations) in 0.01 seconds (0.00 work units)\n",
"Thread count was 32 (of 32 available processors)\n",
"\n",
"Solution count 1: -219.14 \n",
@@ -952,7 +977,10 @@
"import random\n",
"import numpy as np\n",
"from scipy.stats import uniform, randint\n",
"from miplearn.problems.stab import MaxWeightStableSetGenerator, build_stab_model\n",
"from miplearn.problems.stab import (\n",
" MaxWeightStableSetGenerator,\n",
" build_stab_model_gurobipy,\n",
")\n",
"\n",
"# Set random seed to make example reproducible\n",
"random.seed(42)\n",
@@ -974,8 +1002,8 @@
"print()\n",
"\n",
"# Load and optimize the first instance\n",
"model = build_stab_model(data[0])\n",
"model.optimize()"
"model = build_stab_model_gurobipy(data[0])\n",
"model.optimize()\n"
]
},
{
@@ -990,7 +1018,7 @@
},
{
"cell_type": "markdown",
"id": "4074551b",
"id": "aa307ff0",
"metadata": {
"collapsed": false
},
@@ -1002,7 +1030,7 @@
},
{
"cell_type": "markdown",
"id": "5672fbab",
"id": "a5436195",
"metadata": {
"collapsed": false
},
@@ -1022,7 +1050,7 @@
},
{
"cell_type": "markdown",
"id": "257111e2",
"id": "df26c9f5",
"metadata": {
"collapsed": false
},
@@ -1042,7 +1070,7 @@
},
{
"cell_type": "markdown",
"id": "3c20e302",
"id": "0fd000fe",
"metadata": {
"collapsed": false
},
@@ -1052,8 +1080,8 @@
},
{
"cell_type": "code",
"execution_count": 32,
"id": "e08346b5",
"execution_count": 7,
"id": "6ee78519",
"metadata": {
"collapsed": false
},
@@ -1086,8 +1114,11 @@
" [ 668. 446. 317. 648. 469. 752. 394. 286. 274. 0.]]\n",
"\n",
"Set parameter LazyConstraints to value 1\n",
"Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)\n",
"Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)\n",
"\n",
"CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]\n",
"Thread count: 16 physical cores, 32 logical processors, using up to 32 threads\n",
"\n",
"Optimize a model with 10 rows, 45 columns and 90 nonzeros\n",
"Model fingerprint: 0x719675e5\n",
"Variable types: 0 continuous, 45 integer (45 binary)\n",
@@ -1118,7 +1149,7 @@
"Optimal solution found (tolerance 1.00e-04)\n",
"Best objective 2.921000000000e+03, best bound 2.921000000000e+03, gap 0.0000%\n",
"\n",
"User-callback calls 100, time in user-callback 0.00 sec\n"
"User-callback calls 106, time in user-callback 0.00 sec\n"
]
}
],
@@ -1150,7 +1181,7 @@
"\n",
"# Load and optimize the first instance\n",
"model = build_tsp_model(data[0])\n",
"model.optimize()"
"model.optimize()\n"
]
},
{
@@ -1165,7 +1196,7 @@
},
{
"cell_type": "markdown",
"id": "b18b10c9",
"id": "fd30f83e",
"metadata": {
"collapsed": false
},
@@ -1184,7 +1215,7 @@
},
{
"cell_type": "markdown",
"id": "12739207",
"id": "1da000b8",
"metadata": {
"collapsed": false
},
@@ -1220,7 +1251,7 @@
},
{
"cell_type": "markdown",
"id": "b5d85554",
"id": "721f7b0c",
"metadata": {
"collapsed": false
},
@@ -1237,7 +1268,7 @@
},
{
"cell_type": "markdown",
"id": "a2f9e098",
"id": "f49a5e24",
"metadata": {
"collapsed": false
},
@@ -1256,7 +1287,7 @@
},
{
"cell_type": "markdown",
"id": "09e98292",
"id": "cae4f51a",
"metadata": {
"collapsed": false
},
@@ -1267,7 +1298,7 @@
{
"cell_type": "code",
"execution_count": 8,
"id": "e7c16609",
"id": "2d7295e0",
"metadata": {
"collapsed": false
},
@@ -1302,8 +1333,11 @@
" 828.28 775.18 834.99 959.76 865.72 1193.52 1058.92 985.19 893.92\n",
" 962.16 781.88 723.15 639.04 602.4 787.02]\n",
"\n",
"Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)\n",
"Thread count: 6 physical cores, 12 logical processors, using up to 12 threads\n",
"Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)\n",
"\n",
"CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]\n",
"Thread count: 16 physical cores, 32 logical processors, using up to 32 threads\n",
"\n",
"Optimize a model with 578 rows, 360 columns and 2128 nonzeros\n",
"Model fingerprint: 0x4dc1c661\n",
"Variable types: 120 continuous, 240 integer (240 binary)\n",
@@ -1313,22 +1347,22 @@
" Bounds range [1e+00, 1e+00]\n",
" RHS range [1e+00, 1e+03]\n",
"Presolve removed 244 rows and 131 columns\n",
"Presolve time: 0.01s\n",
"Presolve time: 0.02s\n",
"Presolved: 334 rows, 229 columns, 842 nonzeros\n",
"Variable types: 116 continuous, 113 integer (113 binary)\n",
"Found heuristic solution: objective 441426.66550\n",
"Found heuristic solution: objective 440662.46430\n",
"Found heuristic solution: objective 429461.97680\n",
"Found heuristic solution: objective 374043.64040\n",
"\n",
"Root relaxation: objective 3.361348e+05, 139 iterations, 0.00 seconds (0.00 work units)\n",
"Root relaxation: objective 3.361348e+05, 142 iterations, 0.00 seconds (0.00 work units)\n",
"\n",
" Nodes | Current Node | Objective Bounds | Work\n",
" Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time\n",
"\n",
" 0 0 336134.820 0 18 374043.640 336134.820 10.1% - 0s\n",
"H 0 0 368600.14450 336134.820 8.81% - 0s\n",
"H 0 0 364721.76610 364721.766 0.00% - 0s\n",
" 0 0 - 0 364721.766 364721.766 0.00% - 0s\n",
"H 0 0 364721.76610 336134.820 7.84% - 0s\n",
" 0 0 cutoff 0 364721.766 364721.766 0.00% - 0s\n",
"\n",
"Cutting planes:\n",
" Gomory: 3\n",
@@ -1340,10 +1374,10 @@
" RLT: 1\n",
" Relax-and-lift: 7\n",
"\n",
"Explored 1 nodes (232 simplex iterations) in 0.04 seconds (0.02 work units)\n",
"Thread count was 12 (of 12 available processors)\n",
"Explored 1 nodes (234 simplex iterations) in 0.04 seconds (0.02 work units)\n",
"Thread count was 32 (of 32 available processors)\n",
"\n",
"Solution count 5: 364722 368600 374044 ... 441427\n",
"Solution count 5: 364722 368600 374044 ... 440662\n",
"\n",
"Optimal solution found (tolerance 1.00e-04)\n",
"Best objective 3.647217661000e+05, best bound 3.647217661000e+05, gap 0.0000%\n"
@@ -1391,7 +1425,7 @@
"\n",
"# Load and optimize the first instance\n",
"model = build_uc_model(data[0])\n",
"model.optimize()"
"model.optimize()\n"
]
},
{
@@ -1406,7 +1440,7 @@
},
{
"cell_type": "markdown",
"id": "238e9968",
"id": "09ba5ccf",
"metadata": {
"collapsed": false
},
@@ -1419,7 +1453,7 @@
},
{
"cell_type": "markdown",
"id": "d1f1cced",
"id": "c72baa43",
"metadata": {
"collapsed": false
},
@@ -1438,7 +1472,7 @@
},
{
"cell_type": "markdown",
"id": "cbcb1ae0",
"id": "43bb19ae",
"metadata": {
"collapsed": false
},
@@ -1467,8 +1501,11 @@
"weights[0] [37.45 95.07 73.2 59.87 15.6 15.6 5.81 86.62 60.11 70.81]\n",
"weights[1] [ 2.06 96.99 83.24 21.23 18.18 18.34 30.42 52.48 43.19 29.12]\n",
"\n",
"Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)\n",
"Thread count: 6 physical cores, 12 logical processors, using up to 12 threads\n",
"Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)\n",
"\n",
"CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]\n",
"Thread count: 16 physical cores, 32 logical processors, using up to 32 threads\n",
"\n",
"Optimize a model with 15 rows, 10 columns and 30 nonzeros\n",
"Model fingerprint: 0x2d2d1390\n",
"Variable types: 0 continuous, 10 integer (10 binary)\n",
@@ -1491,7 +1528,7 @@
" 0 0 infeasible 0 301.00000 301.00000 0.00% - 0s\n",
"\n",
"Explored 1 nodes (8 simplex iterations) in 0.01 seconds (0.00 work units)\n",
"Thread count was 12 (of 12 available processors)\n",
"Thread count was 32 (of 32 available processors)\n",
"\n",
"Solution count 1: 301 \n",
"\n",
@@ -1504,7 +1541,10 @@
"import random\n",
"import numpy as np\n",
"from scipy.stats import uniform, randint\n",
"from miplearn.problems.vertexcover import MinWeightVertexCoverGenerator, build_vertexcover_model\n",
"from miplearn.problems.vertexcover import (\n",
" MinWeightVertexCoverGenerator,\n",
" build_vertexcover_model,\n",
")\n",
"\n",
"# Set random seed to make example reproducible\n",
"random.seed(42)\n",
@@ -1533,7 +1573,7 @@
{
"cell_type": "code",
"execution_count": null,
"id": "d1d25734",
"id": "c0a76d28",
"metadata": {
"collapsed": false
},
@@ -1557,7 +1597,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.13"
"version": "3.9.12"
}
},
"nbformat": 4,

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>1. Benchmark Problems &#8212; MIPLearn 0.3</title>
<title>4. Benchmark Problems &#8212; MIPLearn 0.3</title>
<link href="../../_static/css/theme.css" rel="stylesheet" />
<link href="../../_static/css/index.c5995385ac14fb8791e8eb36b4908be2.css" rel="stylesheet" />
@@ -24,6 +24,10 @@
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sphinx-book-theme.acff12b8f9c144ce68a297486a2fa670.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/custom.css" />
<link rel="preload" as="script" href="../../_static/js/index.1c5a1a01449ed65a7b51.js">
@@ -38,8 +42,8 @@
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]], "processRefs": false, "processEnvironments": false}})</script>
<link rel="index" title="Index" href="../../genindex/" />
<link rel="search" title="Search" href="../../search/" />
<link rel="next" title="2. Training Data Collectors" href="../collectors/" />
<link rel="prev" title="MIPLearn" href="../../" />
<link rel="next" title="5. Training Data Collectors" href="../collectors/" />
<link rel="prev" title="3. Getting started (JuMP)" href="../../tutorials/getting-started-jump/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
@@ -68,6 +72,28 @@
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
<div class="bd-toc-item active">
<p class="caption">
<span class="caption-text">
Tutorials
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-pyomo/">
1. Getting started (Pyomo)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-gurobipy/">
2. Getting started (Gurobipy)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-jump/">
3. Getting started (JuMP)
</a>
</li>
</ul>
<p class="caption">
<span class="caption-text">
User Guide
</span>
@@ -75,59 +101,59 @@
<ul class="current nav bd-sidenav">
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
1. Benchmark Problems
4. Benchmark Problems
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../collectors/">
2. Training Data Collectors
5. Training Data Collectors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../features/">
3. Feature Extractors
6. Feature Extractors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../primal/">
4. Primal Components
7. Primal Components
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../solvers/">
5. Solvers
8. Solvers
</a>
</li>
</ul>
<p class="caption">
<span class="caption-text">
API Reference
Python API Reference
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../../api/problems/">
6. Benchmark Problems
9. Benchmark Problems
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/collectors/">
7. Collectors &amp; Extractors
10. Collectors &amp; Extractors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/components/">
8. Components
11. Components
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/solvers/">
9. Solvers
12. Solvers
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/helpers/">
10. Helpers
13. Helpers
</a>
</li>
</ul>
@@ -199,12 +225,12 @@
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Overview">
1.1. Overview
4.1. Overview
</a>
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Bin-Packing">
1.2. Bin Packing
4.2. Bin Packing
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -226,7 +252,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Multi-Dimensional-Knapsack">
1.3. Multi-Dimensional Knapsack
4.3. Multi-Dimensional Knapsack
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -248,7 +274,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Capacitated-P-Median">
1.4. Capacitated P-Median
4.4. Capacitated P-Median
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -270,7 +296,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Set-cover">
1.5. Set cover
4.5. Set cover
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -292,7 +318,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Set-Packing">
1.6. Set Packing
4.6. Set Packing
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -314,7 +340,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Stable-Set">
1.7. Stable Set
4.7. Stable Set
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -336,7 +362,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Traveling-Salesman">
1.8. Traveling Salesman
4.8. Traveling Salesman
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -358,7 +384,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Unit-Commitment">
1.9. Unit Commitment
4.9. Unit Commitment
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -380,7 +406,7 @@
</li>
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#Vertex-Cover">
1.10. Vertex Cover
4.10. Vertex Cover
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -411,267 +437,10 @@
<div>
<style>
/* CSS for nbsphinx extension */
/* remove conflicting styling from Sphinx themes */
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt *,
div.nbinput.container div.input_area pre,
div.nboutput.container div.output_area pre,
div.nbinput.container div.input_area .highlight,
div.nboutput.container div.output_area .highlight {
border: none;
padding: 0;
margin: 0;
box-shadow: none;
}
div.nbinput.container > div[class*=highlight],
div.nboutput.container > div[class*=highlight] {
margin: 0;
}
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt * {
background: none;
}
div.nboutput.container div.output_area .highlight,
div.nboutput.container div.output_area pre {
background: unset;
}
div.nboutput.container div.output_area div.highlight {
color: unset; /* override Pygments text color */
}
/* avoid gaps between output lines */
div.nboutput.container div[class*=highlight] pre {
line-height: normal;
}
/* input/output containers */
div.nbinput.container,
div.nboutput.container {
display: -webkit-flex;
display: flex;
align-items: flex-start;
margin: 0;
width: 100%;
}
@media (max-width: 540px) {
div.nbinput.container,
div.nboutput.container {
flex-direction: column;
}
}
/* input container */
div.nbinput.container {
padding-top: 5px;
}
/* last container */
div.nblast.container {
padding-bottom: 5px;
}
/* input prompt */
div.nbinput.container div.prompt pre {
color: #307FC1;
}
/* output prompt */
div.nboutput.container div.prompt pre {
color: #BF5B3D;
}
/* all prompts */
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: 4.5ex;
padding-top: 5px;
position: relative;
user-select: none;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: absolute;
right: 0;
margin-right: 0.3ex;
}
@media (max-width: 540px) {
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: unset;
text-align: left;
padding: 0.4em;
}
div.nboutput.container div.prompt.empty {
padding: 0;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: unset;
}
}
/* disable scrollbars and line breaks on prompts */
div.nbinput.container div.prompt pre,
div.nboutput.container div.prompt pre {
overflow: hidden;
white-space: pre;
}
/* input/output area */
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
-webkit-flex: 1;
flex: 1;
overflow: auto;
}
@media (max-width: 540px) {
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
width: 100%;
}
}
/* input area */
div.nbinput.container div.input_area {
border: 1px solid #e0e0e0;
border-radius: 2px;
/*background: #f5f5f5;*/
}
/* override MathJax center alignment in output cells */
div.nboutput.container div[class*=MathJax] {
text-align: left !important;
}
/* override sphinx.ext.imgmath center alignment in output cells */
div.nboutput.container div.math p {
text-align: left;
}
/* standard error */
div.nboutput.container div.output_area.stderr {
background: #fdd;
}
/* ANSI colors */
.ansi-black-fg { color: #3E424D; }
.ansi-black-bg { background-color: #3E424D; }
.ansi-black-intense-fg { color: #282C36; }
.ansi-black-intense-bg { background-color: #282C36; }
.ansi-red-fg { color: #E75C58; }
.ansi-red-bg { background-color: #E75C58; }
.ansi-red-intense-fg { color: #B22B31; }
.ansi-red-intense-bg { background-color: #B22B31; }
.ansi-green-fg { color: #00A250; }
.ansi-green-bg { background-color: #00A250; }
.ansi-green-intense-fg { color: #007427; }
.ansi-green-intense-bg { background-color: #007427; }
.ansi-yellow-fg { color: #DDB62B; }
.ansi-yellow-bg { background-color: #DDB62B; }
.ansi-yellow-intense-fg { color: #B27D12; }
.ansi-yellow-intense-bg { background-color: #B27D12; }
.ansi-blue-fg { color: #208FFB; }
.ansi-blue-bg { background-color: #208FFB; }
.ansi-blue-intense-fg { color: #0065CA; }
.ansi-blue-intense-bg { background-color: #0065CA; }
.ansi-magenta-fg { color: #D160C4; }
.ansi-magenta-bg { background-color: #D160C4; }
.ansi-magenta-intense-fg { color: #A03196; }
.ansi-magenta-intense-bg { background-color: #A03196; }
.ansi-cyan-fg { color: #60C6C8; }
.ansi-cyan-bg { background-color: #60C6C8; }
.ansi-cyan-intense-fg { color: #258F8F; }
.ansi-cyan-intense-bg { background-color: #258F8F; }
.ansi-white-fg { color: #C5C1B4; }
.ansi-white-bg { background-color: #C5C1B4; }
.ansi-white-intense-fg { color: #A1A6B2; }
.ansi-white-intense-bg { background-color: #A1A6B2; }
.ansi-default-inverse-fg { color: #FFFFFF; }
.ansi-default-inverse-bg { background-color: #000000; }
.ansi-bold { font-weight: bold; }
.ansi-underline { text-decoration: underline; }
div.nbinput.container div.input_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight].math,
div.nboutput.container div.output_area.rendered_html,
div.nboutput.container div.output_area > div.output_javascript,
div.nboutput.container div.output_area:not(.rendered_html) > img{
padding: 5px;
margin: 0;
}
/* fix copybtn overflow problem in chromium (needed for 'sphinx_copybutton') */
div.nbinput.container div.input_area > div[class^='highlight'],
div.nboutput.container div.output_area > div[class^='highlight']{
overflow-y: hidden;
}
/* hide copybtn icon on prompts (needed for 'sphinx_copybutton') */
.prompt .copybtn {
display: none;
}
/* Some additional styling taken form the Jupyter notebook CSS */
.jp-RenderedHTMLCommon table,
div.rendered_html table {
border: none;
border-collapse: collapse;
border-spacing: 0;
color: black;
font-size: 12px;
table-layout: fixed;
}
.jp-RenderedHTMLCommon thead,
div.rendered_html thead {
border-bottom: 1px solid black;
vertical-align: bottom;
}
.jp-RenderedHTMLCommon tr,
.jp-RenderedHTMLCommon th,
.jp-RenderedHTMLCommon td,
div.rendered_html tr,
div.rendered_html th,
div.rendered_html td {
text-align: right;
vertical-align: middle;
padding: 0.5em 0.5em;
line-height: normal;
white-space: normal;
max-width: none;
border: none;
}
.jp-RenderedHTMLCommon th,
div.rendered_html th {
font-weight: bold;
}
.jp-RenderedHTMLCommon tbody tr:nth-child(odd),
div.rendered_html tbody tr:nth-child(odd) {
background: #f5f5f5;
}
.jp-RenderedHTMLCommon tbody tr:hover,
div.rendered_html tbody tr:hover {
background: rgba(66, 165, 245, 0.2);
}
</style>
<div class="section" id="Benchmark-Problems">
<h1><span class="section-number">1. </span>Benchmark Problems<a class="headerlink" href="#Benchmark-Problems" title="Permalink to this headline"></a></h1>
<div class="section" id="Benchmark-Problems">
<h1><span class="section-number">4. </span>Benchmark Problems<a class="headerlink" href="#Benchmark-Problems" title="Permalink to this headline"></a></h1>
<div class="section" id="Overview">
<h2><span class="section-number">1.1. </span>Overview<a class="headerlink" href="#Overview" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">4.1. </span>Overview<a class="headerlink" href="#Overview" title="Permalink to this headline"></a></h2>
<p>Benchmark sets such as <a class="reference external" href="https://miplib.zib.de/">MIPLIB</a> or <a class="reference external" href="http://comopt.ifi.uni-heidelberg.de/software/TSPLIB95/">TSPLIB</a> are usually employed to evaluate the performance of conventional MIP solvers. Two shortcomings, unfortunately, make existing benchmark sets less than ideal for evaluating the performance of learning-enhanced MIP solvers: (i) while existing benchmark sets typically contain hundreds or thousands of instances, machine learning (ML) methods typically benefit from having
orders of magnitude more instances available for training; (ii) current machine learning methods typically provide best performance on sets of homogeneous instances, buch general-purpose benchmark sets contain relatively few examples of each problem type.</p>
<p>To tackle this challenge, MIPLearn provides random instance generators for a wide variety of classical optimization problems, covering applications from different fields, that can be used to evaluate new learning-enhanced MIP techniques in a measurable and reproducible way. As of MIPLearn 0.3, nine problem generators are available, each customizable with user-provided probability distribution and flexible parameters. The generators can be configured, for example, to produce large sets of very
@@ -690,7 +459,7 @@ similar instances of same size, where only the objective function changes, or mo
</div>
</div>
<div class="section" id="Bin-Packing">
<h2><span class="section-number">1.2. </span>Bin Packing<a class="headerlink" href="#Bin-Packing" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">4.2. </span>Bin Packing<a class="headerlink" href="#Bin-Packing" title="Permalink to this headline"></a></h2>
<p><strong>Bin packing</strong> is a combinatorial optimization problem that asks for the optimal way to pack a given set of items into a finite number of containers (or bins) of fixed capacity. More specifically, the problem is to assign indivisible items of different sizes to identical bins, while minimizing the number of bins used. The problem is NP-hard and has many practical applications, including logistics and warehouse management, where it is used to determine how to best store and transport goods using
a limited amount of space.</p>
<div class="section" id="Formulation">
@@ -745,10 +514,10 @@ a limited amount of space.</p>
<span class="c1"># Optimize first instance</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">build_binpack_model</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">model</span><span class="o">.</span><span class="n">optimize</span><span class="p">()</span>
</pre></div>
<br/></pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
@@ -764,9 +533,11 @@ a limited amount of space.</p>
8 [ 8.47 21.9 16.58 15.37 3.76 3.91 1.57 20.57 14.76 18.61] 94.58
9 [ 8.57 22.77 17.06 16.25 4.14 4. 1.56 22.97 14.09 19.09] 100.79
Restricted license - for non-production use only - expires 2023-10-25
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)
Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)
CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]
Thread count: 16 physical cores, 32 logical processors, using up to 32 threads
Optimize a model with 20 rows, 110 columns and 210 nonzeros
Model fingerprint: 0x1ff9913f
Variable types: 0 continuous, 110 integer (110 binary)
@@ -790,7 +561,7 @@ H 0 0 4.0000000 1.27484 68.1% - 0s
H 0 0 2.0000000 1.27484 36.3% - 0s
0 0 1.27484 0 4 2.00000 1.27484 36.3% - 0s
Explored 1 nodes (38 simplex iterations) in 0.00 seconds (0.00 work units)
Explored 1 nodes (38 simplex iterations) in 0.01 seconds (0.00 work units)
Thread count was 32 (of 32 available processors)
Solution count 3: 2 4 5
@@ -799,14 +570,23 @@ Optimal solution found (tolerance 1.00e-04)
Best objective 2.000000000000e+00, best bound 2.000000000000e+00, gap 0.0000%
</pre></div></div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area stderr docutils container">
<div class="highlight"><pre>
/home/axavier/.conda/envs/miplearn2/lib/python3.9/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
</pre></div></div>
</div>
</div>
</div>
<div class="section" id="Multi-Dimensional-Knapsack">
<h2><span class="section-number">1.3. </span>Multi-Dimensional Knapsack<a class="headerlink" href="#Multi-Dimensional-Knapsack" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">4.3. </span>Multi-Dimensional Knapsack<a class="headerlink" href="#Multi-Dimensional-Knapsack" title="Permalink to this headline"></a></h2>
<p>The <strong>multi-dimensional knapsack problem</strong> is a generalization of the classic knapsack problem, which involves selecting a subset of items to be placed in a knapsack such that the total value of the items is maximized without exceeding a maximum weight. In this generalization, items have multiple weights (representing multiple resources), and multiple weight constraints must be satisfied.</p>
<div class="section" id="id1">
<h3>Formulation<a class="headerlink" href="#id1" title="Permalink to this headline"></a></h3>
<p>Let <span class="math notranslate nohighlight">\(n\)</span> be the number of items and <span class="math notranslate nohighlight">\(m\)</span> be the number of resources. For each item <span class="math notranslate nohighlight">\(j\)</span> and resource <span class="math notranslate nohighlight">\(i\)</span>, let <span class="math notranslate nohighlight">\(p_j\)</span> be the price of the item, let <span class="math notranslate nohighlight">\(w_{ij}\)</span> be the amount of resource <span class="math notranslate nohighlight">\(j\)</span> item <span class="math notranslate nohighlight">\(i\)</span> consumes (i.e. the <span class="math notranslate nohighlight">\(j\)</span>-th weight of the item), and let <span class="math notranslate nohighlight">\(b_i\)</span> be the total amount of resource <span class="math notranslate nohighlight">\(i\)</span> available (or the size of the <span class="math notranslate nohighlight">\(j\)</span>-th knapsack). The formulation is given by:</p>
<p>Let <span class="math notranslate nohighlight">\(n\)</span> be the number of items and <span class="math notranslate nohighlight">\(m\)</span> be the number of resources. For each item <span class="math notranslate nohighlight">\(j\)</span> and resource <span class="math notranslate nohighlight">\(i\)</span>, let <span class="math notranslate nohighlight">\(p_j\)</span> be the price of the item, let <span class="math notranslate nohighlight">\(w_{ij}\)</span> be the amount of resource <span class="math notranslate nohighlight">\(j\)</span> item <span class="math notranslate nohighlight">\(i\)</span> consumes (i.e. the <span class="math notranslate nohighlight">\(j\)</span>-th weight of the item), and let <span class="math notranslate nohighlight">\(b_i\)</span> be the total amount of resource <span class="math notranslate nohighlight">\(i\)</span> available (or the size of the <span class="math notranslate nohighlight">\(j\)</span>-th knapsack). The formulation is given by:</p>
<div class="math notranslate nohighlight">
\[\begin{split}\begin{align*}
\text{minimize}\;\;\;
@@ -878,7 +658,7 @@ Best objective 2.000000000000e+00, best bound 2.000000000000e+00, gap 0.0000%
<span class="c1"># Build model and optimize</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">build_multiknapsack_model</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">model</span><span class="o">.</span><span class="n">optimize</span><span class="p">()</span>
</pre></div>
<br/></pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
@@ -897,8 +677,11 @@ weights
capacities
[1310. 988. 1004. 1269. 1007.]
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)
Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)
CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]
Thread count: 16 physical cores, 32 logical processors, using up to 32 threads
Optimize a model with 5 rows, 10 columns and 50 nonzeros
Model fingerprint: 0xaf3ac15e
Variable types: 0 continuous, 10 integer (10 binary)
@@ -924,7 +707,7 @@ H 0 0 -1279.000000 -1428.7265 11.7% - 0s
Cutting planes:
Cover: 1
Explored 1 nodes (4 simplex iterations) in 0.00 seconds (0.00 work units)
Explored 1 nodes (4 simplex iterations) in 0.01 seconds (0.00 work units)
Thread count was 32 (of 32 available processors)
Solution count 2: -1279 -804
@@ -937,7 +720,7 @@ Best objective -1.279000000000e+03, best bound -1.279000000000e+03, gap 0.0000%
</div>
</div>
<div class="section" id="Capacitated-P-Median">
<h2><span class="section-number">1.4. </span>Capacitated P-Median<a class="headerlink" href="#Capacitated-P-Median" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">4.4. </span>Capacitated P-Median<a class="headerlink" href="#Capacitated-P-Median" title="Permalink to this headline"></a></h2>
<p>The <strong>capacitated p-median</strong> problem is a variation of the classic <span class="math notranslate nohighlight">\(p\)</span>-median problem, in which a set of customers must be served by a set of facilities. In the capacitated <span class="math notranslate nohighlight">\(p\)</span>-Median problem, each facility has a fixed capacity, and the goal is to minimize the total cost of serving the customers while ensuring that the capacity of each facility is not exceeded. Variations of problem are often used in logistics and supply chain management to determine the most efficient locations for
warehouses or distribution centers.</p>
<div class="section" id="id4">
@@ -1002,7 +785,7 @@ list of instances that have the same set of customers, but slightly different de
<span class="c1"># Build and optimize model</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">build_pmedian_model</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">model</span><span class="o">.</span><span class="n">optimize</span><span class="p">()</span>
</pre></div>
<br/></pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
@@ -1025,8 +808,11 @@ distances =
demands = [6.12 1.39 2.92 3.66 4.56 7.85 2. 5.14 5.92 0.46]
capacities = [151.89 42.63 16.26 237.22 241.41 202.1 76.15 24.42 171.06 110.04]
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)
Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)
CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]
Thread count: 16 physical cores, 32 logical processors, using up to 32 threads
Optimize a model with 21 rows, 110 columns and 220 nonzeros
Model fingerprint: 0x8d8d9346
Variable types: 0 continuous, 110 integer (110 binary)
@@ -1059,7 +845,7 @@ H 0 0 93.9200000 64.28872 31.5% - 0s
0 0 86.06884 0 15 93.92000 86.06884 8.36% - 0s
* 0 0 0 91.2300000 91.23000 0.00% - 0s
Explored 1 nodes (60 simplex iterations) in 0.01 seconds (0.00 work units)
Explored 1 nodes (70 simplex iterations) in 0.02 seconds (0.00 work units)
Thread count was 32 (of 32 available processors)
Solution count 10: 91.23 93.92 93.98 ... 368.79
@@ -1071,7 +857,7 @@ Best objective 9.123000000000e+01, best bound 9.123000000000e+01, gap 0.0000%
</div>
</div>
<div class="section" id="Set-cover">
<h2><span class="section-number">1.5. </span>Set cover<a class="headerlink" href="#Set-cover" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">4.5. </span>Set cover<a class="headerlink" href="#Set-cover" title="Permalink to this headline"></a></h2>
<p>The <strong>set cover problem</strong> is a classical NP-hard optimization problem which aims to minimize the number of sets needed to cover all elements in a given universe. Each set may contain a different number of elements, and sets may overlap with each other. This problem can be useful in various real-world scenarios such as scheduling, resource allocation, and network design.</p>
<div class="section" id="id7">
<h3>Formulation<a class="headerlink" href="#id7" title="Permalink to this headline"></a></h3>
@@ -1106,7 +892,7 @@ Best objective 9.123000000000e+01, best bound 9.123000000000e+01, gap 0.0000%
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">scipy.stats</span> <span class="kn">import</span> <span class="n">uniform</span><span class="p">,</span> <span class="n">randint</span>
<span class="kn">from</span> <span class="nn">miplearn.problems.setcover</span> <span class="kn">import</span> <span class="n">SetCoverGenerator</span><span class="p">,</span> <span class="n">build_setcover_model</span>
<span class="kn">from</span> <span class="nn">miplearn.problems.setcover</span> <span class="kn">import</span> <span class="n">SetCoverGenerator</span><span class="p">,</span> <span class="n">build_setcover_model_gurobipy</span>
<span class="c1"># Set random seed, to make example reproducible</span>
<span class="n">np</span><span class="o">.</span><span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">42</span><span class="p">)</span>
@@ -1130,9 +916,9 @@ Best objective 9.123000000000e+01, best bound 9.123000000000e+01, gap 0.0000%
<span class="nb">print</span><span class="p">()</span>
<span class="c1"># Build and optimize model</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">build_setcover_model</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">build_setcover_model_gurobipy</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">model</span><span class="o">.</span><span class="n">optimize</span><span class="p">()</span>
</pre></div>
<br/></pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
@@ -1149,8 +935,11 @@ matrix
costs [1044.58 850.13 1014.5 944.83 697.9 971.87 213.49 220.98 70.23
425.33]
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)
Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)
CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]
Thread count: 16 physical cores, 32 logical processors, using up to 32 threads
Optimize a model with 5 rows, 10 columns and 28 nonzeros
Model fingerprint: 0xe5c2d4fa
Variable types: 0 continuous, 10 integer (10 binary)
@@ -1176,7 +965,7 @@ Best objective 2.134900000000e+02, best bound 2.134900000000e+02, gap 0.0000%
</div>
</div>
<div class="section" id="Set-Packing">
<h2><span class="section-number">1.6. </span>Set Packing<a class="headerlink" href="#Set-Packing" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">4.6. </span>Set Packing<a class="headerlink" href="#Set-Packing" title="Permalink to this headline"></a></h2>
<p><strong>Set packing</strong> is a classical optimization problem that asks for the maximum number of disjoint sets within a given list. This problem often arises in real-world situations where a finite number of resources need to be allocated to tasks, such as airline flight crew scheduling.</p>
<div class="section" id="id10">
<h3>Formulation<a class="headerlink" href="#id10" title="Permalink to this headline"></a></h3>
@@ -1229,7 +1018,7 @@ Best objective 2.134900000000e+02, best bound 2.134900000000e+02, gap 0.0000%
<span class="c1"># Build and optimize model</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">build_setpack_model</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">model</span><span class="o">.</span><span class="n">optimize</span><span class="p">()</span>
</pre></div>
<br/></pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
@@ -1246,8 +1035,11 @@ matrix
costs [1044.58 850.13 1014.5 944.83 697.9 971.87 213.49 220.98 70.23
425.33]
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)
Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)
CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]
Thread count: 16 physical cores, 32 logical processors, using up to 32 threads
Optimize a model with 5 rows, 10 columns and 28 nonzeros
Model fingerprint: 0x4ee91388
Variable types: 0 continuous, 10 integer (10 binary)
@@ -1274,7 +1066,7 @@ Best objective -1.986370000000e+03, best bound -1.986370000000e+03, gap 0.0000%
</div>
</div>
<div class="section" id="Stable-Set">
<h2><span class="section-number">1.7. </span>Stable Set<a class="headerlink" href="#Stable-Set" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">4.7. </span>Stable Set<a class="headerlink" href="#Stable-Set" title="Permalink to this headline"></a></h2>
<p>The <strong>maximum-weight stable set problem</strong> is a classical optimization problem in graph theory which asks for the maximum-weight subset of vertices in a graph such that no two vertices in the subset are adjacent. The problem often arises in real-world scheduling or resource allocation situations, where stable sets represent tasks or resources that can be chosen simultaneously without conflicts.</p>
<div class="section" id="id13">
<h3>Formulation<a class="headerlink" href="#id13" title="Permalink to this headline"></a></h3>
@@ -1296,13 +1088,16 @@ other. The class then samples the provided probability distribution <code class=
<div class="section" id="id15">
<h3>Example<a class="headerlink" href="#id15" title="Permalink to this headline"></a></h3>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[24]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[6]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">random</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">scipy.stats</span> <span class="kn">import</span> <span class="n">uniform</span><span class="p">,</span> <span class="n">randint</span>
<span class="kn">from</span> <span class="nn">miplearn.problems.stab</span> <span class="kn">import</span> <span class="n">MaxWeightStableSetGenerator</span><span class="p">,</span> <span class="n">build_stab_model</span>
<span class="kn">from</span> <span class="nn">miplearn.problems.stab</span> <span class="kn">import</span> <span class="p">(</span>
<span class="n">MaxWeightStableSetGenerator</span><span class="p">,</span>
<span class="n">build_stab_model_gurobipy</span><span class="p">,</span>
<span class="p">)</span>
<span class="c1"># Set random seed to make example reproducible</span>
<span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">42</span><span class="p">)</span>
@@ -1324,9 +1119,9 @@ other. The class then samples the provided probability distribution <code class=
<span class="nb">print</span><span class="p">()</span>
<span class="c1"># Load and optimize the first instance</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">build_stab_model</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">build_stab_model_gurobipy</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">model</span><span class="o">.</span><span class="n">optimize</span><span class="p">()</span>
</pre></div>
<br/></pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
@@ -1338,8 +1133,11 @@ graph [(0, 2), (0, 4), (0, 8), (1, 2), (1, 3), (1, 5), (1, 6), (1, 9), (2, 5), (
weights[0] [37.45 95.07 73.2 59.87 15.6 15.6 5.81 86.62 60.11 70.81]
weights[1] [ 2.06 96.99 83.24 21.23 18.18 18.34 30.42 52.48 43.19 29.12]
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)
Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)
CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]
Thread count: 16 physical cores, 32 logical processors, using up to 32 threads
Optimize a model with 10 rows, 10 columns and 24 nonzeros
Model fingerprint: 0xf4c21689
Variable types: 0 continuous, 10 integer (10 binary)
@@ -1361,7 +1159,7 @@ Root relaxation: objective -2.205650e+02, 4 iterations, 0.00 seconds (0.00 work
0 0 infeasible 0 -219.14000 -219.14000 0.00% - 0s
Explored 1 nodes (4 simplex iterations) in 0.00 seconds (0.00 work units)
Explored 1 nodes (4 simplex iterations) in 0.01 seconds (0.00 work units)
Thread count was 32 (of 32 available processors)
Solution count 1: -219.14
@@ -1374,7 +1172,7 @@ Best objective -2.191400000000e+02, best bound -2.191400000000e+02, gap 0.0000%
</div>
</div>
<div class="section" id="Traveling-Salesman">
<h2><span class="section-number">1.8. </span>Traveling Salesman<a class="headerlink" href="#Traveling-Salesman" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">4.8. </span>Traveling Salesman<a class="headerlink" href="#Traveling-Salesman" title="Permalink to this headline"></a></h2>
<p>Given a list of cities and the distances between them, the <strong>traveling salesman problem</strong> asks for the shortest route starting at the first city, visiting each other city exactly once, then returning to the first city. This problem is a generalization of the Hamiltonian path problem, one of Karps 21 NP-complete problems, and has many practical applications, including routing delivery trucks and scheduling airline routes.</p>
<div class="section" id="id16">
<h3>Formulation<a class="headerlink" href="#id16" title="Permalink to this headline"></a></h3>
@@ -1402,7 +1200,7 @@ Best objective -2.191400000000e+02, best bound -2.191400000000e+02, gap 0.0000%
<div class="section" id="id18">
<h3>Example<a class="headerlink" href="#id18" title="Permalink to this headline"></a></h3>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[32]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[7]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">random</span>
@@ -1433,7 +1231,7 @@ Best objective -2.191400000000e+02, best bound -2.191400000000e+02, gap 0.0000%
<span class="c1"># Load and optimize the first instance</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">build_tsp_model</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">model</span><span class="o">.</span><span class="n">optimize</span><span class="p">()</span>
</pre></div>
<br/></pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
@@ -1465,8 +1263,11 @@ distances[1]
[ 668. 446. 317. 648. 469. 752. 394. 286. 274. 0.]]
Set parameter LazyConstraints to value 1
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)
Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)
CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]
Thread count: 16 physical cores, 32 logical processors, using up to 32 threads
Optimize a model with 10 rows, 45 columns and 90 nonzeros
Model fingerprint: 0x719675e5
Variable types: 0 continuous, 45 integer (45 binary)
@@ -1497,13 +1298,13 @@ Solution count 1: 2921
Optimal solution found (tolerance 1.00e-04)
Best objective 2.921000000000e+03, best bound 2.921000000000e+03, gap 0.0000%
User-callback calls 100, time in user-callback 0.00 sec
User-callback calls 106, time in user-callback 0.00 sec
</pre></div></div>
</div>
</div>
</div>
<div class="section" id="Unit-Commitment">
<h2><span class="section-number">1.9. </span>Unit Commitment<a class="headerlink" href="#Unit-Commitment" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">4.9. </span>Unit Commitment<a class="headerlink" href="#Unit-Commitment" title="Permalink to this headline"></a></h2>
<p>The <strong>unit commitment problem</strong> is a mixed-integer optimization problem which asks which power generation units should be turned on and off, at what time, and at what capacity, in order to meet the demand for electricity generation at the lowest cost. Numerous operational constraints are typically enforced, such as <em>ramping constraints</em>, which prevent generation units from changing power output levels too quickly from one time step to the next, and <em>minimum-up</em> and <em>minimum-down</em> constraints,
which prevent units from switching on and off too frequently. The unit commitment problem is widely used in power systems planning and operations.</p>
<div class="admonition note">
@@ -1605,7 +1406,7 @@ enforce bounds to the quantity of power generated by each unit.</p>
<span class="c1"># Load and optimize the first instance</span>
<span class="n">model</span> <span class="o">=</span> <span class="n">build_uc_model</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
<span class="n">model</span><span class="o">.</span><span class="n">optimize</span><span class="p">()</span>
</pre></div>
<br/></pre></div>
</div>
</div>
<div class="nboutput nblast docutils container">
@@ -1639,8 +1440,11 @@ demand[1]
828.28 775.18 834.99 959.76 865.72 1193.52 1058.92 985.19 893.92
962.16 781.88 723.15 639.04 602.4 787.02]
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)
Thread count: 6 physical cores, 12 logical processors, using up to 12 threads
Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)
CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]
Thread count: 16 physical cores, 32 logical processors, using up to 32 threads
Optimize a model with 578 rows, 360 columns and 2128 nonzeros
Model fingerprint: 0x4dc1c661
Variable types: 120 continuous, 240 integer (240 binary)
@@ -1650,22 +1454,22 @@ Coefficient statistics:
Bounds range [1e+00, 1e+00]
RHS range [1e+00, 1e+03]
Presolve removed 244 rows and 131 columns
Presolve time: 0.01s
Presolve time: 0.02s
Presolved: 334 rows, 229 columns, 842 nonzeros
Variable types: 116 continuous, 113 integer (113 binary)
Found heuristic solution: objective 441426.66550
Found heuristic solution: objective 440662.46430
Found heuristic solution: objective 429461.97680
Found heuristic solution: objective 374043.64040
Root relaxation: objective 3.361348e+05, 139 iterations, 0.00 seconds (0.00 work units)
Root relaxation: objective 3.361348e+05, 142 iterations, 0.00 seconds (0.00 work units)
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
0 0 336134.820 0 18 374043.640 336134.820 10.1% - 0s
H 0 0 368600.14450 336134.820 8.81% - 0s
H 0 0 364721.76610 364721.766 0.00% - 0s
0 0 - 0 364721.766 364721.766 0.00% - 0s
H 0 0 364721.76610 336134.820 7.84% - 0s
0 0 cutoff 0 364721.766 364721.766 0.00% - 0s
Cutting planes:
Gomory: 3
@@ -1677,10 +1481,10 @@ Cutting planes:
RLT: 1
Relax-and-lift: 7
Explored 1 nodes (232 simplex iterations) in 0.04 seconds (0.02 work units)
Thread count was 12 (of 12 available processors)
Explored 1 nodes (234 simplex iterations) in 0.04 seconds (0.02 work units)
Thread count was 32 (of 32 available processors)
Solution count 5: 364722 368600 374044 ... 441427
Solution count 5: 364722 368600 374044 ... 440662
Optimal solution found (tolerance 1.00e-04)
Best objective 3.647217661000e+05, best bound 3.647217661000e+05, gap 0.0000%
@@ -1689,7 +1493,7 @@ Best objective 3.647217661000e+05, best bound 3.647217661000e+05, gap 0.0000%
</div>
</div>
<div class="section" id="Vertex-Cover">
<h2><span class="section-number">1.10. </span>Vertex Cover<a class="headerlink" href="#Vertex-Cover" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">4.10. </span>Vertex Cover<a class="headerlink" href="#Vertex-Cover" title="Permalink to this headline"></a></h2>
<p><strong>Minimum weight vertex cover</strong> is a classical optimization problem in graph theory where the goal is to find the minimum-weight set of vertices that are connected to all of the edges in the graph. The problem generalizes one of Karps 21 NP-complete problems and has applications in various fields, including bioinformatics and machine learning.</p>
<div class="section" id="id22">
<h3>Formulation<a class="headerlink" href="#id22" title="Permalink to this headline"></a></h3>
@@ -1706,7 +1510,7 @@ Best objective 3.647217661000e+05, best bound 3.647217661000e+05, gap 0.0000%
</div>
<div class="section" id="id23">
<h3>Random instance generator<a class="headerlink" href="#id23" title="Permalink to this headline"></a></h3>
<p>The class <a class="reference external" href="../../api/problems/#module-miplearn.problems.vertexcover">MinWeightVertexCoverGenerator</a> can be used to generate random instances of this problem. The class accepts exactly the same parameters and behaves exactly in the same way as <a class="reference external" href="../../api/problems/#miplearn.problems.stab.MaxWeightStableSetGenerator">MaxWeightStableSetGenerator</a>. See the <a class="reference external" href="#Stable-Set">stable set section</a> for more details.</p>
<p>The class <a class="reference external" href="../../api/problems/#module-miplearn.problems.vertexcover">MinWeightVertexCoverGenerator</a> can be used to generate random instances of this problem. The class accepts exactly the same parameters and behaves exactly in the same way as <a class="reference external" href="../../api/problems/#miplearn.problems.stab.MaxWeightStableSetGenerator">MaxWeightStableSetGenerator</a>. See the <a class="reference internal" href="#Stable-Set"><span class="std std-ref">stable set section</span></a> for more details.</p>
</div>
<div class="section" id="id24">
<h3>Example<a class="headerlink" href="#id24" title="Permalink to this headline"></a></h3>
@@ -1717,7 +1521,10 @@ Best objective 3.647217661000e+05, best bound 3.647217661000e+05, gap 0.0000%
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">random</span>
<span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">from</span> <span class="nn">scipy.stats</span> <span class="kn">import</span> <span class="n">uniform</span><span class="p">,</span> <span class="n">randint</span>
<span class="kn">from</span> <span class="nn">miplearn.problems.vertexcover</span> <span class="kn">import</span> <span class="n">MinWeightVertexCoverGenerator</span><span class="p">,</span> <span class="n">build_vertexcover_model</span>
<span class="kn">from</span> <span class="nn">miplearn.problems.vertexcover</span> <span class="kn">import</span> <span class="p">(</span>
<span class="n">MinWeightVertexCoverGenerator</span><span class="p">,</span>
<span class="n">build_vertexcover_model</span><span class="p">,</span>
<span class="p">)</span>
<span class="c1"># Set random seed to make example reproducible</span>
<span class="n">random</span><span class="o">.</span><span class="n">seed</span><span class="p">(</span><span class="mi">42</span><span class="p">)</span>
@@ -1753,8 +1560,11 @@ graph [(0, 2), (0, 4), (0, 8), (1, 2), (1, 3), (1, 5), (1, 6), (1, 9), (2, 5), (
weights[0] [37.45 95.07 73.2 59.87 15.6 15.6 5.81 86.62 60.11 70.81]
weights[1] [ 2.06 96.99 83.24 21.23 18.18 18.34 30.42 52.48 43.19 29.12]
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)
Thread count: 6 physical cores, 12 logical processors, using up to 12 threads
Gurobi Optimizer version 10.0.1 build v10.0.1rc0 (linux64)
CPU model: AMD Ryzen 9 7950X 16-Core Processor, instruction set [SSE2|AVX|AVX2|AVX512]
Thread count: 16 physical cores, 32 logical processors, using up to 32 threads
Optimize a model with 15 rows, 10 columns and 30 nonzeros
Model fingerprint: 0x2d2d1390
Variable types: 0 continuous, 10 integer (10 binary)
@@ -1777,7 +1587,7 @@ Root relaxation: objective 2.995750e+02, 8 iterations, 0.00 seconds (0.00 work u
0 0 infeasible 0 301.00000 301.00000 0.00% - 0s
Explored 1 nodes (8 simplex iterations) in 0.01 seconds (0.00 work units)
Thread count was 12 (of 12 available processors)
Thread count was 32 (of 32 available processors)
Solution count 1: 301
@@ -1803,8 +1613,8 @@ Best objective 3.010000000000e+02, best bound 3.010000000000e+02, gap 0.0000%
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="../../" title="previous page">MIPLearn</a>
<a class='right-next' id="next-link" href="../collectors/" title="next page"><span class="section-number">2. </span>Training Data Collectors</a>
<a class='left-prev' id="prev-link" href="../../tutorials/getting-started-jump/" title="previous page"><span class="section-number">3. </span>Getting started (JuMP)</a>
<a class='right-next' id="next-link" href="../collectors/" title="next page"><span class="section-number">5. </span>Training Data Collectors</a>
</div>
@@ -1814,7 +1624,7 @@ Best objective 3.010000000000e+02, best bound 3.010000000000e+02, gap 0.0000%
<div class="container">
<p>
&copy; Copyright 2020-2022, UChicago Argonne, LLC.<br/>
&copy; Copyright 2020-2023, UChicago Argonne, LLC.<br/>
</p>
</div>
</footer>

View File

@@ -14,16 +14,28 @@
},
{
"cell_type": "code",
"execution_count": 3,
"id": "dac704b5",
"execution_count": 1,
"id": "92b09b98",
"metadata": {
"collapsed": false
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/axavier/Software/anaconda3/envs/miplearn/lib/python3.8/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"Restricted license - for non-production use only - expires 2023-10-25\n",
"Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)\n",
"Thread count: 6 physical cores, 12 logical processors, using up to 12 threads\n",
"Optimize a model with 10 rows, 45 columns and 90 nonzeros\n",
@@ -71,7 +83,7 @@
"Cutting planes:\n",
" Lazy constraints: 3\n",
"\n",
"Explored 1 nodes (15 simplex iterations) in 0.02 seconds (0.00 work units)\n",
"Explored 1 nodes (15 simplex iterations) in 0.01 seconds (0.00 work units)\n",
"Thread count was 12 (of 12 available processors)\n",
"\n",
"Solution count 1: 2796 \n",
@@ -152,7 +164,7 @@
"test_data = all_data[40:]\n",
"\n",
"# Collect training data\n",
"bc = BasicCollector(time_limit_sec=3600)\n",
"bc = BasicCollector()\n",
"bc.collect(train_data, build_tsp_model, n_jobs=4)\n",
"\n",
"# Build learning solver\n",
@@ -180,7 +192,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "e27d2cbd-5341-461d-bbc1-8131aee8d949",
"metadata": {},
"outputs": [],
@@ -189,7 +201,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},

View File

@@ -5,7 +5,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>5. Solvers &#8212; MIPLearn 0.3</title>
<title>8. Solvers &#8212; MIPLearn 0.3</title>
<link href="../../_static/css/theme.css" rel="stylesheet" />
<link href="../../_static/css/index.c5995385ac14fb8791e8eb36b4908be2.css" rel="stylesheet" />
@@ -24,6 +24,11 @@
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../_static/sphinx-book-theme.acff12b8f9c144ce68a297486a2fa670.css" type="text/css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/nbsphinx-code-cells.css" />
<link rel="stylesheet" type="text/css" href="../../_static/custom.css" />
<link rel="preload" as="script" href="../../_static/js/index.1c5a1a01449ed65a7b51.js">
@@ -38,8 +43,8 @@
<script type="text/x-mathjax-config">MathJax.Hub.Config({"tex2jax": {"inlineMath": [["\\(", "\\)"]], "displayMath": [["\\[", "\\]"]], "processRefs": false, "processEnvironments": false}})</script>
<link rel="index" title="Index" href="../../genindex/" />
<link rel="search" title="Search" href="../../search/" />
<link rel="next" title="6. Benchmark Problems" href="../../api/problems/" />
<link rel="prev" title="4. Primal Components" href="../primal/" />
<link rel="next" title="9. Benchmark Problems" href="../../api/problems/" />
<link rel="prev" title="7. Primal Components" href="../primal/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="docsearch:language" content="en" />
@@ -68,6 +73,28 @@
</form><nav class="bd-links" id="bd-docs-nav" aria-label="Main navigation">
<div class="bd-toc-item active">
<p class="caption">
<span class="caption-text">
Tutorials
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-pyomo/">
1. Getting started (Pyomo)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-gurobipy/">
2. Getting started (Gurobipy)
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../tutorials/getting-started-jump/">
3. Getting started (JuMP)
</a>
</li>
</ul>
<p class="caption">
<span class="caption-text">
User Guide
</span>
@@ -75,59 +102,59 @@
<ul class="current nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../problems/">
1. Benchmark Problems
4. Benchmark Problems
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../collectors/">
2. Training Data Collectors
5. Training Data Collectors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../features/">
3. Feature Extractors
6. Feature Extractors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../primal/">
4. Primal Components
7. Primal Components
</a>
</li>
<li class="toctree-l1 current active">
<a class="current reference internal" href="#">
5. Solvers
8. Solvers
</a>
</li>
</ul>
<p class="caption">
<span class="caption-text">
API Reference
Python API Reference
</span>
</p>
<ul class="nav bd-sidenav">
<li class="toctree-l1">
<a class="reference internal" href="../../api/problems/">
6. Benchmark Problems
9. Benchmark Problems
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/collectors/">
7. Collectors &amp; Extractors
10. Collectors &amp; Extractors
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/components/">
8. Components
11. Components
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/solvers/">
9. Solvers
12. Solvers
</a>
</li>
<li class="toctree-l1">
<a class="reference internal" href="../../api/helpers/">
10. Helpers
13. Helpers
</a>
</li>
</ul>
@@ -199,7 +226,7 @@
<ul class="visible nav section-nav flex-column">
<li class="toc-h2 nav-item toc-entry">
<a class="reference internal nav-link" href="#LearningSolver">
5.1. LearningSolver
8.1. LearningSolver
</a>
<ul class="nav section-nav flex-column">
<li class="toc-h3 nav-item toc-entry">
@@ -220,271 +247,14 @@
<div>
<style>
/* CSS for nbsphinx extension */
/* remove conflicting styling from Sphinx themes */
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt *,
div.nbinput.container div.input_area pre,
div.nboutput.container div.output_area pre,
div.nbinput.container div.input_area .highlight,
div.nboutput.container div.output_area .highlight {
border: none;
padding: 0;
margin: 0;
box-shadow: none;
}
div.nbinput.container > div[class*=highlight],
div.nboutput.container > div[class*=highlight] {
margin: 0;
}
div.nbinput.container div.prompt *,
div.nboutput.container div.prompt * {
background: none;
}
div.nboutput.container div.output_area .highlight,
div.nboutput.container div.output_area pre {
background: unset;
}
div.nboutput.container div.output_area div.highlight {
color: unset; /* override Pygments text color */
}
/* avoid gaps between output lines */
div.nboutput.container div[class*=highlight] pre {
line-height: normal;
}
/* input/output containers */
div.nbinput.container,
div.nboutput.container {
display: -webkit-flex;
display: flex;
align-items: flex-start;
margin: 0;
width: 100%;
}
@media (max-width: 540px) {
div.nbinput.container,
div.nboutput.container {
flex-direction: column;
}
}
/* input container */
div.nbinput.container {
padding-top: 5px;
}
/* last container */
div.nblast.container {
padding-bottom: 5px;
}
/* input prompt */
div.nbinput.container div.prompt pre {
color: #307FC1;
}
/* output prompt */
div.nboutput.container div.prompt pre {
color: #BF5B3D;
}
/* all prompts */
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: 4.5ex;
padding-top: 5px;
position: relative;
user-select: none;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: absolute;
right: 0;
margin-right: 0.3ex;
}
@media (max-width: 540px) {
div.nbinput.container div.prompt,
div.nboutput.container div.prompt {
width: unset;
text-align: left;
padding: 0.4em;
}
div.nboutput.container div.prompt.empty {
padding: 0;
}
div.nbinput.container div.prompt > div,
div.nboutput.container div.prompt > div {
position: unset;
}
}
/* disable scrollbars and line breaks on prompts */
div.nbinput.container div.prompt pre,
div.nboutput.container div.prompt pre {
overflow: hidden;
white-space: pre;
}
/* input/output area */
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
-webkit-flex: 1;
flex: 1;
overflow: auto;
}
@media (max-width: 540px) {
div.nbinput.container div.input_area,
div.nboutput.container div.output_area {
width: 100%;
}
}
/* input area */
div.nbinput.container div.input_area {
border: 1px solid #e0e0e0;
border-radius: 2px;
/*background: #f5f5f5;*/
}
/* override MathJax center alignment in output cells */
div.nboutput.container div[class*=MathJax] {
text-align: left !important;
}
/* override sphinx.ext.imgmath center alignment in output cells */
div.nboutput.container div.math p {
text-align: left;
}
/* standard error */
div.nboutput.container div.output_area.stderr {
background: #fdd;
}
/* ANSI colors */
.ansi-black-fg { color: #3E424D; }
.ansi-black-bg { background-color: #3E424D; }
.ansi-black-intense-fg { color: #282C36; }
.ansi-black-intense-bg { background-color: #282C36; }
.ansi-red-fg { color: #E75C58; }
.ansi-red-bg { background-color: #E75C58; }
.ansi-red-intense-fg { color: #B22B31; }
.ansi-red-intense-bg { background-color: #B22B31; }
.ansi-green-fg { color: #00A250; }
.ansi-green-bg { background-color: #00A250; }
.ansi-green-intense-fg { color: #007427; }
.ansi-green-intense-bg { background-color: #007427; }
.ansi-yellow-fg { color: #DDB62B; }
.ansi-yellow-bg { background-color: #DDB62B; }
.ansi-yellow-intense-fg { color: #B27D12; }
.ansi-yellow-intense-bg { background-color: #B27D12; }
.ansi-blue-fg { color: #208FFB; }
.ansi-blue-bg { background-color: #208FFB; }
.ansi-blue-intense-fg { color: #0065CA; }
.ansi-blue-intense-bg { background-color: #0065CA; }
.ansi-magenta-fg { color: #D160C4; }
.ansi-magenta-bg { background-color: #D160C4; }
.ansi-magenta-intense-fg { color: #A03196; }
.ansi-magenta-intense-bg { background-color: #A03196; }
.ansi-cyan-fg { color: #60C6C8; }
.ansi-cyan-bg { background-color: #60C6C8; }
.ansi-cyan-intense-fg { color: #258F8F; }
.ansi-cyan-intense-bg { background-color: #258F8F; }
.ansi-white-fg { color: #C5C1B4; }
.ansi-white-bg { background-color: #C5C1B4; }
.ansi-white-intense-fg { color: #A1A6B2; }
.ansi-white-intense-bg { background-color: #A1A6B2; }
.ansi-default-inverse-fg { color: #FFFFFF; }
.ansi-default-inverse-bg { background-color: #000000; }
.ansi-bold { font-weight: bold; }
.ansi-underline { text-decoration: underline; }
div.nbinput.container div.input_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight] > pre,
div.nboutput.container div.output_area div[class*=highlight].math,
div.nboutput.container div.output_area.rendered_html,
div.nboutput.container div.output_area > div.output_javascript,
div.nboutput.container div.output_area:not(.rendered_html) > img{
padding: 5px;
margin: 0;
}
/* fix copybtn overflow problem in chromium (needed for 'sphinx_copybutton') */
div.nbinput.container div.input_area > div[class^='highlight'],
div.nboutput.container div.output_area > div[class^='highlight']{
overflow-y: hidden;
}
/* hide copybtn icon on prompts (needed for 'sphinx_copybutton') */
.prompt .copybtn {
display: none;
}
/* Some additional styling taken form the Jupyter notebook CSS */
.jp-RenderedHTMLCommon table,
div.rendered_html table {
border: none;
border-collapse: collapse;
border-spacing: 0;
color: black;
font-size: 12px;
table-layout: fixed;
}
.jp-RenderedHTMLCommon thead,
div.rendered_html thead {
border-bottom: 1px solid black;
vertical-align: bottom;
}
.jp-RenderedHTMLCommon tr,
.jp-RenderedHTMLCommon th,
.jp-RenderedHTMLCommon td,
div.rendered_html tr,
div.rendered_html th,
div.rendered_html td {
text-align: right;
vertical-align: middle;
padding: 0.5em 0.5em;
line-height: normal;
white-space: normal;
max-width: none;
border: none;
}
.jp-RenderedHTMLCommon th,
div.rendered_html th {
font-weight: bold;
}
.jp-RenderedHTMLCommon tbody tr:nth-child(odd),
div.rendered_html tbody tr:nth-child(odd) {
background: #f5f5f5;
}
.jp-RenderedHTMLCommon tbody tr:hover,
div.rendered_html tbody tr:hover {
background: rgba(66, 165, 245, 0.2);
}
</style>
<div class="section" id="Solvers">
<h1><span class="section-number">5. </span>Solvers<a class="headerlink" href="#Solvers" title="Permalink to this headline"></a></h1>
<div class="section" id="Solvers">
<h1><span class="section-number">8. </span>Solvers<a class="headerlink" href="#Solvers" title="Permalink to this headline"></a></h1>
<div class="section" id="LearningSolver">
<h2><span class="section-number">5.1. </span>LearningSolver<a class="headerlink" href="#LearningSolver" title="Permalink to this headline"></a></h2>
<h2><span class="section-number">8.1. </span>LearningSolver<a class="headerlink" href="#LearningSolver" title="Permalink to this headline"></a></h2>
<div class="section" id="Example">
<h3>Example<a class="headerlink" href="#Example" title="Permalink to this headline"></a></h3>
<div class="nbinput docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[3]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[1]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">random</span>
@@ -528,7 +298,7 @@ div.rendered_html tbody tr:hover {
<span class="n">test_data</span> <span class="o">=</span> <span class="n">all_data</span><span class="p">[</span><span class="mi">40</span><span class="p">:]</span>
<span class="c1"># Collect training data</span>
<span class="n">bc</span> <span class="o">=</span> <span class="n">BasicCollector</span><span class="p">(</span><span class="n">time_limit_sec</span><span class="o">=</span><span class="mi">3600</span><span class="p">)</span>
<span class="n">bc</span> <span class="o">=</span> <span class="n">BasicCollector</span><span class="p">()</span>
<span class="n">bc</span><span class="o">.</span><span class="n">collect</span><span class="p">(</span><span class="n">train_data</span><span class="p">,</span> <span class="n">build_tsp_model</span><span class="p">,</span> <span class="n">n_jobs</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
<span class="c1"># Build learning solver</span>
@@ -555,11 +325,21 @@ div.rendered_html tbody tr:hover {
</pre></div>
</div>
</div>
<div class="nboutput docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area stderr docutils container">
<div class="highlight"><pre>
/home/axavier/Software/anaconda3/envs/miplearn/lib/python3.8/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html
from .autonotebook import tqdm as notebook_tqdm
</pre></div></div>
</div>
<div class="nboutput nblast docutils container">
<div class="prompt empty docutils container">
</div>
<div class="output_area docutils container">
<div class="highlight"><pre>
Restricted license - for non-production use only - expires 2023-10-25
Gurobi Optimizer version 9.5.2 build v9.5.2rc0 (linux64)
Thread count: 6 physical cores, 12 logical processors, using up to 12 threads
Optimize a model with 10 rows, 45 columns and 90 nonzeros
@@ -607,7 +387,7 @@ Root relaxation: objective 2.761000e+03, 14 iterations, 0.00 seconds (0.00 work
Cutting planes:
Lazy constraints: 3
Explored 1 nodes (15 simplex iterations) in 0.02 seconds (0.00 work units)
Explored 1 nodes (15 simplex iterations) in 0.01 seconds (0.00 work units)
Thread count was 12 (of 12 available processors)
Solution count 1: 2796
@@ -646,7 +426,7 @@ User-callback calls 27, time in user-callback 0.00 sec
</pre></div></div>
</div>
<div class="nbinput nblast docutils container">
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[2]:
<div class="prompt highlight-none notranslate"><div class="highlight"><pre><span></span>[1]:
</pre></div>
</div>
<div class="input_area highlight-ipython3 notranslate"><div class="highlight"><pre><span></span>
@@ -663,8 +443,8 @@ User-callback calls 27, time in user-callback 0.00 sec
<div class='prev-next-bottom'>
<a class='left-prev' id="prev-link" href="../primal/" title="previous page"><span class="section-number">4. </span>Primal Components</a>
<a class='right-next' id="next-link" href="../../api/problems/" title="next page"><span class="section-number">6. </span>Benchmark Problems</a>
<a class='left-prev' id="prev-link" href="../primal/" title="previous page"><span class="section-number">7. </span>Primal Components</a>
<a class='right-next' id="next-link" href="../../api/problems/" title="next page"><span class="section-number">9. </span>Benchmark Problems</a>
</div>
@@ -674,7 +454,7 @@ User-callback calls 27, time in user-callback 0.00 sec
<div class="container">
<p>
&copy; Copyright 2020-2022, UChicago Argonne, LLC.<br/>
&copy; Copyright 2020-2023, UChicago Argonne, LLC.<br/>
</p>
</div>
</footer>