All Projects → telkins → laravel-dag-manager

telkins / laravel-dag-manager

Licence: MIT License
A SQL-based Directed Acyclic Graph (DAG) solution for Laravel.

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to laravel-dag-manager

vue-dag
🏗 Data-driven directed acyclic graph (DAG) builder for Vue.js
Stars: ✭ 37 (+54.17%)
Mutual labels:  dag, directed-acyclic-graph
django-postgresql-dag
Directed Acyclic Graphs with a variety of methods for both Nodes and Edges, and multiple exports (NetworkX, Pandas, etc). This project is the foundation for a commercial product, so expect regular improvements. PR's and other contributions are welcomed.
Stars: ✭ 23 (-4.17%)
Mutual labels:  dag, directed-acyclic-graph
batching-toposort
Efficiently sort interdependent tasks into a sequence of concurrently-executable batches
Stars: ✭ 21 (-12.5%)
Mutual labels:  dag, directed-acyclic-graph
obyte-hub
Hub for Obyte network
Stars: ✭ 17 (-29.17%)
Mutual labels:  dag, directed-acyclic-graph
breaking cycles in noisy hierarchies
breaking cycles in noisy hierarchies
Stars: ✭ 59 (+145.83%)
Mutual labels:  dag, directed-acyclic-graph
rosie
A task building library that allows combining custom logic with the execution of command line programs. Designed around a directed acyclic graph allows for expressing non-trivial procedures.
Stars: ✭ 27 (+12.5%)
Mutual labels:  directed-acyclic-graph
go-pdu
Parallel Digital Universe - A decentralized social networking service
Stars: ✭ 39 (+62.5%)
Mutual labels:  dag
Slack-Stock-DAG
This repository holds a list of cool resources for Silica.
Stars: ✭ 94 (+291.67%)
Mutual labels:  dag
xdagj
XDAGJ is an implementation of XDAG in Java. https://xdag.io
Stars: ✭ 81 (+237.5%)
Mutual labels:  dag
avrio-rs
Avrio's core code written in rust.
Stars: ✭ 14 (-41.67%)
Mutual labels:  dag
lineage
Generate beautiful documentation for your data pipelines in markdown format
Stars: ✭ 16 (-33.33%)
Mutual labels:  dag
hathor-core
HathorNetwork's fullnode core
Stars: ✭ 57 (+137.5%)
Mutual labels:  dag
react-monitor-dag
A React-based operation/monitoring DAG diagram.(基于React的运维/监控DAG图)
Stars: ✭ 57 (+137.5%)
Mutual labels:  dag
directed graph
Dart implementation of a directed graph. Provides algorithms for sorting vertices, retrieving a topological ordering or detecting cycles.
Stars: ✭ 37 (+54.17%)
Mutual labels:  directed-acyclic-graph
ipfs-dag-builder-vis
See how the DAGs get built
Stars: ✭ 19 (-20.83%)
Mutual labels:  dag
apollo
An experimental distributed ledger platform based on a sea of DAG Nodes
Stars: ✭ 33 (+37.5%)
Mutual labels:  dag
DaggerGpuMiner
Standalone GPU/CPU miner for Dagger coin
Stars: ✭ 21 (-12.5%)
Mutual labels:  dag
daglib
Directed Acyclic Graphs With Modern Fortran
Stars: ✭ 20 (-16.67%)
Mutual labels:  directed-acyclic-graph
aircal
Visualize Airflow's schedule by exporting future DAG runs as events to Google Calendar.
Stars: ✭ 66 (+175%)
Mutual labels:  dag
algorithms
Algorithms in python and C
Stars: ✭ 71 (+195.83%)
Mutual labels:  dag

A SQL-based Directed Acyclic Graph (DAG) solution for Laravel

Latest Stable Version run tests Total Downloads License

This package allows you to create, persist, and remove directed acyclic graphs.

Basic Usage

Creating a direct edge:

$newEdges = dag()->createEdge($startVertex, $endVertex, $source);
// $newEdges contains all new edges, including the specified direct edge, that were created as a result of the request.

Deleting a direct edge:

$deleted = dag()->deleteEdge($startVertex, $endVertex, $source);
// $deleted is true if any edges were deleted as a result of the request, false otherwise.

Installation

This package requires PHP 7.2 or higher as well as Laravel 6.0 or higher.

You can install the package via composer:

composer require telkins/laravel-dag-manager

The package will automatically register itself.

You can publish the migration with:

php artisan vendor:publish --provider="Telkins\Dag\Providers\DagServiceProvider" --tag="migrations"

Note: The default migration assumes you are using integers for your DAG edge IDs.

You can optionally publish the config file with:

php artisan vendor:publish --provider="Telkins\Dag\Providers\DagServiceProvider" --tag="config"

This is the contents of the published config file:

return [
    /**
     *-------------------------------------------------------------------------
     * Max Hops
     *-------------------------------------------------------------------------
     *
     * This value represents the maximum number of hops that are allowed where
     * hops "[i]ndicates how many vertex hops are necessary for the path; it is
     * zero for direct edges".
     *
     * The more hops that are allowed (and used), then the more DAG edges will
     * be created.  This will have an increasing impact on performance, space,
     * and memory.  Whether or not it's negligible, noticeable, or impactful
     * depends on a variety of factors.
     */
    'max_hops' => 5,

    /**
     *-------------------------------------------------------------------------
     * Default Database Connection Name
     *-------------------------------------------------------------------------
     *
     * This is the name of the database connection where the dag table
     * can be found.
     *
     * Set to `null` to use the default connection.
     */
    'default_database_connection_name' => null,

    /**
     *-------------------------------------------------------------------------
     * Table Name
     *-------------------------------------------------------------------------
     *
     * This is the name of the table where the dag structure
     * will be stored.
     */
    'table_name' => 'dag_edges',
];

Warning

From Kemal Erdogan's article, "A Model to Represent Directed Acyclic Graphs (DAG) on SQL Databases":

In theory, the size of the transitive closure set of a fair DAG can be very large with this model, well beyond the millions. The maximum number of edges for a given DAG itself is a research topic in Graph Theory, but my practical tests show that there exist DAGs with 100 vertices and 300 edges whose transitive closure would create well beyond 20,000,000 rows with this algorithm.

Please be mindful of this when creating "excessively" large and/or complex graphs.

Usage

For Eloquent models that are "DAG managed", you can add the Telkins\Models\Traits\IsDagManaged trait:

use Illuminate\Database\Eloquent\Model;
use Telkins\Models\Traits\IsDagManaged;

class MyModel extends Model
{
    use IsDagManaged;

    // ...
}

This will allow you to easily access certain functionality from your model class.

To apply a scope that only includes models that are descendants of the specified model ID:

$descendants = MyModel::dagDescendantsOf($myModel->id, 'my-source')->get();

An ID and source must be provided.

Likewise, to apply a scope that only includes models that are ancestors of the specified model ID:

$ancestors = MyModel::dagAncestorsOf($myModel->id, 'my-source')->get();

Again, an ID and source must be provided.

Finally, one can apply a scope that will get both ancestors and descendants:

$ancestors = MyModel::dagRelationsOf($myModel->id, 'my-source')->get();

Each of the aforementioned methods also allow the caller to constrain the results based on the number of hops. So, if you want to get the immediate children of the specified model ID, then you could do the following:

$descendants = MyModel::dagDescendantsOf($myModel->id, 'my-source', 0)->get();

And, of course, in order to get the parents and grandparents of the specified model ID, you could do the following:

$ancestors = MyModel::dagAncestorsOf($myModel->id, 'my-source', 1)->get();

Not providing the $maxHops parameter means that all descendants, ancestors, or relations will be returned.

Testing

composer test

Additional Notes

Contributors may want to consider leveraging any of the following:

  • relaxedws/lca: A PHP Library to find Lowest Common ancestor from a Directed Acyclic Graph.
  • clue/graph: A mathematical graph/network library written in PHP.
  • graphp/algorithms: Graph algorithms in PHP, a collection of common (and not so common) ones.

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

tbd

Credits

Additionally:

License

The MIT License (MIT). Please see License File for more information.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].