Как сделать перестановки в матрицах смежности графов так, чтобы они стали подобны?
Мне нужно написать алгоритм проверки изоморфности графов. (Сложность алгоритма можно любую, например O(n!) ). В одной из статей есть теорема которая звучит так:
Теорема 1. Графы изоморфны тогда и только тогда, когда их матрицы смежности перестановочно подобны, то есть их можно получить одну из другой перестановками строк и соответствующих столбцов.
Как можно максимально просто сделать перестановки в матрицах смежности так, чтобы они стали подобны?
UPD. Пытаюсь вывести все перестановки одного графа. Я не понимаю как работает next_permutation(), он выводит не все перестановки
#include <iostream>
#include <algorithm>
using namespace std;
class Graph {
private:
bool** adjMatrix;
int numVertices;
public:
Graph(int numVertices) {
this->numVertices = numVertices;
adjMatrix = new bool* [numVertices];
for (int i = 0; i < numVertices; i++) {
adjMatrix[i] = new bool[numVertices];
for (int j = 0; j < numVertices; j++)
adjMatrix[i][j] = false;
}
}
int getNumVertices() {
return numVertices;
}
void addEdge(int i, int j) {
adjMatrix[i][j] = true;
adjMatrix[j][i] = true;
}
void removeEdge(int i, int j) {
adjMatrix[i][j] = false;
adjMatrix[j][i] = false;
}
void toString() {
cout << "toString" << endl;
for (int i = 0; i < numVertices; i++) {
cout << i << " : ";
for (int j = 0; j < numVertices; j++)
cout << adjMatrix[i][j] << " ";
cout << "\n";
}
cout << endl;
}
void nextPer() {
cout << "nextPer" << endl;
do {
for (int i = 0; i < numVertices; i++) {
cout << i << " : ";
for (int j = 0; j < numVertices; j++)
cout << adjMatrix[i][j] << " ";
cout << "\n";
}
cout << endl;
} while (next_permutation(adjMatrix, adjMatrix + numVertices));
cout << "nextPer after next_permutation" << endl;
for (int i = 0; i < numVertices; i++) {
cout << i << " : ";
for (int j = 0; j < numVertices; j++)
cout << adjMatrix[i][j] << " ";
cout << "\n";
}
cout << endl;
}
~Graph() {
for (int i = 0; i < numVertices; i++)
delete[] adjMatrix[i];
delete[] adjMatrix;
}
};
int main() {
Graph g(4);
g.addEdge(0, 1);
g.addEdge(0, 2);
g.addEdge(1, 2);
g.addEdge(2, 0);
g.addEdge(2, 3);
g.toString();
g.nextPer();
}