Note that there are some explanatory texts on larger screens.

plurals
  1. POCombine two lists of indices to create a 1-1 mapping between two other lists
    primarykey
    data
    text
    <p>We'll start with the example. </p> <p>I have two lists:</p> <pre><code>segments = [16, 19, 22, 26] labels = [horse, cow, mule] </code></pre> <p>These two lists has a prefers (in order) some of the elements in the other list as shown in the tables below. Note that a segment can think that it should have a certain label, while the corresponding label doesn't think it should have that segment.</p> <pre><code> | Preferred Label | Preferred Segment | (in order, L -&gt; R) | (in order, L -&gt; R) ---+------------------- ------+------------------- 16 | horse, cow, mule horse | 26, 19, 22, 16 19 | horse, mule cow | 16, 22, 19 22 | mule, cow, horse mule | 26, 22, 19 26 | mule </code></pre> <p>which can be expressed in the form of two index lists:</p> <pre><code>// We have 4 segments, each have a ranked list (length 0-3) of preferred label labelIndicesForSegments = [[0, 1, 2], [0, 2], [2, 1, 0], [2]] // We have 3 labels, each have a ranked list (length 0-4) of preferred segment segmentIndicesForLabels = [[3, 1, 2, 0], [0, 2, 1], [3, 2, 1]] </code></pre> <p>Now, how do I create the "optimal 1 to 1 mapping" between segments and labels? I.e., the segments gets a label as much to the left as possible in its table, and vice versa. The algorithm should force pairs even if a segment and a label doesn't have each other in their preference list (this, however, should be avoided as far as possible).</p> <p>I do not know what would be the best answer to the example above. Some answers could be</p> <pre><code>1: [(16, horse), (19, mule), (22, cow)] 2: [(16, cow), (19, horse), (26, mule)] 3: [(19, horse), (22, cow), (26, mule)] </code></pre> <p>But how do I choose what segment will be without a matching label? And how do I compute which one is the most optimal? </p> <p>As you can see pretty much everything can vary. Segments and labels doesn't have to be of equal length and the list of indices doesn't have to be of equal length. While algorithm speed always matters I can say that in this case I won't be working with more than 10-20 elements in either segments or labels.</p> <p>My problem is that I have no entry point on how to solve this. Most likely there is an algorithm to solve this but I don't know it's name. I'm also implementing this in Java, in case you want to make a concrete non-pseudocode example ;)</p>
    singulars
    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