Skip to content

Commit 9fb00ec

Browse files
committed
Add a SimpleGraph.pl macro for working with simple graphs from graph theory.
This is intended to replace the PGnauGraphtheory.pl macro. That macro has lots of problems, and I don't see that macro as something worth repairing. One problem is that it has "NAU" (i.e., a institution name or acronym) in its name which is a practice that we want to get away from. Another problem is that is is implemented with a rather horrid function naming scheme which makes its usage rather tedious. It is almost hopeless to remember the method names, and so documentation must be constantly consulted. In addition there is no real documentation. The graph images that are produced by the macro use WWPlot.pm and PGgraphmacros.pl (via the PGnauGraphics.pl macro which also needs to be eliminated). Another problem is that the macro represents a graph by a matrix that is stored as a single string. That leads to rather ugly and inefficient code. At the heart of this macro is the `GraphTheory::SimpleGraph` object. Such an object can be created with the SimpleGraph function, several random graph generation functions, or a few other functions that produce various special types of graphs. Internally, the `GraphTheory::SimpleGraph` represents a graph by a Perl matrix (i.e., an array of arrays -- the natural form of a matrix in computer programming). However, one rarely needs to access that matrix directly since there are numerous convenience methods provided that can be used to get entries or modify the matrix. If you want to know about various properties of the graph there are also convenient methods for that. For example, if `$graph` is a `GraphTheory::SimpleGraph` object, and you want to know if the graph it represents is bipartite, just call `$graph->isBipartite`. To get a picture of the graph for display purposes use the object `image` method. For example, in PGML you can do `[!alt text!]{$graph->image}`. The default image layout arranges the vertices around the perimeter of a circle, but a grid layout, bipartite layout, and wheel layout (similar to the default layout but with a vertex at the center) are also available. These images are created as `Plots::Plot` objects from the `plots.pl` macro. There is one special MathObject Context provided. The `EdgeSet` context. This can be used for student answers to ask for the edge set of a graph. Note that given a `$graph` instance of the `GraphTheory::SimpleGraph` package, you can call `$edgeSet = $graph->edgeSet` to obtain the edge set for the graph already in this context. That can be used directly for an answer. There are two MathObjects that are provided for use in this context that work together. An `EdgeSet` and an `Edge`. Both are sets delimited by braces. An `EdgeSet` may only contain `Edge`s, and `Edge`s must contain exactly two vertices. Note that the vertices must be declared as `String`s in the context and have the `isVertex` flag set. For example, `Context()->strings->add('A' => { isVetex => 1, caseSensitive => 1 })` adds "A" to the context as a vertex. You can remove the `caseSensitive` flag if you don't want to allow "a" to also be entered for the vertex. Note that if you obtain an `EdgeSet` via `$graph->edgeSet`, then the vertices are automatically added to the context of the returned answer for you. The format a student would use to enter an edgeset is, for example, `{{A, B}, {C, E}}`. Although, by setting the cmp option `requireParenMatch => 0`, you can make it so the outer braces do not need to be entered. There is extensive POD documentation for all of this. Read that for more details. There is also a `SimpleGraphCatalog.pl` macro added. This is to replace the `PGnauGraphCatalog.pl` macro, and contains the same graphs formatted to work with the `SimpleGraph.pl` macro.
1 parent bab8339 commit 9fb00ec

File tree

2 files changed

+13401
-0
lines changed

2 files changed

+13401
-0
lines changed

0 commit comments

Comments
 (0)