csReach.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.csReach = csReach;
  6. var _csMarked = require("./csMarked.js");
  7. var _csMark = require("./csMark.js");
  8. var _csDfs = require("./csDfs.js");
  9. /**
  10. * The csReach function computes X = Reach(B), where B is the nonzero pattern of the n-by-1
  11. * sparse column of vector b. The function returns the set of nodes reachable from any node in B. The
  12. * nonzero pattern xi of the solution x to the sparse linear system Lx=b is given by X=Reach(B).
  13. *
  14. * @param {Matrix} g The G matrix
  15. * @param {Matrix} b The B matrix
  16. * @param {Number} k The kth column in B
  17. * @param {Array} xi The nonzero pattern xi[top] .. xi[n - 1], an array of size = 2 * n
  18. * The first n entries is the nonzero pattern, the last n entries is the stack
  19. * @param {Array} pinv The inverse row permutation vector
  20. *
  21. * @return {Number} The index for the nonzero pattern
  22. *
  23. * Reference: http://faculty.cse.tamu.edu/davis/publications.html
  24. */
  25. function csReach(g, b, k, xi, pinv) {
  26. // g arrays
  27. var gptr = g._ptr;
  28. var gsize = g._size;
  29. // b arrays
  30. var bindex = b._index;
  31. var bptr = b._ptr;
  32. // columns
  33. var n = gsize[1];
  34. // vars
  35. var p, p0, p1;
  36. // initialize top
  37. var top = n;
  38. // loop column indeces in B
  39. for (p0 = bptr[k], p1 = bptr[k + 1], p = p0; p < p1; p++) {
  40. // node i
  41. var i = bindex[p];
  42. // check node i is marked
  43. if (!(0, _csMarked.csMarked)(gptr, i)) {
  44. // start a dfs at unmarked node i
  45. top = (0, _csDfs.csDfs)(i, g, top, xi, pinv);
  46. }
  47. }
  48. // loop columns from top -> n - 1
  49. for (p = top; p < n; p++) {
  50. // restore G
  51. (0, _csMark.csMark)(gptr, xi[p]);
  52. }
  53. return top;
  54. }