Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear
- function p = schulzeMethod(d, C)
- p = zeros(size(d))
- for i = 1:C
- for j = 1:C
- if i ~= j then
- if d(i,j) > d(j,i) then
- p(i,j) = d(i,j)
- else
- p(i,j) = 0
- end
- end
- end
- end
- for i = 1:C
- for j = 1:C
- if i ~= j then
- for k = 1:C
- if (i ~= k) & ( j ~= k) then
- p(j,k) = max(p(j,k), min(p(j,i), p(i,k)))
- end
- end
- end
- end
- end
- endfunction
- function res = isWinner(paths, candidate, numberOfCandidates)
- res = 1
- for j = 1:numberOfCandidates
- if (j ~= candidate) then
- if (paths(candidate, j) < paths(j, candidate)) then
- res = 0
- end
- end
- end
- return res
- endfunction
- function preference = countPreference(table, first, second)
- preference = 0
- for j = 1:8
- firstIndex = find( table(j).options == first )
- secondIndex = find( table(j).options == second )
- if firstIndex < secondIndex then
- preference = preference + table(j).voters
- end
- end
- return preference
- endfunction
- SizeOfOptions = 5
- preferencesTableColumn1 = struct('options', ['a', 'c', 'b', 'e', 'd'], 'voters', 5)
- preferencesTableColumn2 = struct('options', ['a', 'd', 'e', 'c', 'b'], 'voters', 5)
- preferencesTableColumn3 = struct('options', ['b', 'e', 'd', 'a', 'c'], 'voters', 8)
- preferencesTableColumn4 = struct('options', ['c', 'a', 'b', 'e', 'd'], 'voters', 3)
- preferencesTableColumn5 = struct('options', ['c', 'a', 'e', 'b', 'd'], 'voters', 7)
- preferencesTableColumn6 = struct('options', ['c', 'b', 'a', 'd', 'e'], 'voters', 2)
- preferencesTableColumn7 = struct('options', ['d', 'c', 'e', 'b', 'a'], 'voters', 7)
- preferencesTableColumn8 = struct('options', ['e', 'b', 'a', 'd', 'c'], 'voters', 8)
- preferencesTable = [preferencesTableColumn1, preferencesTableColumn2, preferencesTableColumn3, preferencesTableColumn4, preferencesTableColumn5, preferencesTableColumn6, preferencesTableColumn7, preferencesTableColumn8]
- numberOfCandidates = SizeOfOptions
- candidates = ['a', 'b', 'c', 'd', 'e']
- for i = 1:numberOfCandidates
- for j = 1:numberOfCandidates
- prefTable(i, j) = countPreference(preferencesTable, candidates(i), candidates(j))
- end
- end
- printf('PAIRS BUILT FROM PREFERENCES TABLE: ')
- disp(prefTable)
- paths = schulzeMethod(prefTable, numberOfCandidates)
- for i = 1:numberOfCandidates
- c(i) = isWinner(paths, i, numberOfCandidates)
- end
- printf('WINNER IS: ')
- disp(candidates(find(c == 1)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement