1struct::graph(n)              Tcl Data Structures             struct::graph(n)
2
3
4
5______________________________________________________________________________
6

NAME

8       struct::graph - Create and manipulate directed graph objects
9

SYNOPSIS

11       package require Tcl  8.4
12
13       package require struct::graph  ?2.4.3?
14
15       package require struct::list  ?1.5?
16
17       package require struct::set  ?2.2.3?
18
19       ::struct::graph ?graphName? ?=|:=|as|deserialize source?
20
21       graphName option ?arg arg ...?
22
23       graphName = sourcegraph
24
25       graphName --> destgraph
26
27       graphName append key value
28
29       graphName deserialize serialization
30
31       graphName destroy
32
33       graphName arc append arc key value
34
35       graphName arc attr key
36
37       graphName arc attr key -arcs list
38
39       graphName arc attr key -glob globpattern
40
41       graphName arc attr key -regexp repattern
42
43       graphName arc delete arc ?arc ...?
44
45       graphName arc exists arc
46
47       graphName arc flip arc
48
49       graphName arc get arc key
50
51       graphName arc getall arc ?pattern?
52
53       graphName arc getunweighted
54
55       graphName arc getweight arc
56
57       graphName arc keys arc ?pattern?
58
59       graphName arc keyexists arc key
60
61       graphName arc insert start end ?child?
62
63       graphName arc lappend arc key value
64
65       graphName arc rename arc newname
66
67       graphName arc set arc key ?value?
68
69       graphName arc setunweighted ?weight?
70
71       graphName arc setweight arc weight
72
73       graphName arc unsetweight arc
74
75       graphName arc hasweight arc
76
77       graphName arc source arc
78
79       graphName arc target arc
80
81       graphName arc nodes arc
82
83       graphName arc move-source arc newsource
84
85       graphName arc move-target arc newtarget
86
87       graphName arc move arc newsource newtarget
88
89       graphName arc unset arc key
90
91       graphName arc weights
92
93       graphName   arcs   ?-key   key?   ?-value  value?  ?-filter  cmdprefix?
94       ?-in|-out|-adj|-inner|-embedding node node...?
95
96       graphName lappend key value
97
98       graphName node append node key value
99
100       graphName node attr key
101
102       graphName node attr key -nodes list
103
104       graphName node attr key -glob globpattern
105
106       graphName node attr key -regexp repattern
107
108       graphName node degree ?-in|-out? node
109
110       graphName node delete node ?node...?
111
112       graphName node exists node
113
114       graphName node get node key
115
116       graphName node getall node ?pattern?
117
118       graphName node keys node ?pattern?
119
120       graphName node keyexists node key
121
122       graphName node insert ?node...?
123
124       graphName node lappend node key value
125
126       graphName node opposite node arc
127
128       graphName node rename node newname
129
130       graphName node set node key ?value?
131
132       graphName node unset node key
133
134       graphName  nodes  ?-key  key?  ?-value   value?   ?-filter   cmdprefix?
135       ?-in|-out|-adj|-inner|-embedding node node...?
136
137       graphName get key
138
139       graphName getall ?pattern?
140
141       graphName keys ?pattern?
142
143       graphName keyexists key
144
145       graphName serialize ?node...?
146
147       graphName set key ?value?
148
149       graphName swap node1 node2
150
151       graphName unset key
152
153       graphName  walk node ?-order order? ?-type type? ?-dir direction? -com‐
154       mand cmd
155
156______________________________________________________________________________
157

DESCRIPTION

159       A directed graph is a structure containing two collections of elements,
160       called  nodes and arcs respectively, together with a relation ("connec‐
161       tivity") that places a general structure upon the nodes and arcs.
162
163       Each arc is connected to two nodes, one of which is called  the  source
164       and  the other the target. This imposes a direction upon the arc, which
165       is said to go from the source to the target. It is allowed that  source
166       and  target  of an arc are the same node. Such an arc is called a loop.
167       Whenever a node is either the source or target of an arc both are  said
168       to be adjacent. This extends into a relation between nodes, i.e. if two
169       nodes are connected through at least one arc they are said to be  adja‐
170       cent too.
171
172       Each node can be the source and target for any number of arcs. The for‐
173       mer are called the outgoing arcs of the node, the latter  the  incoming
174       arcs of the node. The number of arcs in either set is called the in-de‐
175       gree resp. the out-degree of the node.
176
177       In addition to maintaining the node and arc relationships,  this  graph
178       implementation  allows  any number of named attributes to be associated
179       with the graph itself, and each node or arc.
180
181       Note: The major version of the package struct has been changed to  ver‐
182       sion  2.0, due to backward incompatible changes in the API of this mod‐
183       ule. Please read the section Changes for 2.0 for a  full  list  of  all
184       changes, incompatible and otherwise.
185
186       Note:  A  C-implementation  of the command can be had from the location
187       http://www.purl.org/NET/schlenker/tcl/cgraph.         See          also
188       http://wiki.tcl.tk/cgraph.   This implementation uses a bit less memory
189       than the tcl version provided here directly, and is faster. Its support
190       is limited to versions of the package before 2.0.
191
192       As  of  version  2.2 of this package a critcl based C implementation is
193       available from here as well. This implementation however  requires  Tcl
194       8.4 to run.
195
196       The main command of the package is:
197
198       ::struct::graph ?graphName? ?=|:=|as|deserialize source?
199              The command creates a new graph object with an associated global
200              Tcl command whose name is graphName.  This command may  be  used
201              to invoke various operations on the graph.  It has the following
202              general form:
203
204              graphName option ?arg arg ...?
205                     Option and the args determine the exact behavior  of  the
206                     command.
207
208       If  graphName  is  not specified a unique name will be generated by the
209       package itself. If a source is specified the new graph will be initial‐
210       ized  to it. For the operators =, :=, and as the source argument is in‐
211       terpreted as the name of another graph object, and the assignment oper‐
212       ator  =  will be executed. For the operator deserialize the source is a
213       serialized graph object and deserialize will be executed.
214
215       In other words
216
217
218
219                  ::struct::graph mygraph = b
220
221
222       is equivalent to
223
224
225
226                  ::struct::graph mygraph
227                  mygraph = b
228
229
230       and
231
232
233
234                  ::struct::graph mygraph deserialize $b
235
236
237       is equivalent to
238
239
240
241                  ::struct::graph mygraph
242                  mygraph deserialize $b
243
244
245       The following commands are possible for graph objects:
246
247       graphName = sourcegraph
248              This is the assignment operator for graph objects. It copies the
249              graph  contained  in the graph object sourcegraph over the graph
250              data in graphName. The old contents of graphName are deleted  by
251              this operation.
252
253              This operation is in effect equivalent to
254
255
256
257                  graphName deserialize [sourcegraph serialize]
258
259
260       The  operation assumes that the sourcegraph provides the method serial‐
261       ize and that this method returns a valid graph serialization.
262
263       graphName --> destgraph
264              This is the reverse assignment operator for  graph  objects.  It
265              copies  the  graph  contained in the graph object graphName over
266              the graph data in the object destgraph.   The  old  contents  of
267              destgraph are deleted by this operation.
268
269              This operation is in effect equivalent to
270
271
272
273                  destgraph deserialize [graphName serialize]
274
275
276       The  operation assumes that the destgraph provides the method deserial‐
277       ize and that this method takes a graph serialization.
278
279       graphName append key value
280              Appends a value to one of the keyed values associated  with  the
281              graph.  Returns the new value given to the attribute key.
282
283       graphName deserialize serialization
284              This  is the complement to serialize. It replaces the graph data
285              in graphName with  the  graph  described  by  the  serialization
286              value.  The old contents of graphName are deleted by this opera‐
287              tion.
288
289       graphName destroy
290              Destroys the graph, including its storage space  and  associated
291              command.
292
293       graphName arc append arc key value
294              Appends  a  value  to one of the keyed values associated with an
295              arc. Returns the new value given to the attribute key.
296
297       graphName arc attr key
298
299       graphName arc attr key -arcs list
300
301       graphName arc attr key -glob globpattern
302
303       graphName arc attr key -regexp repattern
304              This method retrieves the value of the attribute named key,  for
305              all  arcs  in  the graph (matching the restriction specified via
306              one of the possible options) and having the specified attribute.
307
308              The result is a dictionary mapping from arc names to  the  value
309              of  attribute  key  at  that arc.  Arcs not having the attribute
310              key, or not passing a specified restriction, are not  listed  in
311              the result.
312
313              The possible restrictions are:
314
315              -arcs  The  value  is a list of arcs. Only the arcs mentioned in
316                     this list are searched for the attribute.
317
318              -glob  The value is a glob pattern. Only the arcs in  the  graph
319                     whose  names  match this pattern are searched for the at‐
320                     tribute.
321
322              -regexp
323                     The value is a regular expression. Only the arcs  in  the
324                     graph whose names match this pattern are searched for the
325                     attribute.
326
327
328       graphName arc delete arc ?arc ...?
329              Remove the specified arcs from the graph.
330
331       graphName arc exists arc
332              Return true if the specified arc exists in the graph.
333
334       graphName arc flip arc
335              Reverses the direction of the named arc,  i.e.  the  source  and
336              target nodes of the arc are exchanged with each other.
337
338       graphName arc get arc key
339              Returns the value associated with the key key for the arc.
340
341       graphName arc getall arc ?pattern?
342              Returns a dictionary (suitable for use with [array set]) for the
343              arc.  If the pattern is  specified  only  the  attributes  whose
344              names match the pattern will be part of the returned dictionary.
345              The pattern is a glob pattern.
346
347       graphName arc getunweighted
348              Returns a list containing the names of all  arcs  in  the  graph
349              which have no weight associated with them.
350
351       graphName arc getweight arc
352              Returns  the  weight associated with the arc. Throws an error if
353              the arc has no weight associated with it.
354
355       graphName arc keys arc ?pattern?
356              Returns a list of keys for the arc.  If the pattern is specified
357              only  the  attributes whose names match the pattern will be part
358              of the returned list. The pattern is a glob pattern.
359
360       graphName arc keyexists arc key
361              Return true if the specified key exists for the arc.
362
363       graphName arc insert start end ?child?
364              Insert an arc named child into the graph beginning at  the  node
365              start  and ending at the node end. If the name of the new arc is
366              not specified the system will generate a unique name of the form
367              arcx.
368
369       graphName arc lappend arc key value
370              Appends  a  value (as a list) to one of the keyed values associ‐
371              ated with an arc. Returns the new value given to  the  attribute
372              key.
373
374       graphName arc rename arc newname
375              Renames the arc arc to newname. An error is thrown if either the
376              arc does not exist, or a arc with name newname does  exist.  The
377              result of the command is the new name of the arc.
378
379       graphName arc set arc key ?value?
380              Set  or  get one of the keyed values associated with an arc.  An
381              arc may have any number of keyed values associated with it.   If
382              value  is  not specified, this command returns the current value
383              assigned to the key; if value is specified, this command assigns
384              that value to the key, and returns that value.
385
386       graphName arc setunweighted ?weight?
387              Sets  the weight of all arcs without a weight to weight. Returns
388              the empty string as its result. If not present  weight  defaults
389              to 0.
390
391       graphName arc setweight arc weight
392              Sets the weight of the arc to weight. Returns weight.
393
394       graphName arc unsetweight arc
395              Removes  the  weight of the arc, if present. Does nothing other‐
396              wise. Returns the empty string.
397
398       graphName arc hasweight arc
399              Determines if the arc has a weight associated with it.  The  re‐
400              sult  is a boolean value, True if a weight is defined, and False
401              otherwise.
402
403       graphName arc source arc
404              Return the node the given arc begins at.
405
406       graphName arc target arc
407              Return the node the given arc ends at.
408
409       graphName arc nodes arc
410              Return the nodes the given arc begins and ends at, as a two-ele‐
411              ment list.
412
413       graphName arc move-source arc newsource
414              Changes  the source node of the arc to newsource. It can be said
415              that the arc rotates around its target node.
416
417       graphName arc move-target arc newtarget
418              Changes the target node of the arc to newtarget. It can be  said
419              that the arc rotates around its source node.
420
421       graphName arc move arc newsource newtarget
422              Changes  both  source  and target nodes of the arc to newsource,
423              and newtarget resp.
424
425       graphName arc unset arc key
426              Remove a keyed value from the arc arc. The method will do  noth‐
427              ing if the key does not exist.
428
429       graphName arc weights
430              Returns  a dictionary whose keys are the names of all arcs which
431              have a weight associated with them, and  the  values  are  these
432              weights.
433
434       graphName   arcs   ?-key   key?   ?-value  value?  ?-filter  cmdprefix?
435       ?-in|-out|-adj|-inner|-embedding node node...?
436              Returns a list of arcs in the graph. If no restriction is speci‐
437              fied  a  list  containing all arcs is returned. Restrictions can
438              limit the list of returned arcs based on the nodes that are con‐
439              nected  by the arc, on the keyed values associated with the arc,
440              or both. A general filter command can be used as well.  The  re‐
441              strictions  that  involve connected nodes take a variable number
442              of nodes as argument, specified after the name of  the  restric‐
443              tion itself.
444
445              The  restrictions  imposed by either -in, -out, -adj, -inner, or
446              -embedding are applied first. Specifying more than one  of  them
447              is illegal.
448
449              After  that  the  restrictions set via -key (and -value) are ap‐
450              plied. Specifying more than one -key (and  -value)  is  illegal.
451              Specifying -value alone, without -key is illegal as well.
452
453              Any  restriction set through -filter is applied last. Specifying
454              more than one -filter is illegal.
455
456              Coming back to the restrictions based on a  set  of  nodes,  the
457              command recognizes the following switches:
458
459              -in    Return  a  list  of  all  arcs whose target is one of the
460                     nodes in the set of nodes. I.e. it computes the union  of
461                     all incoming arcs of the nodes in the set.
462
463              -out   Return  a  list  of  all  arcs whose source is one of the
464                     nodes in the set of nodes. I.e. it computes the union  of
465                     all outgoing arcs of the nodes in the set.
466
467              -adj   Return a list of all arcs adjacent to at least one of the
468                     nodes in the set. This is the union of the nodes returned
469                     by -in and -out.
470
471              -inner Return  a  list  of all arcs which are adjacent to two of
472                     the nodes in the set. This is the set of arcs in the sub‐
473                     graph spawned by the specified nodes.
474
475              -embedding
476                     Return  a list of all arcs adjacent to exactly one of the
477                     nodes in the set. This is the set of arcs connecting  the
478                     subgraph  spawned  by  the specified nodes to the rest of
479                     the graph.
480
481              Attention: After the above options any word with a leading  dash
482              which is not a valid option is treated as a node name instead of
483              an invalid option to error out on. This  condition  holds  until
484              either  a  valid option terminates the list of nodes, or the end
485              of the command is reached, whichever comes first.
486
487              The remaining filter options are:
488
489
490              -key key
491                     Limit the list of arcs that are returned  to  those  arcs
492                     that have an associated key key.
493
494              -value value
495                     This  restriction  can  only  be used in combination with
496                     -key. It limits the list of arcs  that  are  returned  to
497                     those arcs whose associated key key has the value value.
498
499              -filter cmdrefix
500                     Limit  the  list  of arcs that are returned to those arcs
501                     that pass the test. The command in  cmdprefix  is  called
502                     with two arguments, the name of the graph object, and the
503                     name of the arc in question. It is executed in  the  con‐
504                     text  of  the  caller  and has to return a boolean value.
505                     Arcs for which the command returns false are removed from
506                     the result list before it is returned to the caller.
507
508       graphName lappend key value
509              Appends  a  value (as a list) to one of the keyed values associ‐
510              ated with the graph. Returns the new value given to  the  attri‐
511              bute key.
512
513       graphName node append node key value
514              Appends  a  value  to one of the keyed values associated with an
515              node. Returns the new value given to the attribute key.
516
517       graphName node attr key
518
519       graphName node attr key -nodes list
520
521       graphName node attr key -glob globpattern
522
523       graphName node attr key -regexp repattern
524              This method retrieves the value of the attribute named key,  for
525              all  nodes  in the graph (matching the restriction specified via
526              one of the possible options) and having the specified attribute.
527
528              The result is a dictionary mapping from node names to the  value
529              of  attribute  key at that node.  Nodes not having the attribute
530              key, or not passing a specified restriction, are not  listed  in
531              the result.
532
533              The possible restrictions are:
534
535              -nodes The value is a list of nodes. Only the nodes mentioned in
536                     this list are searched for the attribute.
537
538              -glob  The value is a glob pattern. Only the nodes in the  graph
539                     whose  names  match this pattern are searched for the at‐
540                     tribute.
541
542              -regexp
543                     The value is a regular expression. Only the nodes in  the
544                     graph whose names match this pattern are searched for the
545                     attribute.
546
547
548       graphName node degree ?-in|-out? node
549              Return the number of arcs adjacent to the specified node. If one
550              of the restrictions -in or -out is given only the incoming resp.
551              outgoing arcs are counted.
552
553       graphName node delete node ?node...?
554              Remove the specified nodes from the graph.  All  of  the  nodes'
555              arcs will be removed as well to prevent unconnected arcs.
556
557       graphName node exists node
558              Return true if the specified node exists in the graph.
559
560       graphName node get node key
561              Return the value associated with the key key for the node.
562
563       graphName node getall node ?pattern?
564              Returns a dictionary (suitable for use with [array set]) for the
565              node.  If the pattern is specified  only  the  attributes  whose
566              names match the pattern will be part of the returned dictionary.
567              The pattern is a glob pattern.
568
569       graphName node keys node ?pattern?
570              Returns a list of keys for the node.  If the pattern  is  speci‐
571              fied  only  the attributes whose names match the pattern will be
572              part of the returned list. The pattern is a glob pattern.
573
574       graphName node keyexists node key
575              Return true if the specified key exists for the node.
576
577       graphName node insert ?node...?
578              Insert one or more nodes into the graph. The new nodes  have  no
579              arcs connected to them. If no node is specified one node will be
580              inserted, and the system will generate a unique name of the form
581              nodex for it.
582
583       graphName node lappend node key value
584              Appends  a  value (as a list) to one of the keyed values associ‐
585              ated with an node. Returns the new value given to the  attribute
586              key.
587
588       graphName node opposite node arc
589              Return the node at the other end of the specified arc, which has
590              to be adjacent to the given node.
591
592       graphName node rename node newname
593              Renames the node node to newname. An error is thrown  if  either
594              the node does not exist, or a node with name newname does exist.
595              The result of the command is the new name of the node.
596
597       graphName node set node key ?value?
598              Set or get one of the keyed values associated  with  a  node.  A
599              node may have any number of keyed values associated with it.  If
600              value is not specified, this command returns the  current  value
601              assigned to the key; if value is specified, this command assigns
602              that value to the key.
603
604       graphName node unset node key
605              Remove a keyed value from the node  node.  The  method  will  do
606              nothing if the key does not exist.
607
608       graphName   nodes   ?-key   key?  ?-value  value?  ?-filter  cmdprefix?
609       ?-in|-out|-adj|-inner|-embedding node node...?
610              Return a list of nodes in the graph. Restrictions can limit  the
611              list  of  returned nodes based on neighboring nodes, or based on
612              the keyed values associated with the node. The restrictions that
613              involve  neighboring  nodes  have  a  list of nodes as argument,
614              specified after the name of the restriction itself.
615
616              The possible restrictions are the same as for method arcs.  Note
617              that  while  the exact meanings change slightly, as they operate
618              on nodes instead of arcs, the general behaviour is the same, es‐
619              pecially  when  it comes to the handling of words with a leading
620              dash in node lists.
621
622              The command recognizes:
623
624              -in    Return a list of all nodes with at least one outgoing arc
625                     ending in a node found in the specified set of nodes. Al‐
626                     ternatively specified as the set of source nodes for  the
627                     -in arcs of the node set. The incoming neighbours.
628
629              -out   Return a list of all nodes with at least one incoming arc
630                     starting in a node found in the specified set  of  nodes.
631                     Alternatively  specified  as  the set of target nodes for
632                     the -out arcs of the node set. The outgoing neighbours.
633
634              -adj   This is the union of the nodes returned by -in and  -out.
635                     The neighbours.
636
637              -inner The  set of neighbours (see -adj above) which are also in
638                     the set of nodes. I.e. the intersection between  the  set
639                     of nodes and the neighbours per -adj.
640
641              -embedding
642                     The  set  of neighbours (see -adj above) which are not in
643                     the set of nodes. I.e. the difference between the  neigh‐
644                     bours as per -adj, and the set of nodes.
645
646              -key key
647                     Limit  the list of nodes that are returned to those nodes
648                     that have an associated key key.
649
650              -value value
651                     This restriction can only be  used  in  combination  with
652                     -key.  It  limits  the list of nodes that are returned to
653                     those nodes whose associated key key has the value value.
654
655              -filter cmdrefix
656                     Limit the list of nodes that are returned to those  nodes
657                     that  pass  the  test. The command in cmdprefix is called
658                     with two arguments, the name of the graph object, and the
659                     name  of the node in question. It is executed in the con‐
660                     text of the caller and has to  return  a  boolean  value.
661                     Nodes  for  which  the  command returns false are removed
662                     from the result list before it is returned to the caller.
663
664       graphName get key
665              Return the value associated with the key key for the graph.
666
667       graphName getall ?pattern?
668              Returns a dictionary (suitable for use with [array set]) for the
669              whole  graph.   If  the pattern is specified only the attributes
670              whose names match the pattern will be part of the returned  dic‐
671              tionary. The pattern is a glob pattern.
672
673       graphName keys ?pattern?
674              Returns  a  list of keys for the whole graph.  If the pattern is
675              specified only the attributes whose names match the pattern will
676              be part of the returned list. The pattern is a glob pattern.
677
678       graphName keyexists key
679              Return true if the specified key exists for the whole graph.
680
681       graphName serialize ?node...?
682              This method serializes the sub-graph spanned up by the nodes. In
683              other words it returns a tcl value  completely  describing  that
684              graph. If no nodes are specified the whole graph will be serial‐
685              ized.  This allows, for example, the transfer of  graph  objects
686              (or  parts  thereof)  over arbitrary channels, persistence, etc.
687              This method is also the basis for both the copy constructor  and
688              the assignment operator.
689
690              The  result of this method has to be semantically identical over
691              all implementations of the graph interface. This  is  what  will
692              enable  us  to copy graph data between different implementations
693              of the same interface.
694
695              The result is a list containing a multiple of three items,  plus
696              one!  In other words, '[llength $serial] % 3 == 1'. Valid values
697              include 1, 4, 7, ...
698
699              The last element of the list is a dictionary containing the  at‐
700              tributes  associated  with the whole graph.  Regarding the other
701              elements; each triple consists of
702
703              [1]    The name of the node to be described,
704
705              [2]    A dictionary containing the  attributes  associated  with
706                     the node,
707
708              [3]    And a list describing all the arcs starting at that node.
709
710       The  elements  of  the arc list are lists containing three or four ele‐
711       ments each, i.e.
712
713              [1]    The name of the arc described by the element,
714
715              [2]    A reference to the destination node of the arc. This ref‐
716                     erence  is an integer number given the index of that node
717                     in the main serialization list. As  that  it  is  greater
718                     than  or equal to zero, less than the length of the seri‐
719                     alization, and a multiple of three.  Note:  For  internal
720                     consistency no arc name may be used twice, whether in the
721                     same node, or at some other node. This is a  global  con‐
722                     sistency requirement for the serialization.
723
724              [3]    And  a  dictionary  containing  the attributes associated
725                     with the arc.
726
727              [4]    The weight associated with the arc.  This  value  is  op‐
728                     tional.  Its  non-presence means that the arc in question
729                     has no weight associated with it.
730
731                     Note: This information is new, compared to the serializa‐
732                     tion  of  graph 2.3 and earlier. By making it an optional
733                     element the new format is maximally compatible  with  the
734                     old.  This  means  that  any graph not using weights will
735                     generate a serialization which is still understood by the
736                     older  graph  package. A serialization will not be under‐
737                     stood any longer by the older packages if,  and  only  if
738                     the  graph  it  was generated from actually has arcs with
739                     weights.
740
741       For all attribute dictionaries they keys  are  the  names  of  the  at‐
742       tributes, and the values are the values for each name.
743
744       Note: The order of the nodes in the serialization has no relevance, nor
745       has the order of the arcs per node.
746
747
748                  # A possible serialization for the graph structure
749                  #
750                  #        d -----> %2
751                  #       /         ^ \
752                  #      /         /   \
753                  #     /         b     \
754                  #    /         /       \
755                  #  %1 <- a - %0         e
756                  #    ^         \\      /
757                  #     \\        c     /
758                  #      \\        \\  /
759                  #       \\        v v
760                  #        f ------ %3
761                  # is
762                  #
763                  # %3 {} {{f 6 {}}} %0 {} {{a 6 {}} {b 9 {}} {c 0 {}}} %1 {} {{d 9 {}}} %2 {} {{e 0 {}}} {}
764                  #
765                  # This assumes that the graph has neither attribute data nor weighted arcs.
766
767
768
769       graphName set key ?value?
770              Set or get one of the keyed values associated with  a  graph.  A
771              graph may have any number of keyed values associated with it. If
772              value is not specified, this command returns the  current  value
773              assigned to the key; if value is specified, this command assigns
774              that value to the key.
775
776       graphName swap node1 node2
777              Swap the position of node1 and node2 in the graph.
778
779       graphName unset key
780              Remove a keyed value from the graph. The method will do  nothing
781              if the key does not exist.
782
783       graphName  walk node ?-order order? ?-type type? ?-dir direction? -com‐
784       mand cmd
785              Perform a breadth-first or depth-first walk of the graph  start‐
786              ing  at  the node node going in either the direction of outgoing
787              or opposite to the incoming arcs.
788
789              The type of walk, breadth-first or depth-first, is determined by
790              the  value  of  type; bfs indicates breadth-first, dfs indicates
791              depth-first.  Depth-first is the default.
792
793              The order of the walk, pre-order, post-order  or  both-order  is
794              determined  by the value of order; pre indicates pre-order, post
795              indicates post-order, both indicates  both-order.  Pre-order  is
796              the  default. Pre-order walking means that a node is visited be‐
797              fore any of its neighbors (as defined by the direction, see  be‐
798              low).  Post-order  walking  means that a parent is visited after
799              any of its neighbors. Both-order walking means that  a  node  is
800              visited  before  and after any of its neighbors. The combination
801              of a breadth-first walk with post- or both-order is illegal.
802
803              The direction of the walk is determined by  the  value  of  dir;
804              backward  indicates the direction opposite to the incoming arcs,
805              forward indicates the direction of the outgoing arcs.
806
807              As the walk progresses, the command cmd  will  be  evaluated  at
808              each node, with the mode of the call (enter or leave) and values
809              graphName and the name of the current node appended. For a  pre-
810              order  walk,  all  nodes are entered, for a post-order all nodes
811              are left. In a both-order walk the first visit of a node  enters
812              it, the second visit leaves it.
813

CHANGES FOR 2.0

815       The following noteworthy changes have occurred:
816
817       [1]    The  API for accessing attributes and their values has been sim‐
818              plified.
819
820              All functionality regarding the  default  attribute  "data"  has
821              been removed. This default attribute does not exist anymore. All
822              accesses to attributes have to specify the name of the attribute
823              in  question.  This  backward  incompatible change allowed us to
824              simplify the signature of all methods handling attributes.
825
826              Especially the flag -key is not required anymore, even more, its
827              use  is now forbidden. Please read the documentation for the arc
828              and node methods  set,  get,  getall,  unset,  append,  lappend,
829              keyexists and keys for a description of the new API's.
830
831       [2]    The  methods  keys and getall now take an optional pattern argu‐
832              ment and will return only attribute data for keys matching  this
833              pattern.
834
835       [3]    Arcs and nodes can now be renamed. See the documentation for the
836              methods arc rename and node rename.
837
838       [4]    The structure has been extended with API's for the serialization
839              and deserialization of graph objects, and a number of operations
840              based on them (graph assignment, copy construction).
841
842              Please read the documentation for the methods serialize, deseri‐
843              alize,  =, and -->, and the documentation on the construction of
844              graph objects.
845
846              Beyond the copying of whole graph objects these new  API's  also
847              enable the transfer of graph objects over arbitrary channels and
848              for easy persistence.
849
850       [5]    A new method, attr, was added to both arc and node allowing  the
851              query  and retrieval of attribute data without regard to arc and
852              node relationships.
853
854       [6]    Both methods arcs and nodes have been extended with the  ability
855              to  select  arcs  and nodes based on an arbitrary filtering cri‐
856              terium.
857

BUGS, IDEAS, FEEDBACK

859       This document, and the package it describes, will  undoubtedly  contain
860       bugs  and other problems.  Please report such in the category struct ::
861       graph of the  Tcllib  Trackers  [http://core.tcl.tk/tcllib/reportlist].
862       Please  also  report any ideas for enhancements you may have for either
863       package and/or documentation.
864
865       When proposing code changes, please provide unified diffs, i.e the out‐
866       put of diff -u.
867
868       Note  further  that  attachments  are  strongly  preferred over inlined
869       patches. Attachments can be made by going  to  the  Edit  form  of  the
870       ticket  immediately  after  its  creation, and then using the left-most
871       button in the secondary navigation bar.
872

KEYWORDS

874       adjacent, arc, cgraph, degree, edge, graph, loop, neighbour, node,  se‐
875       rialization, subgraph, vertex
876

CATEGORY

878       Data structures
879
881       Copyright (c) 2002-2009,2019 Andreas Kupries <andreas_kupries@users.sourceforge.net>
882
883
884
885
886tcllib                               2.4.3                    struct::graph(n)
Impressum