Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot find the proper base case for a recursive function to 'generate' matrices?
    primarykey
    data
    text
    <p>I have a recursive function to generate matrices, called <code>lights</code>.</p> <p>This function is called in <code>light_and_color</code>.</p> <p><code>light_col_permutation</code>, called in <code>lights</code>, gives a vector of vector of vector of int.</p> <p>So, in the loop <code>for(vector&lt;vector&lt;int&gt; &gt; aa:light_col_permutations(rowSums, colSums, colIndex))</code> in the code, <code>aa</code> gives a pair of vector.</p> <p><code>aa[0]</code> is the possible values that could go into the row of the matrix at index <code>colIndex</code>.</p> <p><code>aa[1]</code> is the updated (remaining) <code>rowSums</code> that could be filled in, for unfilled rows after <code>colIndex</code>. This is passed into <code>lights</code> recursively, to fill in the next column.</p> <p>What this function is supposed to do is to find <strong>all</strong> matrices for each of <code>aa</code> in <code>light_col_permutations</code>.</p> <p>With the base case in the code, it only finds one such matrix and quits(<code>return</code>s).</p> <p>How can I generate all of them?</p> <p>The following code is a simplified version, so that you can see the structure of the recursion. Please let me know if there is anything unclear. (the whole program is about 800 lines long, but I will post it if requested)</p> <pre><code>void lights(vector&lt;int&gt;&amp; rowSums, vector&lt;int&gt;&amp; colSums, int colIndex, matrix_c mc) { if(colIndex == mc.r) { mc.print_matrix(); } for(vector&lt;vector&lt;int&gt; &gt; aa:light_col_permutations(rowSums, colSums, colIndex)) { mc.row_assign(colIndex, aa[0]); mc.newRowSum = aa[1]; lights(mc.newRowSum, colSums, colIndex+1, mc); } } void light_and_color(int r, int n, int color, string filename) { matrix_c mc(r, n); //zero matrix of size (r) X (r) //here I get rowSums and colSums, but I omitted them lights(rowSums, colSums, 0, mc); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload