Скачиваний:
69
Добавлен:
16.07.2022
Размер:
253.7 Кб
Скачать

Приложение а

Изменения, внесённые в программу А. А. Поебжимова [12].

bool searchMinInTridiagonal(int num, bool mode)

{ //true - минимум строгий / false - нестрогий

int numOfMin;

bool result = true;

bool first = true;

int right_bound = (this->col > num + 1) ? num + 1 : this->col;

int left_bound = (num - 1 > 0) ? num - 1 : 0;

Tropical_Int min = INT_MAX;

for (int i = left_bound; i < right_bound; ++i)

{

if (this->matrix[num][i] < min)

{

min = this->matrix[num][i];

numOfMin = i;

}

}

for (int i = left_bound; i < right_bound; ++i)

{

if (this->matrix[num][i] == min && !this->conatinsInJ(i))

{

numOfMin = i;

if (first)

first = false;

else

return false;

}

}

if (!this->conatinsInJ(numOfMin))

{

if (mode)

{

this->addInJ(numOfMin);

}

return true;

}

else

return false;

}

void searchDownMatrixInTridiagonal()

{

bool flag;

do

{

do

{

flag = false;

for (int i = 0; i < this->str && !flag; ++i)

{

flag = this->searchMinInTridiagonal(i, 1);

}

} while (flag);

Tropical_Int constant = searchConstantInTridiagonal();

if (constant == 0)

break;

for (int i = 0; i < this->str; ++i)

{

for (int j = 0; j < this->col; ++j)

{

if (!this->conatinsInJ(j))

{

this->matrix[i][j] /= constant;

}

}

}

if (!this->jIsFool())

{

this->jFree();

for (int i = 0; (i < this->str) && !(flag =

searchMinInTridiagonal(i, 0)); ++i)

;

}

else

flag = false;

} while (flag);

}

Приложение б

#include <windows.h>

#include "stdafx.h"

#include "Matrix.h"

#include <string>

#include <fstream>

#include <streambuf>

#include <iostream>

void swap(int *a, int i, int j)

{

int s = a[i];

a[i] = a[j];

a[j] = s;

}

bool NextSet(int *a, int n)

{

int j = n - 2;

while (j != -1 && a[j] >= a[j + 1]) j--;

if (j == -1)

return false; // больше перестановок нет

int k = n - 1;

while (a[j] >= a[k]) k--;

swap(a, j, k);

int l = j + 1, r = n - 1; // сортируем оставшуюся часть последовательности

while (l<r)

swap(a, l++, r--);

return true;

}

// Создание массива перестановок

bool check_variant_tridiagonal(int* variant, int size)

{

int i = 0;

bool finite = true;

for (int j = 0; (j < size) && finite; j++){

if (abs(variant[j] - j) > 1){

finite = false;

}

}

return finite;

}

bool is_solvable (const Matrix matrix, bool is_tridiagonal) {

int* array_with_variants = new int[matrix.col];

for (int i = 0; i < matrix.col; i++){

array_with_variants[i] = i;

}

Tropical_Int min = INT_MAX;

int count = 0;

int index = 0;

Tropical_Int element;

do {

if (!is_tridiagonal || check_variant_tridiagonal(array_with_variants, matrix.col)) {

element = 0;

for (int j = 0; j < matrix.col; j++) {

element *= matrix.matrix[j][array_with_variants[j]];

}

if (element < min){

min = element;

count = 0;

}

else if (element == min)

count++;

index++;

}

}while (NextSet(array_with_variants, matrix.col));

delete(array_with_variants);

array_with_variants = nullptr;

return count > 0;

}