-
-
Notifications
You must be signed in to change notification settings - Fork 81
Add a SimpleGraph.pl macro for working with simple graphs from graph theory. #1321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
drgrice1
wants to merge
1
commit into
openwebwork:develop
Choose a base branch
from
drgrice1:simple-graph-macro
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+13,405
−0
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9fb00ec to
39e3561
Compare
pstaabp
reviewed
Oct 21, 2025
pstaabp
reviewed
Oct 21, 2025
pstaabp
reviewed
Oct 21, 2025
39e3561 to
8183c04
Compare
…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.
8183c04 to
dfa35e7
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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::SimpleGraphobject. 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::SimpleGraphrepresents 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$graphis aGraphTheory::SimpleGraphobject, 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
imagemethod. 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::Plotobjects from theplots.plmacro.There is one special MathObject Context provided. The
EdgeSetcontext. This can be used for student answers to ask for the edge set of a graph. Note that given a$graphinstance of theGraphTheory::SimpleGraphpackage, you can call$edgeSet = $graph->edgeSetto 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. AnEdgeSetand anEdge. Both are sets delimited by braces. AnEdgeSetmay only containEdges, andEdges must contain exactly two vertices. Note that the vertices must be declared asStrings in the context and have theisVertexflag set. For example,Context()->strings->add('A' => { isVetex => 1, caseSensitive => 1 })adds "A" to the context as a vertex. You can remove thecaseSensitiveflag if you don't want to allow "a" to also be entered for the vertex. Note that if you obtain anEdgeSetvia$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.plmacro added. This is to replace thePGnauGraphCatalog.plmacro, and contains the same graphs formatted to work with theSimpleGraph.plmacro.A zip archive is attached that contains two set definition files and a directory containing problem files. The
setPGnauGraphtheory.deffile is a problem set containing all OPL and Contrib problems that use thePGnauGraphtheory.plmacro (there are a few others that load the macro, but don't use it). ThesetSimpleGraph.deffile 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