Compare commits
18 Commits
76fa9fb329
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 6b9987d561 | |||
| 5584df6486 | |||
| 413ff4fce4 | |||
| 49e4d4b1e2 | |||
| 9b84b9bf59 | |||
| bb650e4f2d | |||
| e784a7b471 | |||
| 9a5b99a79d | |||
| ffa0ebf4cb | |||
| 4b3e878bc5 | |||
| 47f250170e | |||
| a4036ae36d | |||
| e6d0785009 | |||
| a135df2e96 | |||
| d9e49d1319 | |||
| e127ff8c29 | |||
| 9b423f9c83 | |||
| fa7e70a437 |
@@ -10,7 +10,7 @@ jobs:
|
|||||||
- name: Install opengl
|
- name: Install opengl
|
||||||
run: |
|
run: |
|
||||||
apt update
|
apt update
|
||||||
apt install libgl-dev -y
|
apt install -y libsdl2-dev
|
||||||
|
|
||||||
- name: Check out repository code
|
- name: Check out repository code
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
@@ -20,7 +20,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
xmake-version: latest
|
xmake-version: latest
|
||||||
actions-cache-folder: '.xmake-cache'
|
actions-cache-folder: '.xmake-cache'
|
||||||
actions-cache-key: 'ubuntu-xmake'
|
actions-cache-key: 'xmake-ubuntu'
|
||||||
|
|
||||||
- name: Cache
|
- name: Cache
|
||||||
uses: actions/cache@v4
|
uses: actions/cache@v4
|
||||||
|
|||||||
21
LICENSE.txt
Normal file
21
LICENSE.txt
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
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.
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <gmp.h>
|
|
||||||
|
|
||||||
/**
|
|
||||||
* \class BigInt
|
|
||||||
* \brief Représente un entier d'une taille quelconque
|
|
||||||
* \warning Prend énormément de place en mémoire. À utiliser avec précaution !
|
|
||||||
*/
|
|
||||||
class BigInt {
|
|
||||||
private:
|
|
||||||
mpz_t m_Data;
|
|
||||||
|
|
||||||
public:
|
|
||||||
BigInt(std::string&& a_Number);
|
|
||||||
|
|
||||||
BigInt(long a_Number = 0);
|
|
||||||
|
|
||||||
BigInt(const BigInt& a_Copy);
|
|
||||||
|
|
||||||
BigInt(BigInt&& a_Move);
|
|
||||||
|
|
||||||
~BigInt();
|
|
||||||
|
|
||||||
BigInt operator+(const BigInt& a_Other);
|
|
||||||
|
|
||||||
BigInt operator-(const BigInt& a_Other);
|
|
||||||
|
|
||||||
BigInt operator*(const BigInt& a_Other);
|
|
||||||
|
|
||||||
BigInt operator/(const BigInt& a_Other);
|
|
||||||
|
|
||||||
BigInt operator+=(const BigInt& a_Other);
|
|
||||||
|
|
||||||
BigInt operator-=(const BigInt& a_Other);
|
|
||||||
|
|
||||||
BigInt operator*=(const BigInt& a_Other);
|
|
||||||
|
|
||||||
BigInt operator/=(const BigInt& a_Other);
|
|
||||||
|
|
||||||
bool operator==(const BigInt& a_Other);
|
|
||||||
|
|
||||||
void operator=(const BigInt& a_Other);
|
|
||||||
|
|
||||||
const std::string ToString() const;
|
|
||||||
|
|
||||||
bool IsEqualZero() const;
|
|
||||||
};
|
|
||||||
@@ -10,14 +10,10 @@
|
|||||||
class Matrix;
|
class Matrix;
|
||||||
class Vect;
|
class Vect;
|
||||||
class VectAffine;
|
class VectAffine;
|
||||||
class BigInt;
|
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& stream, const Matrix& mat);
|
std::ostream& operator<<(std::ostream& stream, const Matrix& mat);
|
||||||
std::istream& operator>>(std::istream& stream, Matrix& mat);
|
std::istream& operator>>(std::istream& stream, Matrix& mat);
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& stream, const BigInt& nbre);
|
|
||||||
std::istream& operator>>(std::istream& stream, BigInt& nbre);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Charge une matrice à partir d'un fichier
|
* \brief Charge une matrice à partir d'un fichier
|
||||||
* \param fileName Le chemin du fichier à charger
|
* \param fileName Le chemin du fichier à charger
|
||||||
|
|||||||
@@ -10,7 +10,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "BigInt.h"
|
#include "NR.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \class Matrix
|
* \class Matrix
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
class Matrix {
|
class Matrix {
|
||||||
public:
|
public:
|
||||||
typedef long double Element;
|
typedef NR Element;
|
||||||
typedef std::vector<Element>::iterator iterator;
|
typedef std::vector<Element>::iterator iterator;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -171,6 +171,6 @@ inline bool IsEqualZero(const long& var) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
inline bool IsEqualZero(const BigInt& var) {
|
inline bool IsEqualZero(const NR& var) {
|
||||||
return var.IsEqualZero();
|
return var == 0;
|
||||||
}
|
}
|
||||||
17
include/NR.h
17
include/NR.h
@@ -3,17 +3,20 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class NR {
|
class NR {
|
||||||
|
public:
|
||||||
|
using Int = long long;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_Numerator;
|
Int m_Numerator;
|
||||||
int m_Denominator; // has to be > 0, sign is carried by the numerator
|
Int m_Denominator; // has to be > 0, sign is carried by the numerator
|
||||||
|
|
||||||
public:
|
public:
|
||||||
NR();
|
NR();
|
||||||
NR(int entier);
|
NR(Int entier);
|
||||||
NR(int numerator, int denominator); // check if denominator != 0
|
NR(Int numerator, Int denominator); // check if denominator != 0
|
||||||
|
|
||||||
int GetNumerator() const;
|
Int GetNumerator() const;
|
||||||
int GetDenominator() 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;
|
||||||
@@ -43,5 +46,3 @@ class NR {
|
|||||||
private:
|
private:
|
||||||
void Reduce();
|
void Reduce();
|
||||||
};
|
};
|
||||||
|
|
||||||
int PGCD(int x, int y);
|
|
||||||
|
|||||||
@@ -105,12 +105,6 @@ class VectAffine {
|
|||||||
*/
|
*/
|
||||||
bool IsElementOf(const Matrix& a_Vector) const;
|
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 {
|
bool operator==(const VectAffine& a_VectAffine) const {
|
||||||
return m_Origin == a_VectAffine.GetOrigin() && m_Base == a_VectAffine.GetBase();
|
return m_Origin == a_VectAffine.GetOrigin() && m_Base == a_VectAffine.GetBase();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,86 +0,0 @@
|
|||||||
#include "BigInt.h"
|
|
||||||
|
|
||||||
#include <cassert>
|
|
||||||
|
|
||||||
BigInt::~BigInt() {
|
|
||||||
mpz_clear(m_Data);
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt::BigInt(BigInt&& a_Move) {
|
|
||||||
std::swap(m_Data, a_Move.m_Data);
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt::BigInt(std::string&& a_Number) {
|
|
||||||
mpz_init_set_str(m_Data, a_Number.c_str(), 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt::BigInt(long a_Number) {
|
|
||||||
mpz_init_set_si(m_Data, a_Number);
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt::BigInt(const BigInt& a_Copy) {
|
|
||||||
mpz_init_set(m_Data, a_Copy.m_Data);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BigInt::operator=(const BigInt& a_Other) {
|
|
||||||
mpz_init_set(m_Data, a_Other.m_Data);
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt BigInt::operator+(const BigInt& a_Other) {
|
|
||||||
BigInt result = *this;
|
|
||||||
result += a_Other;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt BigInt::operator-(const BigInt& a_Other) {
|
|
||||||
BigInt result = *this;
|
|
||||||
result -= a_Other;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt BigInt::operator*(const BigInt& a_Other) {
|
|
||||||
BigInt result = *this;
|
|
||||||
result *= a_Other;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt BigInt::operator/(const BigInt& a_Other) {
|
|
||||||
BigInt result = *this;
|
|
||||||
result /= a_Other;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt BigInt::operator+=(const BigInt& a_Other) {
|
|
||||||
mpz_add(m_Data, m_Data, a_Other.m_Data);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt BigInt::operator-=(const BigInt& a_Other) {
|
|
||||||
mpz_sub(m_Data, m_Data, a_Other.m_Data);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt BigInt::operator*=(const BigInt& a_Other) {
|
|
||||||
mpz_mul(m_Data, m_Data, a_Other.m_Data);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
BigInt BigInt::operator/=(const BigInt& a_Other) {
|
|
||||||
mpz_divexact(m_Data, m_Data, a_Other.m_Data);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BigInt::operator==(const BigInt& a_Other) {
|
|
||||||
return mpz_cmp(m_Data, a_Other.m_Data) == 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
const std::string BigInt::ToString() const {
|
|
||||||
std::string result;
|
|
||||||
result.reserve(mpz_sizeinbase(m_Data, 10) + 2);
|
|
||||||
mpz_get_str(result.data(), 10, m_Data);
|
|
||||||
return result.c_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool BigInt::IsEqualZero() const {
|
|
||||||
return mpz_cmp_si(m_Data, 0) == 0;
|
|
||||||
}
|
|
||||||
12
src/IO.cpp
12
src/IO.cpp
@@ -31,18 +31,6 @@ std::istream& operator>>(std::istream& stream, Matrix& mat) {
|
|||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& stream, const BigInt& nbre) {
|
|
||||||
stream << nbre.ToString();
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::istream& operator>>(std::istream& stream, BigInt& nbre) {
|
|
||||||
long value;
|
|
||||||
stream >> value;
|
|
||||||
nbre = BigInt(value);
|
|
||||||
return stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
Matrix LoadMatrix(const std::string& fileName) {
|
Matrix LoadMatrix(const std::string& fileName) {
|
||||||
std::ifstream in {fileName};
|
std::ifstream in {fileName};
|
||||||
if (!in) {
|
if (!in) {
|
||||||
|
|||||||
@@ -71,11 +71,7 @@ Matrix Matrix::RawVector(std::initializer_list<Element>&& a_Elements) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::Fill(Element a_Element) {
|
void Matrix::Fill(Element a_Element) {
|
||||||
for (std::size_t i = 0; i < m_Raws; i++) {
|
std::fill(GetLineIterator(0), GetLineIterator(m_Raws), a_Element);
|
||||||
for (std::size_t j = 0; j < m_Columns; j++) {
|
|
||||||
at(i, j) = a_Element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Matrix::Augment(const Matrix& a_Right) {
|
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) {
|
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];
|
return m_Data[a_Raw * m_Columns + a_Column];
|
||||||
}
|
}
|
||||||
|
|
||||||
Matrix::Element Matrix::at(std::size_t a_Raw, std::size_t a_Column) const {
|
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];
|
return m_Data[a_Raw * m_Columns + a_Column];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
43
src/NR.cpp
43
src/NR.cpp
@@ -3,7 +3,7 @@
|
|||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
int PGCD(int x, int y) {
|
NR::Int PGCD(NR::Int x, NR::Int y) {
|
||||||
if (x == 0 || y == 0)
|
if (x == 0 || y == 0)
|
||||||
return 1;
|
return 1;
|
||||||
else if (x % y == 0)
|
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() : 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)) {
|
m_Numerator((denominator > 0) ? numerator : -numerator), m_Denominator(std::abs(denominator)) {
|
||||||
assert(denominator != 0);
|
|
||||||
Reduce();
|
Reduce();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NR::Reduce() {
|
void NR::Reduce() {
|
||||||
int divisor = PGCD(m_Denominator, m_Numerator);
|
NR::Int divisor = PGCD(m_Denominator, m_Numerator);
|
||||||
m_Denominator /= divisor;
|
m_Denominator /= divisor;
|
||||||
m_Numerator /= divisor;
|
m_Numerator /= divisor;
|
||||||
|
assert(m_Denominator != 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
NR NR::Inverse() const {
|
NR NR::Inverse() const {
|
||||||
@@ -33,11 +33,11 @@ NR NR::Inverse() const {
|
|||||||
return {m_Denominator, m_Numerator};
|
return {m_Denominator, m_Numerator};
|
||||||
}
|
}
|
||||||
|
|
||||||
int NR::GetNumerator() const {
|
NR::Int NR::GetNumerator() const {
|
||||||
return m_Numerator;
|
return m_Numerator;
|
||||||
}
|
}
|
||||||
|
|
||||||
int NR::GetDenominator() const {
|
NR::Int NR::GetDenominator() const {
|
||||||
return m_Denominator;
|
return m_Denominator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,48 +66,57 @@ bool NR::operator>=(const NR& opNR) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::ostream& operator<<(std::ostream& os, const NR& opNR) {
|
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;
|
return os;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::istream& operator>>(std::istream& is, NR& opNR) {
|
std::istream& operator>>(std::istream& is, NR& opNR) {
|
||||||
char slash;
|
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();
|
opNR.Reduce();
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
NR NR::operator+(const NR& opNR) const {
|
NR NR::operator+(const NR& opNR) const {
|
||||||
int num, den;
|
Int num, den;
|
||||||
num = m_Numerator * opNR.GetDenominator();
|
num = m_Numerator * opNR.GetDenominator();
|
||||||
den = m_Denominator * opNR.GetDenominator();
|
den = m_Denominator * opNR.GetDenominator();
|
||||||
num += (opNR.GetNumerator() * m_Denominator);
|
num += (opNR.GetNumerator() * m_Denominator);
|
||||||
NR result(num, den);
|
NR result(num, num == 0 ? 1 : den);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NR NR::operator-(const NR& opNR) const {
|
NR NR::operator-(const NR& opNR) const {
|
||||||
int num, den;
|
Int num, den;
|
||||||
num = m_Numerator * opNR.GetDenominator();
|
num = m_Numerator * opNR.GetDenominator();
|
||||||
den = m_Denominator * opNR.GetDenominator();
|
den = m_Denominator * opNR.GetDenominator();
|
||||||
num -= (opNR.GetNumerator() * m_Denominator);
|
num -= (opNR.GetNumerator() * m_Denominator);
|
||||||
NR result(num, den);
|
NR result(num, num == 0 ? 1 : den);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NR NR::operator*(const NR& opNR) const {
|
NR NR::operator*(const NR& opNR) const {
|
||||||
int num, den;
|
Int num, den;
|
||||||
num = m_Numerator * opNR.GetNumerator();
|
num = m_Numerator * opNR.GetNumerator();
|
||||||
den = m_Denominator * opNR.GetDenominator();
|
den = m_Denominator * opNR.GetDenominator();
|
||||||
NR result(num, den);
|
NR result(num, num == 0 ? 1 : den);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
NR NR::operator/(const NR& opNR) const {
|
NR NR::operator/(const NR& opNR) const {
|
||||||
int num, den;
|
Int num, den;
|
||||||
num = m_Numerator * opNR.GetDenominator();
|
num = m_Numerator * opNR.GetDenominator();
|
||||||
den = m_Denominator * opNR.GetNumerator();
|
den = m_Denominator * opNR.GetNumerator();
|
||||||
NR result(num, den);
|
NR result(num, num == 0 ? 1 : den);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ Vect Solver::Kernel(Matrix&& a_Matrix) const {
|
|||||||
|
|
||||||
a_Matrix.Transpose();
|
a_Matrix.Transpose();
|
||||||
a_Matrix.Augment(Matrix::Identity(a_Matrix.GetRawCount()));
|
a_Matrix.Augment(Matrix::Identity(a_Matrix.GetRawCount()));
|
||||||
Gauss::GaussJordan(a_Matrix, false, false);
|
Gauss::GaussJordan(a_Matrix, false, true);
|
||||||
a_Matrix.Transpose();
|
a_Matrix.Transpose();
|
||||||
|
|
||||||
// nombre de colonnes non nulles
|
// nombre de colonnes non nulles
|
||||||
@@ -45,14 +45,21 @@ VectAffine Solver::RectangularSystem(Matrix&& a_MatrixA, const Matrix& a_VectorB
|
|||||||
Vect noyau = solver.Kernel(std::move(a_MatrixA));
|
Vect noyau = solver.Kernel(std::move(a_MatrixA));
|
||||||
Matrix origin = mat.SubMatrix(0, mat.GetColumnCount() - 1, mat.GetRawCount(), 1);
|
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};
|
Matrix fullOrigin {mat.GetColumnCount() - 1, 1};
|
||||||
for (std::size_t i = 0; i < mat.GetRawCount(); i++) {
|
for (std::size_t i = 0; i < mat.GetRawCount(); i++) {
|
||||||
int pivot_index = FirstNotNullElementIndexOnLine(mat, i);
|
int pivot_index = FirstNotNullElementIndexOnLine(mat, i);
|
||||||
if(pivot_index >= 0){
|
|
||||||
fullOrigin.at(pivot_index, 0) = origin.at(i, 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};
|
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)) {
|
Vect::Vect(Matrix&& a_Matrix) : m_Data(std::move(a_Matrix)) {
|
||||||
m_Data.Transpose();
|
m_Data.Transpose();
|
||||||
Gauss::GaussJordan(m_Data, false, false);
|
Gauss::GaussJordan(m_Data, false, true);
|
||||||
m_Data.Transpose();
|
m_Data.Transpose();
|
||||||
Simplify();
|
Simplify();
|
||||||
}
|
}
|
||||||
@@ -88,11 +88,3 @@ VectAffine::VectAffine(const Vect& a_Base, const Matrix& a_Origin) :
|
|||||||
bool VectAffine::IsElementOf(const Matrix& a_Vector) const {
|
bool VectAffine::IsElementOf(const Matrix& a_Vector) const {
|
||||||
return m_Base.IsElementOf(a_Vector - m_Origin);
|
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,11 +1,45 @@
|
|||||||
#include "PivotGui.h"
|
#include "PivotGui.h"
|
||||||
|
|
||||||
|
#include "Gauss.h"
|
||||||
#include "Matrix.h"
|
#include "Matrix.h"
|
||||||
#include "Solver.h"
|
#include "Solver.h"
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
static std::string equationsResultImage;
|
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) {
|
static Matrix LoadMatrixFromStdVect(const std::vector<std::vector<int>>& data) {
|
||||||
Matrix result {data.size(), data.empty() ? 0 : data[0].size()};
|
Matrix result {data.size(), data.empty() ? 0 : data[0].size()};
|
||||||
for (std::size_t i = 0; i < result.GetRawCount(); i++) {
|
for (std::size_t i = 0; i < result.GetRawCount(); i++) {
|
||||||
@@ -16,6 +50,25 @@ static Matrix LoadMatrixFromStdVect(const std::vector<std::vector<int>>& data) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string ElementToString(Matrix::Element e) {
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << 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) {
|
static std::string PrintVect(const Vect& vect) {
|
||||||
if (vect.GetCardinal() == 0)
|
if (vect.GetCardinal() == 0)
|
||||||
return "{0}";
|
return "{0}";
|
||||||
@@ -23,112 +76,171 @@ static std::string PrintVect(const Vect& vect) {
|
|||||||
std::string result = "Vect( ";
|
std::string result = "Vect( ";
|
||||||
for (std::size_t i = 0; i < vect.GetCardinal(); i++) {
|
for (std::size_t i = 0; i < vect.GetCardinal(); i++) {
|
||||||
Matrix vector = vect.GetVector(i);
|
Matrix vector = vect.GetVector(i);
|
||||||
result += " (";
|
result += PrintRawMatrix(vector);
|
||||||
for (std::size_t j = 0; j < vect.GetDimension(); j++) {
|
result += ", ";
|
||||||
result += std::to_string(static_cast<int>(vector.at(j, 0))) + ", ";
|
|
||||||
}
|
|
||||||
result += " ), ";
|
|
||||||
}
|
}
|
||||||
|
result = result.substr(0, result.size() - 2);
|
||||||
result += " )";
|
result += " )";
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PivotGui::Init() {}
|
void PivotGui::Init() {}
|
||||||
|
|
||||||
void PivotGui::Render() {
|
static void RenderLeftSystemChild(bool& refresh, GuiMatrix& system, GuiMatrix& origin) {
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
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 = "";
|
||||||
|
|
||||||
static std::vector<std::vector<int>> matrixValues;
|
|
||||||
static int matrixSizeX = 4;
|
|
||||||
static int matrixSizeY = 4;
|
|
||||||
static Solver solver;
|
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
|
// divisions des fenetres
|
||||||
ImVec2 topLeftWindowSize(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.8f);
|
ImVec2 topLeftWindowSize(ImGui::GetContentRegionAvail().x * 0.5f, 0);
|
||||||
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
|
// Begin fenetre top left
|
||||||
ImGui::SetNextWindowSize(topLeftWindowSize);
|
// ImGui::SetNextWindowPos(ImVec2(0, 0)); // Position at the top-left corner
|
||||||
ImGui::SetNextWindowPos(ImVec2(0, 0)); // Position at the top-left corner
|
ImGui::BeginChild("Left Top Window", topLeftWindowSize, ImGuiChildFlags_Border);
|
||||||
ImGui::Begin("Left Top Window", nullptr,
|
/*ImGui::Begin(, nullptr,
|
||||||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
||||||
|
*/
|
||||||
|
// ImGui::BeginTabBar("MainMenu");
|
||||||
|
|
||||||
// Get window position
|
// Get window position
|
||||||
ImVec2 windowPos = ImGui::GetWindowPos();
|
ImVec2 windowPos = ImGui::GetWindowPos();
|
||||||
|
|
||||||
ImGui::Text("Matrice initiale:");
|
ImGui::Text("Matrice initiale:");
|
||||||
|
|
||||||
ImGui::InputInt("##RowsMatriceInitiale", &matrixSizeY);
|
if (ImGui::InputInt("##RowsMatriceInitiale", &guiMatrix.matrixSizeY))
|
||||||
matrixSizeY = std::max(1, matrixSizeY);
|
refresh = true;
|
||||||
|
guiMatrix.matrixSizeY = std::max(1, guiMatrix.matrixSizeY);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Text("Lignes");
|
ImGui::Text("Lignes");
|
||||||
|
|
||||||
|
|
||||||
ImGui::InputInt("##ColumnsMatriceInitiale", &matrixSizeX);
|
if (ImGui::InputInt("##ColumnsMatriceInitiale", &guiMatrix.matrixSizeX))
|
||||||
matrixSizeX = std::max(1, matrixSizeX);
|
refresh = true;
|
||||||
|
guiMatrix.matrixSizeX = std::max(1, guiMatrix.matrixSizeX);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Text("Colonnes");
|
ImGui::Text("Colonnes");
|
||||||
|
|
||||||
ImGui::NewLine();
|
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
|
// Resize matrixValues and initialize new elements to 0
|
||||||
|
|
||||||
matrixValues.resize(matrixSizeY);
|
RenderMatrix(refresh, guiMatrix);
|
||||||
for (auto& row : matrixValues) {
|
|
||||||
row.resize(matrixSizeX, 0);
|
// 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
|
||||||
}
|
}
|
||||||
|
|
||||||
bool refresh = false;
|
|
||||||
|
|
||||||
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();
|
ImGui::PopID();
|
||||||
|
if (j < resultMatrix.GetColumnCount() - 1)
|
||||||
|
ImGui::SameLine();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display the equationsResult strings in the GUI if they are not empty
|
ImGui::EndChild();
|
||||||
if (!equationsResultImage.empty()) {
|
|
||||||
ImGui::TextWrapped(equationsResultImage.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::EndChild(); // End Matrice initiale
|
static void RenderRightGaussChild(bool& refresh, GuiMatrix& guiMatrix) {
|
||||||
|
static Solver solver;
|
||||||
ImGui::End(); // End fenetre top left
|
|
||||||
|
|
||||||
// Begin fenetre top right
|
// Begin fenetre top right
|
||||||
ImGui::SetNextWindowSize(topRightWindowSize);
|
// ImGui::SetNextWindowSize(topRightWindowSize);
|
||||||
ImGui::SetNextWindowPos(ImVec2(windowPos.x + topLeftWindowSize.x, 0)); // Position at the top-right corner
|
// ImGui::SetNextWindowPos(ImVec2(windowPos.x + topLeftWindowSize.x, 0)); // Position at the top-right corner
|
||||||
ImGui::Begin("Right Top Window", nullptr,
|
ImGui::BeginChild("Right Top Window", {0, 0}, ImGuiChildFlags_Border);
|
||||||
ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
// ImGui::Begin("Right Top Window", nullptr,
|
||||||
|
// ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoScrollbar);
|
||||||
|
|
||||||
// rajouter le code pour la partie top right
|
// rajouter le code pour la partie top right
|
||||||
|
|
||||||
static std::string result = "";
|
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) {
|
if (refresh) {
|
||||||
|
|
||||||
// Calculate the kernel and image
|
// Calculate the kernel and image
|
||||||
Vect image = solver.Image(LoadMatrixFromStdVect(matrixValues));
|
Vect image = solver.Image(LoadMatrixFromStdVect(guiMatrix.matrixValues));
|
||||||
Matrix linearSystem = image.GetLinearSystem();
|
Matrix linearSystem = image.GetLinearSystem();
|
||||||
|
|
||||||
// Store the equationsResult strings in the global variable
|
// Store the equationsResult strings in the global variable
|
||||||
@@ -136,17 +248,64 @@ void PivotGui::Render() {
|
|||||||
for (size_t i = 0; i < linearSystem.GetRawCount(); ++i) {
|
for (size_t i = 0; i < linearSystem.GetRawCount(); ++i) {
|
||||||
for (size_t j = 0; j < linearSystem.GetColumnCount(); ++j) {
|
for (size_t j = 0; j < linearSystem.GetColumnCount(); ++j) {
|
||||||
equationsResultImage +=
|
equationsResultImage +=
|
||||||
std::to_string(static_cast<int>(linearSystem.at(i, j))) + "*" + std::string {static_cast<char>('a' + j)} + " + ";
|
ElementToString(linearSystem.at(i, j)) + "*" + std::string {static_cast<char>('a' + j)} + " + ";
|
||||||
}
|
}
|
||||||
equationsResultImage = equationsResultImage.substr(0, equationsResultImage.size() - 3) + " = 0\n";
|
equationsResultImage = equationsResultImage.substr(0, equationsResultImage.size() - 3) + " = 0\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
result = std::string("Noyau: ") + "\n" + PrintVect(solver.Kernel(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" +
|
result = "\nNoyau: \n" + PrintVect(solver.Kernel(LoadMatrixFromStdVect(guiMatrix.matrixValues))) + "\n" +
|
||||||
"Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(matrixValues))) + "\n" + "\n" + "Image: " + "\n" +
|
"\n" + "Rang: " + "\n" + std::to_string(solver.Rank(LoadMatrixFromStdVect(guiMatrix.matrixValues))) + "\n" + "\n" +
|
||||||
PrintVect(image);
|
"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::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
|
||||||
}
|
}
|
||||||
|
|
||||||
void PivotGui::Destroy() {}
|
void PivotGui::Destroy() {}
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \def TEST_SUCCESSFUL
|
* \def TEST_SUCCESSFUL
|
||||||
@@ -37,6 +38,5 @@
|
|||||||
if (!static_cast<bool>(__VA_ARGS__)) { \
|
if (!static_cast<bool>(__VA_ARGS__)) { \
|
||||||
std::cout << __FILE__ << ":" << __LINE__ << ": " << __FUNCTION_NAME__ << ": Assertion failed !\n"; \
|
std::cout << __FILE__ << ":" << __LINE__ << ": " << __FUNCTION_NAME__ << ": Assertion failed !\n"; \
|
||||||
std::cout << " " << __LINE__ << " |\t" << #__VA_ARGS__ << std::endl; \
|
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 <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
static constexpr int EXECUTION_COUNT = 10;
|
static constexpr int EXECUTION_COUNT = 1000;
|
||||||
static constexpr int KERNEL_CHECKS = 100;
|
static constexpr int KERNEL_CHECKS = 100;
|
||||||
static constexpr int MATRIX_MAX_SIZE = 10;
|
static constexpr int MATRIX_MAX_SIZE = 9;
|
||||||
|
|
||||||
static const Solver solver;
|
static const Solver solver;
|
||||||
|
|
||||||
static unsigned int GetRandomInt() {
|
static int GetRandomInt() {
|
||||||
return rand() % MATRIX_MAX_SIZE + 1;
|
return rand() % 11 - 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
|
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;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void Test() {
|
static bool Test() {
|
||||||
Matrix matrix = GetRandomMatrix(GetRandomInt(), GetRandomInt());
|
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 i = 0; i < matrix.GetRawCount(); i++) {
|
||||||
for (std::size_t j = 0; j < matrix.GetColumnCount(); j++) {
|
for (std::size_t j = 0; j < matrix.GetColumnCount(); j++) {
|
||||||
@@ -57,12 +57,13 @@ static void Test() {
|
|||||||
Vect kernel2 = solver.Kernel(kernel.GetLinearSystem());
|
Vect kernel2 = solver.Kernel(kernel.GetLinearSystem());
|
||||||
|
|
||||||
test_assert(kernel == kernel2);
|
test_assert(kernel == kernel2);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
srand(time(0));
|
srand(time(0));
|
||||||
|
|
||||||
std::vector<std::future<void>> results;
|
std::vector<std::future<bool>> results;
|
||||||
|
|
||||||
// appelle la fonction Test() en parallèle
|
// appelle la fonction Test() en parallèle
|
||||||
for (int i = 0; i < EXECUTION_COUNT; i++) {
|
for (int i = 0; i < EXECUTION_COUNT; i++) {
|
||||||
@@ -70,5 +71,10 @@ int main() {
|
|||||||
results.push_back(std::move(handle));
|
results.push_back(std::move(handle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (auto& result : results) {
|
||||||
|
if (!result.get())
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include <algorithm>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@@ -8,21 +9,23 @@
|
|||||||
|
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
const static int EXECUTION_COUNT = 100;
|
const static int EXECUTION_COUNT = 10000;
|
||||||
static constexpr int MATRIX_MAX_SIZE = 5;
|
static constexpr int MATRIX_MAX_SIZE = 5;
|
||||||
|
|
||||||
static unsigned int GetRandomInt() {
|
static int GetRandomSize() {
|
||||||
return rand() % MATRIX_MAX_SIZE + 1;
|
return rand() % MATRIX_MAX_SIZE + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int GetRandomInt() {
|
||||||
|
return GetRandomSize();
|
||||||
|
}
|
||||||
|
|
||||||
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
|
static Matrix GetRandomMatrix(std::size_t a_Raw, std::size_t a_Column) {
|
||||||
Matrix matrix {a_Raw, a_Column};
|
Matrix matrix {a_Raw, a_Column};
|
||||||
|
|
||||||
for (std::size_t i = 0; i < matrix.GetRawCount(); i++) {
|
std::generate(matrix.GetLineIterator(0), matrix.GetLineIterator(a_Raw), []() {
|
||||||
for (std::size_t j = 0; j < matrix.GetColumnCount(); j++) {
|
return GetRandomInt();
|
||||||
matrix.at(i, j) = GetRandomInt();
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
@@ -34,25 +37,18 @@ void TestRectangular(const Matrix& system, const Matrix& origin) {
|
|||||||
|
|
||||||
for (std::size_t i = 0; i < solution.GetBase().GetCardinal(); i++) {
|
for (std::size_t i = 0; i < solution.GetBase().GetCardinal(); i++) {
|
||||||
Matrix vector = solution.GetBase().GetVector(i) + solution.GetOrigin();
|
Matrix vector = solution.GetBase().GetVector(i) + solution.GetOrigin();
|
||||||
for (std::size_t j = 0; j < system.GetRawCount(); j++) {
|
Matrix product = system * vector;
|
||||||
Matrix line = system.SubMatrix(j, 0, 1, system.GetColumnCount());
|
test_assert(product == origin);
|
||||||
test_assert(line * vector == origin.SubMatrix(j, 0, 1, 1));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RandomRectangular() {
|
void RandomRectangular() {
|
||||||
for (int i = 0; i < EXECUTION_COUNT; i++) {
|
for (int i = 0; i < EXECUTION_COUNT; i++) {
|
||||||
|
|
||||||
Matrix system = GetRandomMatrix(GetRandomInt(), GetRandomInt());
|
Matrix system = GetRandomMatrix(GetRandomSize(), GetRandomSize());
|
||||||
|
|
||||||
if (system.GetColumnCount() == system.GetRawCount())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
Matrix origin = GetRandomMatrix(system.GetRawCount(), 1);
|
Matrix origin = GetRandomMatrix(system.GetRawCount(), 1);
|
||||||
|
|
||||||
std::cout << "PIPI\n";
|
|
||||||
|
|
||||||
TestRectangular(system, origin);
|
TestRectangular(system, origin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -85,6 +81,7 @@ void TestKernelImage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
srand(time(0));
|
||||||
TestKernelImage();
|
TestKernelImage();
|
||||||
RandomRectangular();
|
RandomRectangular();
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -1,6 +1,27 @@
|
|||||||
#include "Vect.h"
|
#include "Vect.h"
|
||||||
#include "test_assert.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() {
|
void TestVect() {
|
||||||
Vect vect1 {{3, 2, {
|
Vect vect1 {{3, 2, {
|
||||||
1, 2,
|
1, 2,
|
||||||
@@ -41,8 +62,23 @@ void TestVectAffine() {
|
|||||||
test_assert(!aff.IsElementOf(Matrix::ColumnVector({1, 2, 3})));
|
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() {
|
int main() {
|
||||||
|
srand(time(0));
|
||||||
TestVect();
|
TestVect();
|
||||||
TestVectAffine();
|
TestVectAffine();
|
||||||
|
TestLinearSystem();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
11
xmake.lua
11
xmake.lua
@@ -1,13 +1,18 @@
|
|||||||
|
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_rules("mode.debug", "mode.release")
|
||||||
|
|
||||||
add_requires("libsdl 2.28.3", {configs = {sdlmain = false}})
|
|
||||||
add_requires("imgui", {configs = {sdl2_no_renderer = true, opengl3 = true}})
|
add_requires("imgui", {configs = {sdl2_no_renderer = true, opengl3 = true}})
|
||||||
add_requires("gmp");
|
|
||||||
|
|
||||||
set_languages("c++20")
|
set_languages("c++20")
|
||||||
set_warnings("all")
|
set_warnings("all")
|
||||||
add_includedirs("include")
|
add_includedirs("include")
|
||||||
add_packages("gmp")
|
|
||||||
|
|
||||||
-- Solver Library
|
-- Solver Library
|
||||||
target("Pivot")
|
target("Pivot")
|
||||||
|
|||||||
Reference in New Issue
Block a user