Commit 26633e17 authored by Ahmad Reza's avatar Ahmad Reza
Browse files

changed matter to regular expression Matter

parent 3933bfa6
This diff is collapsed.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Overview: module code &#8212; Opportunistic Robotics Network Simulator 1.0.1 documentation</title>
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" src="../_static/documentation_options.js"></script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Opportunistic Robotics Network Simulator 1.0.1 documentation</a> &#187;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>All modules for which code is available</h1>
<ul><li><a href="csv_generator.html">csv_generator</a></li>
<li><a href="location.html">location</a></li>
<li><a href="matter.html">matter</a></li>
<li><a href="multiple.html">multiple</a></li>
<li><a href="oppnet_csv_generator.html">oppnet_csv_generator</a></li>
<li><a href="particle.html">particle</a></li>
<li><a href="tile.html">tile</a></li>
<li><a href="sim.html">sim</a></li>
</ul>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Opportunistic Robotics Network Simulator 1.0.1 documentation</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Ahmad Reza Cheraghi.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.7.2.
</div>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>multiple &#8212; Opportunistic Robotics Network Simulator 1.0.1 documentation</title>
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" src="../_static/documentation_options.js"></script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Opportunistic Robotics Network Simulator 1.0.1 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Module code</a> &#187;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for multiple</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">sys</span><span class="o">,</span> <span class="nn">getopt</span><span class="o">,</span> <span class="nn">subprocess</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="k">import</span> <span class="n">datetime</span>
<div class="viewcode-block" id="main"><a class="viewcode-back" href="../multiple.html#multiple.main">[docs]</a><span class="k">def</span> <span class="nf">main</span><span class="p">(</span><span class="n">argv</span><span class="p">):</span>
<span class="n">max_round</span> <span class="o">=</span> <span class="mi">100</span>
<span class="n">seedvalue</span> <span class="o">=</span> <span class="mi">5</span>
<span class="n">nTime</span> <span class="o">=</span> <span class="n">datetime</span><span class="o">.</span><span class="n">utcnow</span><span class="p">()</span><span class="o">.</span><span class="n">strftime</span><span class="p">(</span><span class="s1">&#39;%Y-%m-</span><span class="si">%d</span><span class="s1"> %H:%M:%S&#39;</span><span class="p">)[:</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">opts</span><span class="p">,</span> <span class="n">args</span> <span class="o">=</span> <span class="n">getopt</span><span class="o">.</span><span class="n">getopt</span><span class="p">(</span><span class="n">argv</span><span class="p">,</span> <span class="s2">&quot;hs:w:r:n:v:&quot;</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;solution=&quot;</span><span class="p">,</span> <span class="s2">&quot;sim=&quot;</span><span class="p">])</span>
<span class="k">except</span> <span class="n">getopt</span><span class="o">.</span><span class="n">GetoptError</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Error: main.py -r &lt;randomeSeed&gt; -s &lt;solution&gt; -w &lt;sim&gt; -n &lt;maxRounds&gt;&#39;</span><span class="p">)</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="k">for</span> <span class="n">opt</span><span class="p">,</span> <span class="n">arg</span> <span class="ow">in</span> <span class="n">opts</span><span class="p">:</span>
<span class="k">if</span> <span class="n">opt</span> <span class="o">==</span> <span class="s1">&#39;-h&#39;</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;main.py -r &lt;randomeSeed&gt; -s &lt;solution&gt; -w &lt;sim&gt; -n &lt;maxRounds&gt;&#39;</span><span class="p">)</span>
<span class="n">sys</span><span class="o">.</span><span class="n">exit</span><span class="p">()</span>
<span class="k">elif</span> <span class="n">opt</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;-s&quot;</span><span class="p">,</span> <span class="s2">&quot;--solution&quot;</span><span class="p">):</span>
<span class="n">solution_file</span> <span class="o">=</span> <span class="n">arg</span>
<span class="k">elif</span> <span class="n">opt</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;-w&quot;</span><span class="p">,</span> <span class="s2">&quot;--sim&quot;</span><span class="p">):</span>
<span class="n">sim_file</span> <span class="o">=</span> <span class="n">arg</span>
<span class="k">elif</span> <span class="n">opt</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;-r&quot;</span><span class="p">,</span> <span class="s2">&quot;--seed&quot;</span><span class="p">):</span>
<span class="n">seedvalue</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">opt</span> <span class="ow">in</span> <span class="p">(</span><span class="s2">&quot;-n&quot;</span><span class="p">,</span> <span class="s2">&quot;--maxrounds&quot;</span><span class="p">):</span>
<span class="n">max_round</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">arg</span><span class="p">)</span>
<span class="k">for</span> <span class="n">seed</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">seedvalue</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="n">subprocess</span><span class="o">.</span><span class="n">call</span><span class="p">([</span><span class="s2">&quot;python3.6&quot;</span><span class="p">,</span> <span class="s2">&quot;main.py&quot;</span><span class="p">,</span> <span class="s2">&quot;-n&quot;</span><span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">max_round</span><span class="p">),</span> <span class="s2">&quot;-m 1&quot;</span><span class="p">,</span> <span class="s2">&quot;-d&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">nTime</span><span class="p">),</span> <span class="s2">&quot;-r&quot;</span><span class="o">+</span> <span class="nb">str</span><span class="p">(</span><span class="n">seed</span><span class="p">),</span> <span class="s2">&quot;-v 0&quot;</span><span class="p">]</span> <span class="p">)</span>
<span class="n">fout</span><span class="o">=</span><span class="nb">open</span><span class="p">(</span><span class="s2">&quot;./outputs/mulitple/&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">nTime</span><span class="p">)</span><span class="o">+</span><span class="s2">&quot;/all_aggregates.csv&quot;</span><span class="p">,</span><span class="s2">&quot;a&quot;</span><span class="p">)</span>
<span class="c1"># first file:</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&quot;./outputs/mulitple/&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">nTime</span><span class="p">)</span><span class="o">+</span><span class="s2">&quot;/&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">+</span><span class="s2">&quot;/aggregate_rounds.csv&quot;</span><span class="p">):</span>
<span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
<span class="c1"># now the rest:</span>
<span class="k">for</span> <span class="n">seed</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">seedvalue</span><span class="o">+</span><span class="mi">1</span><span class="p">):</span>
<span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="s2">&quot;./outputs/mulitple/&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">nTime</span><span class="p">)</span><span class="o">+</span><span class="s2">&quot;/&quot;</span><span class="o">+</span><span class="nb">str</span><span class="p">(</span><span class="n">seed</span><span class="p">)</span><span class="o">+</span><span class="s2">&quot;/aggregate_rounds.csv&quot;</span><span class="p">)</span>
<span class="n">f</span><span class="o">.</span><span class="fm">__next__</span><span class="p">()</span> <span class="c1"># skip the header</span>
<span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">f</span><span class="p">:</span>
<span class="n">fout</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line</span><span class="p">)</span>
<span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span> <span class="c1"># not really needed</span>
<span class="n">fout</span><span class="o">.</span><span class="n">close</span><span class="p">()</span></div>
<span class="k">if</span> <span class="vm">__name__</span> <span class="o">==</span> <span class="s2">&quot;__main__&quot;</span><span class="p">:</span>
<span class="n">main</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">:])</span>
</pre></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Opportunistic Robotics Network Simulator 1.0.1 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="index.html" >Module code</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Ahmad Reza Cheraghi.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.7.2.
</div>
</body>
</html>
\ No newline at end of file
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>sim &#8212; Opportunistic Robotics Network Simulator 1.0.1 documentation</title>
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" src="../_static/documentation_options.js"></script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-matter nav-matter-0"><a href="../index.html">Opportunistic Robotics Network Simulator 1.0.1 documentation</a> &#187;</li>
<li class="nav-matter nav-matter-1"><a href="index.html" accesskey="U">Module code</a> &#187;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for sim</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;</span>
<span class="sd">The sim module everything for the simulator is provided.</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">importlib</span>
<div class="viewcode-block" id="Sim"><a class="viewcode-back" href="../sim.html#sim.Sim">[docs]</a><span class="k">class</span> <span class="nc">Sim</span><span class="p">:</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">max_round</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span> <span class="n">solution</span><span class="o">=</span><span class="s2">&quot;None&quot;</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> :param seed: seed number for new random numbers</span>
<span class="sd"> :param max_round: the max round number for terminating the simulator</span>
<span class="sd"> :param solution: The name of solution/solution that is going to be used</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">__max_round</span> <span class="o">=</span> <span class="n">max_round</span>
<span class="bp">self</span><span class="o">.</span><span class="n">__round_counter</span> <span class="o">=</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">__seed</span><span class="o">=</span><span class="n">seed</span>
<span class="bp">self</span><span class="o">.</span><span class="n">__solution</span> <span class="o">=</span> <span class="n">solution</span>
<div class="viewcode-block" id="Sim.get_max_round"><a class="viewcode-back" href="../sim.html#sim.Sim.get_max_round">[docs]</a> <span class="k">def</span> <span class="nf">get_max_round</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Return the initialized endding round number</span>
<span class="sd"> :return: The maximum round number</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__max_round</span></div>
<div class="viewcode-block" id="Sim.get_actual_round"><a class="viewcode-back" href="../sim.html#sim.Sim.get_actual_round">[docs]</a> <span class="k">def</span> <span class="nf">get_actual_round</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> The actual round number</span>
<span class="sd"> :return: actual round number</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__round_counter</span></div>
<div class="viewcode-block" id="Sim.inc_round_cnter"><a class="viewcode-back" href="../sim.html#sim.Sim.inc_round_cnter">[docs]</a> <span class="k">def</span> <span class="nf">inc_round_cnter</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Increases the the round counter by</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">__round_counter</span> <span class="o">+=</span> <span class="mi">1</span></div>
<div class="viewcode-block" id="Sim.run"><a class="viewcode-back" href="../sim.html#sim.Sim.run">[docs]</a> <span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sim</span><span class="p">,</span> <span class="n">solution</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> :param sim: The sims object</span>
<span class="sd"> :param solution: The name of the solution file</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">solution</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">mod</span> <span class="o">=</span> <span class="n">importlib</span><span class="o">.</span><span class="n">import_module</span><span class="p">(</span><span class="s1">&#39;lib.solutions.&#39;</span><span class="o">+</span><span class="n">solution</span><span class="o">.</span><span class="n">strip</span><span class="p">(</span><span class="s1">&#39;.py&#39;</span><span class="p">))</span>
<span class="k">while</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_actual_round</span><span class="p">()</span> <span class="o">&lt;=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_max_round</span><span class="p">():</span>
<span class="n">mod</span><span class="o">.</span><span class="n">solution</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sim</span><span class="p">)</span>
<span class="n">sim</span><span class="o">.</span><span class="n">csv_round_writer</span><span class="o">.</span><span class="n">next_line</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">get_actual_round</span><span class="p">())</span>
<span class="bp">self</span><span class="o">.</span><span class="n">__round_counter</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">__round_counter</span> <span class="o">+</span> <span class="mi">1</span>
<span class="n">sim</span><span class="o">.</span><span class="n">csv_round_writer</span><span class="o">.</span><span class="n">aggregate_metrics</span><span class="p">()</span> <span class="c1"># After simulation is finished, aggregate everything</span>
<span class="k">for</span> <span class="n">particle</span> <span class="ow">in</span> <span class="n">sim</span><span class="o">.</span><span class="n">particles</span><span class="p">:</span>
<span class="n">particle</span><span class="o">.</span><span class="n">csv_particle_writer</span><span class="o">.</span><span class="n">close_particle</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span> <span class="p">(</span><span class="s2">&quot;No solution&quot;</span><span class="p">)</span></div></div>
</pre></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-matter nav-matter-0"><a href="../index.html">Opportunistic Robotics Network Simulator 1.0.1 documentation</a> &#187;</li>
<li class="nav-matter nav-matter-1"><a href="index.html" >Module code</a> &#187;</li>
</ul>
</div>
<div class="footer" role="contentinfo">
&#169; Copyright 2018, Ahmad Reza Cheraghi.
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.7.2.
</div>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=Edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>tile &#8212; Opportunistic Robotics Network Simulator 1.0.1 documentation</title>
<link rel="stylesheet" href="../_static/classic.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script type="text/javascript" src="../_static/documentation_options.js"></script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
</head><body>
<div class="related" role="navigation" aria-label="related navigation">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">Opportunistic Robotics Network Simulator 1.0.1 documentation</a> &#187;</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Module code</a> &#187;</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<h1>Source code for tile</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;The tile module provides the interface for the tiles. A tile is a hexogon that can be taken or dropped</span>
<span class="sd"> and be connected to each other to buld up islands&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="c1">#from lib import matter</span>
<span class="n">black</span> <span class="o">=</span> <span class="mi">1</span>
<span class="n">gray</span> <span class="o">=</span> <span class="mi">2</span>
<span class="n">red</span> <span class="o">=</span> <span class="mi">3</span>
<span class="n">green</span> <span class="o">=</span> <span class="mi">4</span>
<span class="n">blue</span> <span class="o">=</span> <span class="mi">5</span>
<span class="n">read</span><span class="o">=</span><span class="mi">0</span>
<span class="n">write</span><span class="o">=</span><span class="mi">1</span>
<div class="viewcode-block" id="Tile"><a class="viewcode-back" href="../tile.html#tile.Tile">[docs]</a><span class="k">class</span> <span class="nc">Tile</span><span class="p">():</span>
<span class="sd">&quot;&quot;&quot;In the classe location all the methods for the characterstic of a location is included&quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sim</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="n">color</span><span class="o">=</span><span class="n">gray</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">mm_limit</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">mm_size</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Initializing the location constructor&quot;&quot;&quot;</span>
<span class="nb">super</span><span class="p">()</span><span class="o">.</span><span class="fm">__init__</span><span class="p">(</span> <span class="n">sim</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="n">color</span><span class="p">,</span> <span class="n">alpha</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="nb">type</span><span class="o">=</span><span class="s2">&quot;tile&quot;</span><span class="p">,</span> <span class="n">mm_limit</span><span class="o">=</span><span class="n">mm_limit</span><span class="p">,</span> <span class="n">mm_size</span><span class="o">=</span><span class="n">mm_size</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">__isCarried</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">created</span> <span class="o">=</span> <span class="kc">False</span>
<div class="viewcode-block" id="Tile.get_tile_status"><a class="viewcode-back" href="../tile.html#tile.Tile.get_tile_status">[docs]</a> <span class="k">def</span> <span class="nf">get_tile_status</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Get the tile status if it taken or not</span>
<span class="sd"> :return: Tiles status</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">__isCarried</span></div>
<div class="viewcode-block" id="Tile.set_tile_status"><a class="viewcode-back" href="../tile.html#tile.Tile.set_tile_status">[docs]</a> <span class="k">def</span> <span class="nf">set_tile_status</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">status</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Sets the tiles status</span>
<span class="sd"> :param status: True: Has been taken; False: Is not taken</span>
<span class="sd"> :return:</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">__isCarried</span> <span class="o">=</span> <span class="n">status</span></div>
<div class="viewcode-block" id="Tile.take"><a class="viewcode-back" href="../tile.html#tile.Tile.take">[docs]</a> <span class="k">def</span> <span class="nf">take</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coords</span><span class="o">=</span><span class="mi">0</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Takes the tile on the given coordinate if it is not taken</span>
<span class="sd"> :param coords: Coordination of tile that should be taken</span>
<span class="sd"> :return: True: Successful taken; False: Cannot be taken or wrong Coordinates</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="n">coords</span><span class="o">==</span><span class="mi">0</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__isCarried</span> <span class="o">==</span> <span class="kc">False</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">coords</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sim</span><span class="o">.</span><span class="n">tile_map</span><span class="p">:</span>
<span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">sim</span><span class="o">.</span><span class="n">tile_map</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">coords</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">__isCarried</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">touch</span><span class="p">()</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">False</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">__isCarried</span> <span class="o">==</span> <span class="kc">False</span><span class="p">:</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">coords</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sim</span><span class="o">.</span><span class="n">tile_map</span><span class="p">:</span>
<span class="k">del</span> <span class="bp">self</span><span class="o">.</span><span class="n">sim</span><span class="o">.</span><span class="n">tile_map</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">coords</span><span class="p">]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">__isCarried</span> <span class="o">=</span> <span class="kc">True</span>
<span class="bp">self</span><span class="o">.</span><span class="n">coords</span> <span class="o">=</span> <span class="n">coords</span>
<span class="bp">self</span><span class="o">.</span><span class="n">touch</span><span class="p">()</span>
<span class="k">return</span> <span class="kc">True</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="kc">False</span></div>
<div class="viewcode-block" id="Tile.drop_me"><a class="viewcode-back" href="../tile.html#tile.Tile.drop_me">[docs]</a> <span class="k">def</span> <span class="nf">drop_me</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">coords</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Drops the tile</span>
<span class="sd"> :param coords: the given position</span>
<span class="sd"> :return: None</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">sim</span><span class="o">.</span><span class="n">tile_map</span><span class="p">[</span><span class="n">coords</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span>
<span class="bp">self</span><span class="o">.</span><span class="n">coords</span> <span class="o">=</span> <span class="n">coords</span>
<span class="bp">self</span><span class="o">.</span><span class="n">__isCarried</span> <span class="o">=</span> <span class="kc">False</span>
<span class="bp">self</span><span class="o">.</span><span class="n">touch</span><span class="p">()</span></div>
<div class="viewcode-block" id="Tile.update_tile_coords"><a class="viewcode-back" href="../tile.html#tile.Tile.update_tile_coords">[docs]</a> <span class="k">def</span> <span class="nf">update_tile_coords</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">tile</span><span class="p">,</span> <span class="n">new_coords</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
<span class="sd"> Upadtes the tiles new coordinates</span>
<span class="sd"> :param tile:</span>
<span class="sd"> :param new_coords: new coorindation points</span>
<span class="sd"> :return: None</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="n">tile</span><span class="o">.</span><span class="n">coords</span> <span class="o">=</span> <span class="n">new_coords</span>
<span class="bp">self</span><span class="o">.</span><span class="n">tile_map</span><span class="p">[</span><span class="n">tile</span><span class="o">.</span><span class="n">coords</span><span class="p">]</span> <span class="o">=</span> <span class="n">tile</span></div>
<div class="viewcode-block" id="Tile.touch"><a class="viewcode-back" href="../tile.html#tile.Tile.touch">[docs]</a> <span class="k">def</span> <span class="nf">touch</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Tells the visualization that something has been modified and that it shoud changed it&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">modified</span> <span class="o">=</span> <span class="kc">True</span></div></div>
</pre></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
<h3>Quick search</h3>
<div class="searchformwrapper">
<form class="search" action="../search.html" method="get">
<input type="text" name="q" />
<input type="submit" value="Go" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>