int IComparer.Compare(Object x, Object y) { BordAlt b1 = (BordAlt)x; BordAlt b2 = (BordAlt)y; if (b1.Grade <= b2.Grade) { return(-1); } else { return(1); } }
private ArrayList Range(int k, ArrayList al) { while (k < al.Count) { BordAlt a = (BordAlt)al[k]; if (a.Sign == 1 || a.Sign == 0) { a.Grade = k + 1; //т.к. шкала оценки не с 0, а с 1 al[k] = a; k++; } else { bool eq = true; int eqCount = 2; //два эквивалентных: k и k+1 int kk = k; while (kk + 1 < al.Count && eq) { BordAlt a2 = (BordAlt)al[kk + 1]; if (a2.Sign == 2) { eqCount++; //найден ещё 1 эквивалентный } else { eq = false; //больше нет эквивалентных } kk++; } int sum = 0; for (int i = k; i <= kk; i++) { sum = sum + i + 1; //т.к. шкала оценки не с 0, а с 1 } for (int i = k; i <= kk; i++) { BordAlt aa = (BordAlt)al[i]; aa.Grade = sum / (double)eqCount; al[i] = aa; } k = kk + 1; } } return(al); }
public TotalForm(int alt, int s) { InitializeComponent(); Bord b = new Bord(); b.Alternatives = StatsArray.Alterns; b.Count = alt; b.Experts = s; b.Do(); resultTB.Text = arrtostrRangeAlt(b.RangAlt); for (int i = 0; i < alt; i++) { dataGridView1.Columns.Add("", ""); dataGridView1.Columns[i + 1].HeaderCell.Value = "a" + (i + 1).ToString(); DataGridViewColumn column = dataGridView1.Columns[i + 1]; column.Width = 40; } for (int i = 0; i < s; i++) { dataGridView1.Rows.Add("", ""); dataGridView1.Rows[i].HeaderCell.Value = (i + 1).ToString(); ArrayList ar = new ArrayList(); ar = b.Alternatives[i]; for (int j = 0; j < alt; j++) { dataGridView1[0, i].Value = arrtostr(ar); BordAlt ba = (BordAlt)ar[j]; dataGridView1[ba.Value, i].Value = ba.Grade.ToString(); } } dataGridView1.Rows.Add("", ""); dataGridView1[0, s].Value = arrtostrRangeAlt(b.RangAlt); dataGridView1.Rows[s].HeaderCell.Value = "~"; for (int j = 0; j < alt; j++) { BordAlt ba = (BordAlt)b.RangAlt[j]; dataGridView1[ba.Value + 1, s].Value = ba.Grade.ToString(); } }
public ArrayList Do() { Ranging(); for (int i = 0; i < Experts; i++) { ArrayList al = new ArrayList(); if (Alternatives.TryGetValue(i, out al)) //список этого эксперта { al = Range(0, al); } Alternatives[i] = al; for (int j = 0; j < Count; j++) //накопление итоговых оценок { BordAlt b = (BordAlt)al[j]; BordAlt bh = (BordAlt)RangAlt[b.Value - 1]; bh.Grade += b.Grade; RangAlt[b.Value - 1] = bh; } } RangAlt.Sort(new altCompaper()); //итоговая сортировка альт SetSign(); return(RangAlt); }