I need to write an algorithm in any language that would order an array based on 3 factors. I use resorts as an example (like Hipmunk). Let\'s say I want to go on vacation.
What about having variable weights, and letting the user adjust it through some input like levers, so that the sort order will be dynamically updated?
I was about to ask the same question about multiple-factor weighted sorting, because my research only came up with answers (e.g. formulas with explanations) for two-factor sorting.
Even though we're both asking about 3 factors, I'll list the possibilities I've found in case they're helpful.
Possibilities:
Note: S
is the "sorting score", which is what you'd sort by (asc or desc).
S = (w1 * F1) + (w2 * F2) + (w3 * F3)
, where wx
are arbitrarily assigned weights, and Fx
are the values of the factors. You'd also want to normalize F
(i.e. Fx_n = Fx / Fmax
).S = 1000 * F1 + 100 * F2 ...
.S = (F2 / F2_max * F1) + ((1 - (F2 / F2_max)) * F1_avg)
, where F1
is the "more important" factor ("bounce rate" in the article), and F2
is the "significance modifying" factor ("visits" in the article).S = (F2 / (F2+F2_lim)) * F1 + (F2_lim / (F2+F2_lim)) × F1_avg
, where Fx
are the same as #3, and F2_lim
is the minimum threshold limit for the "significance" factor (i.e. any value less than X shouldn't be considered).Options #3 and #4 look really promising, since you don't really have to choose an arbitrary weighting scheme like you do in #1 and #2, but then the problem is how do you do this for more than two factors?
In your case, assigning the weights in #1 would probably be fine. You'll need to fine-tune the algorithm depending on what your users consider more important - you could expose the weights wx
as a filter (like 1-10 dropdown) so your users can adjust their search on the fly. Or if you wanted to get clever you could poll your users before they're searching ("Which is more important to you?") and then assign a weighting set based on the response, and after tracking enough polls you could autosuggest the weighting scheme based on most responses.
Hope that gets you on the right track.