package lrgrep
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha256=84a1874d0c063da371e19c84243aac7c40bfcb9aaf204251e0eb0d1f077f2cde
sha512=5a16ff42a196fd741bc64a1bdd45b4dca0098633e73aa665829a44625ec15382891c3643fa210dbe3704336eab095d4024e093e37ae5313810f6754de6119d55
doc/lrijkstra_utils/Mcop/index.html
Module McopSource
Compute solutions to the Matrix Chain Ordering Problem (MCOP). The problem is to find the association of a chain of matrix multiplications that minimize the number of multiplications.
A problem instance is given as an array of integers, representing the dimensions of matrices. The product of matrices M1 : M[i,j] x M2[j,k] is specified by the array [|i; j; k|]. Thus, the multiplication of n matrices is represented by an array of length (n+1).
The solution is given as a binary tree of matrices. Only the shape of the binary tree matters, the 'a parameter is provided as a convenience for user to store custom information. Initially, the 'a is just an integer that represents the index of the matrix to multiply (the values grows from 0 to n-1).
This exception is raised when an empty problem is submitted, as it has no solution.
Map a solution to a user-chosen representation, to make it more convenient to interpret
Left-leaning product tree. This solution is naive solution, the dimensions are not even looked at so nothing is optimized. For benchmarking purposes.
Right-leaning product tree. This solution is naive solution, the dimensions are not even looked at so nothing is optimized. For benchmarking purposes.
An implementation of the algorithm described in "An O(n) algorithm for determining a near-optimal computation order of matrix chain products" by Francis Y. Chin. It gives an approximate solution in O(n) time that does less than 25% more operations that the optimal one (and much less in practice).
An implementation of the dynamic programming algorithm. It gives an optimal solution in O(n^3). A formal description can be found in "Introduction to Algorithms" by Cormen et al.
TODO An algorithm to compute an optimal solution in O(n log n) is described in "Computation of Matrix Chain Products" by Hu and Shing:
- "Part I", doi 10.1.1.695.2923
- "Part II", doi 10.1.1.695.4875 This algorithm is more involved and has not been implemented here. That might be interesting future work.