|
|
////////////////////////////////////////////////////////////////////////////// // // BORDA demonstration (version 2008/08/06) // Copyright (C) 2008 Christophe DAVID // http://www.christophedavid.org/w/c/w.php/Files/DecisionAid // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License version 2 as published // by the Free Software Foundation (http://www.gnu.org/licenses/gpl.html). // ////////////////////////////////////////////////////////////////////////////// // This program was last tested with Scilab 4.1.2 // http://www.scilab.org ////////////////////////////////////////////////////////////////////////////// errclear // clear all errors clear; // kill variables clearglobal // kill global variables clc; // clear command window tohome; // move the cursor to the upper left corner of the Command Window clf; // clear or reset the current graphic figure (window) to default values clear_pixmap; // erase the pixmap buffer ////////////////////////////////////////////////////////////////////////////// function [OutputMatrix] = RankMatrix(InputMatrix) OutputMatrix = zeros(InputMatrix); [s, k] = gsort(InputMatrix, 'r', 'd'); [_rows, _columns] = size(InputMatrix); for col = 1 : _columns _exaequo = 0; _rank = 1; for row = 1 : _rows; OutputMatrix(k(row, col), col) = _rank; if row < _rows if InputMatrix(k(row, col), col) == InputMatrix(k(row + 1, col), col) _exaequo = _exaequo + 1; else _rank = _rank + 1 + _exaequo; _exaequo = 0; end end end end endfunction ////////////////////////////////////////////////////////////////////////////// function [OutputMatrix] = Borda(InputMatrix) // rank each column OutputMatrix = RankMatrix(InputMatrix); // sum all rows OutputMatrix = sum(InputMatrix,'c') ; // rank resulting sums OutputMatrix = RankMatrix(OutputMatrix); endfunction ////////////////////////////////////////////////////////////////////////////// DecisionMatrix = [ 18, 17, 13, 14, 11, 17; 17, 11, 10, 18, 19, 15; 15, 18, 11, 12, 19, 17; 14, 18, 18, 16, 17, 17; 16, 16, 10, 12, 14, 17; ] Borda(DecisionMatrix) // ans = // 3 // 3 // 2 // 1 // 5 ////////////////////////////////////////////////////////////////////////////// << DECIDE for Scilab | index | Decision matrix analysis >>
|