Skip to content

Commit a72dbeb

Browse files
updated docs
1 parent dd748f5 commit a72dbeb

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

docs/flipcoins.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ <h1><a class="anchor" id="FlipCoinsProblemFormulation"></a>
111111
</div>
112112
<h1><a class="anchor" id="FlipCoinsProbabilistic"></a>
113113
Probabilistic Conditions</h1>
114-
<p>We use condition tasks to simulate the five coin tosses. We create five condition tasks each return a random binary number. If the return is zero (head toss), the execution moves to the next condition task; or it (tail toss) goes back to the first condition task to start over the simulation again.</p>
114+
<p>We use condition tasks to simulate the five coin tosses. We create five condition tasks each returning a random binary number. If the return is zero (head toss), the execution moves to the next condition task; or it (tail toss) goes back to the first condition task to start over the simulation.</p>
115115
<div class="fragment"><div class="line"><a class="code" href="classtf_1_1Taskflow.html">tf::Taskflow</a> taskflow;</div><div class="line"><a class="code" href="classtf_1_1Executor.html">tf::Executor</a> executor;</div><div class="line"></div><div class="line"><span class="keywordtype">size_t</span> rounds = 10000;</div><div class="line"><span class="keywordtype">size_t</span> tosses = 0; </div><div class="line"><span class="keywordtype">size_t</span> total_tosses = 0; </div><div class="line"><span class="keywordtype">double</span> average_tosses = 0.0; </div><div class="line"></div><div class="line"><span class="keyword">auto</span> A = taskflow.<a class="code" href="classtf_1_1FlowBuilder.html#a796e29175380f70246cf2a5639adc437">emplace</a>( [&amp;](){ tosses = 0; } ).name(<span class="stringliteral">&quot;init&quot;</span>); </div><div class="line"></div><div class="line"><span class="comment">// start over the flip again</span></div><div class="line"><span class="keyword">auto</span> B = taskflow.<a class="code" href="classtf_1_1FlowBuilder.html#a796e29175380f70246cf2a5639adc437">emplace</a>( [&amp;](){ ++tosses; <span class="keywordflow">return</span> <a class="codeRef" doxygen="/Users/twhuang/PhD/Code/cpp-taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/numeric/random/rand.html">std::rand</a>()%2; } ).name(<span class="stringliteral">&quot;flip-coin-1&quot;</span>);</div><div class="line"><span class="keyword">auto</span> C = taskflow.<a class="code" href="classtf_1_1FlowBuilder.html#a796e29175380f70246cf2a5639adc437">emplace</a>( [&amp;](){ <span class="keywordflow">return</span> <a class="codeRef" doxygen="/Users/twhuang/PhD/Code/cpp-taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/numeric/random/rand.html">std::rand</a>()%2; } ).name(<span class="stringliteral">&quot;flip-coin-2&quot;</span>);</div><div class="line"><span class="keyword">auto</span> D = taskflow.<a class="code" href="classtf_1_1FlowBuilder.html#a796e29175380f70246cf2a5639adc437">emplace</a>( [&amp;](){ <span class="keywordflow">return</span> <a class="codeRef" doxygen="/Users/twhuang/PhD/Code/cpp-taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/numeric/random/rand.html">std::rand</a>()%2; } ).name(<span class="stringliteral">&quot;flip-coin-3&quot;</span>);</div><div class="line"><span class="keyword">auto</span> E = taskflow.<a class="code" href="classtf_1_1FlowBuilder.html#a796e29175380f70246cf2a5639adc437">emplace</a>( [&amp;](){ <span class="keywordflow">return</span> <a class="codeRef" doxygen="/Users/twhuang/PhD/Code/cpp-taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/numeric/random/rand.html">std::rand</a>()%2; } ).name(<span class="stringliteral">&quot;flip-coin-4&quot;</span>);</div><div class="line"><span class="keyword">auto</span> F = taskflow.<a class="code" href="classtf_1_1FlowBuilder.html#a796e29175380f70246cf2a5639adc437">emplace</a>( [&amp;](){ <span class="keywordflow">return</span> <a class="codeRef" doxygen="/Users/twhuang/PhD/Code/cpp-taskflow/doxygen/cppreference-doxygen-web.tag.xml:http://en.cppreference.com/w/" href="http://en.cppreference.com/w/cpp/numeric/random/rand.html">std::rand</a>()%2; } ).name(<span class="stringliteral">&quot;flip-coin-5&quot;</span>);</div><div class="line"></div><div class="line"><span class="comment">// reach the target; record the number of tosses </span></div><div class="line"><span class="keyword">auto</span> G = taskflow.<a class="code" href="classtf_1_1FlowBuilder.html#a796e29175380f70246cf2a5639adc437">emplace</a>( [&amp;](){ total_tosses += tosses; } ).name(<span class="stringliteral">&quot;stop&quot;</span>);</div><div class="line"></div><div class="line">A.precede(B).name;</div><div class="line"></div><div class="line"><span class="comment">// five probabilistic conditions</span></div><div class="line">B.precede(C, B);</div><div class="line">C.precede(D, B);</div><div class="line">D.<a class="code" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(E, B);</div><div class="line">E.<a class="code" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(F, B);</div><div class="line">F.<a class="code" href="classtf_1_1Task.html#a8c78c453295a553c1c016e4062da8588">precede</a>(G, B);</div><div class="line"></div><div class="line"><span class="comment">// repeat the flip-coin simulation by rounds times</span></div><div class="line">executor.<a class="code" href="classtf_1_1Executor.html#adca6cd0ce1bd7e6fa2ed2a55c9ae15e6">run_n</a>(taskflow, rounds).wait();</div><div class="line"></div><div class="line"><span class="comment">// calculate the expected number of tosses</span></div><div class="line">average_tosses = total_tosses / (double)rounds;</div><div class="line"></div><div class="line">assert(std::fabs(average_tosses-32.0)&lt;1.0);</div></div><!-- fragment --><p>Running the taskflow by a fair number of times, the average tosses we have is close to 32. The taskflow diagram is depicted below.</p>
116116
<div class="image">
117117
<object type="image/svg+xml" data="flipcoins_2.svg" width="100%">flipcoins_2.svg</object>
118118
</div>
119-
<p>Although the execution of this taskflow is non-deterministic, its control flow can expand to a tree of tasks based on our scheduling rule for conditional tasking (see <a class="el" href="chapter4.html">C4: Conditional Tasking</a>). Each path from the root to a leaf represents a result of five heads, and none of them can overlap at the same time (no task race). You must follow the same rule when creating a probabilistic condition task.</p>
119+
<p>Although the execution of this taskflow is non-deterministic, its control flow can expand to a tree of tasks based on our scheduling rule for conditional tasking (see <a class="el" href="chapter4.html">C4: Conditional Tasking</a>). Each path from the root to a leaf represents a result of five heads, and none of them can overlap at the same time (no task race). You must follow the same rule when creating a probabilistic framework using conditional tasking.</p>
120120
<h1><a class="anchor" id="FlipCoinsTernaryCoins"></a>
121121
Ternary Coins</h1>
122122
<p>We can extend the binary coin example to a ternary case. Each condition task has one successor going back to the beginning and two successors moving to the next task. The expected number of tosses to reach five identical results is 3*3*3*3*3 = 243.</p>

doxygen/examples/flipcoins.dox

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ It is equivalently to say the expected number we need to toss for obtaining five
1818
@section FlipCoinsProbabilistic Probabilistic Conditions
1919

2020
We use condition tasks to simulate the five coin tosses.
21-
We create five condition tasks each return a random binary number.
21+
We create five condition tasks each returning a random binary number.
2222
If the return is zero (head toss), the execution moves to the next condition task;
23-
or it (tail toss) goes back to the first condition task to start over the simulation again.
23+
or it (tail toss) goes back to the first condition task to start over the simulation.
2424

2525
@code{.cpp}
2626
tf::Taskflow taskflow;
@@ -71,7 +71,7 @@ its control flow can expand to a tree of tasks based on our scheduling rule for
7171
(see @ref chapter4).
7272
Each path from the root to a leaf represents a result of five heads,
7373
and none of them can overlap at the same time (no task race).
74-
You must follow the same rule when creating a probabilistic condition task.
74+
You must follow the same rule when creating a probabilistic framework using conditional tasking.
7575

7676
@section FlipCoinsTernaryCoins Ternary Coins
7777

0 commit comments

Comments
 (0)