Контрольная работа: Многокритериальные задачи. Метод альтернативных решений
{
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;