Add a SimpleGraph.pl macro for working with simple graphs from graph theory. #1321
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 (at least for macros included in PG). 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, theGraphTheory::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 aGraphTheory::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 asPlots::Plot
objects from theplots.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 theGraphTheory::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. AnEdgeSet
and anEdge
. Both are sets delimited by braces. AnEdgeSet
may only containEdge
s, andEdge
s must contain exactly two vertices. Note that the vertices must be declared asString
s in the context and have theisVertex
flag set. For example,Context()->strings->add('A' => { isVetex => 1, caseSensitive => 1 })
adds "A" to the context as a vertex. You can remove thecaseSensitive
flag if you don't want to allow "a" to also be entered for the vertex. Note that if you obtain anEdgeSet
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 optionrequireParenMatch => 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 thePGnauGraphCatalog.pl
macro, and contains the same graphs formatted to work with theSimpleGraph.pl
macro.A zip archive is attached that contains two set definition files and a directory containing problem files. The
setPGnauGraphtheory.def
file is a problem set containing all OPL and Contrib problems that use thePGnauGraphtheory.pl
macro (there are a few others that load the macro, but don't use it). ThesetSimpleGraph.def
file is a problem set containing all of the problems in the directory in the archive, and those problems are the OPL and Contrib problems rewritten to use this new macro.SimpleGraph.zip