4.0.31 • Published 11 months ago

occam-pearce-kelly v4.0.31

Weekly downloads
3
License
MIT, Anti-996
Repository
github
Last release
11 months ago

Occam Pearce-Kelly

An implementation of the Pearce-Kelly algorithm for Occam.

Contents

Introduction

This algorithm maintains a topological ordering of a directed acyclic graph. It does this by re-ordering whenever an edge is added, if possible, or reporting the cycle that breaks the ordering if not.

Installation

With npm:

npm install occam-pearce-kelly

You can also clone the repository with Git...

git clone https://github.com/djalbat/occam-pearce-kelly.git

...and then install the dependencies with npm from within the project's root directory:

npm install

Usage

An empty and therefore trivially acyclic directed graph can be created with the fromNothing() factory method. Then edges and vertices can be added to it incrementally:

import { DirectedAcyclicGraph } from "occam-pearce-kelly";

const directedAcyclicGraph = DirectedAcyclicGraph.fromNothing(),
      vertexName = "i",
      sourceVertexName = "j",
      targetVertexName = "k";

directedAcyclicGraph.addVertexByVertexName(vertexName);

directedAcyclicGraph.addEdgeByVertexNames(sourceVertexName, targetVertexName);

Note that there is no need to add vertices explicitly, they will be added whenever necessary when edges that reference them are added. You can also use the fromVertexNames() factory method. Since no edges are added, the graph is again trivially acyclic.

A better way to create a directed acyclic graph is to a create graph and topologically order its vertices by way of the Kahn algorithm. These topologically ordered vertices, complete with edge information, can then be used as the input for a directed acyclic graph:

import { Graph } from "occam-kahn";

const vertexLiterals = [

         ["a", ["b"]],
         ["b", ["c"]],
         ["d", ["c"]],
         ["e", []],
         ["f", ["g"]],
         ["h", ["g"]]

       ],
       graph = Graph.fromVertexLiterals(vertexLiterals),
       orderedVertices = graph.getOrderedVertices(),
       directedAcyclicGraph =

         DirectedAcyclicGraph.fromOrderedVertices(orderedVertices);

From this point on, edges and vertices can again be added incrementally:

const cyclicVertexNames = directedAcyclicGraph.addEdgeByVertexNames(sourceVertexName, targetVertexName);

The return value of the addEdgeByVertexNames() will be null if the edge does not break the topological ordering. If it does, the cycle that breaks the ordering will be returned in the form of an array of vertex names.

To make use of the topological ordering, call the getOrderedVertexNames() method:

const orderedVertexNames = directedAcyclicGraph.getOrderedVertexNames();

Building

Automation is done with npm scripts, have a look at the package.json file. The pertinent commands are:

npm run build-debug
npm run watch-debug

References

Thisreferences is based on the algorithm described in the following paper:

Contact

  • james.smith@djalbat.com
4.0.30

12 months ago

4.0.31

11 months ago

4.0.29

2 years ago

4.0.19

2 years ago

4.0.21

2 years ago

4.0.20

2 years ago

4.0.27

2 years ago

4.0.26

2 years ago

4.0.28

2 years ago

4.0.23

2 years ago

4.0.22

2 years ago

4.0.25

2 years ago

4.0.24

2 years ago

4.0.18

2 years ago

4.0.17

2 years ago

4.0.10

3 years ago

4.0.16

2 years ago

4.0.15

2 years ago

4.0.12

2 years ago

4.0.11

2 years ago

4.0.14

2 years ago

4.0.13

2 years ago

4.0.9

3 years ago

4.0.8

3 years ago

4.0.7

3 years ago

4.0.6

3 years ago

4.0.5

3 years ago

4.0.4

3 years ago

4.0.3

3 years ago

4.0.2

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.0.4

3 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.7.8

4 years ago

2.7.9

4 years ago

2.7.7

4 years ago

2.7.6

4 years ago

2.7.5

4 years ago

2.7.4

4 years ago

2.7.3

4 years ago

2.7.2

5 years ago

2.7.1

5 years ago

2.7.0

5 years ago

2.6.32

5 years ago

2.6.31

5 years ago

2.6.30

5 years ago

2.6.29

5 years ago

2.6.28

5 years ago

2.6.27

5 years ago

2.6.26

5 years ago

2.6.25

5 years ago

2.6.23

5 years ago

2.6.22

5 years ago

2.6.21

5 years ago

2.6.20

6 years ago

2.6.19

6 years ago

2.6.18

6 years ago

2.6.17

6 years ago

2.6.16

6 years ago

2.6.15

6 years ago

2.6.14

6 years ago

2.6.13

7 years ago

2.6.12

7 years ago

2.6.11

7 years ago

2.6.10

7 years ago

2.6.9

7 years ago

2.6.8

7 years ago

2.6.7

7 years ago

2.6.6

7 years ago

2.6.5

7 years ago

2.6.4

7 years ago

2.6.3

7 years ago

2.6.2

7 years ago

2.6.1

7 years ago

2.5.12

7 years ago

2.6.0

7 years ago

2.5.11

7 years ago

2.5.10

7 years ago

2.5.9

7 years ago

2.5.8

7 years ago

2.5.7

7 years ago

2.5.6

7 years ago

2.5.5

7 years ago

2.5.4

7 years ago

2.5.3

7 years ago

2.5.2

7 years ago

2.5.1

7 years ago

2.5.0

7 years ago

2.4.9

7 years ago

2.4.8

7 years ago

2.4.7

7 years ago

2.4.6

7 years ago

2.4.5

7 years ago

2.4.4

7 years ago

2.4.3

7 years ago

2.4.2

7 years ago

2.4.1

7 years ago

2.4.0

7 years ago

2.3.0

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.0

7 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.0.4

7 years ago

0.0.3

7 years ago

0.0.2

7 years ago