Compare commits
83 Commits
a1d74ec126
...
plot
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c004b64ed | |||
| a135df2e96 | |||
| d9e49d1319 | |||
| e127ff8c29 | |||
| 9b423f9c83 | |||
| fa7e70a437 | |||
| 76fa9fb329 | |||
| 7f1ef38286 | |||
| 2af915057a | |||
| 2975006972 | |||
| 0d071b1cf9 | |||
| a02f71e29e | |||
| 6833811b97 | |||
| b41bcae337 | |||
| 427eeb0b51 | |||
| 5fac74cefc | |||
| b239c0aaff | |||
| 6b763b8481 | |||
| 5391b7b76a | |||
| dc31f1f091 | |||
| 11cc0fadad | |||
| e71bc588e5 | |||
| 36ef301cb9 | |||
| f5a282c455 | |||
| 99c0e2010b | |||
| 851080c7a4 | |||
| 2724ca173d | |||
| 13c9bc40db | |||
| 1b994daf3c | |||
| 99624d1b00 | |||
|
|
f595582948 | ||
| 259750a794 | |||
| 5a44ff311a | |||
| 432fa99f71 | |||
| 911f016bb7 | |||
| 0f72f6603e | |||
| 2b520f6648 | |||
| 57d51a1406 | |||
| 3d01393f02 | |||
| 9d3d78fe16 | |||
| 750781aa5c | |||
| 222d723675 | |||
| e072d30995 | |||
| bbcf3aa88d | |||
| 6ac75b12af | |||
| 034326a21e | |||
| 8c1c3d4f9e | |||
| 9028b553c3 | |||
| 46adc200d1 | |||
| 7c75728180 | |||
| 54346dc77f | |||
| d038ac5884 | |||
| b9a5100cb0 | |||
| 890575bc7d | |||
| 10d2bb1da0 | |||
| 8d940cadf6 | |||
|
|
edb79f725c | ||
| 81e82b27a4 | |||
| b7bf653431 | |||
| ff79704293 | |||
| b8ee47e267 | |||
| abd5c7ac56 | |||
|
|
ad288b3661 | ||
|
|
21e78a8820 | ||
|
|
c7268fe536 | ||
| b9a3fb4ca4 | |||
| ceda1b00df | |||
| 23484289a4 | |||
| 766aa6ada4 | |||
| 208c79800e | |||
| 6b03fab302 | |||
| a35f45015b | |||
| 5a5c247019 | |||
| 99eca82b3a | |||
| 3b07ae783f | |||
| 82ad2e0696 | |||
| efd0a88868 | |||
| 54798d0ff2 | |||
| 99467048e2 | |||
| 88cc529009 | |||
| d156602da7 | |||
| 46dcad1457 | |||
| c2fd2805fa |
@@ -7,6 +7,8 @@ ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
|||||||
PointerAlignment: Left
|
PointerAlignment: Left
|
||||||
SortIncludes: true
|
SortIncludes: true
|
||||||
SpacesBeforeTrailingComments: 2
|
SpacesBeforeTrailingComments: 2
|
||||||
|
SeparateDefinitionBlocks: Always
|
||||||
|
SpaceBeforeCpp11BracedList: true
|
||||||
UseTab: Always
|
UseTab: Always
|
||||||
MaxEmptyLinesToKeep: 5
|
MaxEmptyLinesToKeep: 5
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,26 @@ jobs:
|
|||||||
Build:
|
Build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
|
- name: Install opengl
|
||||||
|
run: |
|
||||||
|
apt update
|
||||||
|
apt install libgl-dev -y
|
||||||
|
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
- name: Prepare XMake
|
- name: Prepare Xmake
|
||||||
uses: xmake-io/github-action-setup-xmake@v1
|
uses: xmake-io/github-action-setup-xmake@v1
|
||||||
with:
|
with:
|
||||||
xmake-version: branch@master
|
xmake-version: latest
|
||||||
actions-cache-folder: '.xmake-cache'
|
actions-cache-folder: '.xmake-cache'
|
||||||
actions-cache-key: 'ubuntu'
|
actions-cache-key: 'ubuntu-xmake'
|
||||||
|
|
||||||
|
- name: Cache
|
||||||
|
uses: actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ~/.xmake
|
||||||
|
key: 'ubuntu'
|
||||||
|
|
||||||
- name: XMake config
|
- name: XMake config
|
||||||
run: xmake f -p linux -y --root
|
run: xmake f -p linux -y --root
|
||||||
|
|||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -7,3 +7,6 @@ build/
|
|||||||
|
|
||||||
# VsCode
|
# VsCode
|
||||||
.vscode
|
.vscode
|
||||||
|
|
||||||
|
#ImGui
|
||||||
|
imgui.ini
|
||||||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
[submodule "doc/doxygen-awesome-css"]
|
||||||
|
path = doc/doxygen-awesome-css
|
||||||
|
url = https://github.com/jothepro/doxygen-awesome-css
|
||||||
11
.vscode/c_cpp_properties.json
vendored
Normal file
11
.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Pivot",
|
||||||
|
"cppStandard": "c++20",
|
||||||
|
"includePath": ["include"],
|
||||||
|
"compileCommands": "${workspaceFolder}/.vscode/compile_commands.json"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
||||||
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@@ -7,8 +7,8 @@
|
|||||||
{
|
{
|
||||||
"type": "xmake",
|
"type": "xmake",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Debug XMake target",
|
"name": "Debug random kernel",
|
||||||
"target": "Pivot",
|
"target": "test_random_kernel",
|
||||||
"cwd": "${workspaceFolder}/matricies",
|
"cwd": "${workspaceFolder}/matricies",
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
19
.vscode/settings.json
vendored
19
.vscode/settings.json
vendored
@@ -44,6 +44,23 @@
|
|||||||
"stdexcept": "cpp",
|
"stdexcept": "cpp",
|
||||||
"streambuf": "cpp",
|
"streambuf": "cpp",
|
||||||
"cinttypes": "cpp",
|
"cinttypes": "cpp",
|
||||||
"typeinfo": "cpp"
|
"typeinfo": "cpp",
|
||||||
|
"codecvt": "cpp",
|
||||||
|
"condition_variable": "cpp",
|
||||||
|
"cstring": "cpp",
|
||||||
|
"ctime": "cpp",
|
||||||
|
"ratio": "cpp",
|
||||||
|
"fstream": "cpp",
|
||||||
|
"future": "cpp",
|
||||||
|
"iomanip": "cpp",
|
||||||
|
"mutex": "cpp",
|
||||||
|
"semaphore": "cpp",
|
||||||
|
"sstream": "cpp",
|
||||||
|
"stop_token": "cpp",
|
||||||
|
"thread": "cpp",
|
||||||
|
"chrono": "cpp",
|
||||||
|
"optional": "cpp",
|
||||||
|
"ranges": "cpp",
|
||||||
|
"span": "cpp"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
12
README.md
12
README.md
@@ -2,16 +2,22 @@
|
|||||||
|
|
||||||
|
|
||||||
# Cahier des charges
|
# Cahier des charges
|
||||||

|

|
||||||
|
|
||||||
# Build
|
# Build ⚙️
|
||||||
|
|
||||||
```
|
```
|
||||||
xmake
|
xmake
|
||||||
```
|
```
|
||||||
|
|
||||||
# Run
|
# Run 🏃
|
||||||
|
|
||||||
```
|
```
|
||||||
xmake run
|
xmake run
|
||||||
```
|
```
|
||||||
|
|
||||||
|
# Test 🛠
|
||||||
|
|
||||||
|
```
|
||||||
|
xmake test
|
||||||
|
```
|
||||||
1
doc/doxygen-awesome-css
Submodule
1
doc/doxygen-awesome-css
Submodule
Submodule doc/doxygen-awesome-css added at c01e51e461
16
imgui.ini
Normal file
16
imgui.ini
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[Window][Debug##Default]
|
||||||
|
Pos=60,60
|
||||||
|
Size=400,400
|
||||||
|
|
||||||
|
[Window][Right Top Window]
|
||||||
|
Pos=640,0
|
||||||
|
Size=640,576
|
||||||
|
|
||||||
|
[Window][Bottom Part]
|
||||||
|
Pos=0,576
|
||||||
|
Size=1280,144
|
||||||
|
|
||||||
|
[Window][Left Top Window]
|
||||||
|
Pos=0,0
|
||||||
|
Size=640,576
|
||||||
|
|
||||||
20
include/Gauss.h
Normal file
20
include/Gauss.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file Gauss.h
|
||||||
|
* \brief Contient la définition de l'algorithme de Gauss
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Matrix;
|
||||||
|
|
||||||
|
namespace Gauss {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Echelonne une matrice en ligne en utilisant l'algorithme de Gauss-Jordan
|
||||||
|
* \param a_Matrix La matrice à échelonner
|
||||||
|
* \param a_Reduite Mets des 0 au dessus des pivots
|
||||||
|
* \param a_Normalise Mets les pivots à 1
|
||||||
|
*/
|
||||||
|
void GaussJordan(Matrix& a_Matrix, bool a_Reduite, bool a_Normalise);
|
||||||
|
|
||||||
|
} // namespace Gauss
|
||||||
52
include/IO.h
Normal file
52
include/IO.h
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file IO.h
|
||||||
|
* \brief Contient des fonctions utiles pour travailler avec les systèmes d'entrée et de sortie
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Matrix;
|
||||||
|
class Vect;
|
||||||
|
class VectAffine;
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& stream, const Matrix& mat);
|
||||||
|
std::istream& operator>>(std::istream& stream, Matrix& mat);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Charge une matrice à partir d'un fichier
|
||||||
|
* \param fileName Le chemin du fichier à charger
|
||||||
|
* \return Une matrice de taille nulle si une erreur intervient
|
||||||
|
*/
|
||||||
|
Matrix LoadMatrix(const std::string& fileName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Sauvegarde une matrice dans un fichier
|
||||||
|
* \param mat La matrice à sauver
|
||||||
|
* \param fileName Le chemin du fichier à écrire
|
||||||
|
*/
|
||||||
|
void SaveMatrix(const Matrix& mat, const std::string& fileName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Permet de saisir une matrice à partir de la console
|
||||||
|
*/
|
||||||
|
Matrix InsertMatrix();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Affiche une matrice dans la console
|
||||||
|
* \param mat La matrice à afficher
|
||||||
|
*/
|
||||||
|
void Print(const Matrix& mat);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Affiche un espace vectoriel dans la console
|
||||||
|
* \param vect L'espace vectoriel à afficher
|
||||||
|
*/
|
||||||
|
void Print(const Vect& vect);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Affiche un espace affine dans la console
|
||||||
|
* \param vect L'espace affine à afficher
|
||||||
|
*/
|
||||||
|
void Print(const VectAffine& vect);
|
||||||
176
include/Matrix.h
Normal file
176
include/Matrix.h
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file Matrix.h
|
||||||
|
* \brief Contient la définition d'une matrice
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "NR.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class Matrix
|
||||||
|
* \brief Représente une matrice d'éléments
|
||||||
|
*/
|
||||||
|
class Matrix {
|
||||||
|
public:
|
||||||
|
typedef long double Element;
|
||||||
|
typedef std::vector<Element>::iterator iterator;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::size_t m_Raws;
|
||||||
|
std::size_t m_Columns;
|
||||||
|
std::vector<Element> m_Data;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* \brief Constructeur par défaut. Crée une matrice de taille nulle
|
||||||
|
*/
|
||||||
|
Matrix() : m_Raws(0), m_Columns(0) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Construit une matrice de taille donnée remplie de données aléatoires (et peut-être invalides !)
|
||||||
|
* \param a_Raws Le nombre de lignes
|
||||||
|
* \param a_Columns Le nombre de colonne
|
||||||
|
*/
|
||||||
|
Matrix(std::size_t a_Raws, std::size_t a_Columns);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Construit une matrice de taille donnée avec des éléments donnés.\n
|
||||||
|
* Exemple :
|
||||||
|
* \code Matrix(2, 2, {1, 2, 3, 4}) \endcode construit la matrice \n
|
||||||
|
* [1, 2]\n
|
||||||
|
* [3, 4]
|
||||||
|
* \param a_Raws Le nombre de lignes
|
||||||
|
* \param a_Columns Le nombre de colonne
|
||||||
|
* \param a_Elements Les élements à mettre
|
||||||
|
*/
|
||||||
|
Matrix(std::size_t a_Raws, std::size_t a_Columns, std::initializer_list<Element>&& a_Elements);
|
||||||
|
|
||||||
|
~Matrix() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retourne le nombre de lignes de la matrice
|
||||||
|
*/
|
||||||
|
std::size_t GetRawCount() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retourne le nombre de colonnes de la matrice
|
||||||
|
*/
|
||||||
|
std::size_t GetColumnCount() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Transpose la matrice
|
||||||
|
*/
|
||||||
|
void Transpose();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Augmente la matrice actuelle à droite avec une autre
|
||||||
|
* \param a_Right Une matrice avec le bon nombre de lignes
|
||||||
|
* \pre Les deux matrices doivent avoir le même nombre de lignes
|
||||||
|
*/
|
||||||
|
void Augment(const Matrix& a_Right);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Augmente la matrice actuelle en dessous avec une autre
|
||||||
|
* \param a_Bottom Une matrice avec le bon nombre de colonnes
|
||||||
|
* \pre Les deux matrices doivent avoir le même nombre de colonnes
|
||||||
|
*/
|
||||||
|
void AugmentBottom(const Matrix& a_Bottom);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Affecte tous les coefficients de la matrice à un élément
|
||||||
|
* \param a_Element L'élément à affecter
|
||||||
|
*/
|
||||||
|
void Fill(Element a_Element);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retourne la sous-matrice spécifiée
|
||||||
|
* \param a_RawOrigin L'indice de la première ligne de la matrice à récupérer
|
||||||
|
* \param a_ColumnOrigin L'indice de la première colonne de la matrice à récupérer
|
||||||
|
* \param a_RawCount Le nombre de lignes de la sous-matrice
|
||||||
|
* \param a_ColumnCount Le nombre de colonnes de la sous-matrice
|
||||||
|
* \pre a_RawOrigin + a_RawCount <= GetRawCount()
|
||||||
|
* \pre a_ColumnOrigin + a_ColumnCount <= GetColumnCount()
|
||||||
|
*/
|
||||||
|
Matrix SubMatrix(std::size_t a_RawOrigin, std::size_t a_ColumnOrigin, std::size_t a_RawCount, std::size_t a_ColumnCount) const;
|
||||||
|
|
||||||
|
Matrix operator+(const Matrix& a_Other) const;
|
||||||
|
Matrix operator-(const Matrix& a_Other) const;
|
||||||
|
|
||||||
|
bool operator==(const Matrix& a_Other) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Effectue un produit matriciel
|
||||||
|
*/
|
||||||
|
Matrix operator*(const Matrix& a_Other) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retourne l'élément à l'indice recherché
|
||||||
|
* \param a_Raw L'indice de la ligne
|
||||||
|
* \param a_Column L'indice de la colonne
|
||||||
|
*/
|
||||||
|
Element& at(std::size_t a_Raw, std::size_t a_Column);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retourne l'élément à l'indice recherché (version constante)
|
||||||
|
* \param a_Raw L'indice de la ligne
|
||||||
|
* \param a_Column L'indice de la colonne
|
||||||
|
*/
|
||||||
|
Element at(std::size_t a_Raw, std::size_t a_Column) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Construit une matrice identité de taille donnée
|
||||||
|
* \param a_Size La taille de la matrice carrée
|
||||||
|
*/
|
||||||
|
static Matrix Identity(std::size_t a_Size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Construit une matrice colonne à partir de données existantes.\n
|
||||||
|
* Exemple :
|
||||||
|
* \code
|
||||||
|
* Matrix::ColumnVector({1, 2, 3, 4});
|
||||||
|
* \endcode
|
||||||
|
* construit une matrice de 4 lignes et 1 colonne de coordonnées (1, 2, 3, 4)
|
||||||
|
*/
|
||||||
|
static Matrix ColumnVector(std::initializer_list<Element>&& a_Elements);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Construit une matrice ligne à partir de données existantes.\n
|
||||||
|
* Exemple :
|
||||||
|
* \code
|
||||||
|
* Matrix::RawVector({1, 2, 3, 4});
|
||||||
|
* \endcode
|
||||||
|
* construit une matrice de 1 ligne et 4 colonnes de coordonnées (1, 2, 3, 4)
|
||||||
|
*/
|
||||||
|
static Matrix RawVector(std::initializer_list<Element>&& a_Elements);
|
||||||
|
|
||||||
|
iterator begin();
|
||||||
|
iterator end();
|
||||||
|
|
||||||
|
iterator GetLineIterator(std::size_t a_Raw);
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
bool IsEqualZero(const T& var) {
|
||||||
|
return std::abs(var) < std::pow(10, -5);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline bool IsEqualZero(const int& var) {
|
||||||
|
return var == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline bool IsEqualZero(const long& var) {
|
||||||
|
return var == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline bool IsEqualZero(const NR& var) {
|
||||||
|
return var == 0;
|
||||||
|
}
|
||||||
48
include/NR.h
Normal file
48
include/NR.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
class NR {
|
||||||
|
public:
|
||||||
|
using Int = long long;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Int m_Numerator;
|
||||||
|
Int m_Denominator; // has to be > 0, sign is carried by the numerator
|
||||||
|
|
||||||
|
public:
|
||||||
|
NR();
|
||||||
|
NR(Int entier);
|
||||||
|
NR(Int numerator, Int denominator); // check if denominator != 0
|
||||||
|
|
||||||
|
Int GetNumerator() const;
|
||||||
|
Int GetDenominator() const;
|
||||||
|
|
||||||
|
bool operator==(const NR& opNR) const;
|
||||||
|
bool operator<(const NR& opNR) const;
|
||||||
|
bool operator>(const NR& opNR) const;
|
||||||
|
|
||||||
|
bool operator!=(const NR& opNR) const;
|
||||||
|
bool operator<=(const NR& opNR) const;
|
||||||
|
bool operator>=(const NR& opNR) const;
|
||||||
|
|
||||||
|
NR operator+(const NR& opNR) const;
|
||||||
|
NR operator-(const NR& opNR) const;
|
||||||
|
NR operator*(const NR& opNR) const;
|
||||||
|
NR operator/(const NR& opNR) const;
|
||||||
|
|
||||||
|
NR& operator+=(const NR& opNR);
|
||||||
|
NR& operator-=(const NR& opNR);
|
||||||
|
NR& operator*=(const NR& opNR);
|
||||||
|
NR& operator/=(const NR& opNR);
|
||||||
|
|
||||||
|
NR operator-() const;
|
||||||
|
|
||||||
|
NR Inverse() const;
|
||||||
|
|
||||||
|
friend std::ostream& operator<<(std::ostream& os, const NR& opNR);
|
||||||
|
friend std::istream& operator>>(std::istream& os, NR& opNR);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Reduce();
|
||||||
|
};
|
||||||
44
include/Solver.h
Normal file
44
include/Solver.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file Solver.h
|
||||||
|
* \brief Contient la définition du solutionneur
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Vect.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class Solver
|
||||||
|
* \brief Permet d'obtenir différentes propriétés d'une matrice comme l'image ou le noyau
|
||||||
|
*/
|
||||||
|
class Solver {
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* \brief Calcule l'image d'une matrice
|
||||||
|
* \param a_Matrix La matrice à traiter
|
||||||
|
* \return L'espace vectoriel correspondant
|
||||||
|
*/
|
||||||
|
Vect Image(Matrix&& a_Matrix) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Calcule le noyau d'une matrice
|
||||||
|
* \param a_Matrix La matrice à traiter
|
||||||
|
* \return L'espace vectoriel correspondant
|
||||||
|
*/
|
||||||
|
Vect Kernel(Matrix&& a_Matrix) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Résout le système rectangulaire de la forme AX=B, avec X et B, des vecteurs colonne.
|
||||||
|
* \param a_MatrixA La matrice jouant le rôle de A
|
||||||
|
* \param a_VectorB La matrice colonne jouant le rôle de B
|
||||||
|
* \return L'espace affine associé
|
||||||
|
*/
|
||||||
|
VectAffine RectangularSystem(Matrix&& a_MatrixA, const Matrix& a_VectorB) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Calcule le rang d'une matrice
|
||||||
|
* \param a_Matrix La matrice à traiter
|
||||||
|
* \note Ceci équivaut à \code Image(a_Matrix).GetCardinal() \endcode
|
||||||
|
*/
|
||||||
|
std::size_t Rank(Matrix&& a_Matrix) const;
|
||||||
|
};
|
||||||
117
include/Vect.h
Normal file
117
include/Vect.h
Normal file
@@ -0,0 +1,117 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file Vect.h
|
||||||
|
* \brief Contient la définition d'un espace affine et d'un espace vectoriel
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Matrix.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class Vect
|
||||||
|
* \brief Représente une base d'un espace vectoriel de dimension finie
|
||||||
|
*/
|
||||||
|
class Vect {
|
||||||
|
private:
|
||||||
|
Matrix m_Data;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* \brief Construit une base d'un espace vectoriel à partir des colonnes d'une matrice.
|
||||||
|
* Les colonnes de 0 sont ignorées
|
||||||
|
* \param a_Matrix Une matrice échelonnée.
|
||||||
|
*/
|
||||||
|
Vect(Matrix&& a_Matrix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Permet d'obtenir le ieme vecteur de la base
|
||||||
|
* \param a_Index l'index du vecteur souhaité
|
||||||
|
* \return Une matrice colonne
|
||||||
|
*/
|
||||||
|
Matrix GetVector(std::size_t a_Index) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retourne le nombre de coordonnées des vecteurs de la base (leur nombre de colonne)
|
||||||
|
*/
|
||||||
|
std::size_t GetDimension() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retourne le nombre de vecteur de la base
|
||||||
|
*/
|
||||||
|
std::size_t GetCardinal() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Exprime l'espace vectoriel comme les solutions d'un système linéaire des coordonnées des vecteurs
|
||||||
|
* \return Une matrice représentant le système linéaire
|
||||||
|
*/
|
||||||
|
Matrix GetLinearSystem() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Concatène la base actuelle avec un nouveau vecteur
|
||||||
|
* \param a_Vector Une matrice colonne de taille GetDimension()
|
||||||
|
*/
|
||||||
|
void AddVector(const Matrix& a_Vector);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Vérifie si le vecteur spécifié appartient au sous-espace vectoriel
|
||||||
|
* \param a_Vector Une matrice colonne représentant le vecteur à tester
|
||||||
|
*/
|
||||||
|
bool IsElementOf(const Matrix& a_Vector) const;
|
||||||
|
|
||||||
|
bool operator==(const Vect& a_Other) const;
|
||||||
|
bool operator!=(const Vect& a_Other) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
void Simplify();
|
||||||
|
|
||||||
|
friend class VectAffine;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \class VectAffine
|
||||||
|
* \brief Représente un espace affine
|
||||||
|
*/
|
||||||
|
class VectAffine {
|
||||||
|
private:
|
||||||
|
Vect m_Base;
|
||||||
|
Matrix m_Origin;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* \brief Construit un espace affine à partir d'un espace vectoriel et d'une origine
|
||||||
|
* \param a_Base La base de l'espace vectoriel
|
||||||
|
* \param a_Origin Le vecteur d'origine (matrice colonne)
|
||||||
|
*/
|
||||||
|
VectAffine(const Vect& a_Base, const Matrix& a_Origin);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retourne l'espace vectoriel correspondant
|
||||||
|
*/
|
||||||
|
const Vect& GetBase() const {
|
||||||
|
return m_Base;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Retourne l'origine de l'espace affine
|
||||||
|
* \return Un vecteur colonne
|
||||||
|
*/
|
||||||
|
const Matrix& GetOrigin() const {
|
||||||
|
return m_Origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Vérifie si le vecteur spécifié appartient à l'espace affine
|
||||||
|
* \param a_Vector Une matrice colonne représentant le vecteur à tester
|
||||||
|
*/
|
||||||
|
bool IsElementOf(const Matrix& a_Vector) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Exprime l'espace vectoriel comme les solutions d'un système linéaire des coordonnées des vecteurs
|
||||||
|
* \return Une matrice représentant le système linéaire
|
||||||
|
*/
|
||||||
|
Matrix GetLinearSystem() const;
|
||||||
|
|
||||||
|
bool operator==(const VectAffine& a_VectAffine) const {
|
||||||
|
return m_Origin == a_VectAffine.GetOrigin() && m_Base == a_VectAffine.GetBase();
|
||||||
|
};
|
||||||
|
};
|
||||||
BIN
matricies/core
Normal file
BIN
matricies/core
Normal file
Binary file not shown.
2067
matricies/plot.eps
Normal file
2067
matricies/plot.eps
Normal file
File diff suppressed because it is too large
Load Diff
BIN
matricies/plot.png
Normal file
BIN
matricies/plot.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 29 KiB |
135
matricies/plot.tex
Normal file
135
matricies/plot.tex
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
% GNUPLOT: LaTeX picture with Postscript
|
||||||
|
\begingroup
|
||||||
|
\makeatletter
|
||||||
|
\providecommand\color[2][]{%
|
||||||
|
\GenericError{(gnuplot) \space\space\space\@spaces}{%
|
||||||
|
Package color not loaded in conjunction with
|
||||||
|
terminal option `colourtext'%
|
||||||
|
}{See the gnuplot documentation for explanation.%
|
||||||
|
}{Either use 'blacktext' in gnuplot or load the package
|
||||||
|
color.sty in LaTeX.}%
|
||||||
|
\renewcommand\color[2][]{}%
|
||||||
|
}%
|
||||||
|
\providecommand\includegraphics[2][]{%
|
||||||
|
\GenericError{(gnuplot) \space\space\space\@spaces}{%
|
||||||
|
Package graphicx or graphics not loaded%
|
||||||
|
}{See the gnuplot documentation for explanation.%
|
||||||
|
}{The gnuplot epslatex terminal needs graphicx.sty or graphics.sty.}%
|
||||||
|
\renewcommand\includegraphics[2][]{}%
|
||||||
|
}%
|
||||||
|
\providecommand\rotatebox[2]{#2}%
|
||||||
|
\@ifundefined{ifGPcolor}{%
|
||||||
|
\newif\ifGPcolor
|
||||||
|
\GPcolortrue
|
||||||
|
}{}%
|
||||||
|
\@ifundefined{ifGPblacktext}{%
|
||||||
|
\newif\ifGPblacktext
|
||||||
|
\GPblacktexttrue
|
||||||
|
}{}%
|
||||||
|
% define a \g@addto@macro without @ in the name:
|
||||||
|
\let\gplgaddtomacro\g@addto@macro
|
||||||
|
% define empty templates for all commands taking text:
|
||||||
|
\gdef\gplbacktext{}%
|
||||||
|
\gdef\gplfronttext{}%
|
||||||
|
\makeatother
|
||||||
|
\ifGPblacktext
|
||||||
|
% no textcolor at all
|
||||||
|
\def\colorrgb#1{}%
|
||||||
|
\def\colorgray#1{}%
|
||||||
|
\else
|
||||||
|
% gray or color?
|
||||||
|
\ifGPcolor
|
||||||
|
\def\colorrgb#1{\color[rgb]{#1}}%
|
||||||
|
\def\colorgray#1{\color[gray]{#1}}%
|
||||||
|
\expandafter\def\csname LTw\endcsname{\color{white}}%
|
||||||
|
\expandafter\def\csname LTb\endcsname{\color{black}}%
|
||||||
|
\expandafter\def\csname LTa\endcsname{\color{black}}%
|
||||||
|
\expandafter\def\csname LT0\endcsname{\color[rgb]{1,0,0}}%
|
||||||
|
\expandafter\def\csname LT1\endcsname{\color[rgb]{0,1,0}}%
|
||||||
|
\expandafter\def\csname LT2\endcsname{\color[rgb]{0,0,1}}%
|
||||||
|
\expandafter\def\csname LT3\endcsname{\color[rgb]{1,0,1}}%
|
||||||
|
\expandafter\def\csname LT4\endcsname{\color[rgb]{0,1,1}}%
|
||||||
|
\expandafter\def\csname LT5\endcsname{\color[rgb]{1,1,0}}%
|
||||||
|
\expandafter\def\csname LT6\endcsname{\color[rgb]{0,0,0}}%
|
||||||
|
\expandafter\def\csname LT7\endcsname{\color[rgb]{1,0.3,0}}%
|
||||||
|
\expandafter\def\csname LT8\endcsname{\color[rgb]{0.5,0.5,0.5}}%
|
||||||
|
\else
|
||||||
|
% gray
|
||||||
|
\def\colorrgb#1{\color{black}}%
|
||||||
|
\def\colorgray#1{\color[gray]{#1}}%
|
||||||
|
\expandafter\def\csname LTw\endcsname{\color{white}}%
|
||||||
|
\expandafter\def\csname LTb\endcsname{\color{black}}%
|
||||||
|
\expandafter\def\csname LTa\endcsname{\color{black}}%
|
||||||
|
\expandafter\def\csname LT0\endcsname{\color{black}}%
|
||||||
|
\expandafter\def\csname LT1\endcsname{\color{black}}%
|
||||||
|
\expandafter\def\csname LT2\endcsname{\color{black}}%
|
||||||
|
\expandafter\def\csname LT3\endcsname{\color{black}}%
|
||||||
|
\expandafter\def\csname LT4\endcsname{\color{black}}%
|
||||||
|
\expandafter\def\csname LT5\endcsname{\color{black}}%
|
||||||
|
\expandafter\def\csname LT6\endcsname{\color{black}}%
|
||||||
|
\expandafter\def\csname LT7\endcsname{\color{black}}%
|
||||||
|
\expandafter\def\csname LT8\endcsname{\color{black}}%
|
||||||
|
\fi
|
||||||
|
\fi
|
||||||
|
\setlength{\unitlength}{0.0500bp}%
|
||||||
|
\ifx\gptboxheight\undefined%
|
||||||
|
\newlength{\gptboxheight}%
|
||||||
|
\newlength{\gptboxwidth}%
|
||||||
|
\newsavebox{\gptboxtext}%
|
||||||
|
\fi%
|
||||||
|
\setlength{\fboxrule}{0.5pt}%
|
||||||
|
\setlength{\fboxsep}{1pt}%
|
||||||
|
\definecolor{tbcol}{rgb}{1,1,1}%
|
||||||
|
\begin{picture}(7200.00,5040.00)%
|
||||||
|
\gplgaddtomacro\gplbacktext{%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(803,554){\makebox(0,0)[r]{\strut{}0}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(803,1141){\makebox(0,0)[r]{\strut{}0.05}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(803,1727){\makebox(0,0)[r]{\strut{}0.1}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(803,2314){\makebox(0,0)[r]{\strut{}0.15}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(803,2901){\makebox(0,0)[r]{\strut{}0.2}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(803,3488){\makebox(0,0)[r]{\strut{}0.25}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(803,4074){\makebox(0,0)[r]{\strut{}0.3}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(803,4661){\makebox(0,0)[r]{\strut{}0.35}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(935,334){\makebox(0,0){\strut{}0}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(1865,334){\makebox(0,0){\strut{}50}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(2795,334){\makebox(0,0){\strut{}100}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(3725,334){\makebox(0,0){\strut{}150}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(4655,334){\makebox(0,0){\strut{}200}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(5585,334){\makebox(0,0){\strut{}250}}%
|
||||||
|
\colorrgb{0.15,0.15,0.15}%%
|
||||||
|
\put(6515,334){\makebox(0,0){\strut{}300}}%
|
||||||
|
}%
|
||||||
|
\gplgaddtomacro\gplfronttext{%
|
||||||
|
\csname LTb\endcsname%%
|
||||||
|
\put(66,2607){\rotatebox{-270}{\makebox(0,0){\strut{}Temps d'exécution (s)}}}%
|
||||||
|
\put(3725,4){\makebox(0,0){\strut{}Taille des matrices}}%
|
||||||
|
\csname LTb\endcsname%%
|
||||||
|
\put(1922,4488){\makebox(0,0)[l]{\strut{}Echelonnage non réduit}}%
|
||||||
|
\csname LTb\endcsname%%
|
||||||
|
\put(1922,4268){\makebox(0,0)[l]{\strut{}Echelonnage réduit}}%
|
||||||
|
\csname LTb\endcsname%%
|
||||||
|
\put(1922,4048){\makebox(0,0)[l]{\strut{}Echelonnage non réduit normalisé}}%
|
||||||
|
\csname LTb\endcsname%%
|
||||||
|
\put(1922,3828){\makebox(0,0)[l]{\strut{}Echelonnage réduit normalisé}}%
|
||||||
|
\csname LTb\endcsname%%
|
||||||
|
\put(3725,4991){\makebox(0,0){/:Bold Echelonnage de matrices}}%
|
||||||
|
}%
|
||||||
|
\gplbacktext
|
||||||
|
\put(0,0){\includegraphics[width={360.00bp},height={252.00bp}]{plot}}%
|
||||||
|
\gplfronttext
|
||||||
|
\end{picture}%
|
||||||
|
\endgroup
|
||||||
12
matricies/test/matrice1.test
Normal file
12
matricies/test/matrice1.test
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
2 3
|
||||||
|
1 2 3
|
||||||
|
4 5 6
|
||||||
|
|
||||||
|
2 2
|
||||||
|
0 1
|
||||||
|
1 0
|
||||||
|
|
||||||
|
3 1
|
||||||
|
1
|
||||||
|
-2
|
||||||
|
1
|
||||||
11
matricies/test/matrice2.test
Normal file
11
matricies/test/matrice2.test
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
3 3
|
||||||
|
1 0 1
|
||||||
|
0 1 3
|
||||||
|
0 4 4
|
||||||
|
|
||||||
|
3 3
|
||||||
|
1 0 0
|
||||||
|
0 1 0
|
||||||
|
0 0 1
|
||||||
|
|
||||||
|
3 0
|
||||||
16
matricies/test/matrice3.test
Normal file
16
matricies/test/matrice3.test
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
4 3
|
||||||
|
1 -1 0
|
||||||
|
2 1 3
|
||||||
|
1 2 3
|
||||||
|
2 -2 0
|
||||||
|
|
||||||
|
4 2
|
||||||
|
1 0
|
||||||
|
1 1
|
||||||
|
0 1
|
||||||
|
2 0
|
||||||
|
|
||||||
|
3 1
|
||||||
|
1
|
||||||
|
1
|
||||||
|
-1
|
||||||
17
matricies/test/matrice4.test
Normal file
17
matricies/test/matrice4.test
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
4 4
|
||||||
|
5 2 3 0
|
||||||
|
9 0 -9 0
|
||||||
|
1 0 -1 0
|
||||||
|
0 0 3 -3
|
||||||
|
|
||||||
|
4 3
|
||||||
|
1 0 0
|
||||||
|
0 0 9
|
||||||
|
0 0 1
|
||||||
|
0 -3 0
|
||||||
|
|
||||||
|
4 1
|
||||||
|
1
|
||||||
|
-4
|
||||||
|
1
|
||||||
|
1
|
||||||
14
matricies/test/matrice5.test
Normal file
14
matricies/test/matrice5.test
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
5 4
|
||||||
|
0 0 0 0
|
||||||
|
0 0 0 0
|
||||||
|
0 0 0 0
|
||||||
|
0 0 0 0
|
||||||
|
0 0 0 0
|
||||||
|
|
||||||
|
5 0
|
||||||
|
|
||||||
|
4 4
|
||||||
|
1 0 0 0
|
||||||
|
0 1 0 0
|
||||||
|
0 0 1 0
|
||||||
|
0 0 0 1
|
||||||
19
matricies/test/matrice6.test
Normal file
19
matricies/test/matrice6.test
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
5 4
|
||||||
|
0 0 0 0
|
||||||
|
0 0 0 1
|
||||||
|
0 0 0 0
|
||||||
|
0 0 0 0
|
||||||
|
0 0 0 0
|
||||||
|
|
||||||
|
5 1
|
||||||
|
0
|
||||||
|
1
|
||||||
|
0
|
||||||
|
0
|
||||||
|
0
|
||||||
|
|
||||||
|
4 3
|
||||||
|
1 0 0
|
||||||
|
0 1 0
|
||||||
|
0 0 1
|
||||||
|
0 0 0
|
||||||
|
Before Width: | Height: | Size: 809 KiB After Width: | Height: | Size: 809 KiB |
175
src/Gauss.cpp
Normal file
175
src/Gauss.cpp
Normal file
@@ -0,0 +1,175 @@
|
|||||||
|
#include "Gauss.h"
|
||||||
|
|
||||||
|
#include "Matrix.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <execution>
|
||||||
|
#include <ranges>
|
||||||
|
|
||||||
|
namespace Gauss {
|
||||||
|
|
||||||
|
static void SwapLines(Matrix& mat, std::size_t line1, std::size_t line2) {
|
||||||
|
std::swap_ranges(
|
||||||
|
std::execution::par_unseq, mat.GetLineIterator(line1), mat.GetLineIterator(line1 + 1), mat.GetLineIterator(line2));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void DivideLine(Matrix& mat, std::size_t line, Matrix::Element number) {
|
||||||
|
std::transform(std::execution::par_unseq, mat.GetLineIterator(line), mat.GetLineIterator(line + 1), mat.GetLineIterator(line),
|
||||||
|
[number](Matrix::Element e) { return e /= number; });
|
||||||
|
|
||||||
|
/*for (std::size_t i = 0; i < mat.GetColumnCount(); i++) {
|
||||||
|
mat.at(line, i) /= number;
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
static int FirstNotNullElementIndexOnColumn(Matrix& mat, std::size_t column, std::size_t startLine = 0) {
|
||||||
|
for (std::size_t i = startLine; i < mat.GetRawCount(); i++) {
|
||||||
|
if (!IsEqualZero(mat.at(i, column))) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void SimplifyLine(Matrix& mat, std::size_t line, std::size_t pivot_line, std::size_t pivot_column) {
|
||||||
|
const Matrix::Element pivot = mat.at(pivot_line, pivot_column);
|
||||||
|
const Matrix::Element anul = mat.at(line, pivot_column);
|
||||||
|
|
||||||
|
auto range = std::views::iota(static_cast<std::size_t>(0), mat.GetColumnCount());
|
||||||
|
|
||||||
|
std::for_each(std::execution::par_unseq, range.begin(), range.end(), [&mat, pivot, anul, line, pivot_line](std::size_t j) {
|
||||||
|
mat.at(line, j) = mat.at(line, j) * pivot - mat.at(pivot_line, j) * anul;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GaussJordanReducedNorma(Matrix& a_Matrix) {
|
||||||
|
int indice_ligne_pivot = -1;
|
||||||
|
|
||||||
|
for (std::size_t j = 0; j < a_Matrix.GetColumnCount(); j++) {
|
||||||
|
|
||||||
|
int indice_ligne_pivot_trouve = FirstNotNullElementIndexOnColumn(a_Matrix, j, indice_ligne_pivot + 1);
|
||||||
|
|
||||||
|
if (indice_ligne_pivot_trouve < 0) // colonne de 0
|
||||||
|
continue; // on regarde la prochaine colonne
|
||||||
|
|
||||||
|
indice_ligne_pivot++;
|
||||||
|
|
||||||
|
if (indice_ligne_pivot_trouve != indice_ligne_pivot) {
|
||||||
|
SwapLines(a_Matrix, indice_ligne_pivot_trouve, indice_ligne_pivot);
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix::Element pivot = a_Matrix.at(indice_ligne_pivot, j);
|
||||||
|
|
||||||
|
DivideLine(a_Matrix, indice_ligne_pivot, pivot);
|
||||||
|
|
||||||
|
auto range = std::views::iota(static_cast<std::size_t>(0), a_Matrix.GetRawCount());
|
||||||
|
|
||||||
|
// On simplifie les autres lignes
|
||||||
|
std::for_each(std::execution::par_unseq, range.begin(), range.end(), [&a_Matrix, j, indice_ligne_pivot](std::size_t i) {
|
||||||
|
if (i != static_cast<std::size_t>(indice_ligne_pivot)) {
|
||||||
|
SimplifyLine(a_Matrix, i, indice_ligne_pivot, j);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GaussJordanReduced(Matrix& a_Matrix) {
|
||||||
|
int indice_ligne_pivot = -1;
|
||||||
|
|
||||||
|
for (std::size_t j = 0; j < a_Matrix.GetColumnCount(); j++) {
|
||||||
|
|
||||||
|
int indice_ligne_pivot_trouve = FirstNotNullElementIndexOnColumn(a_Matrix, j, indice_ligne_pivot + 1);
|
||||||
|
|
||||||
|
if (indice_ligne_pivot_trouve < 0) // colonne de 0
|
||||||
|
continue; // on regarde la prochaine colonne
|
||||||
|
|
||||||
|
indice_ligne_pivot++;
|
||||||
|
|
||||||
|
if (indice_ligne_pivot_trouve != indice_ligne_pivot) {
|
||||||
|
SwapLines(a_Matrix, indice_ligne_pivot_trouve, indice_ligne_pivot);
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix::Element pivot = a_Matrix.at(indice_ligne_pivot, j);
|
||||||
|
|
||||||
|
auto range = std::views::iota(static_cast<std::size_t>(0), a_Matrix.GetRawCount());
|
||||||
|
|
||||||
|
// On simplifie les autres lignes
|
||||||
|
std::for_each(std::execution::par_unseq, range.begin(), range.end(), [&a_Matrix, j, indice_ligne_pivot](std::size_t i) {
|
||||||
|
if (i != static_cast<std::size_t>(indice_ligne_pivot)) {
|
||||||
|
SimplifyLine(a_Matrix, i, indice_ligne_pivot, j);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GaussJordanTriangular(Matrix& a_Matrix) {
|
||||||
|
int indice_ligne_pivot = -1;
|
||||||
|
|
||||||
|
for (std::size_t j = 0; j < a_Matrix.GetColumnCount(); j++) {
|
||||||
|
|
||||||
|
int indice_ligne_pivot_trouve = FirstNotNullElementIndexOnColumn(a_Matrix, j, indice_ligne_pivot + 1);
|
||||||
|
|
||||||
|
if (indice_ligne_pivot_trouve < 0) // colonne de 0
|
||||||
|
continue; // on regarde la prochaine colonne
|
||||||
|
|
||||||
|
indice_ligne_pivot++;
|
||||||
|
|
||||||
|
if (indice_ligne_pivot_trouve != indice_ligne_pivot) {
|
||||||
|
SwapLines(a_Matrix, indice_ligne_pivot_trouve, indice_ligne_pivot);
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix::Element pivot = a_Matrix.at(indice_ligne_pivot, j);
|
||||||
|
|
||||||
|
auto range = std::views::iota(static_cast<std::size_t>(indice_ligne_pivot + 1), a_Matrix.GetRawCount());
|
||||||
|
|
||||||
|
// On simplifie les autres lignes après la ligne du pivot
|
||||||
|
std::for_each(std::execution::par_unseq, range.begin(), range.end(),
|
||||||
|
[&a_Matrix, indice_ligne_pivot, j](std::size_t i) { SimplifyLine(a_Matrix, i, indice_ligne_pivot, j); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void GaussJordanTriangularNorma(Matrix& a_Matrix) {
|
||||||
|
int indice_ligne_pivot = -1;
|
||||||
|
|
||||||
|
for (std::size_t j = 0; j < a_Matrix.GetColumnCount(); j++) {
|
||||||
|
|
||||||
|
int indice_ligne_pivot_trouve = FirstNotNullElementIndexOnColumn(a_Matrix, j, indice_ligne_pivot + 1);
|
||||||
|
|
||||||
|
if (indice_ligne_pivot_trouve < 0) // colonne de 0
|
||||||
|
continue; // on regarde la prochaine colonne
|
||||||
|
|
||||||
|
indice_ligne_pivot++;
|
||||||
|
|
||||||
|
if (indice_ligne_pivot_trouve != indice_ligne_pivot) {
|
||||||
|
SwapLines(a_Matrix, indice_ligne_pivot_trouve, indice_ligne_pivot);
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix::Element pivot = a_Matrix.at(indice_ligne_pivot, j);
|
||||||
|
|
||||||
|
DivideLine(a_Matrix, indice_ligne_pivot, pivot);
|
||||||
|
|
||||||
|
auto range = std::views::iota(static_cast<std::size_t>(indice_ligne_pivot + 1), a_Matrix.GetRawCount());
|
||||||
|
|
||||||
|
// On simplifie les autres lignes après la ligne du pivot
|
||||||
|
std::for_each(std::execution::par_unseq, range.begin(), range.end(),
|
||||||
|
[&a_Matrix, indice_ligne_pivot, j](std::size_t i) { SimplifyLine(a_Matrix, i, indice_ligne_pivot, j); });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GaussJordan(Matrix& a_Matrix, bool a_Reduite, bool a_Normalise) {
|
||||||
|
if (a_Reduite) {
|
||||||
|
if (a_Normalise) {
|
||||||
|
GaussJordanReducedNorma(a_Matrix);
|
||||||
|
} else {
|
||||||
|
GaussJordanReduced(a_Matrix);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (a_Normalise) {
|
||||||
|
GaussJordanTriangularNorma(a_Matrix);
|
||||||
|
} else {
|
||||||
|
GaussJordanTriangular(a_Matrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Gauss
|
||||||
101
src/IO.cpp
Normal file
101
src/IO.cpp
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
#include "IO.h"
|
||||||
|
|
||||||
|
#include "Vect.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& stream, const Matrix& mat) {
|
||||||
|
stream << mat.GetRawCount() << " " << mat.GetColumnCount() << "\n";
|
||||||
|
for (std::size_t i = 0; i < mat.GetRawCount(); i++) {
|
||||||
|
for (std::size_t j = 0; j < mat.GetColumnCount(); j++) {
|
||||||
|
stream << mat.at(i, j) << " ";
|
||||||
|
}
|
||||||
|
stream << "\n";
|
||||||
|
}
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::istream& operator>>(std::istream& stream, Matrix& mat) {
|
||||||
|
std::size_t raw, column;
|
||||||
|
stream >> raw >> column;
|
||||||
|
|
||||||
|
Matrix result {raw, column};
|
||||||
|
mat = result;
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < mat.GetRawCount(); i++) {
|
||||||
|
for (std::size_t j = 0; j < mat.GetColumnCount(); j++) {
|
||||||
|
stream >> mat.at(i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix LoadMatrix(const std::string& fileName) {
|
||||||
|
std::ifstream in {fileName};
|
||||||
|
if (!in) {
|
||||||
|
std::cerr << "Impossible de charger la matrice !\n";
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
Matrix result;
|
||||||
|
in >> result;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SaveMatrix(const Matrix& mat, const std::string& fileName) {
|
||||||
|
std::ofstream out {fileName};
|
||||||
|
if (!out) {
|
||||||
|
std::cerr << "Impossible de sauvegarder la matrice !\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
out << mat;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix InsertMatrix() {
|
||||||
|
std::cout << "Quelle est le nombre de lignes de votre matrice ?" << std::endl;
|
||||||
|
std::size_t lignes;
|
||||||
|
std::cin >> lignes;
|
||||||
|
std::cout << "Quelle est le nombre de colonnes de votre matrice ?" << std::endl;
|
||||||
|
std::size_t colonnes;
|
||||||
|
std::cin >> colonnes;
|
||||||
|
std::cout << "Rentrez les coefficients de la matrice" << std::endl;
|
||||||
|
Matrix result(lignes, colonnes);
|
||||||
|
for (size_t i = 0; i < result.GetRawCount(); ++i) {
|
||||||
|
for (size_t j = 0; j < result.GetColumnCount(); ++j) {
|
||||||
|
std::cin >> result.at(i, j);
|
||||||
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Print(const Matrix& mat) {
|
||||||
|
for (size_t i = 0; i < mat.GetRawCount(); ++i) {
|
||||||
|
std::cout << "[ ";
|
||||||
|
for (size_t j = 0; j < mat.GetColumnCount(); ++j) {
|
||||||
|
std::cout << mat.at(i, j) << " ";
|
||||||
|
}
|
||||||
|
std::cout << "]";
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Print(const Vect& vect) {
|
||||||
|
std::cout << "Espace vectoriel de dimension " << vect.GetCardinal() << " de base :\n\n";
|
||||||
|
for (std::size_t i = 0; i < vect.GetDimension(); i++) {
|
||||||
|
for (std::size_t j = 0; j < vect.GetCardinal(); j++) {
|
||||||
|
Matrix vector = vect.GetVector(j);
|
||||||
|
std::cout << "[ " << vector.at(i, 0) << " ]\t";
|
||||||
|
}
|
||||||
|
std::cout << "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Print(const VectAffine& vect) {
|
||||||
|
std::cout << "\tEspace Affine :\n\n";
|
||||||
|
Print(vect.GetBase());
|
||||||
|
std::cout << "\nOrigine :\n\n";
|
||||||
|
Print(vect.GetOrigin());
|
||||||
|
}
|
||||||
328
src/Matrix.cpp
328
src/Matrix.cpp
@@ -1,38 +1,32 @@
|
|||||||
#include "Matrix.h"
|
#include "Matrix.h"
|
||||||
|
|
||||||
|
#include "IO.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Matrix::Matrix(const std::string& fileNameInput) {
|
Matrix::Matrix(std::size_t a_Raws, std::size_t a_Columns) : m_Raws(a_Raws), m_Columns(a_Columns) {
|
||||||
Load(fileNameInput);
|
m_Data.resize(m_Raws * m_Columns);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix::Matrix(std::size_t lignes, std::size_t colonnes) : m_Lignes(lignes), m_Colonnes(colonnes) {
|
Matrix::Matrix(std::size_t a_Raws, std::size_t a_Columns, std::initializer_list<Element>&& a_Elements) :
|
||||||
m_Data.resize(m_Lignes * m_Colonnes);
|
m_Raws(a_Raws), m_Columns(a_Columns) {
|
||||||
}
|
m_Data = a_Elements;
|
||||||
Matrix::Matrix(std::size_t lignes, std::size_t colonnes, std::initializer_list<long double>&& initList) :
|
m_Data.resize(m_Raws * m_Columns);
|
||||||
m_Lignes(lignes), m_Colonnes(colonnes) {
|
|
||||||
m_Data = initList;
|
|
||||||
m_Data.resize(m_Lignes * m_Colonnes);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix::~Matrix() {}
|
Matrix Matrix::operator*(const Matrix& a_Other) const {
|
||||||
|
assert(m_Columns == a_Other.m_Raws);
|
||||||
|
|
||||||
Matrix Matrix::operator*(const Matrix& other) const {
|
Matrix result(m_Raws, a_Other.m_Columns);
|
||||||
if (m_Colonnes != other.m_Lignes) {
|
|
||||||
std::cerr << "Mutiplication impossible car la dimensions des matrices est incompatible" << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix result(m_Lignes, other.m_Colonnes);
|
for (std::size_t i = 0; i < m_Raws; ++i) {
|
||||||
|
for (std::size_t j = 0; j < a_Other.m_Columns; ++j) {
|
||||||
for (std::size_t i = 0; i < m_Lignes; ++i) {
|
Element sum = 0;
|
||||||
for (std::size_t j = 0; j < other.m_Colonnes; ++j) {
|
for (std::size_t k = 0; k < m_Columns; k++) {
|
||||||
long double sum = 0;
|
sum += at(i, k) * a_Other.at(k, j);
|
||||||
for (std::size_t k = 0; k < m_Colonnes; k++) {
|
|
||||||
sum += at(i, k) * other.at(k, j);
|
|
||||||
}
|
}
|
||||||
result.at(i, j) = sum;
|
result.at(i, j) = sum;
|
||||||
}
|
}
|
||||||
@@ -40,128 +34,118 @@ Matrix Matrix::operator*(const Matrix& other) const {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::Print() const {
|
|
||||||
for (size_t i = 0; i < m_Lignes; ++i) {
|
|
||||||
std::cout << "[ ";
|
|
||||||
for (size_t j = 0; j < m_Colonnes; ++j) {
|
|
||||||
std::size_t indice = i * m_Lignes + j;
|
|
||||||
std::cout << at(i, j) << " ";
|
|
||||||
}
|
|
||||||
std::cout << "]";
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Matrix::PrintDebug() {
|
|
||||||
#ifndef NDEBUG
|
|
||||||
Print();
|
|
||||||
std::cout << "\n";
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void Matrix::Insert() {
|
|
||||||
for (size_t i = 0; i < m_Lignes; ++i) {
|
|
||||||
for (size_t j = 0; j < m_Colonnes; ++j) {
|
|
||||||
std::cin >> at(i, j);
|
|
||||||
}
|
|
||||||
std::cout << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Matrix::Save(const std::string& fileName) {
|
|
||||||
std::ofstream out{fileName};
|
|
||||||
if (!out) {
|
|
||||||
std::cerr << "Impossible de sauvegarder la matrice !\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
out << m_Lignes << " " << m_Colonnes << "\n";
|
|
||||||
for (std::size_t i = 0; i < m_Lignes; i++) {
|
|
||||||
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
|
||||||
out << at(i, j) << " ";
|
|
||||||
}
|
|
||||||
out << "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Matrix::Load(const std::string& filename) {
|
|
||||||
std::ifstream in{filename};
|
|
||||||
if (!in) {
|
|
||||||
std::cerr << "Impossible de charger la matrice !\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
in >> m_Lignes >> m_Colonnes;
|
|
||||||
m_Data.resize(m_Lignes * m_Colonnes);
|
|
||||||
for (std::size_t i = 0; i < m_Lignes; i++) {
|
|
||||||
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
|
||||||
in >> at(i, j);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Matrix::Transpose() {
|
void Matrix::Transpose() {
|
||||||
Matrix result{m_Colonnes, m_Lignes};
|
Matrix result {m_Columns, m_Raws};
|
||||||
for (std::size_t i = 0; i < m_Lignes; i++) {
|
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||||
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||||
result.at(j, i) = at(i, j);
|
result.at(j, i) = at(i, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*this = result;
|
*this = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::Identity() {
|
Matrix Matrix::Identity(std::size_t a_Size) {
|
||||||
assert(m_Lignes == m_Colonnes);
|
Matrix id {a_Size, a_Size};
|
||||||
for (std::size_t i = 0; i < m_Lignes; i++) {
|
for (std::size_t i = 0; i < a_Size; i++) {
|
||||||
for (std::size_t j = i; j < m_Colonnes; j++) {
|
for (std::size_t j = i; j < a_Size; j++) {
|
||||||
at(i, j) = i == j;
|
id.at(i, j) = (i == j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Matrix Matrix::Identity(std::size_t taille) {
|
|
||||||
Matrix id{taille, taille};
|
|
||||||
id.Identity();
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matrix::IsInversed() const {
|
Matrix Matrix::ColumnVector(std::initializer_list<Element>&& a_Elements) {
|
||||||
for (std::size_t i = 0; i < m_Lignes; ++i) {
|
Matrix result {a_Elements.size(), 1};
|
||||||
std::size_t j;
|
|
||||||
for (j = 0; j < m_Colonnes; ++j) {
|
result.m_Data = a_Elements;
|
||||||
if (!IsEqualZero(at(i, j))) {
|
|
||||||
break;
|
return result;
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::Augmenter(const Matrix& droite) {
|
Matrix Matrix::RawVector(std::initializer_list<Element>&& a_Elements) {
|
||||||
assert(droite.m_Lignes == m_Lignes);
|
Matrix result {1, a_Elements.size()};
|
||||||
Matrix temp{m_Lignes, m_Colonnes + droite.m_Colonnes};
|
|
||||||
|
|
||||||
for (std::size_t i = 0; i < m_Lignes; i++) {
|
result.m_Data = a_Elements;
|
||||||
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Matrix::Fill(Element a_Element) {
|
||||||
|
std::fill(GetLineIterator(0), GetLineIterator(m_Raws), a_Element);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Matrix::Augment(const Matrix& a_Right) {
|
||||||
|
assert(a_Right.m_Raws == m_Raws);
|
||||||
|
Matrix temp {m_Raws, m_Columns + a_Right.m_Columns};
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||||
|
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||||
temp.at(i, j) = at(i, j);
|
temp.at(i, j) = at(i, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (std::size_t i = 0; i < m_Lignes; i++) {
|
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||||
for (std::size_t j = 0; j < droite.m_Colonnes; j++) {
|
for (std::size_t j = 0; j < a_Right.m_Columns; j++) {
|
||||||
temp.at(i, j + m_Colonnes) = droite.at(i, j);
|
temp.at(i, j + m_Columns) = a_Right.at(i, j);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*this = temp;
|
*this = temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Matrix::operator==(const Matrix& other) const {
|
void Matrix::AugmentBottom(const Matrix& a_Bottom) {
|
||||||
if (m_Lignes != other.m_Lignes || m_Colonnes != other.m_Colonnes)
|
assert(a_Bottom.m_Columns == m_Columns);
|
||||||
return false;
|
Matrix temp {m_Raws + a_Bottom.GetRawCount(), m_Columns};
|
||||||
|
|
||||||
for (std::size_t i = 0; i < m_Lignes; i++) {
|
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||||
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||||
if (!IsEqualZero(at(i, j) - other.at(i, j)))
|
temp.at(i, j) = at(i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < a_Bottom.GetRawCount(); i++) {
|
||||||
|
for (std::size_t j = 0; j < GetColumnCount(); j++) {
|
||||||
|
temp.at(i + GetRawCount(), j) = a_Bottom.at(i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*this = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix Matrix::operator+(const Matrix& a_Other) const {
|
||||||
|
assert(GetColumnCount() == a_Other.GetColumnCount() && GetRawCount() == a_Other.GetRawCount());
|
||||||
|
|
||||||
|
Matrix result = *this;
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < GetRawCount(); i++) {
|
||||||
|
for (std::size_t j = 0; j < GetColumnCount(); j++) {
|
||||||
|
result.at(i, j) += a_Other.at(i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix Matrix::operator-(const Matrix& a_Other) const {
|
||||||
|
assert(GetColumnCount() == a_Other.GetColumnCount() && GetRawCount() == a_Other.GetRawCount());
|
||||||
|
|
||||||
|
Matrix result = *this;
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < GetRawCount(); i++) {
|
||||||
|
for (std::size_t j = 0; j < GetColumnCount(); j++) {
|
||||||
|
result.at(i, j) -= a_Other.at(i, j);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Matrix::operator==(const Matrix& a_Other) const {
|
||||||
|
assert(m_Raws == a_Other.m_Raws && m_Columns == a_Other.m_Columns);
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||||
|
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||||
|
if (!IsEqualZero(at(i, j) - a_Other.at(i, j)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,101 +153,47 @@ bool Matrix::operator==(const Matrix& other) const {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::GaussNonJordan(bool reduite) {
|
Matrix::Element& Matrix::at(std::size_t a_Raw, std::size_t a_Column) {
|
||||||
int r = -1;
|
assert(a_Raw < m_Raws && a_Column < m_Columns);
|
||||||
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
return m_Data[a_Raw * m_Columns + a_Column];
|
||||||
std::size_t indice_ligne_maximum = r + 1;
|
|
||||||
|
|
||||||
// Recherche maximum
|
|
||||||
for (std::size_t i = r + 1; i < m_Lignes; i++) {
|
|
||||||
if (std::abs(at(i, j)) > std::abs(at(indice_ligne_maximum, j)))
|
|
||||||
indice_ligne_maximum = i;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::cout << "l'indice du maximum est : " << indice_ligne_maximum << "\n\n";
|
Matrix::Element Matrix::at(std::size_t a_Raw, std::size_t a_Column) const {
|
||||||
|
assert(a_Raw < m_Raws && a_Column < m_Columns);
|
||||||
// Si A[k,j]≠0 alors (A[k,j] désigne la valeur de la ligne k et de la colonne j)
|
return m_Data[a_Raw * m_Columns + a_Column];
|
||||||
if (!IsEqualZero(at(indice_ligne_maximum, j))) {
|
|
||||||
r++;
|
|
||||||
|
|
||||||
// PrintDebug();
|
|
||||||
|
|
||||||
// Si k≠r alors
|
|
||||||
if (indice_ligne_maximum != r) {
|
|
||||||
// Échanger les lignes k et r (On place la ligne du pivot en position r)
|
|
||||||
// std::cout << "On échange les lignes " << indice_ligne_maximum << " et " << r << '\n';
|
|
||||||
for (std::size_t k = 0; k < m_Colonnes; k++) {
|
|
||||||
std::swap(at(indice_ligne_maximum, k), at(r, k));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pour i de 1 jusqu'à n (On simplifie les autres lignes)
|
|
||||||
for (std::size_t i = (reduite ? 0 : j); i < m_Lignes; i++) {
|
|
||||||
// Si i≠r alors
|
|
||||||
if (i != r) {
|
|
||||||
// Soustraire à la ligne i la ligne r multipliée par A[i,j] (de façon à
|
|
||||||
// annuler A[i,j])
|
|
||||||
for (int k = m_Colonnes - 1; k >= 0; k--) {
|
|
||||||
long double pivot = at(r, j);
|
|
||||||
long double anul = at(i, j);
|
|
||||||
at(i, k) = at(i, k) * pivot - at(r, k) * anul;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Matrix::GaussJordan(bool reduite) {
|
|
||||||
GaussNonJordan(reduite);
|
|
||||||
for (std::size_t i = 0; i < m_Lignes; i++) {
|
|
||||||
int k = -1;
|
|
||||||
for (std::size_t j = 0; j < m_Colonnes; j++) {
|
|
||||||
if (!IsEqualZero(at(i, j))) {
|
|
||||||
k = j;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ligne de 0
|
|
||||||
if (k == -1)
|
|
||||||
break;
|
|
||||||
// on divise la ligne par (i, k)
|
|
||||||
long double annul = at(i, k);
|
|
||||||
for (int j = 0; j < m_Colonnes; j++) {
|
|
||||||
at(i, j) /= annul;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long double& Matrix::operator[](std::size_t indice) {
|
|
||||||
return m_Data[indice];
|
|
||||||
}
|
|
||||||
|
|
||||||
long double& Matrix::at(std::size_t ligne, std::size_t colonne) {
|
|
||||||
return m_Data[ligne * m_Colonnes + colonne];
|
|
||||||
}
|
|
||||||
|
|
||||||
long double Matrix::at(std::size_t ligne, std::size_t colonne) const {
|
|
||||||
return m_Data[ligne * m_Colonnes + colonne];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t Matrix::GetRawCount() const {
|
std::size_t Matrix::GetRawCount() const {
|
||||||
return m_Lignes;
|
return m_Raws;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t Matrix::GetColumnCount() const {
|
std::size_t Matrix::GetColumnCount() const {
|
||||||
return m_Colonnes;
|
return m_Columns;
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix Matrix::SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const {
|
Matrix Matrix::SubMatrix(
|
||||||
assert(m_Lignes >= ligne && m_Colonnes >= colonne);
|
std::size_t a_RawOrigin, std::size_t a_ColumnOrigin, std::size_t a_RawCount, std::size_t a_ColumnCount) const {
|
||||||
Matrix result{ligne, colonne};
|
assert(m_Raws >= a_RawOrigin + a_RawCount && m_Columns >= a_ColumnOrigin + a_ColumnCount);
|
||||||
|
|
||||||
for (std::size_t i = 0; i < ligne; i++) {
|
Matrix result {a_RawCount, a_ColumnCount};
|
||||||
for (std::size_t j = 0; j < colonne; j++) {
|
|
||||||
result.at(i, j) = at(i + origine_ligne, j + origine_colonne);
|
for (std::size_t i = 0; i < result.GetRawCount(); i++) {
|
||||||
|
for (std::size_t j = 0; j < result.GetColumnCount(); j++) {
|
||||||
|
result.at(i, j) = at(i + a_RawOrigin, j + a_ColumnOrigin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Matrix::iterator Matrix::begin() {
|
||||||
|
return m_Data.begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix::iterator Matrix::end() {
|
||||||
|
return m_Data.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix::iterator Matrix::GetLineIterator(std::size_t a_Raw) {
|
||||||
|
return m_Data.begin() + a_Raw * GetColumnCount();
|
||||||
|
}
|
||||||
63
src/Matrix.h
63
src/Matrix.h
@@ -1,63 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <cmath>
|
|
||||||
#include <cstddef>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
class Matrix {
|
|
||||||
private:
|
|
||||||
std::size_t m_Lignes;
|
|
||||||
std::size_t m_Colonnes;
|
|
||||||
std::vector<long double> m_Data;
|
|
||||||
|
|
||||||
public:
|
|
||||||
Matrix(const std::string& fileNameInput);
|
|
||||||
Matrix(std::size_t lignes, std::size_t colonnes);
|
|
||||||
Matrix(std::size_t lignes, std::size_t colonnes, std::initializer_list<long double>&& initList);
|
|
||||||
~Matrix();
|
|
||||||
|
|
||||||
std::size_t GetRawCount() const;
|
|
||||||
std::size_t GetColumnCount() const;
|
|
||||||
|
|
||||||
Matrix operator*(const Matrix& other) const;
|
|
||||||
|
|
||||||
void GaussNonJordan(bool reduite);
|
|
||||||
|
|
||||||
void GaussJordan(bool reduite);
|
|
||||||
|
|
||||||
void Print() const;
|
|
||||||
|
|
||||||
void PrintDebug();
|
|
||||||
|
|
||||||
void Insert();
|
|
||||||
|
|
||||||
void Save(const std::string& fileName);
|
|
||||||
|
|
||||||
void Load(const std::string& filename);
|
|
||||||
|
|
||||||
void Transpose();
|
|
||||||
|
|
||||||
void Identity();
|
|
||||||
|
|
||||||
static Matrix Identity(std::size_t taille);
|
|
||||||
|
|
||||||
bool IsInversed() const;
|
|
||||||
|
|
||||||
void Augmenter(const Matrix& droite);
|
|
||||||
|
|
||||||
Matrix SubMatrix(std::size_t origine_ligne, std::size_t origine_colonne, std::size_t ligne, std::size_t colonne) const;
|
|
||||||
|
|
||||||
bool operator==(const Matrix& other) const;
|
|
||||||
|
|
||||||
long double& operator[](std::size_t indice);
|
|
||||||
|
|
||||||
long double& at(std::size_t ligne, std::size_t colonne);
|
|
||||||
|
|
||||||
long double at(std::size_t ligne, std::size_t colonne) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
bool IsEqualZero(T var) {
|
|
||||||
return std::abs(var) < std::pow(10, -5);
|
|
||||||
}
|
|
||||||
145
src/NR.cpp
Normal file
145
src/NR.cpp
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
#include "NR.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
NR::Int PGCD(NR::Int x, NR::Int y) {
|
||||||
|
if (x == 0 || y == 0)
|
||||||
|
return 1;
|
||||||
|
else if (x % y == 0)
|
||||||
|
return std::abs(y);
|
||||||
|
else
|
||||||
|
return PGCD(y, x % y);
|
||||||
|
}
|
||||||
|
|
||||||
|
NR::NR() : m_Numerator(0), m_Denominator(1) {}
|
||||||
|
|
||||||
|
NR::NR(NR::Int entier) : m_Numerator(entier), m_Denominator(1) {}
|
||||||
|
|
||||||
|
NR::NR(NR::Int numerator, NR::Int denominator) :
|
||||||
|
m_Numerator((denominator > 0) ? numerator : -numerator), m_Denominator(std::abs(denominator)) {
|
||||||
|
Reduce();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NR::Reduce() {
|
||||||
|
NR::Int divisor = PGCD(m_Denominator, m_Numerator);
|
||||||
|
m_Denominator /= divisor;
|
||||||
|
m_Numerator /= divisor;
|
||||||
|
assert(m_Denominator != 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
NR NR::Inverse() const {
|
||||||
|
assert(*this != 0);
|
||||||
|
return {m_Denominator, m_Numerator};
|
||||||
|
}
|
||||||
|
|
||||||
|
NR::Int NR::GetNumerator() const {
|
||||||
|
return m_Numerator;
|
||||||
|
}
|
||||||
|
|
||||||
|
NR::Int NR::GetDenominator() const {
|
||||||
|
return m_Denominator;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NR::operator==(const NR& opNR) const {
|
||||||
|
return (m_Numerator * opNR.GetDenominator() == m_Denominator * opNR.GetNumerator());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NR::operator<(const NR& opNR) const {
|
||||||
|
return (m_Numerator * opNR.GetDenominator() < m_Denominator * opNR.GetNumerator());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NR::operator>(const NR& opNR) const {
|
||||||
|
return (m_Numerator * opNR.GetDenominator() > m_Denominator * opNR.GetNumerator());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NR::operator!=(const NR& opNR) const {
|
||||||
|
return !(*this == opNR);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NR::operator<=(const NR& opNR) const {
|
||||||
|
return !(*this > opNR);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool NR::operator>=(const NR& opNR) const {
|
||||||
|
return !(*this < opNR);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator<<(std::ostream& os, const NR& opNR) {
|
||||||
|
os << opNR.GetNumerator();
|
||||||
|
if (opNR.GetDenominator() != 1)
|
||||||
|
os << "/" << opNR.GetDenominator();
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::istream& operator>>(std::istream& is, NR& opNR) {
|
||||||
|
char slash;
|
||||||
|
is >> opNR.m_Numerator >> slash;
|
||||||
|
if (slash != '/') {
|
||||||
|
// on revient un charactère en arrière
|
||||||
|
is.seekg(is.tellg() - static_cast<std::streampos>(1));
|
||||||
|
opNR.m_Denominator = 1;
|
||||||
|
} else {
|
||||||
|
is >> opNR.m_Denominator;
|
||||||
|
}
|
||||||
|
opNR.Reduce();
|
||||||
|
return is;
|
||||||
|
}
|
||||||
|
|
||||||
|
NR NR::operator+(const NR& opNR) const {
|
||||||
|
Int num, den;
|
||||||
|
num = m_Numerator * opNR.GetDenominator();
|
||||||
|
den = m_Denominator * opNR.GetDenominator();
|
||||||
|
num += (opNR.GetNumerator() * m_Denominator);
|
||||||
|
NR result(num, num == 0 ? 1 : den);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
NR NR::operator-(const NR& opNR) const {
|
||||||
|
Int num, den;
|
||||||
|
num = m_Numerator * opNR.GetDenominator();
|
||||||
|
den = m_Denominator * opNR.GetDenominator();
|
||||||
|
num -= (opNR.GetNumerator() * m_Denominator);
|
||||||
|
NR result(num, num == 0 ? 1 : den);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
NR NR::operator*(const NR& opNR) const {
|
||||||
|
Int num, den;
|
||||||
|
num = m_Numerator * opNR.GetNumerator();
|
||||||
|
den = m_Denominator * opNR.GetDenominator();
|
||||||
|
NR result(num, num == 0 ? 1 : den);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
NR NR::operator/(const NR& opNR) const {
|
||||||
|
Int num, den;
|
||||||
|
num = m_Numerator * opNR.GetDenominator();
|
||||||
|
den = m_Denominator * opNR.GetNumerator();
|
||||||
|
NR result(num, num == 0 ? 1 : den);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
NR& NR::operator+=(const NR& opNR) {
|
||||||
|
*this = *this + opNR;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
NR& NR::operator-=(const NR& opNR) {
|
||||||
|
*this = *this - opNR;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
NR& NR::operator*=(const NR& opNR) {
|
||||||
|
*this = *this * opNR;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
NR& NR::operator/=(const NR& opNR) {
|
||||||
|
*this = *this / opNR;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
NR NR::operator-() const {
|
||||||
|
return {-m_Numerator, m_Denominator};
|
||||||
|
}
|
||||||
12
src/NR.h
12
src/NR.h
@@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
class NR {
|
|
||||||
private:
|
|
||||||
int m_Numerator;
|
|
||||||
int m_Denominator;
|
|
||||||
|
|
||||||
public:
|
|
||||||
NR() : m_Numerator(0), m_Denominator(1) {}
|
|
||||||
NR(int entier) : m_Numerator(entier), m_Denominator(1) {}
|
|
||||||
NR(int numerator, int denominator) : m_Numerator(numerator), m_Denominator(denominator) {}
|
|
||||||
};
|
|
||||||
@@ -1,31 +1,70 @@
|
|||||||
#include "Solver.h"
|
#include "Solver.h"
|
||||||
|
|
||||||
Solver::Solver(const Matrix& mat) : m_Matrix(mat) {}
|
#include "Gauss.h"
|
||||||
|
|
||||||
Vect Solver::Image() const {
|
static int FirstNotNullElementIndexOnLine(const Matrix& mat, std::size_t line) {
|
||||||
Matrix result = m_Matrix;
|
for (std::size_t i = 0; i < mat.GetColumnCount(); i++) {
|
||||||
result.Transpose();
|
if (!IsEqualZero(mat.at(line, i))) {
|
||||||
result.GaussJordan(true);
|
return i;
|
||||||
result.Transpose();
|
}
|
||||||
return {result};
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vect Solver::Image(Matrix&& a_Matrix) const {
|
||||||
|
a_Matrix.Transpose();
|
||||||
|
Gauss::GaussJordan(a_Matrix, false, false);
|
||||||
|
a_Matrix.Transpose();
|
||||||
|
return {std::move(a_Matrix)};
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://en.wikipedia.org/wiki/Kernel_(linear_algebra)#Computation_by_Gaussian_elimination
|
// https://en.wikipedia.org/wiki/Kernel_(linear_algebra)#Computation_by_Gaussian_elimination
|
||||||
Vect Solver::Noyau() const {
|
Vect Solver::Kernel(Matrix&& a_Matrix) const {
|
||||||
Matrix result = m_Matrix;
|
std::size_t matrixRawCount = a_Matrix.GetRawCount();
|
||||||
result.Transpose();
|
std::size_t matrixColumnCount = a_Matrix.GetColumnCount();
|
||||||
result.Augmenter(Matrix::Identity(result.GetRawCount()));
|
|
||||||
result.GaussJordan(true);
|
a_Matrix.Transpose();
|
||||||
result.Transpose();
|
a_Matrix.Augment(Matrix::Identity(a_Matrix.GetRawCount()));
|
||||||
|
Gauss::GaussJordan(a_Matrix, false, true);
|
||||||
|
a_Matrix.Transpose();
|
||||||
|
|
||||||
// nombre de colonnes non nulles
|
// nombre de colonnes non nulles
|
||||||
std::size_t origine_colonne = Vect(result.SubMatrix(0, 0, m_Matrix.GetRawCount(), m_Matrix.GetColumnCount())).GetDimension();
|
std::size_t origine_colonne = Vect(a_Matrix.SubMatrix(0, 0, matrixRawCount, matrixColumnCount)).GetCardinal();
|
||||||
|
|
||||||
return {result.SubMatrix(m_Matrix.GetRawCount(), origine_colonne, result.GetRawCount() - m_Matrix.GetRawCount(),
|
return {a_Matrix.SubMatrix(
|
||||||
result.GetColumnCount() - origine_colonne)};
|
matrixRawCount, origine_colonne, a_Matrix.GetRawCount() - matrixRawCount, a_Matrix.GetColumnCount() - origine_colonne)};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t Solver::Rang() const {
|
VectAffine Solver::RectangularSystem(Matrix&& a_MatrixA, const Matrix& a_VectorB) const {
|
||||||
Vect image = Image();
|
Matrix mat = a_MatrixA;
|
||||||
return image.GetDimension();
|
mat.Augment(a_VectorB);
|
||||||
|
Gauss::GaussJordan(mat, true, true);
|
||||||
|
|
||||||
|
Solver solver;
|
||||||
|
|
||||||
|
Vect noyau = solver.Kernel(std::move(a_MatrixA));
|
||||||
|
Matrix origin = mat.SubMatrix(0, mat.GetColumnCount() - 1, mat.GetRawCount(), 1);
|
||||||
|
|
||||||
|
// on calcule le vecteur qui dirige l'espace affine
|
||||||
|
Matrix fullOrigin {mat.GetColumnCount() - 1, 1};
|
||||||
|
for (std::size_t i = 0; i < mat.GetRawCount(); i++) {
|
||||||
|
int pivot_index = FirstNotNullElementIndexOnLine(mat, i);
|
||||||
|
|
||||||
|
if (static_cast<std::size_t>(pivot_index) == mat.GetColumnCount() - 1) {
|
||||||
|
// on a une ligne du type 0 = n. Aucune solution !
|
||||||
|
return {Matrix {}, Matrix::ColumnVector({0})};
|
||||||
|
}
|
||||||
|
|
||||||
|
// ligne entière de 0
|
||||||
|
if (pivot_index < 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
fullOrigin.at(pivot_index, 0) = origin.at(i, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {noyau, fullOrigin};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t Solver::Rank(Matrix&& a_Matrix) const {
|
||||||
|
return Image(std::move(a_Matrix)).GetCardinal();
|
||||||
}
|
}
|
||||||
|
|||||||
16
src/Solver.h
16
src/Solver.h
@@ -1,16 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Vect.h"
|
|
||||||
|
|
||||||
class Solver {
|
|
||||||
private:
|
|
||||||
Matrix m_Matrix;
|
|
||||||
public:
|
|
||||||
Solver(const Matrix& mat);
|
|
||||||
~Solver() {}
|
|
||||||
|
|
||||||
Vect Image() const;
|
|
||||||
Vect Noyau() const;
|
|
||||||
|
|
||||||
std::size_t Rang() const;
|
|
||||||
};
|
|
||||||
96
src/Vect.cpp
96
src/Vect.cpp
@@ -1,21 +1,28 @@
|
|||||||
#include "Vect.h"
|
#include "Vect.h"
|
||||||
|
|
||||||
|
#include "Gauss.h"
|
||||||
#include "Solver.h"
|
#include "Solver.h"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
Vect::Vect(const Matrix& mat) : m_Data(mat) {
|
static bool IsColumnNull(Matrix& mat, std::size_t column) {
|
||||||
|
for (std::size_t i = 0; i < mat.GetRawCount(); i++) {
|
||||||
|
if (!IsEqualZero(mat.at(i, column))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vect::Vect(Matrix&& a_Matrix) : m_Data(std::move(a_Matrix)) {
|
||||||
|
m_Data.Transpose();
|
||||||
|
Gauss::GaussJordan(m_Data, false, true);
|
||||||
|
m_Data.Transpose();
|
||||||
Simplify();
|
Simplify();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Vect::Simplify() {
|
void Vect::Simplify() {
|
||||||
Matrix mat = m_Data;
|
Matrix mat = m_Data;
|
||||||
for (std::size_t j = 0; j < mat.GetColumnCount(); j++) {
|
for (std::size_t j = 0; j < mat.GetColumnCount(); j++) {
|
||||||
std::size_t i;
|
if (IsColumnNull(mat, j)) {
|
||||||
for (i = 0; i < mat.GetRawCount(); i++) {
|
|
||||||
if (!IsEqualZero(mat.at(i, j)))
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (i == mat.GetRawCount()) {
|
|
||||||
m_Data = mat.SubMatrix(0, 0, mat.GetRawCount(), j);
|
m_Data = mat.SubMatrix(0, 0, mat.GetRawCount(), j);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -23,26 +30,69 @@ void Vect::Simplify() {
|
|||||||
m_Data = mat;
|
m_Data = mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Matrix Vect::GetVector(std::size_t a_Index) const {
|
||||||
|
return m_Data.SubMatrix(0, a_Index, m_Data.GetRawCount(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t Vect::GetCardinal() const {
|
||||||
|
return m_Data.GetColumnCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vect::IsElementOf(const Matrix& a_Vector) const {
|
||||||
|
Vect base = *this;
|
||||||
|
base.AddVector(a_Vector);
|
||||||
|
return base.GetCardinal() == GetCardinal();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vect::operator==(const Vect& a_Other) const {
|
||||||
|
if (GetDimension() != a_Other.GetDimension() || GetCardinal() != a_Other.GetCardinal())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// on vérifie si chaque vecteur de la deuxième base appartient à l'espace vectoriel engendré par la première base
|
||||||
|
for (std::size_t i = 0; i < GetCardinal(); i++) {
|
||||||
|
if (!IsElementOf(a_Other.GetVector(i)))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Vect::AddVector(const Matrix& a_Vector) {
|
||||||
|
m_Data.Augment(a_Vector);
|
||||||
|
m_Data.Transpose();
|
||||||
|
Gauss::GaussJordan(m_Data, false, false);
|
||||||
|
m_Data.Transpose();
|
||||||
|
Simplify();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Vect::operator!=(const Vect& a_Other) const {
|
||||||
|
return !(*this == a_Other);
|
||||||
|
}
|
||||||
|
|
||||||
Matrix Vect::GetLinearSystem() const {
|
Matrix Vect::GetLinearSystem() const {
|
||||||
Matrix vect = m_Data;
|
Matrix vect = m_Data;
|
||||||
vect.Transpose();
|
vect.Transpose();
|
||||||
|
|
||||||
Solver solver {vect};
|
Solver solver;
|
||||||
vect = solver.Noyau().m_Data;
|
Matrix result = solver.Kernel(std::move(vect)).m_Data;
|
||||||
vect.Transpose();
|
result.Transpose();
|
||||||
return vect;
|
return result;
|
||||||
}
|
|
||||||
|
|
||||||
void Vect::Print() const {
|
|
||||||
std::cout << "Espace vectoriel de dimension " << GetDimension() << " de base :\n\n";
|
|
||||||
for (std::size_t i = 0; i < m_Data.GetRawCount(); i++) {
|
|
||||||
for (std::size_t j = 0; j < m_Data.GetColumnCount(); j++) {
|
|
||||||
printf("[ %.3f ]\t", static_cast<float>(m_Data.at(i, j)));
|
|
||||||
}
|
|
||||||
std::cout << "\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t Vect::GetDimension() const {
|
std::size_t Vect::GetDimension() const {
|
||||||
return m_Data.GetColumnCount();
|
return m_Data.GetRawCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
VectAffine::VectAffine(const Vect& a_Base, const Matrix& a_Origin) :
|
||||||
|
m_Base(a_Base), m_Origin(a_Origin.SubMatrix(0, 0, m_Base.GetDimension(), 1)) {}
|
||||||
|
|
||||||
|
bool VectAffine::IsElementOf(const Matrix& a_Vector) const {
|
||||||
|
return m_Base.IsElementOf(a_Vector - m_Origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
Matrix VectAffine::GetLinearSystem() const {
|
||||||
|
Matrix result = m_Base.GetLinearSystem();
|
||||||
|
|
||||||
|
result.Augment(m_Origin.SubMatrix(0, 0, result.GetRawCount(), 1));
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
29
src/Vect.h
29
src/Vect.h
@@ -1,29 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include "Matrix.h"
|
|
||||||
|
|
||||||
// espace vectoriel
|
|
||||||
class Vect {
|
|
||||||
private:
|
|
||||||
Matrix m_Data;
|
|
||||||
|
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* \brief Construit une base d'un espace vectoriel à partir des colonnes d'une matrice.
|
|
||||||
* Ne prend pas en compte les colonnes de 0
|
|
||||||
* \param mat Une matrice échelonnée.
|
|
||||||
*/
|
|
||||||
Vect(const Matrix& mat);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \brief Affiche la base de l'espace vectoriel dans la console
|
|
||||||
*/
|
|
||||||
void Print() const;
|
|
||||||
|
|
||||||
std::size_t GetDimension() const;
|
|
||||||
|
|
||||||
Matrix GetLinearSystem() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
void Simplify();
|
|
||||||
};
|
|
||||||
166
src/gui/PivotGui.cpp
Normal file
166
src/gui/PivotGui.cpp
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
#include "PivotGui.h"
|
||||||
|
|
||||||
|
#include "Matrix.h"
|
||||||
|
#include "Solver.h"
|
||||||
|
#include <imgui.h>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
static std::string equationsResultImage;
|
||||||
|
|
||||||
|
static Matrix LoadMatrixFromStdVect(const std::vector<std::vector<int>>& data) {
|
||||||
|
Matrix result {data.size(), data.empty() ? 0 : data[0].size()};
|
||||||
|
for (std::size_t i = 0; i < result.GetRawCount(); i++) {
|
||||||
|
for (std::size_t j = 0; j < result.GetColumnCount(); j++) {
|
||||||
|
result.at(i, j) = static_cast<Matrix::Element>(data[i][j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string ElementToString(Matrix::Element e) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << e;
|
||||||
|
return ss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
static std::string PrintVect(const Vect& vect) {
|
||||||
|
if (vect.GetCardinal() == 0)
|
||||||
|
return "{0}";
|
||||||
|
|
||||||
|
std::string result = "Vect( ";
|
||||||
|
for (std::size_t i = 0; i < vect.GetCardinal(); i++) {
|
||||||
|
Matrix vector = vect.GetVector(i);
|
||||||
|
result += " (";
|
||||||
|
for (std::size_t j = 0; j < vect.GetDimension(); j++) {
|
||||||
|
result += ElementToString(vector.at(j, 0)) + ", ";
|
||||||
|
}
|
||||||
|
result = result.substr(0, result.size() - 2);
|
||||||
|
result += " ), ";
|
||||||
|
}
|
||||||
|
result = result.substr(0, result.size() - 2);
|
||||||
|
result += " )";
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PivotGui::Init() {}
|
||||||
|
|
||||||
|
void PivotGui::Render() {
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
|
||||||
|
static std::vector<std::vector<int>> matrixValues;
|
||||||
|
static int matrixSizeX = 4;
|
||||||
|
static int matrixSizeY = 4;
|
||||||
|
static Solver solver;
|
||||||
|
|
||||||
|
static bool refresh = true;
|
||||||
|
|
||||||
|
// divisions des fenetres
|
||||||
|
ImVec2 topLeftWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.8f);
|
||||||
|
ImVec2 topRightWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.8f);
|
||||||
|
ImVec2 bottomWindowSize(io.DisplaySize.x, io.DisplaySize.y * 0.2f);
|
||||||
|
|
||||||
|
// Begin fenetre top left
|
||||||
|
ImGui::SetNextWindowSize(topLeftWindowSize);
|
||||||
|
ImGui::SetNextWindowPos(ImVec2(0, 0)); // Position at the top-left corner
|
||||||
|
ImGui::Begin("Left Top Window", nullptr,
|
||||||
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
||||||
|
|
||||||
|
// Get window position
|
||||||
|
ImVec2 windowPos = ImGui::GetWindowPos();
|
||||||
|
|
||||||
|
ImGui::Text("Matrice initiale:");
|
||||||
|
|
||||||
|
if (ImGui::InputInt("##RowsMatriceInitiale", &matrixSizeY))
|
||||||
|
refresh = true;
|
||||||
|
matrixSizeY = std::max(1, matrixSizeY);
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text("Lignes");
|
||||||
|
|
||||||
|
|
||||||
|
if (ImGui::InputInt("##ColumnsMatriceInitiale", &matrixSizeX))
|
||||||
|
refresh = true;
|
||||||
|
matrixSizeX = std::max(1, matrixSizeX);
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Text("Colonnes");
|
||||||
|
|
||||||
|
ImGui::NewLine();
|
||||||
|
|
||||||
|
ImGui::BeginChild("MatriceInitiale", ImVec2(topLeftWindowSize.x, io.DisplaySize.y * 0.7f), false);
|
||||||
|
|
||||||
|
// Resize matrixValues and initialize new elements to 0
|
||||||
|
|
||||||
|
if (refresh) {
|
||||||
|
matrixValues.resize(matrixSizeY);
|
||||||
|
for (auto& row : matrixValues) {
|
||||||
|
row.resize(matrixSizeX, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int y = 0; y < matrixSizeY; y++) {
|
||||||
|
for (int x = 0; x < matrixSizeX; x++) {
|
||||||
|
if (x > 0)
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::PushID(y * matrixSizeX + x);
|
||||||
|
ImGui::PushItemWidth(30); // Adjust this value to change the cell size
|
||||||
|
if (ImGui::InputInt("", &matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal))
|
||||||
|
refresh = true;
|
||||||
|
ImGui::PopItemWidth();
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display the equationsResult strings in the GUI if they are not empty
|
||||||
|
if (!equationsResultImage.empty()) {
|
||||||
|
ImGui::TextWrapped(equationsResultImage.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndChild(); // End Matrice initiale
|
||||||
|
|
||||||
|
ImGui::End(); // End fenetre top left
|
||||||
|
|
||||||
|
// Begin fenetre top right
|
||||||
|
ImGui::SetNextWindowSize(topRightWindowSize);
|
||||||
|
ImGui::SetNextWindowPos(ImVec2(windowPos.x + topLeftWindowSize.x, 0)); // Position at the top-right corner
|
||||||
|
ImGui::Begin("Right Top Window", nullptr,
|
||||||
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
||||||
|
|
||||||
|
// rajouter le code pour la partie top right
|
||||||
|
|
||||||
|
static std::string result = "";
|
||||||
|
|
||||||
|
ImGui::TextWrapped(result.c_str());
|
||||||
|
|
||||||
|
ImGui::End(); // End fenetre top right
|
||||||
|
|
||||||
|
// Begin fenetre bas
|
||||||
|
ImGui::SetNextWindowSize(bottomWindowSize);
|
||||||
|
ImGui::SetNextWindowPos(ImVec2(0, io.DisplaySize.y * 0.8f)); // Position at the bottom-left corner
|
||||||
|
ImGui::Begin("Bottom Part", nullptr,
|
||||||
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
||||||
|
|
||||||
|
if (refresh) {
|
||||||
|
|
||||||
|
// Calculate the kernel and image
|
||||||
|
Vect image = solver.Image(LoadMatrixFromStdVect(matrixValues));
|
||||||
|
Matrix linearSystem = image.GetLinearSystem();
|
||||||
|
|
||||||
|
// Store the equationsResult strings in the global variable
|
||||||
|
equationsResultImage = "Equations cartesiennes de l'espace vectoriel (Image):\n";
|
||||||
|
for (size_t i = 0; i < linearSystem.GetRawCount(); ++i) {
|
||||||
|
for (size_t j = 0; j < linearSystem.GetColumnCount(); ++j) {
|
||||||
|
equationsResultImage +=
|
||||||
|
ElementToString(linearSystem.at(i, j)) + "*" + std::string {static_cast<char>('a' + j)} + " + ";
|
||||||
|
}
|
||||||
|
equationsResultImage = equationsResultImage.substr(0, equationsResultImage.size() - 3) + " = 0\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
result = std::string("Noyau: ") + "\n" + PrintVect(solver.Kernel(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" +
|
||||||
|
"Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" + "Image: " + "\n" +
|
||||||
|
PrintVect(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
refresh = false;
|
||||||
|
ImGui::End(); // End fenetre bas
|
||||||
|
}
|
||||||
|
|
||||||
|
void PivotGui::Destroy() {}
|
||||||
9
src/gui/PivotGui.h
Normal file
9
src/gui/PivotGui.h
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace PivotGui {
|
||||||
|
|
||||||
|
void Init();
|
||||||
|
void Render();
|
||||||
|
void Destroy();
|
||||||
|
|
||||||
|
} // namespace PivotGui
|
||||||
174
src/gui/mainGui.cpp
Normal file
174
src/gui/mainGui.cpp
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
// Dear ImGui: standalone example application for SDL2 + OpenGL
|
||||||
|
// (SDL is a cross-platform general purpose library for handling windows, inputs, OpenGL/Vulkan/Metal graphics context creation, etc.)
|
||||||
|
|
||||||
|
// Learn about Dear ImGui:
|
||||||
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
// - Getting Started https://dearimgui.com/getting-started
|
||||||
|
// - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
|
||||||
|
// - Introduction, links and more at the top of imgui.cpp
|
||||||
|
|
||||||
|
#include <SDL2/SDL.h>
|
||||||
|
#include <imgui.h>
|
||||||
|
#include <imgui_impl_opengl3.h>
|
||||||
|
#include <imgui_impl_opengl3_loader.h>
|
||||||
|
#include <imgui_impl_sdl2.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "PivotGui.h"
|
||||||
|
|
||||||
|
// This example can also compile and run with Emscripten! See 'Makefile.emscripten' for details.
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
#include "../libs/emscripten/emscripten_mainloop_stub.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Main code
|
||||||
|
int main(int, char**) {
|
||||||
|
// Setup SDL
|
||||||
|
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0) {
|
||||||
|
printf("Error: %s\n", SDL_GetError());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Decide GL+GLSL versions
|
||||||
|
#if defined(IMGUI_IMPL_OPENGL_ES2)
|
||||||
|
// GL ES 2.0 + GLSL 100
|
||||||
|
const char* glsl_version = "#version 100";
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||||
|
#elif defined(__APPLE__)
|
||||||
|
// GL 3.2 Core + GLSL 150
|
||||||
|
const char* glsl_version = "#version 150";
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||||
|
#else
|
||||||
|
// GL 3.0 + GLSL 130
|
||||||
|
const char* glsl_version = "#version 130";
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// From 2.0.18: Enable native IME.
|
||||||
|
#ifdef SDL_HINT_IME_SHOW_UI
|
||||||
|
SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Create window with graphics context
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
|
||||||
|
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
|
||||||
|
SDL_WindowFlags window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
|
||||||
|
SDL_Window* window = SDL_CreateWindow("Solver Gui", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
|
||||||
|
if (window == nullptr) {
|
||||||
|
printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_GLContext gl_context = SDL_GL_CreateContext(window);
|
||||||
|
SDL_GL_MakeCurrent(window, gl_context);
|
||||||
|
SDL_GL_SetSwapInterval(1); // Enable vsync
|
||||||
|
|
||||||
|
// Setup Dear ImGui context
|
||||||
|
IMGUI_CHECKVERSION();
|
||||||
|
ImGui::CreateContext();
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
|
||||||
|
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
|
||||||
|
|
||||||
|
// Setup Dear ImGui style
|
||||||
|
ImGui::StyleColorsDark();
|
||||||
|
// ImGui::StyleColorsLight();
|
||||||
|
|
||||||
|
// Setup Platform/Renderer backends
|
||||||
|
ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
|
||||||
|
ImGui_ImplOpenGL3_Init(glsl_version);
|
||||||
|
|
||||||
|
// Load Fonts
|
||||||
|
// - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use
|
||||||
|
// ImGui::PushFont()/PopFont() to select them.
|
||||||
|
// - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
|
||||||
|
// - If the file cannot be loaded, the function will return a nullptr. Please handle those errors in your application (e.g. use an
|
||||||
|
// assertion, or display an error and quit).
|
||||||
|
// - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling
|
||||||
|
// ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
|
||||||
|
// - Use '#define IMGUI_ENABLE_FREETYPE' in your imconfig file to use Freetype for higher quality font rendering.
|
||||||
|
// - Read 'docs/FONTS.md' for more instructions and details.
|
||||||
|
// - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
|
||||||
|
// - Our Emscripten build process allows embedding fonts to be accessible at runtime from the "fonts/" folder. See
|
||||||
|
// Makefile.emscripten for details.
|
||||||
|
// io.Fonts->AddFontDefault();
|
||||||
|
// io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\segoeui.ttf", 18.0f);
|
||||||
|
// io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
|
||||||
|
// io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
|
||||||
|
// io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
|
||||||
|
// ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, nullptr,
|
||||||
|
// io.Fonts->GetGlyphRangesJapanese()); IM_ASSERT(font != nullptr);
|
||||||
|
|
||||||
|
ImFontConfig cfg;
|
||||||
|
cfg.SizePixels = 30.0f;
|
||||||
|
io.Fonts->AddFontDefault(&cfg);
|
||||||
|
|
||||||
|
PivotGui::Init();
|
||||||
|
|
||||||
|
// Main loop
|
||||||
|
bool done = false;
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
// For an Emscripten build we are disabling file-system access, so let's not attempt to do a fopen() of the imgui.ini file.
|
||||||
|
// You may manually call LoadIniSettingsFromMemory() to load settings from your own storage.
|
||||||
|
io.IniFilename = nullptr;
|
||||||
|
EMSCRIPTEN_MAINLOOP_BEGIN
|
||||||
|
#else
|
||||||
|
while (!done)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
// Poll and handle events (inputs, window resize, etc.)
|
||||||
|
// You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
|
||||||
|
// - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or clear/overwrite your copy
|
||||||
|
// of the mouse data.
|
||||||
|
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or clear/overwrite your
|
||||||
|
// copy of the keyboard data. Generally you may always pass all inputs to dear imgui, and hide them from your application based
|
||||||
|
// on those two flags.
|
||||||
|
SDL_Event event;
|
||||||
|
while (SDL_PollEvent(&event)) {
|
||||||
|
ImGui_ImplSDL2_ProcessEvent(&event);
|
||||||
|
if (event.type == SDL_QUIT)
|
||||||
|
done = true;
|
||||||
|
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE &&
|
||||||
|
event.window.windowID == SDL_GetWindowID(window))
|
||||||
|
done = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start the Dear ImGui frame
|
||||||
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
|
ImGui_ImplSDL2_NewFrame();
|
||||||
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
PivotGui::Render();
|
||||||
|
|
||||||
|
// Rendering
|
||||||
|
ImGui::Render();
|
||||||
|
glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
|
||||||
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
|
SDL_GL_SwapWindow(window);
|
||||||
|
}
|
||||||
|
#ifdef __EMSCRIPTEN__
|
||||||
|
EMSCRIPTEN_MAINLOOP_END;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ImGui_ImplOpenGL3_Shutdown();
|
||||||
|
ImGui_ImplSDL2_Shutdown();
|
||||||
|
ImGui::DestroyContext();
|
||||||
|
|
||||||
|
SDL_GL_DeleteContext(gl_context);
|
||||||
|
SDL_DestroyWindow(window);
|
||||||
|
SDL_Quit();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
42
src/main.cpp
42
src/main.cpp
@@ -1,3 +1,7 @@
|
|||||||
|
#include "Gauss.h"
|
||||||
|
#include "IO.h"
|
||||||
|
#include "Matrix.h"
|
||||||
|
#include "NR.h"
|
||||||
#include "Solver.h"
|
#include "Solver.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
@@ -16,42 +20,36 @@ void test() {
|
|||||||
mat.Print();
|
mat.Print();
|
||||||
// mat.Save("matrice4x4echelonne.mat"); */
|
// mat.Save("matrice4x4echelonne.mat"); */
|
||||||
|
|
||||||
Matrix mat2{"matrice4x4.mat"};
|
Matrix mat2 = LoadMatrix("matrice4x4.mat");
|
||||||
mat2.Print();
|
Print(mat2);
|
||||||
|
|
||||||
Solver solver{mat2};
|
Solver solver;
|
||||||
|
|
||||||
Vect image = solver.Image();
|
Vect image = solver.Image(Matrix{mat2});
|
||||||
Vect noyau = solver.Noyau();
|
Vect noyau = solver.Kernel(Matrix{mat2});
|
||||||
|
|
||||||
std::cout << "\tImage :\n";
|
std::cout << "\tImage :\n";
|
||||||
image.Print();
|
Print(image);
|
||||||
std::cout << "Système :\n";
|
std::cout << "Système :\n";
|
||||||
image.GetLinearSystem().Print();
|
Print(image.GetLinearSystem());
|
||||||
std::cout << "\tNoyau :\n";
|
std::cout << "\tNoyau :\n";
|
||||||
noyau.Print();
|
Print(noyau);
|
||||||
std::cout << "Système :\n";
|
std::cout << "Système :\n";
|
||||||
noyau.GetLinearSystem().Print();
|
Print(noyau.GetLinearSystem());
|
||||||
|
|
||||||
|
std::cout << "\n\n";
|
||||||
|
// Print(solver.TriangularSystem(mat2));
|
||||||
}
|
}
|
||||||
|
|
||||||
void prompt() {
|
void prompt() {
|
||||||
std::cout << "Quelle est le nombre de lignes de votre matrice ?" << std::endl;
|
|
||||||
std::size_t lignes;
|
|
||||||
std::cin >> lignes;
|
|
||||||
std::cout << "Quelle est le nombre de colonnes de votre matrice ?" << std::endl;
|
|
||||||
std::size_t colonnes;
|
|
||||||
std::cin >> colonnes;
|
|
||||||
std::size_t dimension = lignes * colonnes;
|
|
||||||
std::cout << "Rentrez les coefficients de la matrice" << std::endl;
|
|
||||||
Matrix mat(lignes, colonnes);
|
|
||||||
|
|
||||||
mat.Insert();
|
Matrix mat = InsertMatrix();
|
||||||
|
|
||||||
mat.Print();
|
Print(mat);
|
||||||
|
|
||||||
mat.GaussJordan(true);
|
Gauss::GaussJordan(mat, true, true);
|
||||||
|
|
||||||
mat.Print();
|
Print(mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
#include "Matrix.h"
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
#ifdef NDEBUG
|
|
||||||
#error "Il faut être en debug mode ! xmake f -m debug"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct Test{
|
|
||||||
Matrix mat;
|
|
||||||
Matrix res;
|
|
||||||
};
|
|
||||||
|
|
||||||
static const std::vector<Test> TEST_MATRICES = {
|
|
||||||
// test 1
|
|
||||||
{{3, 3, {
|
|
||||||
1, 2, 3,
|
|
||||||
4, 5, 6,
|
|
||||||
7, 8, 9,
|
|
||||||
}}, {3, 3, {
|
|
||||||
1, 0, -1,
|
|
||||||
0, 1, 2,
|
|
||||||
0, 0, 0,
|
|
||||||
}}},
|
|
||||||
// test 2
|
|
||||||
{{3, 3, {
|
|
||||||
4, 5, 6,
|
|
||||||
1, 2, 3,
|
|
||||||
7, 8, 9,
|
|
||||||
}}, {3, 3, {
|
|
||||||
1, 0, -1,
|
|
||||||
0, 1, 2,
|
|
||||||
0, 0, 0,
|
|
||||||
}}}
|
|
||||||
};
|
|
||||||
|
|
||||||
void test() {
|
|
||||||
for (Test test : TEST_MATRICES) {
|
|
||||||
test.mat.GaussJordan(true);
|
|
||||||
assert(test.mat == test.res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
|
||||||
test();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
42
test/test_assert.h
Normal file
42
test/test_assert.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \file Test.h
|
||||||
|
* \brief Contient une assertion utilisable avec les optimisations
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \def TEST_SUCCESSFUL
|
||||||
|
* \brief Indique que le test a été passé
|
||||||
|
*/
|
||||||
|
#define TEST_SUCCESSFUL 0
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \def TEST_FAILED
|
||||||
|
* \brief Indique que le test a échoué
|
||||||
|
*/
|
||||||
|
#define TEST_FAILED 1
|
||||||
|
|
||||||
|
#ifndef __FUNCTION_NAME__
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define __FUNCTION_NAME__ __FUNCTION__
|
||||||
|
#else
|
||||||
|
#define __FUNCTION_NAME__ __PRETTY_FUNCTION__
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \def test_assert
|
||||||
|
* \param ... L'expression à évaluer
|
||||||
|
* \brief Evalue une expression et arrête le programme si elle n'est pas valide
|
||||||
|
* \note Cette macro équivaut à assert() mais fonctionne également avec les optimisations activées
|
||||||
|
*/
|
||||||
|
#define test_assert(...) \
|
||||||
|
if (!static_cast<bool>(__VA_ARGS__)) { \
|
||||||
|
std::cout << __FILE__ << ":" << __LINE__ << ": " << __FUNCTION_NAME__ << ": Assertion failed !\n"; \
|
||||||
|
std::cout << " " << __LINE__ << " |\t" << #__VA_ARGS__ << std::endl; \
|
||||||
|
throw std::runtime_error("Assertion failed !"); \
|
||||||
|
}
|
||||||
84
test/test_jordan.cpp
Normal file
84
test/test_jordan.cpp
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
#include "Gauss.h"
|
||||||
|
#include "Matrix.h"
|
||||||
|
#include "test_assert.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
static constexpr int MATRIX_MAX_SIZE = 300;
|
||||||
|
static constexpr int EXECUTION_COUNT = 1;
|
||||||
|
|
||||||
|
struct Test {
|
||||||
|
Matrix mat;
|
||||||
|
Matrix res;
|
||||||
|
};
|
||||||
|
|
||||||
|
static const std::vector<Test> TEST_MATRICES = {
|
||||||
|
// test 1
|
||||||
|
{{3, 3, {
|
||||||
|
1, 2, 3,
|
||||||
|
4, 5, 6,
|
||||||
|
7, 8, 9,
|
||||||
|
}}, {3, 3, {
|
||||||
|
1, 0, -1,
|
||||||
|
0, 1, 2,
|
||||||
|
0, 0, 0,
|
||||||
|
}}},
|
||||||
|
// test 2
|
||||||
|
{{3, 3, {
|
||||||
|
4, 5, 6,
|
||||||
|
1, 2, 3,
|
||||||
|
7, 8, 9,
|
||||||
|
}}, {3, 3, {
|
||||||
|
1, 0, -1,
|
||||||
|
0, 1, 2,
|
||||||
|
0, 0, 0,
|
||||||
|
}}}
|
||||||
|
};
|
||||||
|
|
||||||
|
static unsigned int GetRandomInt() {
|
||||||
|
return rand() % MATRIX_MAX_SIZE + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
|
||||||
|
Matrix matrix {a_Raw, a_Column};
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < matrix.GetRawCount(); i++) {
|
||||||
|
for (std::size_t j = 0; j < matrix.GetColumnCount(); j++) {
|
||||||
|
matrix.at(i, j) = GetRandomInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void test() {
|
||||||
|
for (Test test : TEST_MATRICES) {
|
||||||
|
Gauss::GaussJordan(test.mat, true, true);
|
||||||
|
test_assert(test.mat == test.res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void gaussTest() {
|
||||||
|
auto start = std::chrono::system_clock::now();
|
||||||
|
|
||||||
|
for (int i = 0; i < EXECUTION_COUNT; i++) {
|
||||||
|
Matrix mat = GetRandomMatrix(500, 500);
|
||||||
|
Gauss::GaussJordan(mat, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto end = std::chrono::system_clock::now();
|
||||||
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
||||||
|
std::cout << "\tgauss jordan elapsed time : " << elapsed_seconds.count() << "s" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void speedTest() {
|
||||||
|
gaussTest();
|
||||||
|
// gaussColumnTest();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
test();
|
||||||
|
speedTest();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
109
test/test_plot.cpp
Normal file
109
test/test_plot.cpp
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <chrono>
|
||||||
|
#include <cmath>
|
||||||
|
#include <execution>
|
||||||
|
#include <future>
|
||||||
|
#include <matplot/matplot.h>
|
||||||
|
|
||||||
|
#include "Gauss.h"
|
||||||
|
#include "Matrix.h"
|
||||||
|
#include "Solver.h"
|
||||||
|
|
||||||
|
static constexpr int EXECUTION_COUNT = 100;
|
||||||
|
static constexpr int MATRIX_MAX_SIZE = 300;
|
||||||
|
|
||||||
|
static unsigned int GetRandomInt() {
|
||||||
|
return rand() % MATRIX_MAX_SIZE + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
|
||||||
|
Matrix matrix {a_Raw, a_Column};
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < matrix.GetRawCount(); i++) {
|
||||||
|
for (std::size_t j = 0; j < matrix.GetColumnCount(); j++) {
|
||||||
|
matrix.at(i, j) = GetRandomInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<double> GaussJordan(const std::vector<double>& x) {
|
||||||
|
std::vector<double> y;
|
||||||
|
|
||||||
|
std::for_each(x.begin(), x.end(), [&y](double size) {
|
||||||
|
auto start = std::chrono::system_clock::now();
|
||||||
|
|
||||||
|
for (int j = 0; j < EXECUTION_COUNT; j++) {
|
||||||
|
Matrix mat = GetRandomMatrix(size, size);
|
||||||
|
Gauss::GaussJordan(mat, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto end = std::chrono::system_clock::now();
|
||||||
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
||||||
|
std::cout << "S " << size << "\n";
|
||||||
|
y.push_back(elapsed_seconds.count() / static_cast<double>(EXECUTION_COUNT));
|
||||||
|
});
|
||||||
|
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<double> GaussJordanReduite(const std::vector<double>& x) {
|
||||||
|
std::vector<double> y;
|
||||||
|
|
||||||
|
std::for_each(x.begin(), x.end(), [&y](double size) {
|
||||||
|
auto start = std::chrono::system_clock::now();
|
||||||
|
|
||||||
|
for (int j = 0; j < EXECUTION_COUNT; j++) {
|
||||||
|
Matrix mat = GetRandomMatrix(size, size);
|
||||||
|
Gauss::GaussJordan(mat, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto end = std::chrono::system_clock::now();
|
||||||
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
||||||
|
std::cout << "R " << size << "\n";
|
||||||
|
y.push_back(elapsed_seconds.count() / static_cast<double>(EXECUTION_COUNT));
|
||||||
|
});
|
||||||
|
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
srand(time(0));
|
||||||
|
|
||||||
|
int start = 1;
|
||||||
|
|
||||||
|
std::vector<double> x = matplot::linspace(start, MATRIX_MAX_SIZE, MATRIX_MAX_SIZE - start + 1);
|
||||||
|
//std::vector<double> x = {5000};
|
||||||
|
std::vector<double> y, y1, y2, y3;
|
||||||
|
|
||||||
|
// y2.resize(x.size());
|
||||||
|
|
||||||
|
{
|
||||||
|
auto result1 = std::async(std::launch::async, &GaussJordan, x);
|
||||||
|
auto result2 = std::async(std::launch::async, &GaussJordanReduite, x);
|
||||||
|
y = result1.get();
|
||||||
|
y1 = result2.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::cout << "Fini !\n";
|
||||||
|
|
||||||
|
|
||||||
|
// std::transform(x.begin(), x.end(), y2.begin(), [](double x) { return 1.0 / (100.0 * 100.0) * 0.6 * x * x; });
|
||||||
|
|
||||||
|
matplot::title("Echelonnage de matrices");
|
||||||
|
matplot::xlabel("Taille des matrices");
|
||||||
|
matplot::ylabel("Temps d'exécution (s)");
|
||||||
|
|
||||||
|
matplot::hold(matplot::on);
|
||||||
|
matplot::plot(x, y);
|
||||||
|
matplot::plot(x, y1);
|
||||||
|
|
||||||
|
auto l = matplot::legend({"Echelonnage non réduit", "Echelonnage réduit", "Echelonnage non réduit normalisé", "Echelonnage réduit normalisé"});
|
||||||
|
l->location(matplot::legend::general_alignment::topleft);
|
||||||
|
|
||||||
|
matplot::show();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
114
test/test_random_kernel.cpp
Normal file
114
test/test_random_kernel.cpp
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
#include "Solver.h"
|
||||||
|
|
||||||
|
#include "test_assert.h"
|
||||||
|
#include <cstdlib>
|
||||||
|
#include <future>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
static constexpr int EXECUTION_COUNT = 1000;
|
||||||
|
static constexpr int KERNEL_CHECKS = 100;
|
||||||
|
static constexpr int MATRIX_MAX_SIZE = 9;
|
||||||
|
|
||||||
|
static const Solver solver;
|
||||||
|
|
||||||
|
static int GetRandomInt() {
|
||||||
|
return rand() % 11 - 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define print_time(i) \
|
||||||
|
end = std::chrono::system_clock::now(); \
|
||||||
|
elapsed_seconds = end - start; \
|
||||||
|
std::cout << "elapsed time " << i << " : " << elapsed_seconds.count() << "s" << std::endl; \
|
||||||
|
start = std::chrono::system_clock::now()
|
||||||
|
|
||||||
|
static unsigned int GetRandomSize() {
|
||||||
|
return rand() % MATRIX_MAX_SIZE + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
|
||||||
|
Matrix matrix {a_Raw, a_Column};
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < matrix.GetRawCount(); i++) {
|
||||||
|
for (std::size_t j = 0; j < matrix.GetColumnCount(); j++) {
|
||||||
|
matrix.at(i, j) = GetRandomInt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool Test() {
|
||||||
|
auto start = std::chrono::system_clock::now();
|
||||||
|
auto begin = start;
|
||||||
|
auto end = start;
|
||||||
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
||||||
|
|
||||||
|
std::cout << "Begin\n";
|
||||||
|
|
||||||
|
Matrix matrix = GetRandomMatrix(GetRandomSize(), GetRandomSize());
|
||||||
|
|
||||||
|
print_time(1);
|
||||||
|
|
||||||
|
Matrix copy = matrix;
|
||||||
|
|
||||||
|
Vect kernel = solver.Kernel(std::move(copy));
|
||||||
|
|
||||||
|
print_time(2);
|
||||||
|
|
||||||
|
Matrix nullVector {matrix.GetRawCount(), 1};
|
||||||
|
nullVector.Fill(0.0);
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < kernel.GetCardinal(); i++) {
|
||||||
|
Matrix result = matrix * kernel.GetVector(i);
|
||||||
|
if(!(result == nullVector)) {
|
||||||
|
test_assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print_time(3);
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < KERNEL_CHECKS; i++) {
|
||||||
|
Matrix vector = GetRandomMatrix(kernel.GetDimension(), 1);
|
||||||
|
|
||||||
|
test_assert(kernel.IsElementOf(vector) == (matrix * vector == nullVector));
|
||||||
|
}
|
||||||
|
|
||||||
|
print_time(4);
|
||||||
|
|
||||||
|
Matrix linearSystem = kernel.GetLinearSystem();
|
||||||
|
|
||||||
|
print_time(5);
|
||||||
|
|
||||||
|
Vect kernel2 = solver.Kernel(std::move(linearSystem));
|
||||||
|
|
||||||
|
test_assert(kernel == kernel2);
|
||||||
|
|
||||||
|
print_time(6);
|
||||||
|
|
||||||
|
elapsed_seconds = end - begin;
|
||||||
|
std::cout << "final elapsed time: " << elapsed_seconds.count() << "s" << std::endl;
|
||||||
|
|
||||||
|
std::cout << "End\n";
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
srand(time(0));
|
||||||
|
|
||||||
|
std::vector<std::future<bool>> results;
|
||||||
|
|
||||||
|
// appelle la fonction Test() en parallèle
|
||||||
|
for (int i = 0; i < EXECUTION_COUNT; i++) {
|
||||||
|
auto handle = std::async(std::launch::async, &Test);
|
||||||
|
results.push_back(std::move(handle));
|
||||||
|
// Test();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (auto& result : results) {
|
||||||
|
if (!result.get())
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
28
test/test_rational.cpp
Normal file
28
test/test_rational.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#include "NR.h"
|
||||||
|
|
||||||
|
#include "test_assert.h"
|
||||||
|
|
||||||
|
static void test() {
|
||||||
|
test_assert((NR {1, 5} == NR {5, 25}));
|
||||||
|
test_assert((NR {1, 5} != NR {4, 25}));
|
||||||
|
|
||||||
|
test_assert(NR {2} == NR {1} + 1);
|
||||||
|
test_assert(NR {1} == (NR {1, 4} + NR {3, 4}));
|
||||||
|
test_assert((NR {-3, -4} == NR {1, 2} + NR {1, 4}));
|
||||||
|
|
||||||
|
test_assert((NR {-1, 4} == NR {1, 4} - NR {1, 2}));
|
||||||
|
test_assert((NR {1, -4} == NR {1, 4} - NR {1, 2}));
|
||||||
|
test_assert((-NR {1, 4} == NR {1, 4} - NR {1, 2}));
|
||||||
|
|
||||||
|
test_assert((NR {2} == NR {4, 3} * NR {3, 2}));
|
||||||
|
test_assert((NR {3, 5} == NR {4, 5} * NR {3, 4}));
|
||||||
|
|
||||||
|
test_assert((NR {21, 16} == NR {7, 8} / NR {6, 9}));
|
||||||
|
|
||||||
|
test_assert((NR {4, 3} == NR {3, 4}.Inverse()));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
test();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
88
test/test_solver.cpp
Normal file
88
test/test_solver.cpp
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <filesystem>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "IO.h"
|
||||||
|
#include "Solver.h"
|
||||||
|
#include "test_assert.h"
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
|
const static int EXECUTION_COUNT = 10000;
|
||||||
|
static constexpr int MATRIX_MAX_SIZE = 7;
|
||||||
|
|
||||||
|
static int GetRandomSize() {
|
||||||
|
return rand() % MATRIX_MAX_SIZE + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int GetRandomInt() {
|
||||||
|
return GetRandomSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
|
||||||
|
Matrix matrix {a_Raw, a_Column};
|
||||||
|
|
||||||
|
std::generate(matrix.GetLineIterator(0), matrix.GetLineIterator(a_Raw), []() {
|
||||||
|
return GetRandomInt();
|
||||||
|
});
|
||||||
|
|
||||||
|
return matrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestRectangular(const Matrix& system, const Matrix& origin) {
|
||||||
|
Solver solver;
|
||||||
|
|
||||||
|
VectAffine solution = solver.RectangularSystem(std::move(Matrix(system)), origin);
|
||||||
|
|
||||||
|
for (std::size_t i = 0; i < solution.GetBase().GetCardinal(); i++) {
|
||||||
|
Matrix vector = solution.GetBase().GetVector(i) + solution.GetOrigin();
|
||||||
|
Matrix product = system * vector;
|
||||||
|
test_assert(product == origin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void RandomRectangular() {
|
||||||
|
for (int i = 0; i < EXECUTION_COUNT; i++) {
|
||||||
|
|
||||||
|
Matrix system = GetRandomMatrix(GetRandomSize(), GetRandomSize());
|
||||||
|
|
||||||
|
Matrix origin = GetRandomMatrix(system.GetRawCount(), 1);
|
||||||
|
|
||||||
|
TestRectangular(system, origin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestKernelImage() {
|
||||||
|
std::string path = "test";
|
||||||
|
for (const auto& entry : fs::directory_iterator(path)) {
|
||||||
|
std::string fileName = entry.path().string();
|
||||||
|
|
||||||
|
std::cout << "Opening " << fileName << " ...\n";
|
||||||
|
|
||||||
|
std::ifstream in {fileName};
|
||||||
|
|
||||||
|
Matrix mat, imageMat, noyauMat;
|
||||||
|
in >> mat >> imageMat >> noyauMat;
|
||||||
|
|
||||||
|
Vect image {std::move(imageMat)};
|
||||||
|
Vect noyau {std::move(noyauMat)};
|
||||||
|
|
||||||
|
Solver solver;
|
||||||
|
|
||||||
|
Matrix copy = mat;
|
||||||
|
|
||||||
|
Vect imageCalc = solver.Image(std::move(copy));
|
||||||
|
Vect kernelCalc = solver.Kernel(std::move(mat));
|
||||||
|
|
||||||
|
test_assert(imageCalc == image);
|
||||||
|
test_assert(kernelCalc == noyau);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
srand(time(0));
|
||||||
|
TestKernelImage();
|
||||||
|
RandomRectangular();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
48
test/test_vect.cpp
Normal file
48
test/test_vect.cpp
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
#include "Vect.h"
|
||||||
|
#include "test_assert.h"
|
||||||
|
|
||||||
|
void TestVect() {
|
||||||
|
Vect vect1 {{3, 2, {
|
||||||
|
1, 2,
|
||||||
|
3, 4,
|
||||||
|
5, 6,
|
||||||
|
}}};
|
||||||
|
Vect vect2 {{3, 2, {
|
||||||
|
1, 0,
|
||||||
|
0, 0,
|
||||||
|
0, 1,
|
||||||
|
}}};
|
||||||
|
Vect vect3 {{3, 2, {
|
||||||
|
1, 3,
|
||||||
|
3, 7,
|
||||||
|
5, 11,
|
||||||
|
}}};
|
||||||
|
Vect vect4 {{3, 2, {
|
||||||
|
1, 0,
|
||||||
|
0, 0,
|
||||||
|
1, 11,
|
||||||
|
}}};
|
||||||
|
|
||||||
|
test_assert(vect1 == vect3);
|
||||||
|
test_assert(vect2 == vect4);
|
||||||
|
test_assert(vect1 != vect2);
|
||||||
|
test_assert(vect2 != vect3);
|
||||||
|
test_assert(vect3 != vect4);
|
||||||
|
|
||||||
|
test_assert(vect1.IsElementOf(Matrix::ColumnVector({3, 7, 11})));
|
||||||
|
test_assert(!vect1.IsElementOf(Matrix::ColumnVector({3, 7, 12})));
|
||||||
|
}
|
||||||
|
|
||||||
|
void TestVectAffine() {
|
||||||
|
VectAffine aff {Matrix::ColumnVector({-2, 3, 7}), Matrix::ColumnVector({5, 2, -8})};
|
||||||
|
|
||||||
|
test_assert(aff.IsElementOf(Matrix::ColumnVector({5, 2, -8})));
|
||||||
|
test_assert(aff.IsElementOf(Matrix::ColumnVector({3, 5, -1})));
|
||||||
|
test_assert(!aff.IsElementOf(Matrix::ColumnVector({1, 2, 3})));
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
TestVect();
|
||||||
|
TestVectAffine();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
64
xmake.lua
64
xmake.lua
@@ -1,23 +1,63 @@
|
|||||||
add_rules("mode.debug", "mode.release")
|
add_rules("mode.debug", "mode.release")
|
||||||
|
|
||||||
|
add_requires("libsdl 2.28.3", {configs = {sdlmain = false}})
|
||||||
|
add_requires("imgui", {configs = {sdl2_no_renderer = true, opengl3 = true}})
|
||||||
|
|
||||||
|
set_languages("c++20")
|
||||||
|
set_warnings("all")
|
||||||
|
add_includedirs("include")
|
||||||
|
|
||||||
|
add_requires("matplotplusplus")
|
||||||
|
|
||||||
|
-- Solver Library
|
||||||
target("Pivot")
|
target("Pivot")
|
||||||
set_kind("binary")
|
set_kind("static")
|
||||||
add_files("src/*.cpp")
|
add_files("src/*.cpp")
|
||||||
|
add_cxxflags("-ffast-math")
|
||||||
|
set_optimize("fastest")
|
||||||
|
remove_files("src/main.cpp")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Solver Main
|
||||||
|
target("PivotMain")
|
||||||
set_rundir("$(projectdir)/matricies")
|
set_rundir("$(projectdir)/matricies")
|
||||||
set_languages("c++17")
|
add_files("src/main.cpp")
|
||||||
|
add_deps("Pivot")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
target("PivotTest")
|
|
||||||
set_kind("binary")
|
|
||||||
add_files("test/*.cpp", "src/Matrix.cpp")
|
|
||||||
add_includedirs("src")
|
|
||||||
set_default(false)
|
set_default(false)
|
||||||
add_tests("compile_and_run")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Gui interface
|
||||||
|
target("PivotGui")
|
||||||
|
set_rundir("$(projectdir)")
|
||||||
|
add_files("src/gui/*.cpp")
|
||||||
|
add_deps("Pivot")
|
||||||
|
set_default(true)
|
||||||
|
add_packages("libsdl", "imgui")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- Solver tests
|
||||||
|
for _, file in ipairs(os.files("test/test_*.cpp")) do
|
||||||
|
local name = path.basename(file)
|
||||||
|
target(name)
|
||||||
|
set_kind("binary")
|
||||||
|
add_files("test/" .. name .. ".cpp")
|
||||||
set_rundir("$(projectdir)/matricies")
|
set_rundir("$(projectdir)/matricies")
|
||||||
|
|
||||||
|
set_default(false)
|
||||||
|
|
||||||
|
add_deps("Pivot")
|
||||||
|
add_packages("matplotplusplus")
|
||||||
|
|
||||||
|
add_tests("compile_and_run")
|
||||||
|
end
|
||||||
|
|
||||||
--
|
--
|
||||||
-- If you want to known more usage about xmake, please see https://xmake.io
|
-- If you want to known more usage about xmake, please see https://xmake.io
|
||||||
--
|
--
|
||||||
|
|||||||
Reference in New Issue
Block a user