Package org.tweetyproject.math.algebra
Class Semiring<T>
java.lang.Object
org.tweetyproject.math.algebra.Semiring<T>
- Type Parameters:
T- The type of elements in the semiring.
- Direct Known Subclasses:
BooleanSemiring,BottleneckSemiring,FuzzySemiring,NonNumericSemiring,ProbabilisticSemiring,WeightedSemiring
This class represents a generic Semiring, an algebraic structure with two binary operations
(addition and multiplication), and two corresponding identity elements (zeroElement and oneElement).
- Author:
- Sandra Hoffmann
-
Constructor Summary
ConstructorsConstructorDescriptionSemiring(BinaryOperator<T> addition, BinaryOperator<T> multiplication, T zeroElement, T oneElement) Constructs a Semiring instance. -
Method Summary
Modifier and TypeMethodDescriptionPerforms the addition operation on two elements.betterOrSame(T a, T b) Returns true if value 'a' is better than or equal to value 'b' in the semiring.abstract TPerforms the division operation as definded in the semiring class.Retrieves the binary addition operation.Retrieves the binary multiplication operation.Retrieves the multiplicative identity element.abstract TGenerates a random element of the semiring.Retrieves the additive identity element.Performs the multiplication operation on two elements.doubletoNumericalValue(T value) Converts a value in a semiring to a numerical representation.validateAndReturn(T value) Validates and returns the given value.
-
Constructor Details
-
Semiring
public Semiring(BinaryOperator<T> addition, BinaryOperator<T> multiplication, T zeroElement, T oneElement) Constructs a Semiring instance.- Parameters:
addition- The binary addition operation.multiplication- The binary multiplication operation.zeroElement- The additive identity element.oneElement- The multiplicative identity element.
-
-
Method Details
-
getAddition
Retrieves the binary addition operation.- Returns:
- The binary addition operation.
-
getMultiplication
Retrieves the binary multiplication operation.- Returns:
- The binary multiplication operation.
-
getZeroElement
Retrieves the additive identity element.- Returns:
- The additive identity element.
-
getOneElement
Retrieves the multiplicative identity element.- Returns:
- The multiplicative identity element.
-
multiply
Performs the multiplication operation on two elements.- Parameters:
a- The first operand.b- The second operand.- Returns:
- The result of the multiplication operation.
-
add
Performs the addition operation on two elements.- Parameters:
a- The first operand.b- The second operand.- Returns:
- The result of the addition operation.
-
betterOrSame
Returns true if value 'a' is better than or equal to value 'b' in the semiring.- Parameters:
a- The first operand.b- The second operand.- Returns:
- True if 'a' is better than or equal to 'b'; otherwise, false.
-
validateAndReturn
Validates and returns the given value.- Parameters:
value- The value to be validated.- Returns:
- The validated value.
-
getRandomElement
Generates a random element of the semiring. Note: Concrete implementations in subclasses should provide the actual logic.- Returns:
- A random element of the semiring.
-
divide
Performs the division operation as definded in the semiring class. Needed for g-defense. Note: Concrete implementations in subclasses should provide the actual logic.- Parameters:
dividend- the dividenddivisor- the divisor- Returns:
- The inverse of element.
-
toNumericalValue
Converts a value in a semiring to a numerical representation.- Parameters:
value- The value in the semiring.- Returns:
- The numerical representation of the semiring value.
- Throws:
IllegalArgumentException- If the provided semiring value is not a valid numeric representation.
-