Add FuzzyImplicationCapable protocol

This commit is contained in:
Alexander Ignatov 2021-12-29 13:55:31 +02:00
parent 522530f69a
commit 84ac87abe5
1 changed files with 10 additions and 6 deletions

View File

@ -36,24 +36,28 @@ public enum ImplicationMethod {
} }
} }
public extension AnyFuzzySet { public protocol FuzzyImplicationCapable: FuzzySet {
func implication(_ other: Self, method: ImplicationMethod = .mamdani) -> Self { func implication(_ other: Self, method: ImplicationMethod) -> Self
}
extension AnyFuzzySet: FuzzyImplicationCapable {
public func implication(_ other: Self, method: ImplicationMethod = .mamdani) -> Self {
.init { .init {
method.function(self[$0], other[$0]) method.function(self[$0], other[$0])
} }
} }
} }
public extension IterableFuzzySet { extension IterableFuzzySet: FuzzyImplicationCapable {
func implication(_ other: Self, method: ImplicationMethod = .mamdani) -> Self { public func implication(_ other: Self, method: ImplicationMethod = .mamdani) -> Self {
.init(sequence) { .init(sequence) {
method.function(self[$0], other[$0]) method.function(self[$0], other[$0])
} }
} }
} }
public extension DiscreteMutableFuzzySet { extension DiscreteMutableFuzzySet: FuzzyImplicationCapable {
func implication(_ other: Self, method: ImplicationMethod = .mamdani) -> Self { public func implication(_ other: Self, method: ImplicationMethod = .mamdani) -> Self {
var result = self var result = self
result.formImplication(other, method: method) result.formImplication(other, method: method)
return result return result