Смекни!
smekni.com

Многокритериальные задачи. Метод альтернативных решений (стр. 2 из 3)

После того как бинарное отношение построено, представляется множество взаимнонедоминирующих альтернатив, на котором построенное бинарное отношение обладает НМ-свойством. Далее ЛПР выбирает окончательное решение из этого множества. Таким образом данный метод позволяет сократить число анализируемых вариантов, облегчая тем самым выбор ЛПР.

3.3 Листингпрограммногокода

public partial class Form1 : Form

{

private int countOfVariant;

private int countOfCriterion;

private double p;

private double q;

private double alfa;

private int max = 0;

private double Interval = 0;

private int count1 = 0;

private int count2 = 0;

private int row1;

private int col1;

private static int rows;

private static int cols;

private Double[,] tablesWeight;

private Double[,] tablesCriterionImportance;

private Double[,] tablesIntervalSuperiority;

private Double[,] TableOfAgreementIndex;

private Double[,] TableOfDisagreementIndex;

private String[,] TableofDecisiveRule;

// private Double[,] tablesCriterionImportance;

private double CriterionSumm = 0;

public Form1()

{

InitializeComponent();

}

// получение числа вариантов, числа критериев и параметра альфа

private void GetDate()

{

countOfVariant = (int)numericUpDown1.Value;

countOfCriterion = (int)numericUpDown2.Value;

alfa = Convert.ToDouble(comboBox1.Text);

}

// создание и заполнение таблицы весов из формы

private void createTableOfWeightFromForm()

{

tablesWeight = new double[rows, cols];

for (int i = 0; i < rows; i++)

{

for (int j = 0; j < cols; j++)

{

tablesWeight[i, j] = Convert.ToDouble(dataGridView1.Rows[i].Cells[j].Value);

}

}

}

// создание и заполнение таблицы важности критериев, числа интервалов превосходства

//и стоимость перехода с уровня на уровень из формы

private void createTableOfCriterionImportanceFromForm()

{

tablesCriterionImportance = new double[cols, 3];

for (int i = 0; i < cols; i++)

{

tablesCriterionImportance[i, 0] = Convert.ToDouble(dataGridView5.Rows[i].Cells[0].Value);

CriterionSumm += tablesCriterionImportance[i, 0];

//textBox1.AppendText(CriterionSumm.ToString());

}

}

//создание таблицы интервалов превосходства из формы

private void createTableOfIntervalSuperiorityFromForm()

{

tablesIntervalSuperiority = new double[cols, (max + 1)];

for (int i = 0; i < cols; i++)

{

for (int j = 0; j < (max + 1); j++)

tablesIntervalSuperiority[i, j] = Convert.ToDouble(dataGridView6.Rows[i].Cells[j].Value);

}

}

//созданиетаблицывесовнаформе

private void CreateTableOfWeightOnForm(int row, int col)

{

int _row = row;

int _col = col;

dataGridView1.ColumnCount = _col;

dataGridView1.RowHeadersVisible = false;

dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

dataGridView1.RowCount= _row;

}

// создание таблицы важности критериев на форме

private void CreateTableOfCriterionImportanceOnForm(int row)

{

int _row = row;

int _col = 3;

dataGridView5.ColumnCount = _col;

dataGridView5.RowHeadersVisible = false;

dataGridView5.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

dataGridView5.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

dataGridView5.RowCount = _row;

}

// созданиетаблицыядраизформы

private void CreateTableofDecisiveRuleFromForm()

{

TableofDecisiveRule = new string[rows, 1];

for (int i = 0; i < rows; i++)

{

TableofDecisiveRule[i, 0] = dataGridView4.Rows[i].Cells[0].Value.ToString();

}

}

private void button1_Click(object sender, EventArgs e)

{

GetDate();

rows = (int)countOfVariant;

cols = (int)countOfCriterion;

CreateTableOfWeightOnForm(rows, cols);

CreateTableOfCriterionImportanceOnForm(cols);

}

//добавлениеинтервалапревосходства

private void IntervalSuperiority(int row)

{

for (int i = 0; i < cols; i++)

{

if (max < Convert.ToDouble(dataGridView5.Rows[i].Cells[1].Value))

{

max = Convert.ToInt16(dataGridView5.Rows[i].Cells[1].Value);

}

}

int _row = row;

int _col = (max + 1);

dataGridView6.ColumnCount = _col;

dataGridView6.RowHeadersVisible = false;

dataGridView6.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

dataGridView6.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

dataGridView6.RowCount = _row;

}

// получение матрицы индексов согласия

private void GetTableOfAgreementIndex(int row, int col)

{

double IPlus = 0;

double IMinus = 0;

double IZero = 0;

int _row = row;

int _col = col;

dataGridView2.ColumnCount = _col;

dataGridView2.RowHeadersVisible = false;

dataGridView2.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

dataGridView2.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

dataGridView2.RowCount = _row;

TableOfAgreementIndex = new double[rows, rows];

for (int i = 0; i < rows; i++)

{

for (int j = 0; j < rows; j++)

{

if (i == j)

{

TableOfAgreementIndex[i, j] = 0;

}

else

{

IPlus = 0;

IMinus = 0;

IZero = 0;

for(int k = 0; k < cols; k++)

{

if (Convert.ToDouble(dataGridView1.Rows[i].Cells[k].Value) > Convert.ToDouble(dataGridView1.Rows[j].Cells[k].Value))

{

IPlus += Convert.ToDouble(dataGridView5.Rows[k].Cells[0].Value);

}

else if (Convert.ToDouble(dataGridView1.Rows[i].Cells[k].Value) == Convert.ToDouble(dataGridView1.Rows[j].Cells[k].Value))

{

IZero += Convert.ToDouble(dataGridView5.Rows[k].Cells[0].Value);

}

else

{

IMinus += Convert.ToDouble(dataGridView5.Rows[k].Cells[0].Value);

}

}

TableOfAgreementIndex[i, j] = (IPlus + alfa * IZero) / (CriterionSumm);

}

dataGridView2.Rows[i].Cells[j].Value = TableOfAgreementIndex[i, j];

}

}

}

получениематрицыиндексовнесогласия

private void GetTableOfDisagreementIndex(int row, int col)

{

Double[,] count;

int _row = row;

int _col = col;

dataGridView3.ColumnCount = _col;

dataGridView3.RowHeadersVisible = false;

dataGridView3.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

dataGridView3.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

dataGridView3.RowCount = _row;

count = new double[cols, 2];

TableOfDisagreementIndex = new double[rows, rows];

for (int i = 0; i < rows; i++)

{

for (int j = 0; j < rows; j++)

{

if (i == j)

{

TableOfDisagreementIndex[i, j] = 0;

}

else

{

Interval = 0;

for (int k = 0; k < cols; k++)

{

count[k, 0] = 0;

count[k, 1] = 0;

count1 = 0;

count2 = 0;

for (int m = 0; m < (Convert.ToInt32(dataGridView5.Rows[k].Cells[1].Value) + 1); m++)

{

if (Convert.ToDouble(dataGridView1.Rows[i].Cells[k].Value) > Convert.ToDouble(dataGridView6.Rows[k].Cells[m].Value))

{

count1 += 1;

}

else

{

count1 = count1;

}

if (Convert.ToDouble(dataGridView1.Rows[j].Cells[k].Value) > Convert.ToDouble(dataGridView6.Rows[k].Cells[m].Value))

{

count2 += 1;

}

else

{

count2 = count2;

}

/* textBox1.AppendText(" ");

textBox1.AppendText(count1.ToString());

textBox1.AppendText(" ");

textBox1.AppendText(count2.ToString());

//textBox1.AppendText(" ");

//textBox1.AppendText(dataGridView1.Rows[i].Cells[k].Value.ToString());*/

}

count[k, 0] = count1;

count[k, 1] = count2;

if (count[k, 0] < count[k, 1])

{

Interval += (count[k, 1] - count[k, 0]) * (Convert.ToDouble(dataGridView5.Rows[k].Cells[2].Value));

}

else

{

Interval = Interval;

}

TableOfDisagreementIndex[i, j] = Interval/100;

textBox1.AppendText(" ");

textBox1.AppendText(Interval.ToString());

}

}

dataGridView3.Rows[i].Cells[j].Value = TableOfDisagreementIndex[i, j];

}

}

}

получениепараметровp иq

private void GetParametrsForDecisiveRule()

{

p = Convert.ToDouble(numericUpDown3.Value);

q = Convert.ToDouble(numericUpDown4.Value);

}

//построениерешающегоправила

private void GetDecisiveRule(int row,int col)

{

bool flag = false;

int count = 0;

int countOfq = 0;

int countOfp = 0;

int _row = row;

int _col = col;

dataGridView4.ColumnCount = _col;

dataGridView4.RowHeadersVisible = false;

dataGridView4.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

dataGridView4.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;

dataGridView4.RowCount = _row;

for (int i = 0; i < rows; i++)

{

count = 0;

countOfq = 0;

countOfp = 0;

for (int j = 0; j < cols; j++)

{

count += 1;

if (i != j)

{

if (Convert.ToInt32(dataGridView3.Rows[i].Cells[j].Value) < q)

{

countOfq += 1;

if (Convert.ToInt32(dataGridView2.Rows[i].Cells[j].Value) < p)

{

countOfp += 1;

}

else

{

if ((count == cols) & (countOfp == 0))

{

flag = true;

}

}

}

else

{

if ((count == cols) & (countOfq == 0))

{

flag = true;

}

}

}

}

dataGridView4.Rows[i].Cells[0].Value = flag;

}

}

private void button2_Click(object sender, EventArgs e)

{

createTableOfCriterionImportanceFromForm();

createTableOfWeightFromForm();

GetTableOfAgreementIndex(rows, rows);

}

private void button3_Click(object sender, EventArgs e)

{

GetTableOfDisagreementIndex(rows, rows);

}

private void закрытьToolStripMenuItem_Click(object sender, EventArgs e)

{

Close();

}

private void button6_Click(object sender, EventArgs e)

{

IntervalSuperiority(cols);

}

private void button5_Click(object sender, EventArgs e)

{

GetDecisiveRule(rows, 1);

CreateTableofDecisiveRuleFromForm();

}

private void button4_Click(object sender, EventArgs e)

{

GetParametrsForDecisiveRule();

}

//загрузкатаблицывесов

private void button8_Click(object sender, EventArgs e)

{

string FN;

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

openFileDialog1.InitialDirectory = "G:&bsol;temp";

openFileDialog1.Filter = "diag files(*.diag)|*.abs|All files|*.*";

FN = openFileDialog1.FileName;

Reader My = new Reader(FN);

My.ReadTable(out tablesWeight, out rows, out cols);

alfa = Convert.ToDouble(comboBox1.Text);

CreateTableOfWeightOnForm(rows, cols);

for (int i = 0; i < rows; i++)

{

for (int j = 0; j < cols; j++)

{

dataGridView1.Rows[i].Cells[j].Value = tablesWeight[i, j];

}

}

}

}

// сохранениетаблицывесов

private void button7_Click(object sender, EventArgs e)

{

string FN;

saveFileDialog1.InitialDirectory = "G:&bsol;temp";

saveFileDialog1.Filter = "diag files(*.diag)|*.abs|All files|*.*";

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

FN = saveFileDialog1.FileName;

Writer.WriteTable(FN, tablesWeight);

}

}

// загрузкатаблицыкритериевважности

private void button9_Click(object sender, EventArgs e)

{

string FN;

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

openFileDialog1.InitialDirectory = "G:&bsol;temp";

openFileDialog1.Filter = "diag files(*.diag)|*.abs|All files|*.*";

FN = openFileDialog1.FileName;

Reader My = new Reader(FN);

My.ReadTable(out tablesCriterionImportance, out row1, out col1);

alfa = Convert.ToDouble(comboBox1.Text);

CreateTableOfCriterionImportanceOnForm(row1);

for (int i = 0; i < row1; i++)

{

for (int j = 0; j < col1; j++)

{

dataGridView5.Rows[i].Cells[j].Value = tablesCriterionImportance[i, j];

}

}

}

}

// загрузкатаблицыинтерваловпревосходства

private void button11_Click(object sender, EventArgs e)

{

string FN;

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

openFileDialog1.InitialDirectory = "G:&bsol;temp";

openFileDialog1.Filter = "diag files(*.diag)|*.abs|All files|*.*";

FN = openFileDialog1.FileName;

Reader My = new Reader(FN);

My.ReadTable(out tablesIntervalSuperiority, out row1, out col1);

alfa = Convert.ToDouble(comboBox1.Text);

IntervalSuperiority(row1);

for (int i = 0; i < row1; i++)

{

for (int j = 0; j < col1; j++)

{

dataGridView6.Rows[i].Cells[j].Value = tablesIntervalSuperiority[i, j];

}

}

}

}

//сохранениетаблицыкритериевважности

private void button10_Click(object sender, EventArgs e)

{

string FN;

saveFileDialog1.InitialDirectory = "G:&bsol;temp";

saveFileDialog1.Filter = "diag files(*.diag)|*.abs|All files|*.*";

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

FN = saveFileDialog1.FileName;

Writer.WriteTable(FN, tablesCriterionImportance);

}

}

// сохранениетаблицыинтерваловпревосходства

private void button12_Click(object sender, EventArgs e)

{

string FN;

saveFileDialog1.InitialDirectory = "G:&bsol;temp";

saveFileDialog1.Filter = "diag files(*.diag)|*.abs|All files|*.*";

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

FN = saveFileDialog1.FileName;

Writer.WriteTable(FN, tablesIntervalSuperiority);

}

}

// сохранениематрицыиндексовсогласия

private void button13_Click(object sender, EventArgs e)

{

string FN;

saveFileDialog1.InitialDirectory = "G:&bsol;temp";

saveFileDialog1.Filter = "diag files(*.diag)|*.abs|All files|*.*";

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

FN = saveFileDialog1.FileName;

Writer.WriteTable(FN, TableOfAgreementIndex);

}

}

//сохранениематрицыиндексовнесогласия

private void button14_Click(object sender, EventArgs e)

{

string FN;

saveFileDialog1.InitialDirectory = "G:&bsol;temp";

saveFileDialog1.Filter = "diag files(*.diag)|*.abs|All files|*.*";

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

FN = saveFileDialog1.FileName;

Writer.WriteTable(FN, TableOfDisagreementIndex);

}

}

//сохранениеядра

private void button15_Click(object sender, EventArgs e)

{

string FN;

saveFileDialog1.InitialDirectory = "G:&bsol;temp";

saveFileDialog1.Filter = "diag files(*.diag)|*.abs|All files|*.*";

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

FN = saveFileDialog1.FileName;

Writer.WriteTableOfRule(FN, TableofDecisiveRule);

}

}

}

class Reader

{

private string fileName;

private string[] inputTxt;

private double[,] matrix;

private int row;

private int col;

private System.Globalization.NumberFormatInfo numberFormat;

public Reader(string Name)

{

fileName = Name;

}

public void ReadTable(out double[,] table, out int rows, out int cols)

{