UNPKG

gramoloss

Version:

Graph theory package for edition and computation

67 lines (66 loc) 2.96 kB
"use strict"; var _a, _b, _c, _d, _e, _f, _g, _h; Object.defineProperty(exports, "__esModule", { value: true }); const graph_1 = require("../graph"); const g1 = graph_1.Graph.fromEdges([[0, 1], [1, 2], [2, 3], [3, 1]]); const f1 = g1.FloydWarshall(undefined); // console.log([...distances]) // console.log([...next]) console.log(((_a = f1.distances.get(0)) === null || _a === void 0 ? void 0 : _a.get(2)) == 2); console.log(((_b = f1.next.get(0)) === null || _b === void 0 ? void 0 : _b.get(2)) == 1); console.log(((_c = f1.distances.get(0)) === null || _c === void 0 ? void 0 : _c.get(3)) == 2); console.log(((_d = f1.next.get(0)) === null || _d === void 0 ? void 0 : _d.get(3)) == 1); const g2 = graph_1.Graph.fromEdges([[0, 3], [3, 1], [1, 2], [2, 5], [5, 1], [1, 4], [4, 0]]); const f2 = g2.FloydWarshall(undefined); console.log(((_e = f2.distances.get(3)) === null || _e === void 0 ? void 0 : _e.get(2)) == 2); console.log(((_f = f2.next.get(3)) === null || _f === void 0 ? void 0 : _f.get(2)) == 1); console.log(((_g = f2.distances.get(0)) === null || _g === void 0 ? void 0 : _g.get(5)) == 3); console.log(((_h = f2.next.get(5)) === null || _h === void 0 ? void 0 : _h.get(0)) == 1); const g3 = graph_1.Graph.fromArcs([[0, 1], [1, 0], [1, 2]]); const f3 = g3.FloydWarshall(undefined); console.log(f3.distances.get(0)); console.log(f3.distances.get(1)); console.log(f3.distances.get(2)); // Compute the diameter of random tournaments // It seems that the probability of that it has diameter <= 2 tends to 1 when n tends to +infinity // for (let i = 0 ; i < 10 ; i ++){ // const g = generateRandomTournament(40); // const vertices = new Array(); // for (const v of g.vertices.values()){ // vertices.push( [v.data.pos.x, v.data.pos.y, ""]); // } // const arcs = new Array(); // for (const arc of g.links.values()){ // arcs.push( [arc.startVertex.index, arc.endVertex.index, ""]) // } // const bg = Graph.fromArcs(vertices, arcs); // console.log(bg.diameter(undefined)); // } // -------------- // LongestGeodesic // The graph C4 console.log(graph_1.Graph.cycle(4).longestGeodesic(undefined)[0].length == 3); console.log(graph_1.Graph.cycle(4).longestGeodesic(undefined)[1] == 2); console.log(graph_1.Graph.cycle(5).longestGeodesic(undefined)[1] == 2); console.log(graph_1.Graph.cycle(6).longestGeodesic(undefined)[1] == 3); // I2 (independent graph with 2 vertices) console.log(new graph_1.Graph(2).longestGeodesic(undefined)[1] == Infinity); console.log(new graph_1.Graph(2).longestGeodesic(undefined)[0].length == 2); // -------- // Diameter console.log(graph_1.Graph.cycle(4).diameter(undefined) == 2); console.log(graph_1.Graph.cycle(5).diameter(undefined) == 2); console.log(graph_1.Graph.cycle(6).diameter(undefined) == 3); console.log(graph_1.Graph.clique(3).diameter(undefined) == 1); console.log(graph_1.Graph.clique(4).diameter(undefined) == 1);