mirror of
https://github.com/ANL-CEEESA/MIPLearn.git
synced 2025-12-06 09:28:51 -06:00
Update 0.2 docs
This commit is contained in:
@@ -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,
|
||||
) -> MIPSolveStats:
|
||||
) -> LearningSolveStats:
|
||||
|
||||
# Load instance from file, if necessary
|
||||
filename = None
|
||||
@@ -229,15 +229,24 @@ class LearningSolver:
|
||||
|
||||
# Solve MILP
|
||||
logger.info("Solving MILP...")
|
||||
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 "LP value" in training_sample.keys():
|
||||
stats["LP value"] = training_sample["LP value"]
|
||||
stats["Solver"] = "default"
|
||||
stats["Gap"] = self._compute_gap(
|
||||
ub=stats["Upper bound"],
|
||||
lb=stats["Lower bound"],
|
||||
)
|
||||
stats["Mode"] = self.mode
|
||||
|
||||
# Read MIP solution and bounds
|
||||
# Add some information to training_sample
|
||||
training_sample["Lower bound"] = stats["Lower bound"]
|
||||
training_sample["Upper bound"] = stats["Upper bound"]
|
||||
training_sample["MIP log"] = stats["Log"]
|
||||
@@ -268,7 +277,7 @@ class LearningSolver:
|
||||
output_filename: Optional[str] = None,
|
||||
discard_output: bool = False,
|
||||
tee: bool = False,
|
||||
) -> MIPSolveStats:
|
||||
) -> LearningSolveStats:
|
||||
"""
|
||||
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: "Lower bound", "Upper bound", "Wallclock time", "Nodes",
|
||||
"Sense", "Log", "Warm start value" and "LP value".
|
||||
@@ -337,7 +346,7 @@ class LearningSolver:
|
||||
label: str = "Solve",
|
||||
output_filenames: Optional[List[str]] = None,
|
||||
discard_outputs: bool = False,
|
||||
) -> List[MIPSolveStats]:
|
||||
) -> List[LearningSolveStats]:
|
||||
"""
|
||||
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) -> Dict:
|
||||
self.internal_solver = None
|
||||
return self.__dict__</code></pre>
|
||||
return self.__dict__
|
||||
|
||||
@staticmethod
|
||||
def _compute_gap(ub: Optional[float], lb: Optional[float]) -> Optional[float]:
|
||||
if lb is None or ub is None or lb * ub < 0:
|
||||
# solver did not find a solution and/or bound
|
||||
return None
|
||||
elif abs(ub - lb) < 1e-6:
|
||||
# avoid division by zero when ub = lb = 0
|
||||
return 0.0
|
||||
else:
|
||||
# divide by max(abs(ub),abs(lb)) to ensure gap <= 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,
|
||||
) -> MIPSolveStats:
|
||||
) -> 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("Solving MILP...")
|
||||
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 "LP value" in training_sample.keys():
|
||||
stats["LP value"] = training_sample["LP value"]
|
||||
stats["Solver"] = "default"
|
||||
stats["Gap"] = self._compute_gap(
|
||||
ub=stats["Upper bound"],
|
||||
lb=stats["Lower bound"],
|
||||
)
|
||||
stats["Mode"] = self.mode
|
||||
|
||||
# Read MIP solution and bounds
|
||||
# Add some information to training_sample
|
||||
training_sample["Lower bound"] = stats["Lower bound"]
|
||||
training_sample["Upper bound"] = stats["Upper bound"]
|
||||
training_sample["MIP log"] = stats["Log"]
|
||||
@@ -646,7 +676,7 @@ the theoretical performance of perfect ML models.</dd>
|
||||
output_filename: Optional[str] = None,
|
||||
discard_output: bool = False,
|
||||
tee: bool = False,
|
||||
) -> MIPSolveStats:
|
||||
) -> LearningSolveStats:
|
||||
"""
|
||||
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: "Lower bound", "Upper bound", "Wallclock time", "Nodes",
|
||||
"Sense", "Log", "Warm start value" and "LP value".
|
||||
@@ -715,7 +745,7 @@ the theoretical performance of perfect ML models.</dd>
|
||||
label: str = "Solve",
|
||||
output_filenames: Optional[List[str]] = None,
|
||||
discard_outputs: bool = False,
|
||||
) -> List[MIPSolveStats]:
|
||||
) -> List[LearningSolveStats]:
|
||||
"""
|
||||
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) -> Dict:
|
||||
self.internal_solver = None
|
||||
return self.__dict__</code></pre>
|
||||
return self.__dict__
|
||||
|
||||
@staticmethod
|
||||
def _compute_gap(ub: Optional[float], lb: Optional[float]) -> Optional[float]:
|
||||
if lb is None or ub is None or lb * ub < 0:
|
||||
# solver did not find a solution and/or bound
|
||||
return None
|
||||
elif abs(ub - lb) < 1e-6:
|
||||
# avoid division by zero when ub = lb = 0
|
||||
return 0.0
|
||||
else:
|
||||
# divide by max(abs(ub),abs(lb)) to ensure gap <= 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='Solve', 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 = "Solve",
|
||||
output_filenames: Optional[List[str]] = None,
|
||||
discard_outputs: bool = False,
|
||||
) -> List[MIPSolveStats]:
|
||||
) -> List[LearningSolveStats]:
|
||||
"""
|
||||
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,
|
||||
) -> MIPSolveStats:
|
||||
) -> LearningSolveStats:
|
||||
"""
|
||||
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: "Lower bound", "Upper bound", "Wallclock time", "Nodes",
|
||||
"Sense", "Log", "Warm start value" and "LP value".
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user