Skip to content

Commit

Permalink
Merge pull request #117 from james-d-mitchell/fix-issue-111
Browse files Browse the repository at this point in the history
Fix issue #111
  • Loading branch information
james-d-mitchell authored Apr 26, 2018
2 parents 8318582 + f5f0dd7 commit 49192a0
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 6 deletions.
70 changes: 64 additions & 6 deletions src/homos.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ void (*HOOK)(void*, // HOOK function applied to every homo found
static jmp_buf outofhere; // so we can jump out of the deepest
// level of recursion

// Values in MAP are restricted to those positions in IMAGE_RESTRICT which are
// set to true.
static BitArray* IMAGE_RESTRICT;

////////////////////////////////////////////////////////////////////////////////
// For the orbit reps calculation, and stabiliser chain . . .
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -245,6 +249,26 @@ static inline UIntS size_bit_array(BitArray* bit_array) {
return n;
}

#ifdef DIGRAPHS_KERNEL_DEBUG
static inline void print_bit_array(BitArray* bit_array) {
printf("<bit array {");
for (UIntS i = 0; i < bit_array->nr_bits; i++) {
if (get_bit_array(bit_array, i)) {
printf(" %d", i);
}
}
printf(" }>");
}

static inline void print_array(UIntS* array, UIntS len) {
printf("<array {");
for (UIntS i = 0; i < len; i++) {
printf(" %d", array[i]);
}
printf(" }>");
}
#endif

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// conditions: this is a data structure for keeping track of what possible
Expand Down Expand Up @@ -458,8 +482,17 @@ static void orbit_reps(UIntS rep_depth) {
}

fst = 0;
while (fst < deg && !get_bit_array(DOMAIN, fst))
fst++;
if (IMAGE_RESTRICT != NULL) {
while (fst < deg
&& (!get_bit_array(DOMAIN, fst)
|| !get_bit_array(IMAGE_RESTRICT, fst))) {
fst++;
}
} else {
while (fst < deg && !get_bit_array(DOMAIN, fst)) {
fst++;
}
}

while (fst < deg) {
ORB[0] = fst;
Expand All @@ -480,8 +513,17 @@ static void orbit_reps(UIntS rep_depth) {
}
}
}
while (fst < deg && !get_bit_array(DOMAIN, fst))
fst++;
if (IMAGE_RESTRICT != NULL) {
while (fst < deg
&& (!get_bit_array(DOMAIN, fst)
|| !get_bit_array(IMAGE_RESTRICT, fst))) {
fst++;
}
} else {
while (fst < deg && !get_bit_array(DOMAIN, fst)) {
fst++;
}
}
}
}

Expand Down Expand Up @@ -646,7 +688,8 @@ find_digraph_homos(Digraph* digraph1,
UIntS pos, // the last position filled
UIntS rep_depth,
bool has_trivial_stab,
UIntS rank) { // current number of distinct values in MAP
// current number of distinct values in MAP
UIntS rank) {
UIntS i, min, next;
bool is_trivial;

Expand Down Expand Up @@ -801,6 +844,9 @@ void DigraphHomomorphisms(Digraph* digraph1,
// intersect everything in the first row of conditions with <image>
}
}
// Used by orbit_reps, so that orbit reps are chosen from among the
// restricted values of the image.
IMAGE_RESTRICT = image_arg;

// partial_map_arg is an array of UIntS's partially defining a map from
// digraph1 to digraph2.
Expand Down Expand Up @@ -1039,6 +1085,10 @@ void DigraphMonomorphisms(Digraph* digraph1,
}
}

// Used by orbit_reps, so that orbit reps are chosen from among the
// restricted values of the image.
IMAGE_RESTRICT = image_arg;

// partial_map_arg is an array of UIntS's partially defining a map from
// digraph1 to digraph2.
bit_array = new_bit_array(NR2); // every position is false by default
Expand Down Expand Up @@ -1296,7 +1346,8 @@ find_graph_homos(Graph* graph1,
UIntS pos, // the last position filled
UIntS rep_depth,
bool has_trivial_stab,
UIntS rank) { // current number of distinct values in MAP
// current number of distinct values in MAP
UIntS rank) {
UIntS i, min, next;
bool is_trivial;

Expand Down Expand Up @@ -1437,6 +1488,9 @@ void GraphHomomorphisms(Graph* graph1,
// intersect everything in the first row of conditions with <image_arg>
}
}
// Used by orbit_reps, so that orbit reps are chosen from among the
// restricted values of the image.
IMAGE_RESTRICT = image_arg;

// partial_map_arg is an array of UIntS's partially defining a map from graph1
// to graph2.
Expand Down Expand Up @@ -1470,6 +1524,7 @@ void GraphHomomorphisms(Graph* graph1,
}

if (colors1 != NULL) { // colors1 and colors2 specified
DIGRAPHS_ASSERT(colors2 != NULL);
for (i = 0; i < NR1; i++) {
init_bit_array(bit_array, false);
for (j = 0; j < NR2; j++) {
Expand Down Expand Up @@ -1669,6 +1724,9 @@ void GraphMonomorphisms(Graph* graph1,
// intersect everything in the first row of conditions with <image>
}
}
// Used by orbit_reps, so that orbit reps are chosen from among the
// restricted values of the image.
IMAGE_RESTRICT = image_arg;

// partial_map_arg is an array of UIntS's partially defining a map from
// graph1 to graph2.
Expand Down
12 changes: 12 additions & 0 deletions tst/standard/grahom.tst
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,18 @@ fail
gap> DigraphEmbedding(gr1, gr1);
IdentityTransformation

# From GR, Issue #111, bug in homomorphism finding code for restricted images.
gap> gr := DigraphFromDigraph6String(Concatenation(
> "+U^{?A?BrwAHv_CNu@SMwHQm`GpyGbUYLAbfGTO?Enool[WrI",
> "HBSatQlC[TIC{iSBlo_VrO@u[_Eyk?]YS?"));
<digraph with 22 vertices, 198 edges>
gap> t := HomomorphismDigraphsFinder(gr, gr, fail, [], 1, fail, false,
> [2, 6, 7, 11, 12, 13, 14, 15, 19, 20, 21], [], fail, fail)[1];
Transformation( [ 2, 13, 20, 19, 21, 19, 14, 13, 15, 14, 20, 6, 15, 21, 11,
12, 6, 7, 7, 12, 2, 11 ] )
gap> ForAll(DigraphEdges(gr), e -> IsDigraphEdge(gr, e[1] ^ t, e[2] ^ t));
true

#T# DIGRAPHS_UnbindVariables
gap> Unbind(edges);
gap> Unbind(epis);
Expand Down

0 comments on commit 49192a0

Please sign in to comment.