You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following graph is not acyclic and node 1 has a path to any other node in the graph:
import{DirectedGraph,CDanNode,CDanArc}from'dangraph';constmyGraph=newDirectedGraph.DanDirectedGraph<number,undefined>();myGraph.addArcToNode(newCDanNode({id: 1}),newCDanArc({weight: 1,node: newCDanNode({id: 2})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 2}),newCDanArc({weight: 1,node: newCDanNode({id: 3})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 2}),newCDanArc({weight: 1,node: newCDanNode({id: 4})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 4}),newCDanArc({weight: 1,node: newCDanNode({id: 5})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 5}),newCDanArc({weight: 1,node: newCDanNode({id: 6})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 4}),newCDanArc({weight: 1,node: newCDanNode({id: 6})}),DirectedGraph.ArcType.incoming);myGraph.addArcToNode(newCDanNode({id: 6}),newCDanArc({weight: 1,node: newCDanNode({id: 3})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 5}),newCDanArc({weight: 1,node: newCDanNode({id: 7})}),DirectedGraph.ArcType.incoming);myGraph.addArcToNode(newCDanNode({id: 3}),newCDanArc({weight: 1,node: newCDanNode({id: 7})}),DirectedGraph.ArcType.outgoing);console.log(myGraph.toString());if(myGraph.isAcyclic()){console.log('The graph is acyclic');}else{console.log('The graph is not acyclic');}if(myGraph.sourceConnectedToAllNodes(1)){console.log('Node 1 has a path to any other node in the graph');}else{console.log('Node 1 does not have a path to any other node in the graph');}
The following graph is acyclic and node 1 does not have a path to node 7
import{DirectedGraph,CDanNode,CDanArc}from'dangraph';constmyGraph=newDirectedGraph.DanDirectedGraph<number,undefined>();myGraph.addArcToNode(newCDanNode({id: 1}),newCDanArc({weight: 1,node: newCDanNode({id: 2})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 2}),newCDanArc({weight: 1,node: newCDanNode({id: 3})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 2}),newCDanArc({weight: 1,node: newCDanNode({id: 4})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 4}),newCDanArc({weight: 1,node: newCDanNode({id: 5})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 5}),newCDanArc({weight: 1,node: newCDanNode({id: 6})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 4}),newCDanArc({weight: 1,node: newCDanNode({id: 6})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 6}),newCDanArc({weight: 1,node: newCDanNode({id: 3})}),DirectedGraph.ArcType.outgoing);myGraph.addArcToNode(newCDanNode({id: 5}),newCDanArc({weight: 1,node: newCDanNode({id: 7})}),DirectedGraph.ArcType.incoming);myGraph.addArcToNode(newCDanNode({id: 3}),newCDanArc({weight: 1,node: newCDanNode({id: 7})}),DirectedGraph.ArcType.incoming);console.log(myGraph.toString());if(myGraph.isAcyclic()){console.log('The graph is acyclic');}else{console.log('The graph is not acyclic');}if(myGraph.sourceConnectedToAllNodes(1)){console.log('Node 1 has a path to any other node in the graph');}else{console.log('Node 1 does not have a path to any other node in the graph');}