Implement CFL single-path path-finding and extraction algorithm#8
Implement CFL single-path path-finding and extraction algorithm#8b08lsoai wants to merge 16 commits intoSparseLinearAlgebra:stablefrom
Conversation
add algorithm for single path extracting, finding, add tests and structures for LAGraphX
after freeing the element type of the output matrix, it becomes an invalid type instead of a user-defined type
add tests for invalid input
previously, it was not possible to free the PathIndex type; now its creation and initialization of matrices in the output data are required outside the function
refactor CFL algorithms by introducing a semiring-parameterized CFPQ_core and task-specific wrapper functions
the path start and end parameters are now optional and passed by pointer passing NULL extracts paths from all vertices
| @@ -0,0 +1,227 @@ | |||
| #define LG_FREE_ALL \ | |||
There was a problem hiding this comment.
Шапку бы сюда с описанием того, что в этом файле происходит.
| GrB_Index *end, | ||
| int32_t nonterm, | ||
| const GrB_Matrix *adj_matrices, | ||
| const GrB_Matrix *T, |
| "The number of rules must be greater than zero."); | ||
| LG_ASSERT_MSG(nonterm < nonterms_count, GrB_INVALID_VALUE, | ||
| "The start non-terminal must be no greater than the number of non-terminals."); | ||
| LG_ASSERT_MSG(T != NULL, GrB_NULL_POINTER, "The T array cannot be null."); |
| return GrB_NULL_POINTER; | ||
| } | ||
|
|
||
| // Find null T matrices |
There was a problem hiding this comment.
Кто такие эти T? Может заодно дать более "говорящее" название?
| bool is_rule_bin = rule.prod_A != -1 && rule.prod_B != -1; | ||
|
|
||
| // Check that all rules are well-formed | ||
| if (rule.nonterm < 0 || rule.nonterm >= nonterms_count) |
There was a problem hiding this comment.
Кажется, проверка входных данных раскопирована между разными файлами. Можно ли её как-то вынести?
| GrB_Index end, | ||
| int32_t nonterm, | ||
| const GrB_Matrix *adj_matrices, | ||
| const GrB_Matrix *T, |
| { | ||
| if (index.height == 1) | ||
| { | ||
| if (start == end) // Height = 1 and start = end is an empty eps-path |
There was a problem hiding this comment.
Точно? А что, если в графе есть петля? например, S -> a S | a, граф: 0 -a-> 0 Или что-то подобное.
| // Rules of the form Nonterm -> Nonterm * Nonterm are traversed recursively and merged | ||
| for (size_t i = 0; i < bin_rules_count; i++) | ||
| { | ||
| LAGraph_rule_WCNF term_rule = rules[bin_rules[i]]; |
| ) | ||
| { | ||
| // Semiring components | ||
| GrB_Type PI_type = NULL; // Type PathIndex |
There was a problem hiding this comment.
Почему не вынести PathIndex в название, вместо PI? Тогда и комментарий не нужен, и читается очевиднее.
| //==================== | ||
| // Grammars | ||
| //==================== | ||
|
|
There was a problem hiding this comment.
Кажется, можно создать единую базу графов и грамматик для всех разновидностей КС запросов. Потом использовать её в разных тестах.
This PR adds an implementation of Rustam Azimov's algorithms for searching and restoring a single path in a graph with context-free constraints using matrix multiplication. During the path search, auxiliary information is stored, which is later used to restore the path.
Unit tests were written for both algorithms, ensuring good coverage.