simon-git: puzzles (main): Simon Tatham

Commits to Tartarus hosted VCS tartarus-commits at lists.tartarus.org
Fri Sep 27 13:31:05 BST 2024


TL;DR:
  c3800c5 Test program for findloop.c.
  2ac951e Adapt Untangle into a graph editor.
  5044e00 findloop-test: add some fixed test cases.
  3dbd97b Rewrite findloop.c for a simpler variant of Tarjan's algorithm.
  a9601a6 Untangle: fix a memory leak.

Repository:     https://git.tartarus.org/simon/puzzles.git
On the web:     https://git.tartarus.org/?p=simon/puzzles.git
Branch updated: main
Committer:      Simon Tatham <anakin at pobox.com>
Date:           2024-09-27 13:31:05

commit c3800c59d59b807b74fdf7d9b959211e11295770
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=c3800c59d59b807b74fdf7d9b959211e11295770;hp=2ca58c1de1ea516babf9b996c457f71dde99d3b3
Author: Simon Tatham <anakin at pobox.com>
Date:   Thu Sep 12 20:38:32 2024 +0100

    Test program for findloop.c.
    
    Thanks to Amir Livne Bar-on for contributing this. It's about to be
    used to build confidence in a rewrite of findloop.c in a followup
    commit. I also expect that it will be useful later on for testing
    other graph algorithms.
    
    This patch is not Amir's original. I've polished the code in various
    small ways. The biggest change is that when it outputs a failing
    graph, the graph is printed in the form of an Untangle game id, in the
    hope that that will make it possible to visualise easily while
    debugging the problem!

 auxiliary/CMakeLists.txt  |   1 +
 auxiliary/findloop-test.c | 225 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 226 insertions(+)

commit 2ac951e70afa8561599b774ceca6ec8e73d28113
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=2ac951e70afa8561599b774ceca6ec8e73d28113;hp=c3800c59d59b807b74fdf7d9b959211e11295770
Author: Simon Tatham <anakin at pobox.com>
Date:   Wed Sep 18 16:09:07 2024 +0100

    Adapt Untangle into a graph editor.
    
    This builds a secondary GUI program sharing most of the Untangle code,
    similar to galaxieseditor. You can still drag points around as in the
    actual Untangle game, but also you can right-drag to add or remove an
    edge between two points. And the 'copy to clipboard' action generates
    the Untangle game id corresponding to whatever you ended up with.
    
    This could be used for hand-designing actual Untangle games, but my
    more immediate use for it is as a convenient method of constructing
    test cases for the new graph testing code.

 CMakeLists.txt |   2 +
 untangle.c     | 383 ++++++++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 313 insertions(+), 72 deletions(-)

commit 5044e00588e70e82fe72bc2a255eeb4adacb3fa4
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=5044e00588e70e82fe72bc2a255eeb4adacb3fa4;hp=2ac951e70afa8561599b774ceca6ec8e73d28113
Author: Simon Tatham <anakin at pobox.com>
Date:   Fri Sep 27 11:29:56 2024 +0100

    findloop-test: add some fixed test cases.
    
    This increases the chance of detecting a bug in a simple fixed case
    before a complicated random one that's harder to debug. It also allows
    adding regression tests for bugs found later, if any.

 auxiliary/findloop-test.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 60 insertions(+)

commit 3dbd97b60fae08a2bff2abc04fc03685d1d852e6
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=3dbd97b60fae08a2bff2abc04fc03685d1d852e6;hp=5044e00588e70e82fe72bc2a255eeb4adacb3fa4
Author: Simon Tatham <anakin at pobox.com>
Date:   Thu Sep 12 20:38:50 2024 +0100

    Rewrite findloop.c for a simpler variant of Tarjan's algorithm.
    
    Thanks to Amir Livne Bar-on, who implemented this variant from a
    description posted in the Mastodon thread following up my recent blog
    post about loop-finding.
    
    The revised algorithm has the same asymptotic complexity as the one I
    already had. But it has better constant factors, and less code: it can
    run in a single depth-first pass over the graph instead of three
    separate passes, and it needs to store fewer variables per vertex.
    
    This version relies on the insight that if you DFS over an undirected
    graph and imagine it constructing a rooted spanning forest with each
    component's tree rooted at whatever vertex you started that component
    from, then every edge that the DFS visits without making it part of
    the spanning forest must join a vertex to one of its direct ancestors
    in that component's tree.
    
    (Because the other options are that it joins the DFS's current vertex
    to one the search hasn't visited at all yet – in which case the DFS
    _would_ follow it, and make it a forest edge after all. Or else it
    joins this vertex to a cousin in an earlier finished subtree – but
    then when the DFS processed that subtree, it would have explored the
    same edge in the other direction, and added our current vertex to that
    subtree, which by assumption it didn't.)
    
    Hence, instead of assigning every vertex a distinct integer label and
    calculating the min/max label reachable from each subtree, we can
    instead assign each vertex its tree depth, and simply calculate the
    minimum _depth_ of vertex reachable from each subtree: if a subtree
    starting at depth D can reach a vertex at depth <D, it's because
    there's one of those non-tree edges to a vertex outside the subtree,
    so the tree edge entering the subtree isn't a bridge.
    
    And since every non-tree edge must point to a vertex we've already
    seen (and hence assigned a depth to), this can be done in the same
    pass as calculating the depths in the first place - and we don't even
    need to _store_ the spanning forest we generate.

 findloop.c | 432 ++++++++++++++++++++-----------------------------------------
 1 file changed, 138 insertions(+), 294 deletions(-)

commit a9601a678a0613b388a1bcbd5141759acf6a577f
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=a9601a678a0613b388a1bcbd5141759acf6a577f;hp=3dbd97b60fae08a2bff2abc04fc03685d1d852e6
Author: Simon Tatham <anakin at pobox.com>
Date:   Fri Sep 27 12:51:34 2024 +0100

    Untangle: fix a memory leak.
    
    Spotted by Leak Sanitiser while re-testing after the previous commits:
    the separately allocated 'crosses' array in game_state was never freed.

 untangle.c | 3 +++
 1 file changed, 3 insertions(+)



More information about the tartarus-commits mailing list