Skip to content

Commit 0e0eede

Browse files
committed
Implement Term and Variable types for fuzzy logic
Added Term wrapper for membership functions and Variable type for crisp domains with named fuzzy terms. Implemented insertion, lookup, and evaluation logic with error handling. Added prelude module for convenient re-exports. Improved formatting and error handling in membership functions. Includes comprehensive unit tests for new types.
1 parent 4ec278c commit 0e0eede

File tree

22 files changed

+396
-115
lines changed

22 files changed

+396
-115
lines changed

benches/evaluate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

examples/FCM.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
fn main(){
2-
3-
}
1+
fn main() {}

examples/GradientDescent.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
fn main(){
2-
3-
}
1+
fn main() {}

examples/batch.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
//pub use rust_fuzzylogic::builder::FuzzySystem;
2-
fn main(){
3-
4-
}
2+
fn main() {}

examples/temperature.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
fn main(){
2-
3-
}
1+
fn main() {}

src/builder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/defuzz.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/error.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,40 @@ pub type Result<T> = std::result::Result<T, FuzzyError>;
99
#[non_exhaustive]
1010

1111
///Basic errors that can occur in the rust-fuzzylogic library
12-
pub enum FuzzyError{
12+
pub enum FuzzyError {
1313
BadArity,
1414
EmptyInput,
1515
TypeMismatch,
1616
OutOfBounds,
1717
}
1818

19-
impl fmt::Display for FuzzyError{
20-
fn fmt(&self, f:&mut fmt::Formatter) -> fmt::Result{
21-
match self{
22-
FuzzyError::BadArity => {write!(f, "Bad arity")},
23-
FuzzyError::EmptyInput => {write!(f, "Empty input")},
24-
FuzzyError::TypeMismatch => {write!(f, "Invalid type input")},
25-
FuzzyError::OutOfBounds => {write!(f, "Out of bounds")},
19+
impl fmt::Display for FuzzyError {
20+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
21+
match self {
22+
FuzzyError::BadArity => {
23+
write!(f, "Bad arity")
24+
}
25+
FuzzyError::EmptyInput => {
26+
write!(f, "Empty input")
27+
}
28+
FuzzyError::TypeMismatch => {
29+
write!(f, "Invalid type input")
30+
}
31+
FuzzyError::OutOfBounds => {
32+
write!(f, "Out of bounds")
33+
}
2634
}
2735
}
2836
}
2937

30-
impl Error for FuzzyError{}
38+
impl Error for FuzzyError {}
3139

3240
//Basic Unit Tests
3341
#[cfg(test)]
34-
mod tests{
42+
mod tests {
3543
use crate::error::FuzzyError;
3644
#[test]
37-
fn print_error(){
45+
fn print_error() {
3846
assert_eq!(FuzzyError::BadArity.to_string(), "Bad arity");
3947
assert_eq!(FuzzyError::EmptyInput.to_string(), "Empty input");
4048
assert_eq!(FuzzyError::TypeMismatch.to_string(), "Invalid type input");

src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pub mod membership;
22

3-
//Temporary Module Decleration to avoid error
3+
//Temporary Module Decleration to avoid error
44
pub mod builder;
55
pub mod defuzz;
66
pub mod error;
@@ -11,6 +11,8 @@ pub mod system;
1111
pub mod term;
1212
pub mod variable;
1313

14+
pub mod prelude;
15+
1416
//pub use rust_fuzzylogic::triangular::Triangular;
1517

1618
//type definitions
@@ -24,4 +26,4 @@ pub type Float = f32;
2426
pub type Float = f64;
2527

2628
#[cfg(feature = "serde")]
27-
pub use serde::{Deserialize, Serialize};
29+
pub use serde::{Deserialize, Serialize};

src/main.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
2-
3-
fn main() {
4-
5-
}
6-
1+
fn main() {}

0 commit comments

Comments
 (0)