occam-directed-graphs 3.0.32 → 3.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +125 -124
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,124 +1,125 @@
1
- # Occam Directed Graphs
2
-
3
- Directed graphs comprised of directed acyclic graphs together with cycles for [Occam](https://github.com/djalbat/occam).
4
-
5
- ### Contents
6
-
7
- - [Introduction](#introduction)
8
- - [Installation](#installation)
9
- - [Usage](#usage)
10
- - [Building](#building)
11
- - [Contact](#contact)
12
-
13
- ## Introduction
14
-
15
- The reason for not simply implementing a directed graph trivially is to keep track of cycles and recover them quickly. Given the name of any vertex, the implementation will report whether or not it is part of a cycle. If it is, you can retrieve a cycle of which it is part, but bear in mind that a vertex may be the part of more than one cycle, any one of which can be returned.
16
-
17
- ## Installation
18
-
19
- With [npm](https://www.npmjs.com/):
20
-
21
- npm install occam-directed-graph
22
-
23
- You can also clone the repository with [Git](https://git-scm.com/)...
24
-
25
- https://github.com/djalbat/occam-directed-graph.git
26
-
27
- ...and then install the dependencies with npm from within the project's root directory:
28
-
29
- npm install
30
-
31
- ## Usage
32
-
33
- An empty directed graph can be created by calling the `fromNothing()` factory method, after which vertices and edges can be added incrementally:
34
-
35
- ```
36
- import { DirectedGraph } from "occam-directed-graphs";
37
-
38
- const directedGraph = DirectedGraph.fromNothing(),
39
- vertexName = "i",
40
- sourceVertexName = "j",
41
- targetVertexName = "k";
42
-
43
- directedGraph.addVertexByVertexName(vertexName);
44
-
45
- directedGraph.addEdgeByVertexNames(sourceVertexName, targetVertexName);
46
- ```
47
-
48
- Note that there is no need to add vertices explicitly, they will be added whenever necessary when edges that reference them are added.
49
-
50
- Alternatively, a directed graph can be constructed with the `fromVertexLiterals()` factory method as follows:
51
-
52
- ```
53
- import { DirectedGraph } from "occam-directed-graphs";
54
-
55
- const graph = Graph.fromVertexLiterals([
56
-
57
- ["a", ["b"]],
58
- ["b", ["c"]],
59
- ["d", ["c"]],
60
- ["e", []],
61
- ["f", ["g"]],
62
- ["h", ["g"]]
63
-
64
- ]);
65
- ```
66
-
67
- Note that the array of names that is the second element of each literal gives the *ancestors* of the vertex and not its descendants.
68
-
69
- You can also remove vertices and edges from the graph. Removing a vertex may of course result in removing edges. When you remove an edge, you can additionally specify that the any stranded vertices that result are also removed:
70
-
71
- ```
72
- const vertexName = "i",
73
- sourceVertexName = "j",
74
- targetVertexName = "k",
75
- removeStrandedVertices = true;
76
-
77
- directedGraph.removeVertexByName(vertexName);
78
-
79
- directedGraph.removeEdgeByVertexNames(sourceVertexName, targetVertexName, removeStrandedVertices);
80
- ```
81
-
82
- The default is to leave stranded vertices in place.
83
-
84
- You can detect and recover cycles thus:
85
-
86
- ```
87
- const vertexName = "i",
88
- cyclePresent = directedGraph.isCyclePresentByVertexName(vertexName);
89
-
90
- if (cyclePresent) {
91
- const cycle = directedGraph.getFirstCycleByVertexName(vertexName),
92
- cycleVertexNames = cycle.getVertexNames();
93
-
94
- ...
95
- }
96
- ```
97
- As already pointed out in the introduction, if a vertex is part of more than one cycle, any of of them can be given.
98
-
99
- You can get a topologically ordered list of vertices at any time.
100
- Bear in mind that this will gotten from the underlying directed acyclic graph, however, and therefore may not be useful if there are cycles present.
101
- A method is also provided to ascertain whether cycles are generally present and it is left up to you to decide whether the topologically ordered list of vertices is useful in the event that they are:
102
-
103
- ```
104
- const cyclesPresent = directedGraph.areCyclesPresent();
105
-
106
- if (cyclesPresent) {
107
- ///
108
- } else {
109
- const orderedVertexNames = directedGraph.getOrderedVertexNames();
110
-
111
- ...
112
- }
113
- ```
114
-
115
- ## Building
116
-
117
- Automation is done with [npm scripts](https://docs.npmjs.com/misc/scripts), have a look at the `package.json` file. The pertinent commands are:
118
-
119
- npm run build-debug
120
- npm run watch-debug
121
-
122
- ## Contact
123
-
124
- * james.smith@openmathematics.org
1
+ # Occam Directed Graphs
2
+
3
+ Directed graphs comprised of directed acyclic graphs together with cycles for [Occam](https://github.com/djalbat/occam).
4
+
5
+ ### Contents
6
+
7
+ - [Introduction](#introduction)
8
+ - [Installation](#installation)
9
+ - [Usage](#usage)
10
+ - [Building](#building)
11
+ - [Contact](#contact)
12
+
13
+ ## Introduction
14
+
15
+ The reason for not simply implementing a directed graph trivially is to keep track of cycles and recover them quickly. Given the name of any vertex, the implementation will report whether or not it is part of a cycle. If it is, you can retrieve a cycle of which it is part, but bear in mind that a vertex may be the part of more than one cycle, any one of which can be returned.
16
+
17
+ ## Installation
18
+
19
+ With [npm](https://www.npmjs.com/):
20
+
21
+ npm install occam-directed-graph
22
+
23
+ You can also clone the repository with [Git](https://git-scm.com/)...
24
+
25
+ https://github.com/djalbat/occam-directed-graph.git
26
+
27
+ ...and then install the dependencies with npm from within the project's root directory:
28
+
29
+ npm install
30
+
31
+ ## Usage
32
+
33
+ An empty directed graph can be created by calling the `fromNothing()` factory method, after which vertices and edges can be added incrementally:
34
+
35
+ ```
36
+ import { DirectedGraph } from "occam-directed-graphs";
37
+
38
+ const directedGraph = DirectedGraph.fromNothing(),
39
+ vertexName = "i",
40
+ sourceVertexName = "j",
41
+ targetVertexName = "k";
42
+
43
+ directedGraph.addVertexByVertexName(vertexName);
44
+
45
+ directedGraph.addEdgeByVertexNames(sourceVertexName, targetVertexName);
46
+ ```
47
+
48
+ Note that there is no need to add vertices explicitly, they will be added whenever necessary when edges that reference them are added.
49
+
50
+ Alternatively, a directed graph can be constructed with the `fromVertexLiterals()` factory method as follows:
51
+
52
+ ```
53
+ import { DirectedGraph } from "occam-directed-graphs";
54
+
55
+ const graph = Graph.fromVertexLiterals([
56
+
57
+ ["a", ["b"]],
58
+ ["b", ["c"]],
59
+ ["d", ["c"]],
60
+ ["e", []],
61
+ ["f", ["g"]],
62
+ ["h", ["g"]]
63
+
64
+ ]);
65
+ ```
66
+
67
+ Note that the array of names that is the second element of each literal gives the *ancestors* of the vertex and not its descendants.
68
+
69
+ You can also remove vertices and edges from the graph. Removing a vertex may of course result in removing edges. When you remove an edge, you can additionally specify that the any stranded vertices that result are also removed:
70
+
71
+ ```
72
+ const vertexName = "i",
73
+ sourceVertexName = "j",
74
+ targetVertexName = "k",
75
+ removeStrandedVertices = true;
76
+
77
+ directedGraph.removeVertexByName(vertexName);
78
+
79
+ directedGraph.removeEdgeByVertexNames(sourceVertexName, targetVertexName, removeStrandedVertices);
80
+ ```
81
+
82
+ The default is to leave stranded vertices in place.
83
+
84
+ You can detect and recover cycles thus:
85
+
86
+ ```
87
+ const vertexName = "i",
88
+ cyclePresent = directedGraph.isCyclePresentByVertexName(vertexName);
89
+
90
+ if (cyclePresent) {
91
+ const cycle = directedGraph.getFirstCycleByVertexName(vertexName),
92
+ cycleVertexNames = cycle.getVertexNames();
93
+
94
+ ...
95
+ }
96
+ ```
97
+ As already pointed out in the introduction, if a vertex is part of more than one cycle, any of of them can be given.
98
+
99
+ You can get a topologically ordered list of vertices at any time.
100
+ Bear in mind that this will gotten from the underlying directed acyclic graph, however, and therefore may not be useful if there are cycles present.
101
+ A method is also provided to ascertain whether cycles are generally present and it is left up to you to decide whether the topologically ordered list of vertices is useful in the event that they are:
102
+
103
+ ```
104
+ const cyclesPresent = directedGraph.areCyclesPresent();
105
+
106
+ if (cyclesPresent) {
107
+ ///
108
+ } else {
109
+ const orderedVertexNames = directedGraph.getOrderedVertexNames();
110
+
111
+ ...
112
+ }
113
+ ```
114
+
115
+ ## Building
116
+
117
+ Automation is done with [npm scripts](https://docs.npmjs.com/misc/scripts), have a look at the `package.json` file. The pertinent commands are:
118
+
119
+ npm run build-debug
120
+ npm run watch-debug
121
+
122
+ ## Contact
123
+
124
+ * james.smith@djalbat.com
125
+
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "occam-directed-graphs",
3
3
  "author": "James Smith",
4
- "version": "3.0.32",
4
+ "version": "3.0.34",
5
5
  "license": "MIT, Anti-996",
6
6
  "homepage": "https://github.com/djalbat/occam-directed-graphs",
7
7
  "description": "Directed graphs comprised of directed acyclic graphs together with cycles.",