Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ok, lets try. We have 8 students (1..8) and 4 sections. Each student is in a section and each section has room for 2 students. Most students want to switch but not all.</p> <p>In the table below, we see the students their current section, their required section and the position on the queue (if any).</p> <pre><code>+------+-----+-----+-----+ | stud | now | req | que | +------+-----+-----+-----+ | 1 | A | D | 2 | | 2 | A | D | 1 | | 3 | B | B | - | | 4 | B | A | 2 | | 5 | C | A | 1 | | 6 | C | C | - | | 7 | D | C | 1 | | 8 | D | B | 1 | +------+-----+-----+-----+ </code></pre> <p>We can present this information in a graph:</p> <pre><code>+-----+ +-----+ +-----+ | C |---[5]---&gt;1| A |2&lt;---[4]---| B | +-----+ +-----+ +-----+ 1 | | 1 ^ | | ^ | [1] [2] | | | | | [7] | | [8] | V V | | 2 1 | | +-----+ | \--------------| D |--------------/ +-----+ </code></pre> <p>We try to find a section with a vacancy, but we find none. So because all sections are full, we need a dirty trick. So lets take a random section with a non empty queue. In this case section A and assume, it has an extra position. This means student 5 can enter section A, leaving a vacancy at section C which is taken by student 7. This leaves a vacancy in section D which is taken by student 2. We now have a vacancy at section A. But we assumed that section A has an extra position, so we can remove this assumption and have gained a simpler graph. </p> <p>If the path never returned to section A, undo the moves and mark A as an invalid startingpoint. Retry with another section. If there are no valid sections left we are finished.</p> <p>Right now we have the following situation:</p> <pre><code>+-----+ +-----+ +-----+ | C | | A |1&lt;---[4]---| B | +-----+ +-----+ +-----+ | 1 | ^ [1] | | | | [8] V | 1 | +-----+ | | D |--------------/ +-----+ </code></pre> <p>We repeat the trick with another random section, and this solves the graph.</p> <p>If you start with several students currently not assigned, you add an extra dummy section as their startingpoint. Of course, this means that there must be vacancies in any sections or the problem is not solvable.</p> <p>Note that due to the order in the queue, it can be possible that there is no solution. </p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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