-
Notifications
You must be signed in to change notification settings - Fork 2
Operations
Currently there are implemented the following operations:
- Addition
- Negation
- Subtraction
- Multiplication
- Division
- Remainder
- Exponentiation
- Factorial
- Conjunction
- Disjunction
- Binary negation
- Equivalency
- Material implication
- Exclusive disjunction
- Is greater or equal
- Is greater than
- Is less or equal
- Is less than
- Is equal
- Is not equal
- Maximum
- Minimum
- Absolute value
- GCD
- Different values count
Sums variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Addition, b);
or
manager.Operation(OperationType.Addition, a, b);
Sums variables. Works for all variables, requires at least one argument.
Negates variable
IMilpManager manager;
IVariable a;
...
a.Operation(OperationType.Negation);
or
manager.Operation(OperationType.Negation, a);
Negates a variable (changes its sign). Works for all variables, requires exactly one argument.
Subtracts two variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Subtraction, b);
or
manager.Operation(OperationType.Subtraction, a, b);
Subtracts two variables, works for all variables. Requires exactly two arguments.
Multiplies variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Multiplication, b);
or
manager.Operation(OperationType.Multiplication, a, b);
Multiplies variables. Accepts the following sets of at least one variable:
- All variables are constants — exact value is calculated using multiplication by constant provided by the solver implementation
- All variables are binary variables — conjunction is used to calculate exact value
- At most one variable is not constant — exact value is calculated using multiplication by constant provided by the solver implementation
- All variables are integers — multiplies integers using Unsigned magnitude decomposition and Minimum operation
The last case can give incorrect result: it uses solver's integer width in order to estimate highest possible value so it is prone to overflow. See Multiplication, Faster multiplication, and Multiplication of negative numbers
Divides variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Division, b);
or
manager.Operation(OperationType.Division, a, b);
Divides exactly two variables. Accepts the following input:
- Second parameter is constant — in that case solver uses division by constant provided by the solver implementation (which might come down to multiplication by constant)
- All arguments are non-negative integers — in that case solver calculates the result using multiplication, see Division, remainder, exponentitation, roots
Divide by 0 is not supported, solver might return infeasible solution.
Calculates division remainder
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Remainder, b);
or
manager.Operation(OperationType.Remainder, a, b);
Divides exactly two variables and returns remainder. Accepts the same input as division.
Calculates exponentiation of two variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Exponentiation, b);
or
manager.Operation(OperationType.Exponentiation, a, b);
Raises a
to the power of b
. Accepts exactly two arguments. Calculates result when all variables are constant, or when all are non-negative integers. Defines 0
to the power of 0
as 1
. See Exponentiation
Calculates factorial
IMilpManager manager;
IVariable a;
...
a.Operation(OperationType.Factorial);
or
manager.Operation(OperationType.Factorial, a);
Calculates factorial of a variable. It makes assumption about biggest possible result, accepts exactly one non-negative integer. See Factorial
Calculates conjunction of binary variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Conjunction, b);
or
manager.Operation(OperationType.Conjunction, a, b);
Calculates conjunction of binary variables. See Boolean algebra
Calculates disjunction of binary variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Disjunction, b);
or
manager.Operation(OperationType.Disjunction, a, b);
Calculates disjunction of binary variables. See Boolean algebra
Negates binary variable
IMilpManager manager;
IVariable a;
...
a.Operation(OperationType.BinaryNegation);
or
manager.Operation(OperationType.BinaryNegation, a);
Negates binary variable. See Boolean algebra
Calculates equivalency of binary variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Equivalency, b);
or
manager.Operation(OperationType.Equivalency, a, b);
Calculates equivalency of binary variables. See Boolean algebra. Returns true
when all arguments all equal.
Calculates material implication of binary variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.MaterialImplication, b);
or
manager.Operation(OperationType.MaterialImplication, a, b);
Calculates material implication of binary variables. See Boolean algebra. Returns false
when first argument is true
and second is false
, otherwise returns true
. Accepts exactly two binary variables.
Calculates exclusive disjunction of binary variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.ExclusiveDisjunction, b);
or
manager.Operation(OperationType.ExclusiveDisjunction, a, b);
Calculates exclusive disjunction of binary variables. See Boolean algebra. Returns true
when there is odd number of true
arguments passed.
Compares two variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.IsGreaterOrEqual, b);
or
manager.Operation(OperationType.IsGreaterOrEqual, a, b);
Accepts exactly two arguments. Returns true when a
is greater or equal than b
. See Comparisons. Makes assumption about maximum possible value. Uses solver epsilon to compare real numbers only when needed.
Compares two variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.IsGreaterThan, b);
or
manager.Operation(OperationType.IsGreaterThan, a, b);
Accepts exactly two arguments. Returns true when a
is greater than b
. See Comparisons. Makes assumption about maximum possible value. Uses solver epsilon to compare real numbers only when needed.
Compares two variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.IsLessOrEqual, b);
or
manager.Operation(OperationType.IsLessOrEqual, a, b);
Accepts exactly two arguments. Returns true when a
is less or equal than b
. See Comparisons. Makes assumption about maximum possible value. Uses solver epsilon to compare real numbers only when needed.
Compares two variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.IsLessThan, b);
or
manager.Operation(OperationType.IsLessThan, a, b);
Accepts exactly two arguments. Returns true when a
is less than b
. See Comparisons. Makes assumption about maximum possible value. Uses solver epsilon to compare real numbers only when needed.
Compares two variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.IsEqual, b);
or
manager.Operation(OperationType.IsEqual, a, b);
Accepts exactly two arguments. Returns true when a
is equal to b
. See Comparisons. Makes assumption about maximum possible value. Uses solver epsilon to compare real numbers only when needed.
Compares two variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.IsNotEqual, b);
or
manager.Operation(OperationType.IsNotEqual, a, b);
Accepts exactly two arguments. Returns true when a
is not equal to b
. See Comparisons. Makes assumption about maximum possible value. Uses solver epsilon to compare real numbers only when needed.
Calculates maximum of variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Maximum, b);
or
manager.Operation(OperationType.Maximum, a, b);
Accepts at least two arguments. Calculates maximum of provided variables, makes assumption about maximum possible value. See Absolute value, maximum, minimum
Calculates minimum of variables
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Minimum, b);
or
manager.Operation(OperationType.Minimum, a, b);
Accepts at least two arguments. Calculates minimum of provided variables, makes assumption about maximum possible value. See Absolute value, maximum, minimum
Calculates absolute value of a variable
IMilpManager manager;
IVariable a;
...
a.Operation(OperationType.AbsoluteValue);
or
manager.Operation(OperationType.AbsoluteValue, a);
Accepts exactly one argument. Calculates absolute value of provided variable, makes assumption about maximum possible value. See Absolute value, maximum, minimum
Calculates GCD (Greatest Common Divisor, HCF, Highest Common Factor)
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.GCD, b);
or
manager.Operation(OperationType.GCD, a, b);
Accepts exactly two non-negative integer arguments. Calculates GCD of provided variables. See Multiple and GCD
Returns number of different values within provided arguments
IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.DifferentValuesCount, b);
or
manager.Operation(OperationType.DifferentValuesCount, a, b);
Calculates number of different values within provided arguments. Makes assumption about highest possible value. See Basic set operations