Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's possible to do this with bash scripts if that is what you are limited to, but it would be easier to handle a problem like this with Python / C++ / Java because this is a version of optimized bipartite matching problem (you'd have to read each line repeatedly if done in script, or use a lot of helper variables)</p> <p>==> If we can assume that values in both columns are sorted and increasing, a naive solution would be:</p> <p>For every value in the 2nd column:</p> <ul> <li>Read over values in the 1st column sequentially until the difference of col2_value - col1_value goes from negative to positive</li> <li>Then find min( abs(negative_difference), positive_difference ) and pick the col1_value that corresponds to the smaller difference</li> <li>Remove both entries from col1 and col2 and add them to the result table</li> <li>Repeat this process until there is nothing left in col2 of the original table</li> </ul> <p>This has worst-case run time of m*n, where m is # entries in col1 and n is # entries in col2 and average run time of O(n) if you are clever and do a constant time alternating check (compare -1, +1 from index of last chosen col1_value, since -2, +2 etc would of course result in bigger differences) instead of a sequential one to find the minimal difference between the current value in col2 and the values in vol1.</p> <p>This is a naive solution because it does not minimize overall difference in the system. Optimum solution is NP, so for large datasets, the best you can probably do is use one of the approximation graphing algorithms for matching.</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.
    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.
    3. VO
      singulars
      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