forked from airbus/discrete-optimization
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b66c3c5
Showing
333 changed files
with
149,221 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
641 changes: 641 additions & 0 deletions
641
master/_modules/discrete_optimization/coloring/coloring_model.html
Large diffs are not rendered by default.
Oops, something went wrong.
208 changes: 208 additions & 0 deletions
208
master/_modules/discrete_optimization/coloring/coloring_parser.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
<!DOCTYPE html> | ||
<html class="writer-html5" lang="en" data-content_root="../../../"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>discrete_optimization.coloring.coloring_parser — discrete-optimization master documentation</title> | ||
<link rel="stylesheet" type="text/css" href="../../../_static/pygments.css?v=80d5e7a1" /> | ||
<link rel="stylesheet" type="text/css" href="../../../_static/css/theme.css?v=19f00094" /> | ||
|
||
|
||
<!--[if lt IE 9]> | ||
<script src="../../../_static/js/html5shiv.min.js"></script> | ||
<![endif]--> | ||
|
||
<script src="../../../_static/jquery.js?v=5d32c60e"></script> | ||
<script src="../../../_static/_sphinx_javascript_frameworks_compat.js?v=2cd50e6c"></script> | ||
<script src="../../../_static/documentation_options.js?v=30d551ce"></script> | ||
<script src="../../../_static/doctools.js?v=9a2dae69"></script> | ||
<script src="../../../_static/sphinx_highlight.js?v=dc90522c"></script> | ||
<script src="../../../_static/versions.js?v=dd1a30db"></script> | ||
<script src="../../../_static/js/theme.js"></script> | ||
<link rel="index" title="Index" href="../../../genindex.html" /> | ||
<link rel="search" title="Search" href="../../../search.html" /> | ||
</head> | ||
|
||
<body class="wy-body-for-nav"> | ||
<div class="wy-grid-for-nav"> | ||
<nav data-toggle="wy-nav-shift" class="wy-nav-side"> | ||
<div class="wy-side-scroll"> | ||
<div class="wy-side-nav-search" > | ||
|
||
|
||
|
||
<a href="../../../index.html" class="icon icon-home"> | ||
discrete-optimization | ||
</a> | ||
<div class="version"> | ||
master | ||
</div> | ||
<div role="search"> | ||
<form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get"> | ||
<input type="text" name="q" placeholder="Search docs" aria-label="Search docs" /> | ||
<input type="hidden" name="check_keywords" value="yes" /> | ||
<input type="hidden" name="area" value="default" /> | ||
</form> | ||
</div> | ||
</div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu"> | ||
<p class="caption" role="heading"><span class="caption-text">Contents</span></p> | ||
<ul> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../install.html">Installation</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../getting_started.html">Getting started</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../notebooks.html">Notebooks</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../api/modules.html">API Reference</a></li> | ||
<li class="toctree-l1"><a class="reference internal" href="../../../contribute.html">Contributing</a></li> | ||
<li class="toctree-l1"><a class="reference external" href="https://github.com/airbus/discrete-optimization">Github</a></li> | ||
</ul> | ||
|
||
</div> | ||
</div> | ||
</nav> | ||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" > | ||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i> | ||
<a href="../../../index.html">discrete-optimization</a> | ||
</nav> | ||
|
||
<div class="wy-nav-content"> | ||
<div class="rst-content style-external-links"> | ||
<div role="navigation" aria-label="Page navigation"> | ||
<ul class="wy-breadcrumbs"> | ||
<li><a href="../../../index.html" class="icon icon-home" aria-label="Home"></a></li> | ||
<li class="breadcrumb-item"><a href="../../index.html">Module code</a></li> | ||
<li class="breadcrumb-item active">discrete_optimization.coloring.coloring_parser</li> | ||
<li class="wy-breadcrumbs-aside"> | ||
</li> | ||
</ul> | ||
<hr/> | ||
</div> | ||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> | ||
<div itemprop="articleBody"> | ||
|
||
<h1>Source code for discrete_optimization.coloring.coloring_parser</h1><div class="highlight"><pre> | ||
<span></span><span class="c1"># Copyright (c) 2022 AIRBUS and its affiliates.</span> | ||
<span class="c1"># This source code is licensed under the MIT license found in the</span> | ||
<span class="c1"># LICENSE file in the root directory of this source tree.</span> | ||
|
||
<span class="kn">import</span> <span class="nn">os</span> | ||
<span class="kn">from</span> <span class="nn">collections.abc</span> <span class="kn">import</span> <span class="n">Hashable</span> | ||
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Any</span><span class="p">,</span> <span class="n">Optional</span> | ||
|
||
<span class="kn">from</span> <span class="nn">discrete_optimization.coloring.coloring_model</span> <span class="kn">import</span> <span class="n">ColoringProblem</span> | ||
<span class="kn">from</span> <span class="nn">discrete_optimization.datasets</span> <span class="kn">import</span> <span class="n">get_data_home</span> | ||
<span class="kn">from</span> <span class="nn">discrete_optimization.generic_tools.graph_api</span> <span class="kn">import</span> <span class="n">Graph</span> | ||
|
||
|
||
<div class="viewcode-block" id="get_data_available"> | ||
<a class="viewcode-back" href="../../../api/discrete_optimization.coloring.html#discrete_optimization.coloring.coloring_parser.get_data_available">[docs]</a> | ||
<span class="k">def</span> <span class="nf">get_data_available</span><span class="p">(</span> | ||
<span class="n">data_folder</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span><span class="p">,</span> <span class="n">data_home</span><span class="p">:</span> <span class="n">Optional</span><span class="p">[</span><span class="nb">str</span><span class="p">]</span> <span class="o">=</span> <span class="kc">None</span> | ||
<span class="p">)</span> <span class="o">-></span> <span class="nb">list</span><span class="p">[</span><span class="nb">str</span><span class="p">]:</span> | ||
<span class="w"> </span><span class="sd">"""Get datasets available for coloring.</span> | ||
|
||
<span class="sd"> Params:</span> | ||
<span class="sd"> data_folder: folder where datasets for coloring whould be find.</span> | ||
<span class="sd"> If None, we look in "coloring" subdirectory of `data_home`.</span> | ||
<span class="sd"> data_home: root directory for all datasets. Is None, set by</span> | ||
<span class="sd"> default to "~/discrete_optimization_data "</span> | ||
|
||
<span class="sd"> """</span> | ||
<span class="k">if</span> <span class="n">data_folder</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span> | ||
<span class="n">data_home</span> <span class="o">=</span> <span class="n">get_data_home</span><span class="p">(</span><span class="n">data_home</span><span class="o">=</span><span class="n">data_home</span><span class="p">)</span> | ||
<span class="n">data_folder</span> <span class="o">=</span> <span class="sa">f</span><span class="s2">"</span><span class="si">{</span><span class="n">data_home</span><span class="si">}</span><span class="s2">/coloring"</span> | ||
|
||
<span class="k">try</span><span class="p">:</span> | ||
<span class="n">datasets</span> <span class="o">=</span> <span class="p">[</span> | ||
<span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">abspath</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">data_folder</span><span class="p">,</span> <span class="n">f</span><span class="p">))</span> | ||
<span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">data_folder</span><span class="p">)</span> | ||
<span class="p">]</span> | ||
<span class="k">except</span> <span class="ne">FileNotFoundError</span><span class="p">:</span> | ||
<span class="n">datasets</span> <span class="o">=</span> <span class="p">[]</span> | ||
<span class="k">return</span> <span class="n">datasets</span></div> | ||
|
||
|
||
|
||
<div class="viewcode-block" id="parse"> | ||
<a class="viewcode-back" href="../../../api/discrete_optimization.coloring.html#discrete_optimization.coloring.coloring_parser.parse">[docs]</a> | ||
<span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="n">input_data</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">ColoringProblem</span><span class="p">:</span> | ||
<span class="w"> </span><span class="sd">"""From a text input, initialise a coloring problem instance.</span> | ||
|
||
<span class="sd"> Args:</span> | ||
<span class="sd"> input_data: text input in the format of {data_home}/coloring files</span> | ||
|
||
<span class="sd"> Returns: a ColoringProblem instance</span> | ||
<span class="sd"> """</span> | ||
<span class="c1"># parse the input</span> | ||
<span class="n">lines</span> <span class="o">=</span> <span class="n">input_data</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">"</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span> | ||
<span class="n">first_line</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">()</span> | ||
<span class="n">node_count</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">first_line</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span> | ||
<span class="n">edge_count</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">first_line</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span> | ||
<span class="n">edges</span><span class="p">:</span> <span class="nb">list</span><span class="p">[</span><span class="nb">tuple</span><span class="p">[</span><span class="n">Hashable</span><span class="p">,</span> <span class="n">Hashable</span><span class="p">,</span> <span class="nb">dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">]]]</span> <span class="o">=</span> <span class="p">[]</span> | ||
<span class="n">nodes</span><span class="p">:</span> <span class="nb">list</span><span class="p">[</span><span class="nb">tuple</span><span class="p">[</span><span class="n">Hashable</span><span class="p">,</span> <span class="nb">dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="n">Any</span><span class="p">]]]</span> <span class="o">=</span> <span class="p">[(</span><span class="n">i</span><span class="p">,</span> <span class="p">{})</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">node_count</span><span class="p">)]</span> | ||
<span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="n">edge_count</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span> | ||
<span class="n">line</span> <span class="o">=</span> <span class="n">lines</span><span class="p">[</span><span class="n">i</span><span class="p">]</span> | ||
<span class="n">parts</span> <span class="o">=</span> <span class="n">line</span><span class="o">.</span><span class="n">split</span><span class="p">()</span> | ||
<span class="n">edges</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="nb">int</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span> <span class="nb">int</span><span class="p">(</span><span class="n">parts</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span> <span class="p">{}))</span> | ||
<span class="k">return</span> <span class="n">ColoringProblem</span><span class="p">(</span> | ||
<span class="n">Graph</span><span class="p">(</span><span class="n">nodes</span><span class="p">,</span> <span class="n">edges</span><span class="p">,</span> <span class="n">undirected</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">compute_predecessors</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span> | ||
<span class="p">)</span></div> | ||
|
||
|
||
|
||
<div class="viewcode-block" id="parse_file"> | ||
<a class="viewcode-back" href="../../../api/discrete_optimization.coloring.html#discrete_optimization.coloring.coloring_parser.parse_file">[docs]</a> | ||
<span class="k">def</span> <span class="nf">parse_file</span><span class="p">(</span><span class="n">file_path</span><span class="p">:</span> <span class="nb">str</span><span class="p">)</span> <span class="o">-></span> <span class="n">ColoringProblem</span><span class="p">:</span> | ||
<span class="w"> </span><span class="sd">"""From an absolute path to a coloring text file, return the corresponding coloring instance</span> | ||
<span class="sd"> Args:</span> | ||
<span class="sd"> file_path (str): absolute path to the file</span> | ||
|
||
<span class="sd"> Returns: a ColoringProblem instance</span> | ||
|
||
<span class="sd"> """</span> | ||
<span class="k">with</span> <span class="nb">open</span><span class="p">(</span><span class="n">file_path</span><span class="p">,</span> <span class="s2">"r"</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">"utf-8"</span><span class="p">)</span> <span class="k">as</span> <span class="n">input_data_file</span><span class="p">:</span> | ||
<span class="n">input_data</span> <span class="o">=</span> <span class="n">input_data_file</span><span class="o">.</span><span class="n">read</span><span class="p">()</span> | ||
<span class="n">coloring_model</span> <span class="o">=</span> <span class="n">parse</span><span class="p">(</span><span class="n">input_data</span><span class="p">)</span> | ||
<span class="k">return</span> <span class="n">coloring_model</span></div> | ||
|
||
</pre></div> | ||
|
||
</div> | ||
</div> | ||
<footer> | ||
|
||
<hr/> | ||
|
||
<div role="contentinfo"> | ||
<p>© Copyright 2022, Airbus.</p> | ||
</div> | ||
|
||
Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a | ||
<a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a> | ||
provided by <a href="https://readthedocs.org">Read the Docs</a>. | ||
|
||
|
||
</footer> | ||
</div> | ||
</div> | ||
</section> | ||
</div> | ||
|
||
<div class="rst-versions" data-toggle="rst-versions" role="note" aria-label="versions"> | ||
<span class="rst-current-version" data-toggle="rst-current-version"> | ||
<span class="fa fa-book"> Versions</span> | ||
v: master | ||
<span class="fa fa-caret-down"></span> | ||
</span> | ||
<div class="rst-other-versions"> | ||
<dl id="docs-versions"> | ||
</dl> | ||
</div> | ||
</div> | ||
<script> | ||
jQuery(function () { | ||
SphinxRtdTheme.Navigation.enable(true); | ||
}); | ||
</script> | ||
|
||
</body> | ||
</html> |
Oops, something went wrong.