I have multiple devices that support different resolutions. I want to assign them all to the same resolution, or to the nearest resolution that it supports.
So, for example. If I have a desired resolution of "1280x720" and the device supports video resolutions of 1280x960 and 160x120, I'm going to want my code to pick the 1280x960.
The problem is that my current setup has attempted to pick the closest "distance" of the strings using the http://en.wikipedia.org/wiki/Levenshtein_distance
'match reswidth to closest support
For i As Integer = 0 To ResArray.Count - 1
'get string distance/difference amount
LevDist(i) = LevenshteinDistance(ResArray(i), templateRes)
Next
Dim min = LevDist.Min()
Dim x = ResArray(Array.IndexOf(LevDist, min))
Return x
And the Lev function that I got off of a trusted site:
Public Function LevenshteinDistance(ByVal s As String,
ByVal t As String) As Integer
Dim n As Integer = s.Length
Dim m As Integer = t.Length
Dim d(n + 1, m + 1) As Integer
If n = 0 Then
Return m
End If
If m = 0 Then
Return n
End If
Dim i As Integer
Dim j As Integer
For i = 0 To n
d(i, 0) = i
Next
For j = 0 To m
d(0, j) = j
Next
For i = 1 To n
For j = 1 To m
Dim cost As Integer
If t(j - 1) = s(i - 1) Then
cost = 0
Else
cost = 1
End If
d(i, j) = Math.Min(Math.Min(d(i - 1, j) + 1, d(i, j - 1) + 1),
d(i - 1, j - 1) + cost)
Next
Next
Return d(n, m)
End Function
My problem is, that just tells you the closest function in the strings. What if I had the same strings within it, but they were all in different places? It wouldn't pick the closest resolution but the closest string. I don't think this is the best method.
Any suggestions on how to find the closest one in the array?
I saw another stack flow link with one for java, but I really didn't understand it. Nor could I get it to translate to vb.net.
(Stack flow php)