项目作者: TheDesignium

项目描述 :
Algorithm to find a Minimum Path Cover of an arbitary DAG in JS/TS.
高级语言: TypeScript
项目地址: git://github.com/TheDesignium/dagmpc-js.git
创建时间: 2020-10-31T03:27:08Z
项目社区:https://github.com/TheDesignium/dagmpc-js

开源协议:MIT License

下载


dagmpc: Algorithm to find a Minimum Path Cover of an arbitary DAG.

dagmpc provides a function which finds a minimum path cover of a DAG. This can’t list all answers but finds an example. This works on both of browser and node.

Example Usage

Consider an DAG like this figure.

Example DAG

Input the number of node and the all edges to this library, like here:

  1. import { minimumPathCover } from 'dagmpc';
  2. const n = 7;
  3. const edges = [
  4. [0, 3],
  5. [0, 4],
  6. [0, 5],
  7. [1, 0],
  8. [1, 3],
  9. [1, 4],
  10. [1, 5],
  11. [1, 6],
  12. [2, 3],
  13. [2, 4],
  14. [2, 5],
  15. [2, 6],
  16. [6, 4],
  17. ];
  18. const paths = minimumPathCover(n, edges);
  19. console.log(paths);

It outputs:

  1. [[[1, 0, 3], [2, 5], [6, 4]]]

This means the calcurated MPC is the 3 paths, 1 -> 0 -> 3, 2 -> 5 and 6 -> 4. As figure:

Example MPC

Installation

  1. npm i @thedesignium/dagmpc

Documentation

It is documented as JSDoc so read it through your editor, or read index.ts directly.