From 435fff3ff7f861becb17c526e99b27f79cdde91a Mon Sep 17 00:00:00 2001 From: Bruno Peixoto Date: Sun, 9 Jan 2022 18:17:31 -0300 Subject: [PATCH] Server response: graph --- src/server.js | 48 +++++++++--------------------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/src/server.js b/src/server.js index 8d107cb7..c1566b81 100644 --- a/src/server.js +++ b/src/server.js @@ -5,6 +5,7 @@ import express from 'express' import Graph from './data-structures/graph/Graph.js' import GraphVertex from './data-structures/graph/GraphVertex.js' import GraphEdge from './data-structures/graph/GraphEdge.js' +import depthFirstSearch from './algorithms/depth-first-search/depthFirstSearch.js' const app = express(); @@ -25,6 +26,7 @@ app.get('/', (req, res) => { // Create a sample graph // const graph = req.blueprint.nodes; + // A directed graph let graph_ = new Graph(true); // Nodes @@ -41,11 +43,14 @@ app.get('/', (req, res) => { let CA = new GraphEdge(C, A); let CB = new GraphEdge(C, B); - graph_.addVertex(A); - graph_.addVertex(B); - graph_.addVertex(C); - graph_.addVertex(D); + // Add vertices + graph_ + .addVertex(A) + .addVertex(B) + .addVertex(C) + .addVertex(D); + // Add edges graph_ .addEdge(AB) .addEdge(AC) @@ -54,42 +59,7 @@ app.get('/', (req, res) => { .addEdge(CA) .addEdge(CB); - console.log(graph_.getAllEdges()); - console.log(graph_.getAllVertices()); res.send(graph_.toString()); - - /* - // arbitrary source - let from_ = 1; - - // arbitrary destination - let to = 3; - - let all_paths = s.allPaths(from_, to); - let all_vicinity = s.allVicinity(); - let loose_nodes = s.looseNodes(); - - console.log('Paths from '+from_+' to '+to+' :'); - console.log(all_paths); - - console.log('Reachibility: '); - console.log(all_vicinity); - - console.log('Loose nodes: '); - console.log(loose_nodes); - - let text_ = "Original code from the URL : Graph paths original post " + "
"; - - if(all_paths.length==0){ - text_ = text_ + 'There is no path available from ' + from_ + ' to ' + to + '!'; - } else { - text_ = text_ + "Following are all different paths from " + from_ + " to " + to + "
"; - - for (let i=0; i"; - } - } - */ }); // [END app]