Skip to content

Conversation

drgrice1
Copy link
Member

@drgrice1 drgrice1 commented Oct 7, 2025

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, 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 Edges, and Edges must contain exactly two vertices. Note that the vertices must be declared as Strings 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.

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 the PGnauGraphtheory.pl macro (there are a few others that load the macro, but don't use it). The setSimpleGraph.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

@drgrice1 drgrice1 force-pushed the simple-graph-macro branch 3 times, most recently from 68502ea to a8acb40 Compare October 8, 2025 10:27
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant