<html><body><div style="color:#000; background-color:#fff; font-family:times new roman, new york, times, serif;font-size:10pt"><div style="margin-bottom: 6px; padding: 0px 0px 0px 5px; border: none; font-size: 14px; line-height: 19px; font-family: sans-serif;">Hi experts!</div><div style="margin-bottom: 6px; padding: 0px 0px 0px 5px; border: none; font-size: 14px; line-height: 19px; font-family: sans-serif;">I wrote an algorithm for study stick percolation (i.e.: networks between line segments that intersect between them). In my algorithm N sticks (line segments) are created inside a rectanglar box of sides 'b' and 'h' and then, one by one, the algorithm explores the intersection between all line segments. This is a Monte Carlo simulation, so the 'experiment' is executed many times (no less than 100 times). Writen like that, very much RAM is consumed:</div><pre class="prettyprint" style="font-family: Consolas, Monaco, 'Liberation Mono', 'Lucida Console',
monospace; font-size: 14px; margin-bottom: 10px; background-color: rgb(245, 245, 245); padding: 3px; border: 0px solid rgb(136, 136, 136); line-height: 20px;"><code style="font-family: Consolas, Monaco, 'Liberation Mono', 'Lucida Console', monospace;"><span class="pln">array_x1</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">uniform</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">rvs</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">loc</span><span class="pun" style="color: rgb(102, 102, 0);">=-</span><span class="pln">b</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="lit" style="color: rgb(0, 102, 102);">2</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> scale</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">b</span><span class="pun" style="color:
rgb(102, 102, 0);">,</span><span class="pln"> size</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">N</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> <br>array_y1</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">uniform</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">rvs</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">loc</span><span class="pun" style="color: rgb(102, 102, 0);">=-</span><span class="pln">h</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="lit" style="color: rgb(0, 102, 102);">2</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> scale</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">h</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln">
size</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">N</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"><br>array_x2</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">uniform</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">rvs</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">loc</span><span class="pun" style="color: rgb(102, 102, 0);">=-</span><span class="pln">b</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="lit" style="color: rgb(0, 102, 102);">2</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> scale</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">b</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> size</span><span class="pun" style="color: rgb(102,
102, 0);">=</span><span class="pln">N</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> <br>array_y2</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">uniform</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">rvs</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">loc</span><span class="pun" style="color: rgb(102, 102, 0);">=-</span><span class="pln">h</span><span class="pun" style="color: rgb(102, 102, 0);">/</span><span class="lit" style="color: rgb(0, 102, 102);">2</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> scale</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">h</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln"> size</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span
class="pln">N</span><span class="pun" style="color: rgb(102, 102, 0);">)</span><span class="pln"> <br><br>M </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> np</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln">zeros</span><span class="pun" style="color: rgb(102, 102, 0);">([</span><span class="pln">N</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln">N</span><span class="pun" style="color: rgb(102, 102, 0);">])</span><span class="pln"> <br><br></span><span class="kwd" style="color: rgb(0, 0, 136);">for</span><span class="pln"> u </span><span class="kwd" style="color: rgb(0, 0, 136);">in</span><span class="pln"> xrange</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="lit" style="color: rgb(0, 102, 102);">100</span><span class="pun" style="color: rgb(102, 102, 0);">):</span><span class="pln"> </span><span
class="pun" style="color: rgb(102, 102, 0);">----></span><span class="pln"> </span><span class="typ" style="color: rgb(102, 0, 102);">This</span><span class="pln"> </span><span class="str" style="color: rgb(0, 136, 0);">'100'</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">is</span><span class="pln"> the number of experiments</span><span class="pun" style="color: rgb(102, 102, 0);">.</span><span class="pln"><br> </span><span class="kwd" style="color: rgb(0, 0, 136);">for</span><span class="pln"> j </span><span class="kwd" style="color: rgb(0, 0, 136);">in</span><span class="pln"> xrange</span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">N</span><span class="pun" style="color: rgb(102, 102, 0);">):</span><span class="pln"><br> </span><span class="kwd" style="color: rgb(0, 0, 136);">if</span><span class="pln"> j</span><span class="pun" style="color:
rgb(102, 102, 0);">></span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln"><br> x_A1B1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_x2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_x1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br> y_A1B1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_y2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span
class="pln">array_y1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br> x_A1A2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_x1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_x1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br> y_A1A2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_y1</span><span
class="pun" style="color: rgb(102, 102, 0);">[</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_y1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"> <br> x_A2A1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">x_A1A2<br> y_A2A1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">
</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">y_A1A2<br> x_A2B2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_x2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_x1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br>
y_A2B2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_y2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_y1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br> x_A1B2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_x2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="lit" style="color: rgb(0, 102,
102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_x1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br> y_A1B2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_y2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_y1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span
class="pln"><br> x_A2B1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_x2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_x1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br> y_A2B1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_y2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_y1</span><span
class="pun" style="color: rgb(102, 102, 0);">[</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br><br> p1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> x_A1B1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">y_A1A2 </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln"> y_A1B1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">x_A1A2<br> p2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> x_A1B1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">y_A1B2 </span><span class="pun" style="color:
rgb(102, 102, 0);">-</span><span class="pln"> y_A1B1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">x_A1B2<br> p3 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> x_A2B2</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">y_A2B1 </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln"> y_A2B2</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">x_A2B1<br> p4 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> x_A2B2</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">y_A2A1 </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln"> y_A2B2</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span
class="pln">x_A2A1<br><br> condition_1</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">p1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">p2<br> condition_2</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">p3</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">p4 <br><br> </span><span class="kwd" style="color: rgb(0, 0, 136);">for</span><span class="pln"> k </span><span class="kwd" style="color: rgb(0, 0, 136);">in</span><span class="pln"> xrange </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">):</span><span
class="pln"><br> </span><span class="kwd" style="color: rgb(0, 0, 136);">if</span><span class="pln"> condicion_1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">k</span><span class="pun" style="color: rgb(102, 102, 0);">]<=</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">and</span><span class="pln"> condicion_2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">k</span><span class="pun" style="color: rgb(102, 102, 0);">]<=</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln"><br> M</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span
class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln">k</span><span class="pun" style="color: rgb(102, 102, 0);">]=</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pln"><br><br> </span><span class="kwd" style="color: rgb(0, 0, 136);">if</span><span class="pln"> j</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);"><</span><span class="pln">N</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">4</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln"><br> x_A1B1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_x2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span
class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_x1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br> y_A1B1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_y2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_y1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br> x_A1A2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_x1</span><span class="pun" style="color: rgb(102, 102,
0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">:]-</span><span class="pln">array_x1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br> y_A1A2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_y1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">:]-</span><span class="pln">array_y1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun"
style="color: rgb(102, 102, 0);">]</span><span class="pln"> <br> x_A2A1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">x_A1A2<br> y_A2A1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">y_A1A2<br> x_A2B2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_x2</span><span class="pun" style="color: rgb(102, 102,
0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">:]-</span><span class="pln">array_x1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">:]</span><span class="pln"><br> y_A2B2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_y2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">:]-</span><span
class="pln">array_y1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">:]</span><span class="pln"><br> x_A1B2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_x2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">:]-</span><span class="pln">array_x1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br>
y_A1B2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_y2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">:]-</span><span class="pln">array_y1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]</span><span class="pln"><br> x_A2B1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_x2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_x1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span
class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">:]</span><span class="pln"><br> y_A2B1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> array_y2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">]-</span><span class="pln">array_y1</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">:]</span><span class="pln"><br><br> p1 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">
x_A1B1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">y_A1A2 </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln"> y_A1B1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">x_A1A2<br> p2 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> x_A1B1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">y_A1B2 </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln"> y_A1B1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">x_A1B2<br> p3 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> x_A2B2</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">y_A2B1 </span><span class="pun" style="color:
rgb(102, 102, 0);">-</span><span class="pln"> y_A2B2</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">x_A2B1<br> p4 </span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln"> x_A2B2</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">y_A2A1 </span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln"> y_A2B2</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">x_A2A1<br><br> condicion_1</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">p1</span><span class="pun" style="color: rgb(102, 102, 0);">*</span><span class="pln">p2<br> condicion_2</span><span class="pun" style="color: rgb(102, 102, 0);">=</span><span class="pln">p3</span><span class="pun"
style="color: rgb(102, 102, 0);">*</span><span class="pln">p4 <br><br> </span><span class="kwd" style="color: rgb(0, 0, 136);">for</span><span class="pln"> k </span><span class="kwd" style="color: rgb(0, 0, 136);">in</span><span class="pln"> xrange </span><span class="pun" style="color: rgb(102, 102, 0);">(</span><span class="pln">N</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">-</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">):</span><span class="pln"><br> </span><span class="kwd" style="color: rgb(0, 0, 136);">if</span><span class="pln"> condicion_1</span><span class="pun" style="color: rgb(102, 102,
0);">[</span><span class="pln">k</span><span class="pun" style="color: rgb(102, 102, 0);">]<=</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pln"> </span><span class="kwd" style="color: rgb(0, 0, 136);">and</span><span class="pln"> condicion_2</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">k</span><span class="pun" style="color: rgb(102, 102, 0);">]<=</span><span class="lit" style="color: rgb(0, 102, 102);">0</span><span class="pun" style="color: rgb(102, 102, 0);">:</span><span class="pln"><br> M</span><span class="pun" style="color: rgb(102, 102, 0);">[</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102, 0);">,</span><span class="pln">k</span><span class="pun" style="color: rgb(102, 102, 0);">+</span><span class="pln">j</span><span class="pun" style="color: rgb(102, 102,
0);">+</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pun" style="color: rgb(102, 102, 0);">]=</span><span class="lit" style="color: rgb(0, 102, 102);">1</span><span class="pln"><br></span></code></pre><div style="margin-bottom: 6px; padding: 0px 0px 0px 5px; border: none; font-size: 14px; line-height: 19px; font-family: sans-serif;">Here, the element Mij=1 if stick i intersect stick j and Mij=0 if not.</div><div style="margin-bottom: 6px; padding: 0px 0px 0px 5px; border: none; font-size: 14px; line-height: 19px; font-family: sans-serif;">How can i optimize my algorithm? Graph theory is usefull in this case?</div><div style="margin-bottom: 6px; padding: 0px 0px 0px 5px; border: none; font-size: 14px; line-height: 19px; font-family: sans-serif;">Waiting for your answers.</div><div style="margin-bottom: 6px; padding: 0px 0px 0px 5px; border: none; font-size: 14px; line-height: 19px; font-family: sans-serif;">Thanks a
lot!</div><div style="margin-bottom: 6px; padding: 0px 0px 0px 5px; border: none; font-size: 14px; line-height: 19px; font-family: sans-serif;">Best regards</div></div></body></html>