I wrote a problem using the code developed for graph theory by folks at NAU, which is used in a number of problems they wrote that are in the Open Problem Library. This code produces and draws random graphs, and can calculate various parameters of the graphs.

My problem uses their code to produce and draw a small random graph, and then uses one of their functions that finds the degree of any vertex to count the number of vertices that have odd degree, and determine accordingly whether or not the graph has an Euler Tour or an Euler Trail.

This problem renders beautifully and produces the correct solutions when I access it through the Library Browser on our local WebWork server, or when I put it into a Homework Set and access it through the homework sets editor. However, if I (or my students) try to access it from within the homework set, the problem doesn't render. The line that calls on the function that finds the degree of a vertex produces an error that seems to indicate it's finding an infinite loop, and only this error appears.

I'm not sure if the issue is with our server, since it works in some contexts but not others, with the code, or what, and I have no idea of how to fix it! I've included the code below. The problematic function is &GRdegree_graph_vertex($graph,$currentvx) (if I change that or comment it out the problem renders fine in all contexts, but of course I can't get it to find the correct solutions without that function).

##DESCRIPTION

## DBsubject(Graph theory)

## DBchapter(walks)

## Institution(University of Lethbridge)

## Author(Joy Morris)

## Level(2)

## KEYWORDS('graph', 'Eulerian', 'degree')

##ENDDESCRIPTION

# File Created: 8/22/21

DOCUMENT(); # This should be the first executable line in the problem.

loadMacros(

"PGstandard.pl",

"PGnauGraphtheory.pl",

"PGcourse.pl"

);

# COMMENT('Please limit the number of trials.');

TEXT(&beginproblem);

$showPartialCorrectAnswers = 0;

$size = random(5,8,1); # number of vertices

$letters = join '', 'A'..'Z';

$offset = random(0,25 - $size, 1);

$labels = substr $letters, $offset, $size ;

$vertices = GRvertices_labels_size($labels,$size);

$graph = GRgraph_size_random($size,0.4);

$edges = GRedgesstr_graph_labels($graph,$labels);

$pic = GRpic_graph_labels($graph,$labels);

$currentvx = 0;

$oddverts = 0;

do {

if (&GRdegree_graph_vertex($graph,$currentvx)%2 == 1) {$oddverts = $oddverts +1};

$currentvx = $currentvx + 1;

} while ($currentvx <= $size);

$vertexlabel1 = GRlabel_vertex_labels(0,$labels);

$vertexlabel2 = GRlabel_vertex_labels(1,$labels);

$vertexlabel3 = GRlabel_vertex_labels(2,$labels);

$vertexlabel4 = GRlabel_vertex_labels(3,$labels);

$vertexlabel5 = GRlabel_vertex_labels(4,$labels);

$ans1 = &GRdegree_graph_vertex($graph,0);

$ans2 = &GRdegree_graph_vertex($graph,1);

$ans3 = &GRdegree_graph_vertex($graph,2);

$ans4 = &GRdegree_graph_vertex($graph,3);

$ans5 = &GRdegree_graph_vertex($graph,4);

if ($oddverts == 0) {$EulerTour = "Y"} else {$EulerTour = "N"};

if ($oddverts <= 2) {$EulerTrail = "Y"} else {$EulerTrail = "N"};

BEGIN_TEXT

$PAR

\{ Plot($pic)\}

$PAR

Consider the graph given above.

$PAR

a. How many vertices of odd valency are there?

\{ ans_rule(5) \}

$PAR

b. Does the graph have an Eulerian Tour (Y/N)?

\{ ans_rule(5) \}

$PAR

b. Does the graph have an Eulerian Trail (Y/N)?

\{ ans_rule(5) \}

END_TEXT

ANS(strict_num_cmp($oddverts));

ANS(str_cmp($EulerTour));

ANS(str_cmp($EulerTrail));

ENDDOCUMENT(); # This should be the last executable line in the problem.