Package org.tweetyproject.math.algebra
Class WeightedSemiring
This class represents a Weighted Semiring, where elements are interpreted as weights or costs.
In this semiring, the multiplication operation corresponds to finding the minimum of two weights,
the addition operation corresponds to adding weights, Double.POSITIVE_INFINITY represents the
additive identity, and 0.0 represents the multiplicative identity.
- Author:
- Sandra Hoffmann
-
Constructor Summary
ConstructorDescriptionConstructs a WeightedSemiring instance.WeightedSemiring
(double maxWeight) Constructs a WeightedSemiring instance with a max weight. -
Method Summary
Modifier and TypeMethodDescriptionPerforms a custom division operation on two Double values.Generates a random element from the semiring within the specified maximum value.validateAndReturn
(Double value) Validates and returns the given value if valid.Methods inherited from class org.tweetyproject.math.algebra.Semiring
add, betterOrSame, getAddition, getMultiplication, getOneElement, getZeroElement, multiply, toNumericalValue
-
Constructor Details
-
WeightedSemiring
public WeightedSemiring()Constructs a WeightedSemiring instance. -
WeightedSemiring
public WeightedSemiring(double maxWeight) Constructs a WeightedSemiring instance with a max weight.- Parameters:
maxWeight
- the max weight
-
-
Method Details
-
validateAndReturn
Validates and returns the given value if valid.- Overrides:
validateAndReturn
in classSemiring<Double>
- Parameters:
value
- The value to be validated.- Returns:
- The validated value.
- Throws:
IllegalArgumentException
- If the value is outside the valid range [0.0, maxValue].
-
getRandomElement
Generates a random element from the semiring within the specified maximum value.- Specified by:
getRandomElement
in classSemiring<Double>
- Returns:
- A randomly chosen Double element.
-
divide
Performs a custom division operation on two Double values. If the divisor is greater than or equal to the dividend, returns the multiplicative identity (oneElement). Otherwise, returns the result of subtracting the divisor from the dividend.
-