1.0.0 A flowchart and generalised graph library.
Table of Contents
About Flow
Flow is a flowchart graph library. Unlike other graphing libraries, this one focuses on nodes in a graph having distinct "ports" through which connections to other nodes are formed. This helps in many concrete scenarios where it is important to distinguish not only which nodes are connected, but also how they are connected to each other.
Particularly, a lot of data flow and exchange problems can be reduced to such a "flowchart". For example, an audio processing library may present its pipeline as a flowchart of segments that communicate with each other through audio sample buffers. Flow gives a convenient view onto this kind of problem, and even allows the generic visualisation of graphs in this format.
How To
In a Flow graph there's three kinds of units: nodes, ports, and connections. A node is analogous to a vertex in a graph, a port is analogous to a place where a connection can be made on a node, and a connection is analogous to an edge in a graph.
Of the nodes, there's two kinds:
dynamic-nodeA dynamic node's ports are determined at runtime for each individual instance. This is useful for when you're constructing your graph out of elements that you don't know ahead of time.static-nodeA static node's ports are determined at class definition time, and each port corresponds to a special kind of slot on the graph. This is usually what you want when you define your graph entirely yourself.
Of the ports, there's several mixin classes that can be used to define the kind of port you want. Naturally, if you want to add extra information you can define your own port classes to use instead.
n-portA port that accepts an arbitrary number of connections.1-portA port that only accepts a single connection.in-portA port that only accepts incoming connections.out-portA port that only accepts outgoing connections.
Of the connections, only two are predefined, though it is easy to imagine situations where other kinds of connections might also come in handy.
connectionA basic undirected connection that goes both ways.directed-connectionA directed connection that only goes from left to right.
You can then manage connections between ports using connect, disconnect, and sever. You can also inspect nodes and ports with ports, and connections.
A Flow Chart Example
If you wanted to build a classic flow chart library, you could use something like this as your basic building blocks:
(defclass in (in-port n-port)
())
(defclass out (out-port 1-port)
())
(define-node start ()
((out :port-type out)))
(define-node end ()
((in :port-type in)))
(define-node process ()
((in :port-type in)
(out :port-type out)))
(define-node decision ()
((in :port-type in)
(true :port-type out)
(false :port-type out)))
Using these basic classes we can then create a flow chart like this:
(let ((start (make-instance 'start))
(pick-library (make-instance 'process))
(evaluate-library (make-instance 'process))
(decide-if-good (make-instance 'decision))
(end (make-instance 'end)))
(connect (port start 'out) (port pick-library 'in))
(connect (port pick-library 'out) (port evaluate-library 'in))
(connect (port evaluate-library 'out) (port decide-if-good 'in))
(connect (port decide-if-good 'true) (port end 'in))
(connect (port decide-if-good 'false) (port pick-library 'in))
start)
Operating on Flow Graphs
Flow also includes a couple of operations to help your process the graphs you created using the library. It can do a topological-sort, extract-graph for you, color-nodes, and allocate-ports. There's also a generic visit to allow you to quickly traverse the graph. See the docstrings of the functions for an in-depth explanation of what they do.
Visualising a Flow Graph
There is an additional system included called flow-visualizer. This system includes a primitive graph visualizer that lets you view and edit a graph directly in a GUI. It isn't very advanced at this point, but will probably be extended in the future to a usable flowchart editor.
System Information
Definition Index
-
FLOW
- ORG.SHIRAKUMO.FLOW
No documentation provided.-
EXTERNAL SPECIAL-VARIABLE *RESOLVE-PORT*
Whether a slot-value/slot-makunbound/slot-boundp call should resolve the port. If this is T (the default), then the port's slot within the object's slot is resolved, rather than directly resolving the slot that the port is itself contained in.
-
EXTERNAL CLASS 1-PORT
A port that only accepts a single connection. See PORT
-
EXTERNAL CLASS CONNECTION
Representation of a connection between two ports. This connection is undirected, meaning that it is intended to represent information flowing in both directions. See LEFT See RIGHT See UNIT See CONNECTION= See SEVER
-
EXTERNAL CLASS DIRECTED-CONNECTION
A connection for which information only flows from left to right. See CONNECTION
-
EXTERNAL CLASS DYNAMIC-NODE
Superclass for all dynamic nodes. A dynamic node's ports are allocated on a per-instance basis, rather than on a per-class basis like for the static-node. See NODE
-
EXTERNAL CLASS IN-PORT
A port that only accepts incoming connections. See PORT
-
EXTERNAL CLASS N-PORT
A port that accepts an arbitrary number of connections. See PORT
-
EXTERNAL CLASS NODE
Superclass for all nodes in a Flow graph. A node has a set of PORT instances that are used to form connections to other nodes over. See UNIT See PORT See PORTS See SEVER See CONNECTIONS See REMOVE-CONNECTION See DISCONNECT
-
EXTERNAL CLASS OUT-PORT
A port that only accepts outgoing connections. See PORT
-
EXTERNAL CLASS PORT
Representation of a connection port on a node. Ports are named places on a node through which connections between nodes can be made. See UNIT See CONNECTIONS See NODE See SLOT See CONNECT See DISCONNECT See REMOVE-CONNECTION See CHECK-CONNECTION-ACCEPTED See SEVER
-
EXTERNAL CLASS PORT-DEFINITION
Superclass for port definition slot classes. See PORT-TYPE
-
EXTERNAL CLASS STATIC-NODE
Superclass for all static nodes. The set of ports of a static node is defined per-class and is thus the same for each instance of the class. In addition to the standard slot keywords, a node supports the :PORT-TYPE keyword. This takes a symbol as argument, designating the name of the class to use for the port of this slot. If a slot is a port on the class, connections to other ports may be established through that port. See NODE See STATIC-NODE-CLASS See DEFINE-NODE See PORTS See PORT See SEVER See CONNECTIONS See REMOVE-CONNECTION See DISCONNECT
-
EXTERNAL CLASS STATIC-NODE-CLASS
Metaclass for all static nodes. This class allows the usage of the :PORT-TYPE initarg on slots. If non-null, the slot is treated as a port of the node, allowing to be used for connections between nodes. When such a slot is accessed normally, it immediately resolves to the PORT-VALUE of the port contained in the slot. Every port of a port-typed slot is also automatically instantiated upon instantiation of the class itself, ensuring that it is consistent with the definition. If an access to the actual port object contained in the slot is necessary, the PORT-SLOT-VALUE and PORT-SLOT-BOUNDP functions can be used instead. See PORT-VALUE See DIRECT-PORT-DEFINITION See EFFECTIVE-PORT-DEFINITION See DEFINE-NODE See PORT-SLOT-VALUE See PORT-SLOT-BOUNDP
-
EXTERNAL CLASS UNIT
Superclass for all any entity in a Flow graph. See ATTRIBUTES See ATTRIBUTE See REMOVE-ATTRIBUTE See WITH-ATTRIBUTES
-
EXTERNAL CONDITION CONNECTION-ALREADY-EXISTS
Error signalled if an equivalent connection is added. See NEW-CONNECTION See OLD-CONNECTION See FLOW-CONDITION
-
EXTERNAL CONDITION DESIGNATOR-NOT-A-PORT
-
EXTERNAL CONDITION FLOW-CONDITION
Base type for all conditions from the Flow library.
-
EXTERNAL CONDITION GRAPH-CONTAINS-CYCLES
Error signalled if the graph is cyclic. This error is signalled on algorithms that expect an acyclic graph. See NODE See GRAPH-STRUCTURE-ERROR
-
EXTERNAL CONDITION GRAPH-IS-BIPARTITE
Error signalled if the graph is bipartite. This error is signalled on algorithms that expect a singular, connected graph. See NODE-A See NODE-B See GRAPH-STRUCTURE-ERROR
-
EXTERNAL CONDITION GRAPH-STRUCTURE-ERROR
Base type for conditions related to structural problems in graphs. These conditions are used by the various generic algorithms offered in Flow to signal that a precondition of an operation is not fulfilled in some way. See FLOW-CONDITION
-
EXTERNAL CONDITION ILLEGAL-CONNECTION
Error signalled if the connection is not permitted by the ports. See CONNECTION See MESSAGE See FLOW-CONDITION
-
EXTERNAL FUNCTION A*
- START
- GOAL
- COST-FUN
- &KEY
- TEST
Performs an A* shortest-path calculation. Returns a list of connections along the shortest path. START and GOAL must be nodes of the same graph. COST-FUN must be a function of two arguments that returns an estimated cost to move from the first to the second node that is passed. The TEST function can be used to exclude connections from the shortest path computation. Only connections for which TEST returns T will be considered viable for use in the path. Signals an error of type GRAPH-IS-BIPARTITE if no valid path can be found between START and GOAL. See GRAPH-IS-BIPARTITE
-
EXTERNAL FUNCTION ALLOCATE-PORTS
- NODES
- &KEY
- ATTRIBUTE
- CLEAR
- IN-PLACE-ATTRIBUTE
- TEST
- SORT
Perform a colour "allocation" on the ports of the graph. Each port reachable in the graph from the given starting nodes out that is not of type in-port is assigned a "colour" to the specified attribute. If clear is non-NIL, the colour attribute is first cleared off of each port, ensuring a clean colouring. The colouring rules are as follows: A port may not have the same colour as any of the other ports on the same node. Unless the node's in-place-attribute is non-NIL, the colour must also be distinct from the colour of any of the node's predecessor ports. A predecessor port being any port that is connected to an in-port of the node. In effect this produces a colouring that is useful to calculate the allocation of buffers and other resources necessary to perform a calculation for a node. These rules ensure that the calculation can be performed without accidentally overwriting buffer data necessary at a later point in the execution of the graph, while at the same time also minimising the number of necessary buffers. The given graph may not contain any cycles. Before the nodes are processed, they are sorted by SORT, defaulting to a TOPOLOGICAL-SORT. The sorted nodes must be in such an order that the nodes appear in a topological order. If TEST is given, only ports for which the TEST function returns non-NIL are considered for the colouring. This allows you to distribute multiple colour "kinds" across a single graph by running the colouring once for each kind of colour and excluding the ports that should not be coloured for that kind. See TOPOLOGICAL-SORT
-
EXTERNAL FUNCTION COLOR-NODES
- NODE
- &KEY
- ATTRIBUTE
- CLEAR
Perform a graph colouring. Each node in the graph from the given starting node out is assigned a "colour" to the specified attribute. This colour is in practise an integer in the range [0,n] where n is the number of nodes in the graph. The colours are distributed in such a way that no neighbouring nodes have the same colour. The employed algorithm is greedy and cannot guarantee an optimal colouring. Optimal colouring is an NP- complete problem, and the results produced by a greedy algorithm are usually shown to be good enough. The full list of coloured nodes is returned.
-
EXTERNAL FUNCTION EXTRACT-GRAPH
- NODE
Extract the graph starting from the given node. This returns two lists, the first being the list of vertices (nodes), and the second being the list of edges, with each edge being a list of left and right vertex that are connected. The edges are intended to be directed. Undirected edges are represented by two edges, one from left to right and one from right to left. The order of the vertices and edges in the returned lists is unspecified. See VISIT
-
EXTERNAL FUNCTION OTHER-NODE
- NODE
- CONNECTION
Return the node on the other side of the connection. This works with both directed and undirected connections. See TARGET-NODE
-
EXTERNAL FUNCTION TARGET-NODE
- NODE
- CONNECTION
Return the node on the other side of the connection. If the connection is directed, the target node is only returned if the left-side of the connection is the given node. Otherwise NIL is returned. For undirected connections this acts the same as OTHER-NODE. See OTHER-NODE
-
EXTERNAL FUNCTION TOPOLOGICAL-SORT
- NODES
Produces a topological sorting of the given nodes. This uses Tarjan's algorithm to compute the topological sorting. Note that if the given list of nodes does not include all reachable nodes, the result may be erroneous. Signals an error of type GRAPH-CONTAINS-CYCLES if the graph contains cycles. See GRAPH-CONTAINS-CYCLES
-
EXTERNAL FUNCTION VISIT
- NODE
- FUNCTION
Visit each node in the graph, starting from the given node. The visiting proceeds by calling the function on a node, then recursing through each connection of the node. The recursion does not respect directed connections. It is guaranteed that each node is only visited once, regardless of cycles.
-
EXTERNAL GENERIC-FUNCTION ATTRIBUTE
- UNIT
- NAME
- &OPTIONAL
- DEFAULT
Accessor to the named attribute on the unit. The attribute's name must be comparable by EQL. If the attribute does not exist on the unit, the default value is returned instead. See ATTRIBUTES See REMOVE-ATTRIBUTE See UNIT
-
EXTERNAL GENERIC-FUNCTION (SETF ATTRIBUTE)
- VALUE
- UNIT
- NAME
No documentation provided. -
EXTERNAL GENERIC-FUNCTION ATTRIBUTES
- OBJECT
Accessor to the unit's hash table of attributes. See UNIT See ATTRIBUTE See REMOVE-ATTRIBUTE
-
EXTERNAL GENERIC-FUNCTION (SETF ATTRIBUTES)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION CHECK-CONNECTION-ACCEPTED
- CONNECTION
- PORT
Check whether the given connection is accepted on the given unit. If it is not accepted, an error is signalled. This generic function uses a PROGN method combination, which forces tests of all superclasses to be performed as well. See CONNECTION-ALREADY-EXISTS See ILLEGAL-CONNECTION
-
EXTERNAL GENERIC-FUNCTION CONNECT
- LEFT
- RIGHT
- &OPTIONAL
- CONNECTION-TYPE
- &REST
- INITARGS
Forge a connection between the two units. The connection is only made if it is accepted on both left and right hand sides by CHECK-CONNECTION-ACCEPTED. If both accept the connection, it is pushed onto their respective connections lists. See PORT See CHECK-CONNECTION-ACCEPTED See CONNECTIONS
-
EXTERNAL GENERIC-FUNCTION CONNECTION
- CONDITION
Returns the connection that could not be added. See ILLEGAL-CONNECTION
-
EXTERNAL GENERIC-FUNCTION CONNECTION=
- A
- B
Tests whether two connections are considered equal. Connections are the same under this comparison, if they are connected to the same ports "in the same way". This simply means that whether ports are connected the same may depend on the specific connection being tested. For example, directed connections are only the same if the left and right ports match up, whereas undirected connections are the same regardless of the order between them. See CONNECTION
-
EXTERNAL GENERIC-FUNCTION CONNECTIONS
- OBJECT
-
EXTERNAL GENERIC-FUNCTION (SETF CONNECTIONS)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION DISCONNECT
- LEFT
- RIGHT
Remove any matching connection from left to right. This constructs a directed-connection between the two and then removes all connections from each of them that matches the constructed connection by CONNECTION=. See PORT See DIRECTED-CONNECTION See REMOVE-CONNECTION See CONNECTION=
-
EXTERNAL GENERIC-FUNCTION LEFT
- OBJECT
Accessor to the "left" port of a connection. See CONNECTION
-
EXTERNAL GENERIC-FUNCTION (SETF LEFT)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION MESSAGE
- CONDITION
Returns a reason for the failure. See ILLEGAL-CONNECTION
-
EXTERNAL GENERIC-FUNCTION NAME
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION (SETF NAME)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION NEW-CONNECTION
- CONDITION
Returns the new connection that was attempted to be added. See CONNECTION-ALREADY-EXISTS
-
EXTERNAL GENERIC-FUNCTION NODE
- CONDITION
Accessor to the node this port is home to. See PORT
-
EXTERNAL GENERIC-FUNCTION (SETF NODE)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION NODE-A
- CONDITION
Returns the first node associated with the failure. See GRAPH-IS-BIPARTITE
-
EXTERNAL GENERIC-FUNCTION NODE-B
- CONDITION
Returns the second node associated with the failure. See GRAPH-IS-BIPARTITE
-
EXTERNAL GENERIC-FUNCTION OLD-CONNECTION
- CONDITION
Returns the old connection that already exists on the ports. See CONNECTION-ALREADY-EXISTS
-
EXTERNAL GENERIC-FUNCTION PORT
- NODE
- NAME
Return the port object contained in the node with the specified name. If the name does not designate a port, an error of type DESIGNATOR-NOT-A-PORT is signalled. See NODE See DESIGNATOR-NOT-A-PORT
-
EXTERNAL GENERIC-FUNCTION PORT-TYPE
- OBJECT
Accessor to the port type contained in this slot. See PORT-DEFINITION
-
EXTERNAL GENERIC-FUNCTION (SETF PORT-TYPE)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION PORT-VALUE
- PORT
Accessor to the primary "value" contained in this static port. For standard ports this is the CONNECTIONS slot. See STATIC-NODE See PORT-VALUE-BOUNDP See PORT-VALUE-MAKUNBOUND See DEFINE-PORT-VALUE-SLOT
-
EXTERNAL GENERIC-FUNCTION (SETF PORT-VALUE)
- VALUE
- PORT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION PORT-VALUE-BOUNDP
- PORT
Returns non-NIL if the value slot in this static port is bound. See STATIC-NODE See PORT-VALUE See PORT-VALUE-MAKUNBOUND See DEFINE-PORT-VALUE-SLOT
-
EXTERNAL GENERIC-FUNCTION PORT-VALUE-MAKUNBOUND
- PORT
Makes the value slot in this static port unbound. See STATIC-NODE See PORT-VALUE See PORT-VALUE-BOUNDP See DEFINE-PORT-VALUE-SLOT
-
EXTERNAL GENERIC-FUNCTION PORTS
- OBJECT
Returns a list of port objects that the node contains. This list may not be fresh and thus must not be modified. See NODE
-
EXTERNAL GENERIC-FUNCTION (SETF PORTS)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION REMOVE-ATTRIBUTE
- UNIT
- NAME
Remove the named attribute from the unit. See ATTRIBUTES See ATTRIBUTE See UNIT
-
EXTERNAL GENERIC-FUNCTION REMOVE-CONNECTION
- CONNECTION
- PORT
- &KEY
- TEST
Remove the given connection from the unit. See PORT See NODE See CONNECTIONS
-
EXTERNAL GENERIC-FUNCTION RIGHT
- OBJECT
Accessor to the "right" port of a connection. See CONNECTION
-
EXTERNAL GENERIC-FUNCTION (SETF RIGHT)
- NEW-VALUE
- OBJECT
No documentation provided. -
EXTERNAL GENERIC-FUNCTION SEVER
- CONNECTION
Sever the connections of this unit. For a connection, severing it means simply removing that connection. For a port severing means severing all connections of the port. For a node severing severing all connections of all of its ports. See CONNECTION See PORT See NODE
-
EXTERNAL MACRO DEFINE-NODE
- NAME
- DIRECT-SUPERCLASSES
- DIRECT-SLOTS
- &REST
- OPTIONS
Shorthand macro to define a static node class. All this does is add the necessary :METACLASS option and inject STATIC-NODE as a direct-superclass. See STATIC-NODE
-
EXTERNAL MACRO DEFINE-PORT-VALUE-SLOT
- PORT-CLASS
- SLOT
- &OPTIONAL
- ACCESSOR
Easily define a slot to be used for the port value of a port class. If ACCESSOR is given it should be a symbol denoting the name of an accessor responsible for getting and setting the appropriate value on the port. If it is not given, SLOT-VALUE is used instead. This automatically generates appropriate methods for the port value functions. See PORT-VALUE See PORT-VALUE-BOUNDP See PORT-VALUE-MAKUNBOUND
-
EXTERNAL MACRO WITH-ATTRIBUTES
- ATTRIBUTES
- UNIT
- &BODY
- BODY
Shorthand macro to access the given attributes through a variable. This is similar to WITH-SLOTS. See UNIT See ATTRIBUTE See CL:WITH-SLOTS