Skip to content

Commit

Permalink
deploy: 7d30cd2
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrozocca committed Oct 23, 2023
1 parent 402a6ba commit 7c36b06
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 12 deletions.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 20 additions & 8 deletions _sources/notebooks/04/mincost-flow.ipynb

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions notebooks/04/mincost-flow.html
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@ <h2>Mathematical formulation<a class="headerlink" href="#mathematical-formulatio
<span class="n">draw</span><span class="p">,</span>
<span class="n">draw_networkx_labels</span> <span class="k">as</span> <span class="n">draw_labels</span><span class="p">,</span>
<span class="n">draw_networkx_edge_labels</span> <span class="k">as</span> <span class="n">draw_edge_labels</span><span class="p">,</span>
<span class="n">draw_networkx_edges</span> <span class="k">as</span> <span class="n">draw_edges</span><span class="p">,</span>
<span class="p">)</span>
<span class="kn">from</span> <span class="nn">IPython.display</span> <span class="kn">import</span> <span class="n">HTML</span><span class="p">,</span> <span class="n">Markdown</span>

Expand All @@ -616,7 +617,18 @@ <h2>Mathematical formulation<a class="headerlink" href="#mathematical-formulatio
<span class="n">g</span> <span class="o">=</span> <span class="n">DiGraph</span><span class="p">(</span><span class="n">network</span><span class="p">[</span><span class="s2">&quot;edges&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
<span class="n">pos</span> <span class="o">=</span> <span class="n">layout</span><span class="o">.</span><span class="n">kamada_kawai_layout</span><span class="p">(</span><span class="n">g</span><span class="p">,</span> <span class="n">weight</span><span class="o">=</span><span class="kc">None</span><span class="p">)</span>
<span class="n">draw</span><span class="p">(</span><span class="n">g</span><span class="p">,</span> <span class="n">pos</span><span class="o">=</span><span class="n">pos</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span> <span class="n">with_labels</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">font_color</span><span class="o">=</span><span class="s2">&quot;white&quot;</span><span class="p">)</span>

<span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">edge_flows</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">):</span>
<span class="n">F</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">edge_flows</span><span class="o">.</span><span class="n">items</span><span class="p">()</span> <span class="k">if</span> <span class="n">v</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">}</span>
<span class="n">draw_edges</span><span class="p">(</span>
<span class="n">g</span><span class="p">,</span>
<span class="n">pos</span><span class="o">=</span><span class="n">pos</span><span class="p">,</span>
<span class="n">edgelist</span><span class="o">=</span><span class="n">F</span><span class="o">.</span><span class="n">keys</span><span class="p">(),</span>
<span class="n">width</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span>
<span class="n">edge_color</span><span class="o">=</span><span class="s2">&quot;lightblue&quot;</span><span class="p">,</span>
<span class="n">style</span><span class="o">=</span><span class="s2">&quot;solid&quot;</span><span class="p">,</span>
<span class="n">alpha</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
<span class="n">arrowstyle</span><span class="o">=</span><span class="s2">&quot;-&quot;</span><span class="p">,</span>
<span class="p">),</span>
<span class="n">shifted_pos</span> <span class="o">=</span> <span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span> <span class="o">-</span> <span class="mf">0.08</span><span class="p">)</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">y</span><span class="p">)</span> <span class="ow">in</span> <span class="n">pos</span><span class="o">.</span><span class="n">items</span><span class="p">()}</span>
<span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">data</span> <span class="ow">in</span> <span class="n">network</span><span class="p">[</span><span class="s2">&quot;nodes&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
<span class="n">label</span> <span class="o">=</span> <span class="s2">&quot;,&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">k</span><span class="si">}</span><span class="s2">=</span><span class="si">{</span><span class="n">v</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">data</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
Expand Down Expand Up @@ -647,6 +659,7 @@ <h2>Mathematical formulation<a class="headerlink" href="#mathematical-formulatio
<span class="p">},</span>
<span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="n">draw_edges</span><span class="p">(</span><span class="n">g</span><span class="p">,</span> <span class="n">pos</span><span class="o">=</span><span class="n">pos</span><span class="p">),</span>
<span class="n">draw_edge_labels</span><span class="p">(</span>
<span class="n">g</span><span class="p">,</span> <span class="n">pos</span><span class="o">=</span><span class="n">pos</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">11</span><span class="p">,</span> <span class="n">font_weight</span><span class="o">=</span><span class="s2">&quot;bold&quot;</span><span class="p">,</span> <span class="n">edge_labels</span><span class="o">=</span><span class="n">edge_flows</span>
<span class="p">)</span>
Expand Down Expand Up @@ -708,7 +721,6 @@ <h2>Mathematical formulation<a class="headerlink" href="#mathematical-formulatio
<span class="p">)</span>
<span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="sa">f</span><span class="s2">&quot;Objective value: </span><span class="si">{</span><span class="n">model</span><span class="o">.</span><span class="n">objective</span><span class="p">()</span><span class="si">:</span><span class="s2">.0f</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>

<span class="n">fig</span><span class="p">,</span> <span class="n">ax</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">subplots</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">figsize</span><span class="o">=</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">))</span>
<span class="n">draw_network</span><span class="p">(</span><span class="n">network</span><span class="p">,</span> <span class="n">ax</span><span class="o">=</span><span class="n">ax</span><span class="p">,</span> <span class="n">edge_flows</span><span class="o">=</span><span class="n">flows</span><span class="p">)</span>
</pre></div>
Expand All @@ -722,7 +734,7 @@ <h2>Mathematical formulation<a class="headerlink" href="#mathematical-formulatio
<div class="output stream highlight-myst-ansi notranslate"><div class="highlight"><pre><span></span>Objective value: 93
</pre></div>
</div>
<img alt="../../_images/0301fa985034d89cb4cc92b28d62ab631fa15e2650d5211090991e31d65f2a53.png" src="../../_images/0301fa985034d89cb4cc92b28d62ab631fa15e2650d5211090991e31d65f2a53.png" />
<img alt="../../_images/e3dfb0ec8da349f04fb64275df10f094b4add3ae013d5973a33c83f9aef5f01d.png" src="../../_images/e3dfb0ec8da349f04fb64275df10f094b4add3ae013d5973a33c83f9aef5f01d.png" />
</div>
</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion searchindex.js

Large diffs are not rendered by default.

0 comments on commit 7c36b06

Please sign in to comment.