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

public abstract class Semiring<T> extends Object
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 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

      public BinaryOperator<T> getAddition()
      Retrieves the binary addition operation.
      Returns:
      The binary addition operation.
    • getMultiplication

      public BinaryOperator<T> getMultiplication()
      Retrieves the binary multiplication operation.
      Returns:
      The binary multiplication operation.
    • getZeroElement

      public T getZeroElement()
      Retrieves the additive identity element.
      Returns:
      The additive identity element.
    • getOneElement

      public T getOneElement()
      Retrieves the multiplicative identity element.
      Returns:
      The multiplicative identity element.
    • multiply

      public T multiply(T a, T b)
      Performs the multiplication operation on two elements.
      Parameters:
      a - The first operand.
      b - The second operand.
      Returns:
      The result of the multiplication operation.
    • add

      public T add(T a, T b)
      Performs the addition operation on two elements.
      Parameters:
      a - The first operand.
      b - The second operand.
      Returns:
      The result of the addition operation.
    • betterOrSame

      public Boolean betterOrSame(T a, T b)
      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

      public T validateAndReturn(T value)
      Validates and returns the given value.
      Parameters:
      value - The value to be validated.
      Returns:
      The validated value.
    • getRandomElement

      public abstract T 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

      public abstract T divide(T dividend, T divisor)
      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 dividend
      divisor - the divisor
      Returns:
      The inverse of element.
    • toNumericalValue

      public double toNumericalValue(T value)
      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.