Skip to content

Comments

Implement CFL single-path path-finding and extraction algorithm#8

Open
b08lsoai wants to merge 16 commits intoSparseLinearAlgebra:stablefrom
b08lsoai:b08lsoai/single_path
Open

Implement CFL single-path path-finding and extraction algorithm#8
b08lsoai wants to merge 16 commits intoSparseLinearAlgebra:stablefrom
b08lsoai:b08lsoai/single_path

Conversation

@b08lsoai
Copy link

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.

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 \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Шапку бы сюда с описанием того, что в этом файле происходит.

GrB_Index *end,
int32_t nonterm,
const GrB_Matrix *adj_matrices,
const GrB_Matrix *T,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кто это?

"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.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кто такой этот T?

return GrB_NULL_POINTER;
}

// Find null T matrices
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кто такие эти 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, проверка входных данных раскопирована между разными файлами. Можно ли её как-то вынести?

GrB_Index end,
int32_t nonterm,
const GrB_Matrix *adj_matrices,
const GrB_Matrix *T,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кто это?

{
if (index.height == 1)
{
if (start == end) // Height = 1 and start = end is an empty eps-path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Точно? А что, если в графе есть петля? например, 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]];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нейминг.

)
{
// Semiring components
GrB_Type PI_type = NULL; // Type PathIndex
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Почему не вынести PathIndex в название, вместо PI? Тогда и комментарий не нужен, и читается очевиднее.

//====================
// Grammars
//====================

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется, можно создать единую базу графов и грамматик для всех разновидностей КС запросов. Потом использовать её в разных тестах.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants