Skip to content

Commit

Permalink
publish documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
g-poveda committed Mar 28, 2024
0 parents commit eea15fe
Show file tree
Hide file tree
Showing 818 changed files with 380,246 additions and 0 deletions.
Empty file added .nojekyll
Empty file.
4 changes: 4 additions & 0 deletions 0.2.1/.buildinfo
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 6aa803ac513344dededf8a723d617965
tags: 645f666f9bcd5a90fca523b33c5a78b7
Empty file added 0.2.1/.nojekyll
Empty file.
456 changes: 456 additions & 0 deletions 0.2.1/_modules/discrete_optimization/coloring/coloring_model.html

Large diffs are not rendered by default.

193 changes: 193 additions & 0 deletions 0.2.1/_modules/discrete_optimization/coloring/coloring_parser.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>discrete_optimization.coloring.coloring_parser &mdash; discrete-optimization 0.2.1 documentation</title>
<link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
<script src="../../../_static/js/html5shiv.min.js"></script>
<![endif]-->

<script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
<script src="../../../_static/jquery.js"></script>
<script src="../../../_static/underscore.js"></script>
<script src="../../../_static/_sphinx_javascript_frameworks_compat.js"></script>
<script src="../../../_static/doctools.js"></script>
<script src="../../../_static/sphinx_highlight.js"></script>
<script src="../../../_static/versions.js"></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">
0.2.1
</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" />
<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"></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">typing</span> <span class="kn">import</span> <span class="n">Any</span><span class="p">,</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">Hashable</span><span class="p">,</span> <span class="n">List</span><span class="p">,</span> <span class="n">Optional</span><span class="p">,</span> <span class="n">Tuple</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="sd">&quot;&quot;&quot;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 &quot;coloring&quot; 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 &quot;~/discrete_optimization_data &quot;</span>

<span class="sd"> &quot;&quot;&quot;</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">&quot;</span><span class="si">{</span><span class="n">data_home</span><span class="si">}</span><span class="s2">/coloring&quot;</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="o">-&gt;</span> <span class="n">ColoringProblem</span><span class="p">:</span>
<span class="sd">&quot;&quot;&quot;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"> &quot;&quot;&quot;</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">&quot;</span><span class="se">\n</span><span class="s2">&quot;</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="n">List</span><span class="p">[</span><span class="n">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="n">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="n">List</span><span class="p">[</span><span class="n">Tuple</span><span class="p">[</span><span class="n">Hashable</span><span class="p">,</span> <span class="n">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="o">-&gt;</span> <span class="n">ColoringProblem</span><span class="p">:</span>
<span class="sd">&quot;&quot;&quot;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"> &quot;&quot;&quot;</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">&quot;r&quot;</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="s2">&quot;utf-8&quot;</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>&#169; 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: 0.2.1
<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>
Loading

0 comments on commit eea15fe

Please sign in to comment.