January 2018
Intermediate to advanced
332 pages
7h 36m
English
So far, we have the dataset up as described earlier. Now, we will generate the edges from that data and then pass it on to our spanning tree class to generate the MST. So let us add the following code to greeds/travel.js:
const _ = require('lodash');const MST = require('./mst');const graph = { 'SF': { 'SB': 326, 'MT': 118, 'SJ': 49 }, 'SJ': { 'MT': 72, 'FR': 151, 'BK': 241 }, 'MT': { 'SB': 235, 'LA': 320 }, 'SB': { 'LA': 95 }, 'LA': { 'SD': 120 }, 'SD': { 'PX': 355 }, 'FR': { 'LV': 391 }, 'BK': { 'LA': 112, 'SD': 232, 'PX': 483, 'LV': 286 }, 'LV': { 'PX': 297 }, 'PX': {}};const edges= [];_.forEach(graph, (values, node) => { _.forEach(values, (weight, city) => { edges.push({ from ...
Read now
Unlock full access