Skip to content

Commit

Permalink
eventour uses satellite instead of matrix because used on sparse graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
make-github-pseudonymous-again committed May 24, 2014
1 parent 3c3780b commit 858c33f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
11 changes: 5 additions & 6 deletions js/src/001 undirected/offline/algo/eulerian/eventour.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ var eventour_t = function(){
* @param graph g
* @param vertices V
* @param index i node from where to start the search
* @param square matrix free showing free edges
* @param flag list done to label saturated edges
* @param iterator list it that stores info on already processed edges
* @param list tour the output tour
* @param list tour the output tour vertex sequence
* @param list edges the output tour edges
*/

var eventour = function(g, V, i, free, done, it, tour, edges){
var eventour = function(g, V, i, done, it, tour, edges){

var u, j, z = [i, 0];

Expand All @@ -33,16 +33,15 @@ var eventour_t = function(){
while(true){
var end = true;
it[i] = g.eitr(u, function(e, v){
if(free[i][v[0]] > 0){
if(e.free){
tour.splice(j, 0, i);
edges.splice(j, 0, e);
u = v;

++j;
if (!done[u[0]]) r.push([u[0], j]);

--free[i][u[0]];
--free[u[0]][i];
e.free = false;
end = false;
i = u[0];
return true;
Expand Down
18 changes: 12 additions & 6 deletions test/js/src/undirected/offline/algo/eulerian/eventour.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ var check = function(label, n, x, E, _E){

var v = new Array(i);

var free = gn.sqmat(2, n, 0);
var edges = [];


while(i--) v[n-i-1] = g.vadd(n-i-1);

for(j = 0; j < E.length; ++j){
e = E[j];
g.eadd(v[e[0]], v[e[1]], e[2]);
++free[e[0]][e[1]];
++free[e[1]][e[0]];
var tmp = g.eadd(v[e[0]], v[e[1]], e[2]);
edges.push(tmp);
tmp.free = true;
}


Expand All @@ -43,10 +43,16 @@ var check = function(label, n, x, E, _E){
var it = gn.sqmat(1, n, undefined);
var tour = [];

eventour(g, v, x, free, done, it, tour, []);
eventour(g, v, x, done, it, tour, []);

deepEqual(tour.length, E.length, 'check length');
deepEqual(free, gn.sqmat(2, n, 0), 'check free');

var free = [];
edges.forEach(function(e){
free.push(e.free);
});

deepEqual(free, gn.sqmat(1, E.length, false), 'check free');


i = tour.length;
Expand Down

0 comments on commit 858c33f

Please sign in to comment.