Skip to content

libinter/chinese-postman-problem

 
 

Repository files navigation

Chinese Postman Problem (WASM)

Adapted from dilsonpereira/chinese-postman-problem, compiled with emscriptem / web assembly, and converted into npm module - module will find the shortest path (lowest cost) along all edges between nodes.

Function is called with three arguments:

/*
	1) number of nodes / vertices 
	2) number of edges / connections 
	3) list of connections as [ [ from, to, cost ] or { from, to, cost } ]
*/

Example:

import cpp from './index.js'

const numberOfNodes = 10
const numberOfEdges = 15

const nodesAndCosts = [
    [ 0, 1, 1 ], // node A, node B, cost or distance
    [ 0, 4, 3 ],
    [ 1, 2, 0 ],
    [ 1, 4, 10 ],
    [ 2, 3, 9 ],
    [ 2, 5, 2 ],
    [ 2, 6, 7 ],
    [ 3, 6, 3 ],
    [ 4, 5, 4 ],
    [ 4, 7, 2 ],
    [ 5, 7, 6 ],
    [ 6, 8, 4 ],
    [ 6, 9, 2 ],
    [ 7, 8, 1 ],
    [ 8, 9, 5 ]
]


const result = await cpp( numberOfNodes, numberOfEdges, nodesAndCosts )

// returns { totalCost: integer, result: [ ... ] }

About

Solve shortest route along all edges using Chinese Postman Problem algorithm (WASM).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 77.4%
  • C++ 9.5%
  • C 7.4%
  • Makefile 2.5%
  • Shell 1.9%
  • HTML 1.3%