1 Commits
master ... plot

Author SHA1 Message Date
8c004b64ed caca
All checks were successful
Linux arm64 / Build (push) Successful in 41m33s
2024-05-14 19:00:04 +02:00
20 changed files with 2595 additions and 304 deletions

View File

@@ -10,7 +10,7 @@ jobs:
- name: Install opengl
run: |
apt update
apt install -y libsdl2-dev
apt install libgl-dev -y
- name: Check out repository code
uses: actions/checkout@v3
@@ -20,7 +20,7 @@ jobs:
with:
xmake-version: latest
actions-cache-folder: '.xmake-cache'
actions-cache-key: 'xmake-ubuntu'
actions-cache-key: 'ubuntu-xmake'
- name: Cache
uses: actions/cache@v4

4
.vscode/launch.json vendored
View File

@@ -7,8 +7,8 @@
{
"type": "xmake",
"request": "launch",
"name": "Debug XMake target",
"target": "Pivot",
"name": "Debug random kernel",
"target": "test_random_kernel",
"cwd": "${workspaceFolder}/matricies",
}
]

19
.vscode/settings.json vendored
View File

@@ -44,6 +44,23 @@
"stdexcept": "cpp",
"streambuf": "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"
}
}

View File

@@ -1,21 +0,0 @@
MIT License
Copyright (c) 2024 Simon Pribylski, Thibaut Alessi, Houssem Zammali, Julien Chataigner
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

16
imgui.ini Normal file
View 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

View File

@@ -18,7 +18,7 @@
*/
class Matrix {
public:
typedef NR Element;
typedef long double Element;
typedef std::vector<Element>::iterator iterator;
private:

View File

@@ -105,6 +105,12 @@ class VectAffine {
*/
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

Binary file not shown.

2067
matricies/plot.eps Normal file

File diff suppressed because it is too large Load Diff

BIN
matricies/plot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

135
matricies/plot.tex Normal file
View 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

View File

@@ -16,6 +16,10 @@ static void SwapLines(Matrix& mat, std::size_t line1, std::size_t 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) {
@@ -38,7 +42,7 @@ static void SimplifyLine(Matrix& mat, std::size_t line, std::size_t pivot_line,
});
}
static void GaussJordanReduced(Matrix& a_Matrix, bool a_Normalise) {
static void GaussJordanReducedNorma(Matrix& a_Matrix) {
int indice_ligne_pivot = -1;
for (std::size_t j = 0; j < a_Matrix.GetColumnCount(); j++) {
@@ -56,9 +60,7 @@ static void GaussJordanReduced(Matrix& a_Matrix, bool a_Normalise) {
Matrix::Element pivot = a_Matrix.at(indice_ligne_pivot, j);
if (a_Normalise) {
DivideLine(a_Matrix, indice_ligne_pivot, pivot);
}
DivideLine(a_Matrix, indice_ligne_pivot, pivot);
auto range = std::views::iota(static_cast<std::size_t>(0), a_Matrix.GetRawCount());
@@ -71,7 +73,7 @@ static void GaussJordanReduced(Matrix& a_Matrix, bool a_Normalise) {
}
}
static void GaussJordanTriangular(Matrix& a_Matrix, bool a_Normalise) {
static void GaussJordanReduced(Matrix& a_Matrix) {
int indice_ligne_pivot = -1;
for (std::size_t j = 0; j < a_Matrix.GetColumnCount(); j++) {
@@ -89,25 +91,85 @@ static void GaussJordanTriangular(Matrix& a_Matrix, bool a_Normalise) {
Matrix::Element pivot = a_Matrix.at(indice_ligne_pivot, j);
if (a_Normalise) {
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 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);
});
[&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)
GaussJordanReduced(a_Matrix, a_Normalise);
else
GaussJordanTriangular(a_Matrix, 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

View File

@@ -88,3 +88,11 @@ VectAffine::VectAffine(const Vect& a_Base, const Matrix& a_Origin) :
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;
}

View File

@@ -1,6 +1,5 @@
#include "PivotGui.h"
#include "Gauss.h"
#include "Matrix.h"
#include "Solver.h"
#include <imgui.h>
@@ -8,38 +7,6 @@
static std::string equationsResultImage;
struct GuiMatrix {
std::vector<std::vector<int>> matrixValues;
int matrixSizeX = 4;
int matrixSizeY = 4;
};
static void ResizeGuiMatrix(bool refresh, GuiMatrix& guiMatrix) {
if (refresh) {
guiMatrix.matrixValues.resize(guiMatrix.matrixSizeY);
for (auto& row : guiMatrix.matrixValues) {
row.resize(guiMatrix.matrixSizeX, 0);
}
}
}
static void RenderMatrix(bool& refresh, GuiMatrix& guiMatrix) {
ResizeGuiMatrix(refresh, guiMatrix);
for (int y = 0; y < guiMatrix.matrixSizeY; y++) {
for (int x = 0; x < guiMatrix.matrixSizeX; x++) {
if (x > 0)
ImGui::SameLine();
ImGui::PushID((guiMatrix.matrixSizeX * 20 + guiMatrix.matrixSizeY * 50) + y * guiMatrix.matrixSizeX + x);
ImGui::PushItemWidth(60); // Adjust this value to change the cell size
if (ImGui::InputInt("", &guiMatrix.matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal))
refresh = true;
ImGui::PopItemWidth();
ImGui::PopID();
}
}
}
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++) {
@@ -56,19 +23,6 @@ static std::string ElementToString(Matrix::Element e) {
return ss.str();
}
static std::string PrintRawMatrix(const Matrix& mat) {
if (mat.GetRawCount() == 0)
return "";
std::string result = " ( ";
for (std::size_t j = 0; j < mat.GetRawCount(); j++) {
result += ElementToString(mat.at(j, 0)) + ", ";
}
result = result.substr(0, result.size() - 2);
result += " )";
return result;
}
static std::string PrintVect(const Vect& vect) {
if (vect.GetCardinal() == 0)
return "{0}";
@@ -76,8 +30,12 @@ static std::string PrintVect(const Vect& vect) {
std::string result = "Vect( ";
for (std::size_t i = 0; i < vect.GetCardinal(); i++) {
Matrix vector = vect.GetVector(i);
result += PrintRawMatrix(vector);
result += ", ";
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 += " )";
@@ -86,161 +44,104 @@ static std::string PrintVect(const Vect& vect) {
void PivotGui::Init() {}
static void RenderLeftSystemChild(bool& refresh, GuiMatrix& system, GuiMatrix& origin) {
ImVec2 topLeftWindowSize(ImGui::GetContentRegionAvail().x * 0.5f, 0);
ImGui::BeginChild("Left Child", topLeftWindowSize, ImGuiChildFlags_Border);
ImGui::Text("Système de la forme AX=B");
ImGui::Separator();
ImGui::Text("Taille matrice A :");
if (ImGui::InputInt("##RowsMatriceInitiale", &system.matrixSizeY))
refresh = true;
system.matrixSizeY = std::max(1, system.matrixSizeY);
ImGui::SameLine();
ImGui::Text("Lignes");
if (ImGui::InputInt("##ColumnsMatriceInitiale", &system.matrixSizeX))
refresh = true;
system.matrixSizeX = std::max(1, system.matrixSizeX);
ImGui::SameLine();
ImGui::Text("Colonnes");
ImGui::NewLine();
RenderMatrix(refresh, system);
if (refresh) {
origin.matrixSizeX = 1;
origin.matrixSizeY = system.matrixSizeY;
}
ImGui::NewLine();
ImGui::Separator();
ImGui::Text("Matrice B :");
ImGui::NewLine();
RenderMatrix(refresh, origin);
ImGui::EndChild();
}
static void RenderRightSystemChild(bool& refresh, GuiMatrix& system, GuiMatrix& origin) {
ImGui::BeginChild("Right Child", {0, 0}, ImGuiChildFlags_Border);
static std::string result = "";
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;
if (refresh) {
VectAffine solutions =
solver.RectangularSystem(LoadMatrixFromStdVect(system.matrixValues), LoadMatrixFromStdVect(origin.matrixValues));
result = "Solutions :\n";
result += PrintVect(solutions.GetBase());
result += "\n\n+\n\n";
result += PrintRawMatrix(solutions.GetOrigin());
}
ImGui::TextWrapped("%s", result.c_str());
ImGui::EndChild();
}
static void RenderSystemTab() {
static GuiMatrix guiMatrix, originMatrix;
static bool refresh = true;
RenderLeftSystemChild(refresh, guiMatrix, originMatrix);
ImGui::SameLine();
RenderRightSystemChild(refresh, guiMatrix, originMatrix);
}
static void RenderLeftGaussChild(bool& refresh, GuiMatrix& guiMatrix) {
// divisions des fenetres
ImVec2 topLeftWindowSize(ImGui::GetContentRegionAvail().x * 0.5f, 0);
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::SetNextWindowPos(ImVec2(0, 0)); // Position at the top-left corner
ImGui::BeginChild("Left Top Window", topLeftWindowSize, ImGuiChildFlags_Border);
/*ImGui::Begin(, nullptr,
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);
*/
// ImGui::BeginTabBar("MainMenu");
// Get window position
ImVec2 windowPos = ImGui::GetWindowPos();
ImGui::Text("Matrice initiale:");
if (ImGui::InputInt("##RowsMatriceInitiale", &guiMatrix.matrixSizeY))
if (ImGui::InputInt("##RowsMatriceInitiale", &matrixSizeY))
refresh = true;
guiMatrix.matrixSizeY = std::max(1, guiMatrix.matrixSizeY);
matrixSizeY = std::max(1, matrixSizeY);
ImGui::SameLine();
ImGui::Text("Lignes");
if (ImGui::InputInt("##ColumnsMatriceInitiale", &guiMatrix.matrixSizeX))
if (ImGui::InputInt("##ColumnsMatriceInitiale", &matrixSizeX))
refresh = true;
guiMatrix.matrixSizeX = std::max(1, guiMatrix.matrixSizeX);
matrixSizeX = std::max(1, matrixSizeX);
ImGui::SameLine();
ImGui::Text("Colonnes");
ImGui::NewLine();
// ImGui::BeginChild("MatriceInitiale", ImVec2(topLeftWindowSize.x, io.DisplaySize.y * 0.7f), false);
ImGui::BeginChild("MatriceInitiale", ImVec2(topLeftWindowSize.x, io.DisplaySize.y * 0.7f), false);
// Resize matrixValues and initialize new elements to 0
RenderMatrix(refresh, guiMatrix);
// ImGui::EndChild(); // End Matrice initiale
ImGui::NewLine();
ImGui::Text("Matrice échelonnée:");
// Convert the "result" string back to a matrix
Matrix resultMatrix = LoadMatrixFromStdVect(guiMatrix.matrixValues);
// Apply the Gauss-Jordan elimination to the matrix
Gauss::GaussJordan(resultMatrix, true, true); // Assuming you want to reduce and normalize the matrix
// Display the matrix
for (std::size_t i = 0; i < resultMatrix.GetRawCount(); i++) {
for (std::size_t j = 0; j < resultMatrix.GetColumnCount(); j++) {
ImGui::PushID(i * resultMatrix.GetColumnCount() + j);
if (ImGui::Button(ElementToString(resultMatrix.at(i, j)).c_str(), ImVec2(70, 70))) { // Adjust the size as needed
// Handle button click here if needed
}
ImGui::PopID();
if (j < resultMatrix.GetColumnCount() - 1)
ImGui::SameLine();
if (refresh) {
matrixValues.resize(matrixSizeY);
for (auto& row : matrixValues) {
row.resize(matrixSizeX, 0);
}
}
ImGui::EndChild();
}
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
static void RenderRightGaussChild(bool& refresh, GuiMatrix& guiMatrix) {
static Solver solver;
// Begin fenetre top right
// ImGui::SetNextWindowSize(topRightWindowSize);
// ImGui::SetNextWindowPos(ImVec2(windowPos.x + topLeftWindowSize.x, 0)); // Position at the top-right corner
ImGui::BeginChild("Right Top Window", {0, 0}, ImGuiChildFlags_Border);
// ImGui::Begin("Right Top Window", nullptr,
// ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
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(guiMatrix.matrixValues));
Vect image = solver.Image(LoadMatrixFromStdVect(matrixValues));
Matrix linearSystem = image.GetLinearSystem();
// Store the equationsResult strings in the global variable
@@ -253,59 +154,13 @@ static void RenderRightGaussChild(bool& refresh, GuiMatrix& guiMatrix) {
equationsResultImage = equationsResultImage.substr(0, equationsResultImage.size() - 3) + " = 0\n";
}
result = "\nNoyau: \n" + PrintVect(solver.Kernel(LoadMatrixFromStdVect(guiMatrix.matrixValues))) + "\n" +
"\n" + "Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(guiMatrix.matrixValues))) + "\n" + "\n" +
"Image: " + "\n" + PrintVect(image);
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;
// Display the equationsResult strings in the GUI if they are not empty
if (!equationsResultImage.empty()) {
ImGui::TextWrapped("%s", equationsResultImage.c_str());
}
ImGui::TextWrapped("%s", result.c_str());
ImGui::EndChild(); // End fenetre top right
}
static void RenderGaussTab() {
static GuiMatrix guiMatrix;
static bool refresh = true;
RenderLeftGaussChild(refresh, guiMatrix);
ImGui::SameLine();
RenderRightGaussChild(refresh, guiMatrix);
}
static void RenderMainWindow() {
ImGuiIO& io = ImGui::GetIO();
ImGui::SetNextWindowSize(io.DisplaySize);
ImGui::SetNextWindowPos({0, 0});
ImGui::Begin("MainWindow", nullptr,
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
ImGui::BeginTabBar("MainBar");
if (ImGui::BeginTabItem("Noyau et Image")) {
RenderGaussTab();
ImGui::EndTabItem();
}
if (ImGui::BeginTabItem("Systèmes")) {
RenderSystemTab();
ImGui::EndTabItem();
}
ImGui::EndTabBar();
ImGui::End();
}
void PivotGui::Render() {
RenderMainWindow();
#ifndef NDEBUG
ImGui::ShowDemoWindow(nullptr);
#endif
ImGui::End(); // End fenetre bas
}
void PivotGui::Destroy() {}

View File

@@ -2,6 +2,12 @@
#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;
@@ -30,6 +36,22 @@ static const std::vector<Test> TEST_MATRICES = {
}}}
};
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);
@@ -37,7 +59,26 @@ void test() {
}
}
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
View 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;
}

View File

@@ -16,6 +16,16 @@ 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};
@@ -29,34 +39,57 @@ static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
}
static bool Test() {
Matrix matrix = GetRandomMatrix(rand() % MATRIX_MAX_SIZE + 1, rand() % MATRIX_MAX_SIZE + 1);
auto start = std::chrono::system_clock::now();
auto begin = start;
auto end = start;
std::chrono::duration<double> elapsed_seconds = end - start;
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();
}
}
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++) {
test_assert(matrix * kernel.GetVector(i) == nullVector);
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));
}
Vect kernel2 = solver.Kernel(kernel.GetLinearSystem());
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;
}
@@ -69,6 +102,7 @@ int main() {
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) {

View File

@@ -10,7 +10,7 @@
namespace fs = std::filesystem;
const static int EXECUTION_COUNT = 10000;
static constexpr int MATRIX_MAX_SIZE = 5;
static constexpr int MATRIX_MAX_SIZE = 7;
static int GetRandomSize() {
return rand() % MATRIX_MAX_SIZE + 1;

View File

@@ -1,27 +1,6 @@
#include "Vect.h"
#include "test_assert.h"
#include <algorithm>
const static int EXECUTION_COUNT = 100000;
static constexpr int MATRIX_MAX_SIZE = 5;
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 TestVect() {
Vect vect1 {{3, 2, {
1, 2,
@@ -62,23 +41,8 @@ void TestVectAffine() {
test_assert(!aff.IsElementOf(Matrix::ColumnVector({1, 2, 3})));
}
void TestLinearSystem() {
for (std::size_t i = 0; i < EXECUTION_COUNT; i++) {
Vect vect = GetRandomMatrix(GetRandomSize(), GetRandomSize());
Matrix systeme = vect.GetLinearSystem();
for (std::size_t j = 0; j < vect.GetCardinal(); j++) {
Matrix nullMatrix {systeme.GetColumnCount(), 1};
test_assert(systeme * vect.GetVector(j) == nullMatrix);
}
}
}
int main() {
srand(time(0));
TestVect();
TestVectAffine();
TestLinearSystem();
return 0;
}

View File

@@ -1,23 +1,20 @@
set_project("Pivot")
set_description("Solutionneur de matrice par le pivot de Gauss")
set_license("MIT")
set_xmakever("2.8.5")
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")
set_kind("static")
add_files("src/*.cpp")
add_cxxflags("-ffast-math")
set_optimize("fastest")
remove_files("src/main.cpp")
@@ -56,6 +53,7 @@ for _, file in ipairs(os.files("test/test_*.cpp")) do
set_default(false)
add_deps("Pivot")
add_packages("matplotplusplus")
add_tests("compile_and_run")
end