Learn R Programming

tropicalSparse (version 0.1.0)

tropicalsparse.add: Addition With or Without Storage Techniques

Description

tropicalsparse.add function adds the provided inputs in Tropical Algebra based on type of Tropical Algebra.

Usage

tropicalsparse.add(A, B, store = NULL, algebraType)

Arguments

A

is matrix or vector.

B

is matrix or vector.

store

is storage technique.

algebraType

is string input that can be minplus or maxplus.

Value

Addition of A and B in Tropical Algebra.

Details

The compulsory inputs of the function tropicalsparse.add are A, B and algebraType while the remaining input is optional that is store. The inputs A and B can be matrix/matrix, matrix/vector, vector/matrix and vector/vector otherwise the function generates an error. For A and B, the order of the input does not matter. It can be in any of the following way: the first input of the function is matrix and second input is a vector. Similarly, vise versa. store can be coo, csc and csr for applying following storage techniques respectively: Coordinate-Wise, Compressed Sparse Row, Compressed Sparse Column. This input is case sensitive. If the store input is other than the specified storage techniques then the function generates an error. The input algebraType is used to specify type of Tropical Algebra. This can be minplus or maxplus. For more details about algebraType, see detail section of check.infinityM or check.infinityV. tropicalsparse.storage function is used to apply storage technique depends upon the input given. If store input is not specified then the functionality will be performed without using any storage technique.

See Also

tropicalsparse.mul, tropicalsparse.storage

Examples

Run this code
# NOT RUN {
a <- matrix(data = c(2, Inf, Inf, 0, Inf, Inf, Inf, 10, Inf),
nrow = 3, ncol = 3, byrow = TRUE)

b <- matrix(data = c(Inf, Inf, 4, Inf, -0.3, Inf, Inf, 2, Inf),
nrow = 3, ncol = 3, byrow = TRUE)

tropicalsparse.add(a, b, 'csr', 'minplus')

#     [,1] [,2]  [,3]
# [1,]    2  Inf    4
# [2,]    0 -0.3  Inf
# [3,]  Inf  2.0  Inf

# also

a <- matrix(data = c(5, -Inf, -Inf, -Inf, -Inf, -Inf, -Inf, 10, 2),
nrow = 3, ncol = 3, byrow = TRUE)

b <- matrix(data = c(-Inf, -Inf, 3, -Inf, -0.5, -Inf, 1.1, -Inf, -Inf),
nrow = 3, ncol = 3, byrow = TRUE)

tropicalsparse.add(a, b, 'coo', 'maxplus')

#      [,1] [,2] [,3]
# [1,]  5.0 -Inf    3
# [2,] -Inf -0.5 -Inf
# [3,]  1.1 10.0    2

# also

a <- matrix(data = c(2, Inf, Inf, 0, Inf, Inf, Inf, 2, Inf),
nrow = 3, ncol = 3, byrow = TRUE)

b <- c(Inf, 0, 10)

tropicalsparse.add(a, b, algebraType = 'minplus')

#      [,1] [,2] [,3]
# [1,]    2  Inf  Inf
# [2,]    0    0    0
# [3,]   10    2   10

# }

Run the code above in your browser using DataLab