Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Struct::graph

Help
Deepak
2012-08-29
2013-05-30
  • Deepak
    Deepak
    2012-08-29

    Hi,
    I have created a graph using the tcllib package, struct::graph. Now i want to perform a bfs traversal on the geraph, In the package it has been specified that we have to use the function "walk" for performing traversal on the graph. In that function there is a field called "-command cmd" , can somebody help me as what value i have to specify in that field.
    Thanks
    Deepak

     
  • The documentation at http://docs.activestate.com/activetcl/8.5/tcllib/struct/graph.html#67
    says:

    As the walk progresses, the command cmd will be evaluated at each node,
      with the mode of the call (enter or leave) and values graphName and the name of the current node appended.

    I.e. the command is called for each node visited by the walk.
    It is called like

        uplevel #0 $cmd [list $mode $graph $node]
    

    So, the command can be a procedure X, defined as

      proc X {mode graph node} {
         ...
      }
    

    Does this help ?

     
  • Deepak
    Deepak
    2012-08-30

    Hi,
    Can you please specify what should i write inside the procedure X. I need to display the node names.

    Thanks
    Deepak

     
  • Deepak
    Deepak
    2012-08-30

    Hi,
    If my start node is "node1", order is "pre" , type is "bfs" , object name is "my" and dir is "forward" ,the command will look like the following

    my walk node1 -order pre -type bfs -dir forward -command cmd
    I have the doubt , what value should i specify for cmd?

    Thanks
    Deepak

     
  • Re:

    Can you please specify what should i write inside the procedure X. I need to display the node names.

    The node name is the 'node' argument of X.
    Therefore

    puts $node
    

    is what you want.

    If the node name you speak of is an attribute of the node itself, then it would be more like

    puts [$graph node get $node <attribute>]
    

    where '<attribute>' is my placeholder for the name of the attribute holding the node name.

    Re:

    I have the doubt , what value should i specify for cmd?

    The cmd is independent of the other options. You choose the name of the procedure to use, and then use that name as the cmd.

    In the example shown in my first reply I choose to name the procedure "X". You are free to use whatever name you want.

     
  • Deepak
    Deepak
    2012-09-03

    Hi

    Thank You.

    Regards
    Deepak