vraiment la merde
This commit is contained in:
@ -35,7 +35,7 @@ impl<'a> BitFlipDecoder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
println!("poid syndome: {s_w}");
|
||||
// println!("poid syndome: {s_w}");
|
||||
// Aucune erreurs
|
||||
if s_w == 0 {
|
||||
return Some(curr_bits);
|
||||
|
||||
@ -7,6 +7,7 @@ mod encoder;
|
||||
mod matrix;
|
||||
mod simulation;
|
||||
mod tanner;
|
||||
mod utils;
|
||||
|
||||
use analysis::{AnalysisConfig, Analyzer, DecoderAlgorithm};
|
||||
|
||||
@ -28,5 +29,6 @@ fn main() {
|
||||
// let res = Analyzer::run_batch(config);
|
||||
// Analyzer::save_csv(&res, "ldpc_analysis_results.csv");
|
||||
|
||||
simulation::run_simulation(300, 3, 6, 0.012);
|
||||
let message = "Je";
|
||||
simulation::run_simulation(message, 3, 6, 0.02);
|
||||
}
|
||||
|
||||
@ -6,12 +6,15 @@ use crate::code::{self, LdpcCode};
|
||||
use crate::construction::random::{generate_random_h, generate_random_h_for_k};
|
||||
use crate::decoder::bit_flip::BitFlipDecoder;
|
||||
use crate::encoder::dense::DenseEncoder;
|
||||
use crate::utils;
|
||||
use rand::{Rng, RngExt};
|
||||
|
||||
pub fn run_simulation(k: usize, wc: usize, wr: usize, error_prob: f64) {
|
||||
pub fn run_simulation(text: &str, wc: usize, wr: usize, error_prob: f64) {
|
||||
let mut message_bits = utils::string_to_bits(text);
|
||||
let k = message_bits.len();
|
||||
println!(
|
||||
"\nSimulation LDPC : k = {} bits, wc = {}, wr = {}, p = {:.2}",
|
||||
k, wc, wr, error_prob
|
||||
"\nSimulation LDPC : k = {} bits, wc = {}, wr = {}, p = {:.2}, text : {}",
|
||||
k, wc, wr, error_prob, text
|
||||
);
|
||||
|
||||
println!("Construction");
|
||||
@ -68,17 +71,22 @@ pub fn run_simulation(k: usize, wc: usize, wr: usize, error_prob: f64) {
|
||||
|
||||
match decoder.decode(&received, max_iter) {
|
||||
Some(decoded) => {
|
||||
let decoded_message = &decoded[0..encoder.k];
|
||||
let res_text = utils::bits_to_string(decoded_message);
|
||||
if decoded == codeword {
|
||||
println!(" -> Réussite");
|
||||
} else {
|
||||
println!(" -> Echec : le decoder a convergé vers un mauvais codeword");
|
||||
}
|
||||
println!(" -> Texte recu : {}", res_text);
|
||||
}
|
||||
None => {
|
||||
let failed_text = utils::bits_to_string(&received[0..encoder.k]);
|
||||
println!(
|
||||
" -> Echec : impossible decorriger après {} itérations",
|
||||
max_iter
|
||||
);
|
||||
println!(" -> Texte recu : {}", failed_text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
26
Code/ldpc/src/utils.rs
Normal file
26
Code/ldpc/src/utils.rs
Normal file
@ -0,0 +1,26 @@
|
||||
pub fn string_to_bits(s: &str) -> Vec<u8> {
|
||||
let mut bits = Vec::new();
|
||||
for byte in s.as_bytes() {
|
||||
for i in (0..8).rev() {
|
||||
bits.push((byte >> i) & 1);
|
||||
}
|
||||
}
|
||||
bits
|
||||
}
|
||||
|
||||
pub fn bits_to_string(bits: &[u8]) -> String {
|
||||
let mut bytes = Vec::new();
|
||||
for chunk in bits.chunks(8) {
|
||||
if chunk.len() < 8 {
|
||||
break;
|
||||
}
|
||||
let mut byte = 0u8;
|
||||
for (i, &bit) in chunk.iter().enumerate() {
|
||||
if bit == 1 {
|
||||
byte |= 1 << (7 - i);
|
||||
}
|
||||
}
|
||||
bytes.push(byte);
|
||||
}
|
||||
String::from_utf8_lossy(&bytes).into_owned()
|
||||
}
|
||||
Reference in New Issue
Block a user