Compare commits
16 Commits
a02f71e29e
...
imgui
| Author | SHA1 | Date | |
|---|---|---|---|
| 9a5b99a79d | |||
| ffa0ebf4cb | |||
| 4b3e878bc5 | |||
| 47f250170e | |||
| a4036ae36d | |||
| e6d0785009 | |||
| a135df2e96 | |||
| d9e49d1319 | |||
| e127ff8c29 | |||
| 9b423f9c83 | |||
| fa7e70a437 | |||
| 76fa9fb329 | |||
| 7f1ef38286 | |||
| 2af915057a | |||
| 2975006972 | |||
| 0d071b1cf9 |
3
.vscode/c_cpp_properties.json
vendored
3
.vscode/c_cpp_properties.json
vendored
@@ -3,7 +3,8 @@
|
||||
{
|
||||
"name": "Pivot",
|
||||
"cppStandard": "c++20",
|
||||
"includePath": ["include"]
|
||||
"includePath": ["include"],
|
||||
"compileCommands": "${workspaceFolder}/.vscode/compile_commands.json"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
|
||||
@@ -10,13 +10,15 @@
|
||||
#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 NR Element;
|
||||
typedef std::vector<Element>::iterator iterator;
|
||||
|
||||
private:
|
||||
@@ -154,6 +156,21 @@ class Matrix {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
bool IsEqualZero(T var) {
|
||||
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;
|
||||
}
|
||||
|
||||
17
include/NR.h
17
include/NR.h
@@ -3,17 +3,20 @@
|
||||
#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
|
||||
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
|
||||
NR(Int entier);
|
||||
NR(Int numerator, Int denominator); // check if denominator != 0
|
||||
|
||||
int GetNumerator() const;
|
||||
int GetDenominator() const;
|
||||
Int GetNumerator() const;
|
||||
Int GetDenominator() const;
|
||||
|
||||
bool operator==(const NR& opNR) const;
|
||||
bool operator<(const NR& opNR) const;
|
||||
@@ -43,5 +46,3 @@ class NR {
|
||||
private:
|
||||
void Reduce();
|
||||
};
|
||||
|
||||
int PGCD(int x, int y);
|
||||
|
||||
@@ -105,12 +105,6 @@ 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();
|
||||
};
|
||||
|
||||
@@ -71,11 +71,7 @@ Matrix Matrix::RawVector(std::initializer_list<Element>&& a_Elements) {
|
||||
}
|
||||
|
||||
void Matrix::Fill(Element a_Element) {
|
||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
||||
for (std::size_t j = 0; j < m_Columns; j++) {
|
||||
at(i, j) = a_Element;
|
||||
}
|
||||
}
|
||||
std::fill(GetLineIterator(0), GetLineIterator(m_Raws), a_Element);
|
||||
}
|
||||
|
||||
void Matrix::Augment(const Matrix& a_Right) {
|
||||
@@ -158,10 +154,12 @@ bool Matrix::operator==(const Matrix& a_Other) const {
|
||||
}
|
||||
|
||||
Matrix::Element& Matrix::at(std::size_t a_Raw, std::size_t a_Column) {
|
||||
assert(a_Raw < m_Raws && a_Column < m_Columns);
|
||||
return m_Data[a_Raw * m_Columns + a_Column];
|
||||
}
|
||||
|
||||
Matrix::Element Matrix::at(std::size_t a_Raw, std::size_t a_Column) const {
|
||||
assert(a_Raw < m_Raws && a_Column < m_Columns);
|
||||
return m_Data[a_Raw * m_Columns + a_Column];
|
||||
}
|
||||
|
||||
|
||||
43
src/NR.cpp
43
src/NR.cpp
@@ -3,7 +3,7 @@
|
||||
#include <cassert>
|
||||
#include <iostream>
|
||||
|
||||
int PGCD(int x, int y) {
|
||||
NR::Int PGCD(NR::Int x, NR::Int y) {
|
||||
if (x == 0 || y == 0)
|
||||
return 1;
|
||||
else if (x % y == 0)
|
||||
@@ -14,18 +14,18 @@ int PGCD(int x, int y) {
|
||||
|
||||
NR::NR() : m_Numerator(0), m_Denominator(1) {}
|
||||
|
||||
NR::NR(int entier) : m_Numerator(entier), m_Denominator(1) {}
|
||||
NR::NR(NR::Int entier) : m_Numerator(entier), m_Denominator(1) {}
|
||||
|
||||
NR::NR(int numerator, int denominator) :
|
||||
NR::NR(NR::Int numerator, NR::Int denominator) :
|
||||
m_Numerator((denominator > 0) ? numerator : -numerator), m_Denominator(std::abs(denominator)) {
|
||||
assert(denominator != 0);
|
||||
Reduce();
|
||||
}
|
||||
|
||||
void NR::Reduce() {
|
||||
int divisor = PGCD(m_Denominator, m_Numerator);
|
||||
NR::Int divisor = PGCD(m_Denominator, m_Numerator);
|
||||
m_Denominator /= divisor;
|
||||
m_Numerator /= divisor;
|
||||
assert(m_Denominator != 0);
|
||||
}
|
||||
|
||||
NR NR::Inverse() const {
|
||||
@@ -33,11 +33,11 @@ NR NR::Inverse() const {
|
||||
return {m_Denominator, m_Numerator};
|
||||
}
|
||||
|
||||
int NR::GetNumerator() const {
|
||||
NR::Int NR::GetNumerator() const {
|
||||
return m_Numerator;
|
||||
}
|
||||
|
||||
int NR::GetDenominator() const {
|
||||
NR::Int NR::GetDenominator() const {
|
||||
return m_Denominator;
|
||||
}
|
||||
|
||||
@@ -66,48 +66,57 @@ bool NR::operator>=(const NR& opNR) const {
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const NR& opNR) {
|
||||
os << opNR.GetNumerator() << "/" << opNR.GetDenominator();
|
||||
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 >> opNR.m_Denominator;
|
||||
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;
|
||||
Int num, den;
|
||||
num = m_Numerator * opNR.GetDenominator();
|
||||
den = m_Denominator * opNR.GetDenominator();
|
||||
num += (opNR.GetNumerator() * m_Denominator);
|
||||
NR result(num, den);
|
||||
NR result(num, num == 0 ? 1 : den);
|
||||
return result;
|
||||
}
|
||||
|
||||
NR NR::operator-(const NR& opNR) const {
|
||||
int num, den;
|
||||
Int num, den;
|
||||
num = m_Numerator * opNR.GetDenominator();
|
||||
den = m_Denominator * opNR.GetDenominator();
|
||||
num -= (opNR.GetNumerator() * m_Denominator);
|
||||
NR result(num, den);
|
||||
NR result(num, num == 0 ? 1 : den);
|
||||
return result;
|
||||
}
|
||||
|
||||
NR NR::operator*(const NR& opNR) const {
|
||||
int num, den;
|
||||
Int num, den;
|
||||
num = m_Numerator * opNR.GetNumerator();
|
||||
den = m_Denominator * opNR.GetDenominator();
|
||||
NR result(num, den);
|
||||
NR result(num, num == 0 ? 1 : den);
|
||||
return result;
|
||||
}
|
||||
|
||||
NR NR::operator/(const NR& opNR) const {
|
||||
int num, den;
|
||||
Int num, den;
|
||||
num = m_Numerator * opNR.GetDenominator();
|
||||
den = m_Denominator * opNR.GetNumerator();
|
||||
NR result(num, den);
|
||||
NR result(num, num == 0 ? 1 : den);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,15 @@
|
||||
|
||||
#include "Gauss.h"
|
||||
|
||||
static int FirstNotNullElementIndexOnLine(const Matrix& mat, std::size_t line) {
|
||||
for (std::size_t i = 0; i < mat.GetColumnCount(); i++) {
|
||||
if (!IsEqualZero(mat.at(line, i))) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
Vect Solver::Image(Matrix&& a_Matrix) const {
|
||||
a_Matrix.Transpose();
|
||||
Gauss::GaussJordan(a_Matrix, false, false);
|
||||
@@ -36,15 +45,21 @@ VectAffine Solver::RectangularSystem(Matrix&& a_MatrixA, const Matrix& a_VectorB
|
||||
Vect noyau = solver.Kernel(std::move(a_MatrixA));
|
||||
Matrix origin = mat.SubMatrix(0, mat.GetColumnCount() - 1, mat.GetRawCount(), 1);
|
||||
|
||||
// on rajoute des 0 si il faut
|
||||
|
||||
// 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++) {
|
||||
fullOrigin.at(i, 0) = origin.at(i, 0);
|
||||
}
|
||||
int pivot_index = FirstNotNullElementIndexOnLine(mat, i);
|
||||
|
||||
for (std::size_t i = mat.GetRawCount(); i < mat.GetColumnCount() - 1; i++) {
|
||||
fullOrigin.at(i, 0) = 0;
|
||||
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};
|
||||
|
||||
10
src/Vect.cpp
10
src/Vect.cpp
@@ -14,7 +14,7 @@ static bool IsColumnNull(Matrix& mat, std::size_t column) {
|
||||
|
||||
Vect::Vect(Matrix&& a_Matrix) : m_Data(std::move(a_Matrix)) {
|
||||
m_Data.Transpose();
|
||||
Gauss::GaussJordan(m_Data, false, false);
|
||||
Gauss::GaussJordan(m_Data, false, true);
|
||||
m_Data.Transpose();
|
||||
Simplify();
|
||||
}
|
||||
@@ -88,11 +88,3 @@ 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;
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
#include "PivotGui.h"
|
||||
|
||||
#include "Gauss.h"
|
||||
#include "Matrix.h"
|
||||
#include "Solver.h"
|
||||
#include <imgui.h>
|
||||
#include <sstream>
|
||||
|
||||
static std::string equationsResultImage;
|
||||
|
||||
@@ -16,8 +18,14 @@ static Matrix LoadMatrixFromStdVect(const std::vector<std::vector<int>>& data) {
|
||||
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)
|
||||
if (vect.GetCardinal() == 0)
|
||||
return "{0}";
|
||||
|
||||
std::string result = "Vect( ";
|
||||
@@ -25,11 +33,13 @@ static std::string PrintVect(const Vect& vect) {
|
||||
Matrix vector = vect.GetVector(i);
|
||||
result += " (";
|
||||
for (std::size_t j = 0; j < vect.GetDimension(); j++) {
|
||||
result += std::to_string(static_cast<int>((vector.at(j, 0)))) + ", ";
|
||||
result += ElementToString(vector.at(j, 0)) + ", ";
|
||||
}
|
||||
result = result.substr(0, result.size() - 2);
|
||||
result += " ), ";
|
||||
}
|
||||
result += " )";
|
||||
result = result.substr(0, result.size() - 2);
|
||||
result += " )";
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -43,10 +53,11 @@ void PivotGui::Render() {
|
||||
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);
|
||||
ImVec2 topLeftWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y);
|
||||
ImVec2 topRightWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y);
|
||||
|
||||
// Begin fenetre top left
|
||||
ImGui::SetNextWindowSize(topLeftWindowSize);
|
||||
@@ -59,22 +70,30 @@ void PivotGui::Render() {
|
||||
|
||||
ImGui::Text("Matrice initiale:");
|
||||
|
||||
ImGui::InputInt("##RowsMatriceInitiale", &matrixSizeY);
|
||||
if (ImGui::InputInt("##RowsMatriceInitiale", &matrixSizeY))
|
||||
refresh = true;
|
||||
matrixSizeY = std::max(1, matrixSizeY);
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("Lignes");
|
||||
|
||||
|
||||
ImGui::InputInt("##ColumnsMatriceInitiale", &matrixSizeX);
|
||||
if (ImGui::InputInt("##ColumnsMatriceInitiale", &matrixSizeX))
|
||||
refresh = true;
|
||||
matrixSizeX = std::max(1, matrixSizeX);
|
||||
ImGui::SameLine();
|
||||
ImGui::Text("Colonnes");
|
||||
|
||||
ImGui::BeginChild("MatriceInitiale", ImVec2(topLeftWindowSize.x, io.DisplaySize.y * 0.7f), false);
|
||||
ImGui::NewLine();
|
||||
|
||||
// ImGui::BeginChild("MatriceInitiale", ImVec2(topLeftWindowSize.x, io.DisplaySize.y * 0.7f), false);
|
||||
|
||||
// Resize matrixValues and initialize new elements to 0
|
||||
|
||||
matrixValues.resize(matrixSizeY);
|
||||
for (auto& row : matrixValues) {
|
||||
row.resize(matrixSizeX, 0);
|
||||
if (refresh) {
|
||||
matrixValues.resize(matrixSizeY);
|
||||
for (auto& row : matrixValues) {
|
||||
row.resize(matrixSizeX, 0);
|
||||
}
|
||||
}
|
||||
|
||||
for (int y = 0; y < matrixSizeY; y++) {
|
||||
@@ -82,19 +101,38 @@ void PivotGui::Render() {
|
||||
if (x > 0)
|
||||
ImGui::SameLine();
|
||||
ImGui::PushID(y * matrixSizeX + x);
|
||||
ImGui::PushItemWidth(30); // Adjust this value to change the cell size
|
||||
ImGui::InputInt("", &matrixValues[y][x], 0, 0, ImGuiInputTextFlags_CharsDecimal);
|
||||
ImGui::PushItemWidth(60); // 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::EndChild(); // End Matrice initiale
|
||||
ImGui::NewLine();
|
||||
|
||||
ImGui::Text("Matrice échelonnée:");
|
||||
|
||||
// Convert the "result" string back to a matrix
|
||||
Matrix resultMatrix = LoadMatrixFromStdVect(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();
|
||||
}
|
||||
}
|
||||
|
||||
ImGui::End(); // End fenetre top left
|
||||
|
||||
@@ -106,51 +144,39 @@ void PivotGui::Render() {
|
||||
|
||||
// rajouter le code pour la partie top right
|
||||
|
||||
static std::string result = "RIEN";
|
||||
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 (ImGui::Button("Calcul")) {
|
||||
if (refresh) {
|
||||
|
||||
// Calculate the kernel and image
|
||||
Vect image = solver.Image(LoadMatrixFromStdVect(matrixValues));
|
||||
Matrix linearSystem = image.GetLinearSystem();
|
||||
|
||||
// Create a column matrix with as many elements as the number of columns in the linear system
|
||||
std::vector<std::string> columnMatrix(linearSystem.GetColumnCount());
|
||||
for (size_t i = 0; i < linearSystem.GetColumnCount(); ++i) {
|
||||
columnMatrix[i] = std::string(1, 'a' + static_cast<char>(i));
|
||||
}
|
||||
|
||||
// Multiply the linear system matrix by the column matrix
|
||||
std::vector<std::string> resultMatrix(linearSystem.GetRawCount());
|
||||
for (size_t i = 0; i < linearSystem.GetRawCount(); ++i) {
|
||||
for (size_t j = 0; j < linearSystem.GetColumnCount(); ++j) {
|
||||
resultMatrix[i] += std::to_string(static_cast<int>(linearSystem.at(i, j))) + "*" + columnMatrix[j] + " + ";
|
||||
}
|
||||
resultMatrix[i] = resultMatrix[i].substr(0, resultMatrix[i].length() - 3) + " = 0";
|
||||
}
|
||||
|
||||
// Store the equationsResult strings in the global variable
|
||||
equationsResultImage = "Equations cartesiennes de l'espace vectoriel (Image):\n";
|
||||
for (const auto& equation : resultMatrix) {
|
||||
equationsResultImage += equation + "\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);
|
||||
"Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" + "Image: " + "\n" +
|
||||
PrintVect(image);
|
||||
}
|
||||
|
||||
ImGui::End(); // End fenetre bas
|
||||
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::End(); // End fenetre top right
|
||||
}
|
||||
|
||||
void PivotGui::Destroy() {}
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
|
||||
namespace PivotGui {
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
|
||||
/**
|
||||
* \def TEST_SUCCESSFUL
|
||||
@@ -37,6 +38,5 @@
|
||||
if (!static_cast<bool>(__VA_ARGS__)) { \
|
||||
std::cout << __FILE__ << ":" << __LINE__ << ": " << __FUNCTION_NAME__ << ": Assertion failed !\n"; \
|
||||
std::cout << " " << __LINE__ << " |\t" << #__VA_ARGS__ << std::endl; \
|
||||
std::exit(TEST_FAILED); \
|
||||
throw std::runtime_error("Assertion failed !"); \
|
||||
}
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
static constexpr int EXECUTION_COUNT = 100;
|
||||
static constexpr int EXECUTION_COUNT = 1000;
|
||||
static constexpr int KERNEL_CHECKS = 100;
|
||||
static constexpr int MATRIX_MAX_SIZE = 100;
|
||||
static constexpr int MATRIX_MAX_SIZE = 9;
|
||||
|
||||
static const Solver solver;
|
||||
|
||||
static unsigned int GetRandomInt() {
|
||||
return rand() % MATRIX_MAX_SIZE + 1;
|
||||
static int GetRandomInt() {
|
||||
return rand() % 11 - 5;
|
||||
}
|
||||
|
||||
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
|
||||
@@ -28,8 +28,8 @@ static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
|
||||
return matrix;
|
||||
}
|
||||
|
||||
static void Test() {
|
||||
Matrix matrix = GetRandomMatrix(GetRandomInt(), GetRandomInt());
|
||||
static bool Test() {
|
||||
Matrix matrix = GetRandomMatrix(rand() % MATRIX_MAX_SIZE + 1, rand() % MATRIX_MAX_SIZE + 1);
|
||||
|
||||
for (std::size_t i = 0; i < matrix.GetRawCount(); i++) {
|
||||
for (std::size_t j = 0; j < matrix.GetColumnCount(); j++) {
|
||||
@@ -57,12 +57,13 @@ static void Test() {
|
||||
Vect kernel2 = solver.Kernel(kernel.GetLinearSystem());
|
||||
|
||||
test_assert(kernel == kernel2);
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
srand(time(0));
|
||||
|
||||
std::vector<std::future<void>> results;
|
||||
std::vector<std::future<bool>> results;
|
||||
|
||||
// appelle la fonction Test() en parallèle
|
||||
for (int i = 0; i < EXECUTION_COUNT; i++) {
|
||||
@@ -70,5 +71,10 @@ int main() {
|
||||
results.push_back(std::move(handle));
|
||||
}
|
||||
|
||||
for (auto& result : results) {
|
||||
if (!result.get())
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
@@ -8,18 +9,48 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
void TestRectangular() {
|
||||
Matrix mat2 = {2, 4, {
|
||||
1, 1, 1, 1,
|
||||
1, -1, -1, 2
|
||||
}};
|
||||
const static int EXECUTION_COUNT = 10000;
|
||||
static constexpr int MATRIX_MAX_SIZE = 7;
|
||||
|
||||
VectAffine aff {Matrix::ColumnVector({0, -1, 1}), Matrix::ColumnVector({3.0 / 2.0, 0, -1.0 / 2.0})};
|
||||
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;
|
||||
|
||||
std::cout << solver.RectangularSystem(std::move(mat2), Matrix::ColumnVector({1, 2})).GetLinearSystem() << std::endl;
|
||||
std::cout << aff.GetLinearSystem() << std::endl;
|
||||
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() {
|
||||
@@ -41,13 +72,17 @@ void TestKernelImage() {
|
||||
|
||||
Matrix copy = mat;
|
||||
|
||||
test_assert(solver.Image(std::move(copy)) == image);
|
||||
test_assert(solver.Kernel(std::move(mat)) == noyau);
|
||||
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();
|
||||
TestRectangular();
|
||||
RandomRectangular();
|
||||
return 0;
|
||||
}
|
||||
@@ -1,6 +1,27 @@
|
||||
#include "Vect.h"
|
||||
#include "test_assert.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
const static int EXECUTION_COUNT = 100000;
|
||||
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 TestVect() {
|
||||
Vect vect1 {{3, 2, {
|
||||
1, 2,
|
||||
@@ -41,8 +62,23 @@ 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;
|
||||
}
|
||||
Reference in New Issue
Block a user