Update 0.2 docs

This commit is contained in:
2021-01-22 07:25:10 -06:00
parent 894f4b4668
commit 144523a5c0
73 changed files with 607 additions and 842 deletions

View File

@@ -3,7 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1" />
<meta name="generator" content="pdoc 0.7.0" />
<meta name="generator" content="pdoc 0.7.5" />
<title>miplearn.solvers.learning API documentation</title>
<meta name="description" content="" />
<link href='https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css' rel='stylesheet'>
@@ -46,7 +46,7 @@ from miplearn.instance import Instance
from miplearn.solvers import _RedirectOutput
from miplearn.solvers.internal import InternalSolver
from miplearn.solvers.pyomo.gurobi import GurobiPyomoSolver
from miplearn.types import MIPSolveStats, TrainingSample
from miplearn.types import MIPSolveStats, TrainingSample, LearningSolveStats
logger = logging.getLogger(__name__)
@@ -153,7 +153,7 @@ class LearningSolver:
output_filename: Optional[str] = None,
discard_output: bool = False,
tee: bool = False,
) -&gt; MIPSolveStats:
) -&gt; LearningSolveStats:
# Load instance from file, if necessary
filename = None
@@ -229,15 +229,24 @@ class LearningSolver:
# Solve MILP
logger.info(&#34;Solving MILP...&#34;)
stats = self.internal_solver.solve(
tee=tee,
iteration_cb=iteration_cb_wrapper,
lazy_cb=lazy_cb,
stats = cast(
LearningSolveStats,
self.internal_solver.solve(
tee=tee,
iteration_cb=iteration_cb_wrapper,
lazy_cb=lazy_cb,
),
)
if &#34;LP value&#34; in training_sample.keys():
stats[&#34;LP value&#34;] = training_sample[&#34;LP value&#34;]
stats[&#34;Solver&#34;] = &#34;default&#34;
stats[&#34;Gap&#34;] = self._compute_gap(
ub=stats[&#34;Upper bound&#34;],
lb=stats[&#34;Lower bound&#34;],
)
stats[&#34;Mode&#34;] = self.mode
# Read MIP solution and bounds
# Add some information to training_sample
training_sample[&#34;Lower bound&#34;] = stats[&#34;Lower bound&#34;]
training_sample[&#34;Upper bound&#34;] = stats[&#34;Upper bound&#34;]
training_sample[&#34;MIP log&#34;] = stats[&#34;Log&#34;]
@@ -268,7 +277,7 @@ class LearningSolver:
output_filename: Optional[str] = None,
discard_output: bool = False,
tee: bool = False,
) -&gt; MIPSolveStats:
) -&gt; LearningSolveStats:
&#34;&#34;&#34;
Solves the given instance. If trained machine-learning models are
available, they will be used to accelerate the solution process.
@@ -301,7 +310,7 @@ class LearningSolver:
Returns
-------
MIPSolveStats
LearningSolveStats
A dictionary of solver statistics containing at least the following
keys: &#34;Lower bound&#34;, &#34;Upper bound&#34;, &#34;Wallclock time&#34;, &#34;Nodes&#34;,
&#34;Sense&#34;, &#34;Log&#34;, &#34;Warm start value&#34; and &#34;LP value&#34;.
@@ -337,7 +346,7 @@ class LearningSolver:
label: str = &#34;Solve&#34;,
output_filenames: Optional[List[str]] = None,
discard_outputs: bool = False,
) -&gt; List[MIPSolveStats]:
) -&gt; List[LearningSolveStats]:
&#34;&#34;&#34;
Solves multiple instances in parallel.
@@ -364,7 +373,7 @@ class LearningSolver:
Returns
-------
List[MIPSolveStats]
List[LearningSolveStats]
List of solver statistics, with one entry for each provided instance.
The list is the same you would obtain by calling
`[solver.solve(p) for p in instances]`
@@ -409,7 +418,19 @@ class LearningSolver:
def __getstate__(self) -&gt; Dict:
self.internal_solver = None
return self.__dict__</code></pre>
return self.__dict__
@staticmethod
def _compute_gap(ub: Optional[float], lb: Optional[float]) -&gt; Optional[float]:
if lb is None or ub is None or lb * ub &lt; 0:
# solver did not find a solution and/or bound
return None
elif abs(ub - lb) &lt; 1e-6:
# avoid division by zero when ub = lb = 0
return 0.0
else:
# divide by max(abs(ub),abs(lb)) to ensure gap &lt;= 1
return (ub - lb) / max(abs(ub), abs(lb))</code></pre>
</details>
</section>
<section>
@@ -531,7 +552,7 @@ the theoretical performance of perfect ML models.</dd>
output_filename: Optional[str] = None,
discard_output: bool = False,
tee: bool = False,
) -&gt; MIPSolveStats:
) -&gt; LearningSolveStats:
# Load instance from file, if necessary
filename = None
@@ -607,15 +628,24 @@ the theoretical performance of perfect ML models.</dd>
# Solve MILP
logger.info(&#34;Solving MILP...&#34;)
stats = self.internal_solver.solve(
tee=tee,
iteration_cb=iteration_cb_wrapper,
lazy_cb=lazy_cb,
stats = cast(
LearningSolveStats,
self.internal_solver.solve(
tee=tee,
iteration_cb=iteration_cb_wrapper,
lazy_cb=lazy_cb,
),
)
if &#34;LP value&#34; in training_sample.keys():
stats[&#34;LP value&#34;] = training_sample[&#34;LP value&#34;]
stats[&#34;Solver&#34;] = &#34;default&#34;
stats[&#34;Gap&#34;] = self._compute_gap(
ub=stats[&#34;Upper bound&#34;],
lb=stats[&#34;Lower bound&#34;],
)
stats[&#34;Mode&#34;] = self.mode
# Read MIP solution and bounds
# Add some information to training_sample
training_sample[&#34;Lower bound&#34;] = stats[&#34;Lower bound&#34;]
training_sample[&#34;Upper bound&#34;] = stats[&#34;Upper bound&#34;]
training_sample[&#34;MIP log&#34;] = stats[&#34;Log&#34;]
@@ -646,7 +676,7 @@ the theoretical performance of perfect ML models.</dd>
output_filename: Optional[str] = None,
discard_output: bool = False,
tee: bool = False,
) -&gt; MIPSolveStats:
) -&gt; LearningSolveStats:
&#34;&#34;&#34;
Solves the given instance. If trained machine-learning models are
available, they will be used to accelerate the solution process.
@@ -679,7 +709,7 @@ the theoretical performance of perfect ML models.</dd>
Returns
-------
MIPSolveStats
LearningSolveStats
A dictionary of solver statistics containing at least the following
keys: &#34;Lower bound&#34;, &#34;Upper bound&#34;, &#34;Wallclock time&#34;, &#34;Nodes&#34;,
&#34;Sense&#34;, &#34;Log&#34;, &#34;Warm start value&#34; and &#34;LP value&#34;.
@@ -715,7 +745,7 @@ the theoretical performance of perfect ML models.</dd>
label: str = &#34;Solve&#34;,
output_filenames: Optional[List[str]] = None,
discard_outputs: bool = False,
) -&gt; List[MIPSolveStats]:
) -&gt; List[LearningSolveStats]:
&#34;&#34;&#34;
Solves multiple instances in parallel.
@@ -742,7 +772,7 @@ the theoretical performance of perfect ML models.</dd>
Returns
-------
List[MIPSolveStats]
List[LearningSolveStats]
List of solver statistics, with one entry for each provided instance.
The list is the same you would obtain by calling
`[solver.solve(p) for p in instances]`
@@ -787,7 +817,19 @@ the theoretical performance of perfect ML models.</dd>
def __getstate__(self) -&gt; Dict:
self.internal_solver = None
return self.__dict__</code></pre>
return self.__dict__
@staticmethod
def _compute_gap(ub: Optional[float], lb: Optional[float]) -&gt; Optional[float]:
if lb is None or ub is None or lb * ub &lt; 0:
# solver did not find a solution and/or bound
return None
elif abs(ub - lb) &lt; 1e-6:
# avoid division by zero when ub = lb = 0
return 0.0
else:
# divide by max(abs(ub),abs(lb)) to ensure gap &lt;= 1
return (ub - lb) / max(abs(ub), abs(lb))</code></pre>
</details>
<h3>Methods</h3>
<dl>
@@ -808,7 +850,7 @@ the theoretical performance of perfect ML models.</dd>
</details>
</dd>
<dt id="miplearn.solvers.learning.LearningSolver.parallel_solve"><code class="name flex">
<span>def <span class="ident">parallel_solve</span></span>(<span>self, instances, n_jobs=4, label=&#39;Solve&#39;, output_filenames=None, discard_outputs=False)</span>
<span>def <span class="ident">parallel_solve</span></span>(<span>self, instances, n_jobs=4, label='Solve', output_filenames=None, discard_outputs=False)</span>
</code></dt>
<dd>
<section class="desc"><p>Solves multiple instances in parallel.</p>
@@ -834,7 +876,7 @@ them instead. Useful during benchmarking.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>List</code>[<code>MIPSolveStats</code>]</dt>
<dt><code>List</code>[<code>LearningSolveStats</code>]</dt>
<dd>List of solver statistics, with one entry for each provided instance.
The list is the same you would obtain by calling
<code>[solver.solve(p) for p in instances]</code></dd>
@@ -850,7 +892,7 @@ The list is the same you would obtain by calling
label: str = &#34;Solve&#34;,
output_filenames: Optional[List[str]] = None,
discard_outputs: bool = False,
) -&gt; List[MIPSolveStats]:
) -&gt; List[LearningSolveStats]:
&#34;&#34;&#34;
Solves multiple instances in parallel.
@@ -877,7 +919,7 @@ The list is the same you would obtain by calling
Returns
-------
List[MIPSolveStats]
List[LearningSolveStats]
List of solver statistics, with one entry for each provided instance.
The list is the same you would obtain by calling
`[solver.solve(p) for p in instances]`
@@ -933,7 +975,7 @@ them. Useful during benchmarking.</dd>
</dl>
<h2 id="returns">Returns</h2>
<dl>
<dt><code>MIPSolveStats</code></dt>
<dt><code>LearningSolveStats</code></dt>
<dd>
<p>A dictionary of solver statistics containing at least the following
keys: "Lower bound", "Upper bound", "Wallclock time", "Nodes",
@@ -955,7 +997,7 @@ details.</p>
output_filename: Optional[str] = None,
discard_output: bool = False,
tee: bool = False,
) -&gt; MIPSolveStats:
) -&gt; LearningSolveStats:
&#34;&#34;&#34;
Solves the given instance. If trained machine-learning models are
available, they will be used to accelerate the solution process.
@@ -988,7 +1030,7 @@ details.</p>
Returns
-------
MIPSolveStats
LearningSolveStats
A dictionary of solver statistics containing at least the following
keys: &#34;Lower bound&#34;, &#34;Upper bound&#34;, &#34;Wallclock time&#34;, &#34;Nodes&#34;,
&#34;Sense&#34;, &#34;Log&#34;, &#34;Warm start value&#34; and &#34;LP value&#34;.
@@ -1050,7 +1092,7 @@ details.</p>
</nav>
</main>
<footer id="footer">
<p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.0</a>.</p>
<p>Generated by <a href="https://pdoc3.github.io/pdoc"><cite>pdoc</cite> 0.7.5</a>.</p>
</footer>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad()</script>