Skip to content

Operations

Adam Furmanek edited this page Jul 17, 2016 · 2 revisions

List

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

Addition

Sums variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Addition, b);
or
manager.Operation(OperationType.Addition, a, b);

Details

Sums variables. Works for all variables, requires at least one argument.


Negation

Negates variable

Usage

IMilpManager manager;
IVariable a;
...
a.Operation(OperationType.Negation);
or
manager.Operation(OperationType.Negation, a);

Details

Negates a variable (changes its sign). Works for all variables, requires exactly one argument.


Subtraction

Subtracts two variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Subtraction, b);
or
manager.Operation(OperationType.Subtraction, a, b);

Details

Subtracts two variables, works for all variables. Requires exactly two arguments.


Multiplication

Multiplies variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Multiplication, b);
or
manager.Operation(OperationType.Multiplication, a, b);

Details

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


Division

Divides variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Division, b);
or
manager.Operation(OperationType.Division, a, b);

Details

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.


Remainder

Calculates division remainder

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Remainder, b);
or
manager.Operation(OperationType.Remainder, a, b);

Details

Divides exactly two variables and returns remainder. Accepts the same input as division.


Exponentiation

Calculates exponentiation of two variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Exponentiation, b);
or
manager.Operation(OperationType.Exponentiation, a, b);

Details

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


Factorial

Calculates factorial

Usage

IMilpManager manager;
IVariable a;
...
a.Operation(OperationType.Factorial);
or
manager.Operation(OperationType.Factorial, a);

Details

Calculates factorial of a variable. It makes assumption about biggest possible result, accepts exactly one non-negative integer. See Factorial


Conjunction

Calculates conjunction of binary variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Conjunction, b);
or
manager.Operation(OperationType.Conjunction, a, b);

Details

Calculates conjunction of binary variables. See Boolean algebra


Disjunction

Calculates disjunction of binary variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Disjunction, b);
or
manager.Operation(OperationType.Disjunction, a, b);

Details

Calculates disjunction of binary variables. See Boolean algebra


Binary negation

Negates binary variable

Usage

IMilpManager manager;
IVariable a;
...
a.Operation(OperationType.BinaryNegation);
or
manager.Operation(OperationType.BinaryNegation, a);

Details

Negates binary variable. See Boolean algebra


Equivalency

Calculates equivalency of binary variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Equivalency, b);
or
manager.Operation(OperationType.Equivalency, a, b);

Details

Calculates equivalency of binary variables. See Boolean algebra. Returns true when all arguments all equal.


Material implication

Calculates material implication of binary variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.MaterialImplication, b);
or
manager.Operation(OperationType.MaterialImplication, a, b);

Details

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.


Exclusive disjunction

Calculates exclusive disjunction of binary variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.ExclusiveDisjunction, b);
or
manager.Operation(OperationType.ExclusiveDisjunction, a, b);

Details

Calculates exclusive disjunction of binary variables. See Boolean algebra. Returns true when there is odd number of true arguments passed.


Is greater or equal

Compares two variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.IsGreaterOrEqual, b);
or
manager.Operation(OperationType.IsGreaterOrEqual, a, b);

Details

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.


Is greater than

Compares two variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.IsGreaterThan, b);
or
manager.Operation(OperationType.IsGreaterThan, a, b);

Details

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.


Is less or equal

Compares two variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.IsLessOrEqual, b);
or
manager.Operation(OperationType.IsLessOrEqual, a, b);

Details

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.


Is less than

Compares two variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.IsLessThan, b);
or
manager.Operation(OperationType.IsLessThan, a, b);

Details

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.


Is equal

Compares two variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.IsEqual, b);
or
manager.Operation(OperationType.IsEqual, a, b);

Details

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.


Is not equal

Compares two variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.IsNotEqual, b);
or
manager.Operation(OperationType.IsNotEqual, a, b);

Details

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.


Maximum

Calculates maximum of variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Maximum, b);
or
manager.Operation(OperationType.Maximum, a, b);

Details

Accepts at least two arguments. Calculates maximum of provided variables, makes assumption about maximum possible value. See Absolute value, maximum, minimum


Minimum

Calculates minimum of variables

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.Minimum, b);
or
manager.Operation(OperationType.Minimum, a, b);

Details

Accepts at least two arguments. Calculates minimum of provided variables, makes assumption about maximum possible value. See Absolute value, maximum, minimum


Absolute value

Calculates absolute value of a variable

Usage

IMilpManager manager;
IVariable a;
...
a.Operation(OperationType.AbsoluteValue);
or
manager.Operation(OperationType.AbsoluteValue, a);

Details

Accepts exactly one argument. Calculates absolute value of provided variable, makes assumption about maximum possible value. See Absolute value, maximum, minimum


GCD

Calculates GCD (Greatest Common Divisor, HCF, Highest Common Factor)

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.GCD, b);
or
manager.Operation(OperationType.GCD, a, b);

Details

Accepts exactly two non-negative integer arguments. Calculates GCD of provided variables. See Multiple and GCD


Different values count

Returns number of different values within provided arguments

Usage

IMilpManager manager;
IVariable a;
IVariable b;
...
a.Operation(OperationType.DifferentValuesCount, b);
or
manager.Operation(OperationType.DifferentValuesCount, a, b);

Details

Calculates number of different values within provided arguments. Makes assumption about highest possible value. See Basic set operations