Subscribe Bookmark RSS Feed

Associative Arrays in Graph Theory Example?

tumblewoods2

Community Trekker

Joined:

Dec 1, 2015

Hi All,

Am I missing something?  As described below, the result I get differs from what is shown in the Scripting Guide.  (I'm new to JMP, but I already asked one experienced user and he was stumped too.)

I copied and pasted the following code from the Associative Arrays in Graph Theory example (pages 215 and 216 of the Scripting Guide for 12.1).

g = Associative Array();

g[1] = Associative Array( {1, 2, 4} );

g[2] = Associative Array( {1, 3} );

g[3] = Associative Array( {4, 5} );

g[4] = Associative Array( {4, 5} );

g[5] = Associative Array( {1, 2} );

dfs = Function( {ref, node, visited}, Local( {chnode, tmp},

Write( "Node: " || Char( node ) || ", " || Char( ref[node] << get contents ) || "\!N" );

visited[node] = 1;

tmp = ref[node];

chnode = tmp << first; While( !Is Missing( chnode ),

If( !visited[chnode],

visited = Recurse( ref, chnode, visited )

);

chnode = tmp << next( chnode ); );

visited; )

);

dfs( g, 2, J( N Items( g << get keys ), 1, 0 ) );

The book shows the following result:

Node 2: {1, 3}

Node 1: {1, 2, 4}

Node 4: {4, 5}

Node 5: {1, 2}

Node 3: {4, 5}


[1, 1, 1, 1, 1]

I get this result:

Node: 2, {{1, 1}, {3, 1}}

Node: 1, {{1, 1}, {2, 1}, {4, 1}}

Node: 4, {{4, 1}, {5, 1}}

Node: 5, {{1, 1}, {2, 1}}

Node: 3, {{4, 1}, {5, 1}}

[1, 1, 1, 1, 1]

Any suggestions?


Thanks!


1 ACCEPTED SOLUTION

Accepted Solutions
Solution

The doc is wrong. Thanks for reporting it. Replacing "get contents" with "get keys" will produce the provided output.

2 REPLIES
Solution

The doc is wrong. Thanks for reporting it. Replacing "get contents" with "get keys" will produce the provided output.

tumblewoods2

Community Trekker

Joined:

Dec 1, 2015

Perfect.  Thank you, Xan!