simon-git: puzzles (master): Simon Tatham
Commits to Tartarus hosted VCS
tartarus-commits at lists.tartarus.org
Sun Apr 22 17:14:38 BST 2018
TL;DR:
b7034ae Move fgetline out into misc.c.
ef6f642 Recipe: centralise dependencies for latin.c.
4408476 Implementation of the Hopcroft-Karp algorithm.
000ebc5 Use the new matching() for latin.c.
dcc4d82 Convert Tents to use matching instead of maxflow.
3d04dd3 Remove maxflow completely.
60a929a Add a request_keys() function with a midend wrapper.
Repository: https://git.tartarus.org/simon/puzzles.git
On the web: https://git.tartarus.org/?p=simon/puzzles.git
Branch updated: master
Committer: Simon Tatham <anakin at pobox.com>
Date: 2018-04-22 17:14:38
commit b7034aeb51a99336fca2e15837c8337481964f6d
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=b7034aeb51a99336fca2e15837c8337481964f6d;hp=12cb1adc886078d715abbc04e80912703340f496
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Apr 22 13:58:27 2018 +0100
Move fgetline out into misc.c.
I'm about to want to use it outside the GTK front end.
gtk.c | 19 -------------------
misc.c | 19 +++++++++++++++++++
puzzles.h | 1 +
3 files changed, 20 insertions(+), 19 deletions(-)
commit ef6f6427a263627de1d0fed22d8f367b15e2fb1a
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=ef6f6427a263627de1d0fed22d8f367b15e2fb1a;hp=b7034aeb51a99336fca2e15837c8337481964f6d
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Apr 22 16:45:34 2018 +0100
Recipe: centralise dependencies for latin.c.
It's silly to have every puzzle using latin.c separately specify in
its .R file the list of additional modules that latin.c depends on, or
for that matter to have them all have to separately know how to adjust
that for the STANDALONE_SOLVER mode of latin.c.
So I've centralised a new pair of definitions into the core Recipe
file, called LATIN and LATIN_SOLVER, and now a client of latin.c need
only ask for that to get all the necessary dependencies too.
Also, while I'm here, I've moved the non-puzzle-specific 'latincheck'
test program out of unequal.R into the central Recipe.
Recipe | 8 ++++++++
keen.R | 8 ++++----
singles.R | 2 +-
towers.R | 8 ++++----
unequal.R | 10 ++++------
unfinished/group.R | 8 ++++----
6 files changed, 25 insertions(+), 19 deletions(-)
commit 4408476b7584b9a316466fe1bd10867103cddf57
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=4408476b7584b9a316466fe1bd10867103cddf57;hp=ef6f6427a263627de1d0fed22d8f367b15e2fb1a
Author: Simon Tatham <anakin at pobox.com>
Date: Wed Apr 18 20:28:17 2018 +0100
Implementation of the Hopcroft-Karp algorithm.
This is a dedicated algorithm for finding a maximal matching in a
bipartite graph.
Previously I've been solving that problem in this code base using
maxflow.c, modelling the graph matching problem as a restricted case
of the optimal network flow problem and then using a full-strength
algorithm for the latter. That's overkill, and also algorithmically
wasteful - the H-K algorithm is asymptotically better, because it can
find multiple augmenting paths in each pass (hence getting the maximum
benefit out of each expensive breadth-first search), as a consequence
of not having to worry about lower- or higher-value augmenting paths
in this restricted problem.
So I expect this algorithm to be faster, at least in principle or in
large cases, when it takes over the jobs currently being done by
maxflow. But that's not the only benefit. Another is that the data
representation is better suited to the problems actually being solved,
which should simplify all the call sites; a third is that I've
incorporated randomisation of the generated matching into the H-K
module itself, which will further save effort at each call site
because they will no longer have to worry about permuting the
algorithm's input - they just have to pass it a random_state and it
will take care of that internally.
This commit only introduces the new matching.c and builds a test
utility for it. I haven't yet migrated any clients of maxflow.
Recipe | 4 +
matching.c | 753 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
matching.h | 80 +++++++
3 files changed, 837 insertions(+)
commit 000ebc50785c5c066465fc17668ae64975188d04
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=000ebc50785c5c066465fc17668ae64975188d04;hp=4408476b7584b9a316466fe1bd10867103cddf57
Author: Simon Tatham <anakin at pobox.com>
Date: Sun Apr 22 13:48:07 2018 +0100
Use the new matching() for latin.c.
The new client code is a lot smaller and nicer, because we can throw
away the col[] and num[] permutations entirely.
Of course, this also means that every puzzle that incorporated latin.c
now has to link against matching.c instead of maxflow.c - but since I
centralised that secondary dependency into Recipe a few commits ago,
it's trivial to switch them all over at once.
Recipe | 2 +-
latin.c | 135 +++++++++++++++++++++-------------------------------------------
2 files changed, 45 insertions(+), 92 deletions(-)
commit dcc4d82b23095b07673d7c13cb2439c738a67fa1
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=dcc4d82b23095b07673d7c13cb2439c738a67fa1;hp=000ebc50785c5c066465fc17668ae64975188d04
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Apr 21 16:51:03 2018 +0100
Convert Tents to use matching instead of maxflow.
Tents needs to construct maximal matchings in two different
situations. One is the completion check during play, in which the
existence of a perfect matching between tents and trees is part of the
win condition; the other is the initial grid generation, in which we
find a _maximal_ matching between the tents we've already placed and
all the possible neighbouring squares that are candidates for the tree
positions. Both of those are switched over.
tents.R | 2 +-
tents.c | 241 ++++++++++++++++++++++++++++++----------------------------------
2 files changed, 115 insertions(+), 128 deletions(-)
commit 3d04dd3335a2c4c6007ff4e2a58a2855c7a9c52a
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=3d04dd3335a2c4c6007ff4e2a58a2855c7a9c52a;hp=dcc4d82b23095b07673d7c13cb2439c738a67fa1
Author: Simon Tatham <anakin at pobox.com>
Date: Sat Apr 21 17:03:10 2018 +0100
Remove maxflow completely.
Its ability to solve general network flow problems was never actually
used in this code base; it was _always_ used for the restricted
problem of finding a matching in an unweighted bipartite graph. So now
I've switched all its clients over to the new matching.c, maxflow is
no longer needed.
maxflow.c | 461 --------------------------------------------------------------
maxflow.h | 95 -------------
2 files changed, 556 deletions(-)
commit 60a929a250cf4f7f87ac082e5705f9a838a7f8c8
web diff https://git.tartarus.org/?p=simon/puzzles.git;a=commitdiff;h=60a929a250cf4f7f87ac082e5705f9a838a7f8c8;hp=3d04dd3335a2c4c6007ff4e2a58a2855c7a9c52a
Author: Franklin Wei <me at fwei.tk>
Date: Tue Apr 17 16:18:16 2018 -0400
Add a request_keys() function with a midend wrapper.
This function gives the front end a way to find out what keys the back
end requires; and as such it is mostly useful for ports without a
keyboard. It is based on changes originally found in Chris Boyle's
Android port, though some modifications were needed to make it more
flexible.
blackbox.c | 1 +
bridges.c | 1 +
cube.c | 1 +
devel.but | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
dominosa.c | 1 +
fifteen.c | 1 +
filling.c | 19 ++++++++++++++++
flip.c | 1 +
flood.c | 1 +
galaxies.c | 1 +
guess.c | 1 +
inertia.c | 1 +
keen.c | 22 ++++++++++++++++++
lightup.c | 1 +
loopy.c | 1 +
magnets.c | 1 +
map.c | 1 +
midend.c | 21 ++++++++++++++++++
mines.c | 1 +
misc.c | 45 +++++++++++++++++++++++++++++++++++++
net.c | 1 +
netslide.c | 1 +
nullgame.c | 1 +
palisade.c | 1 +
pattern.c | 1 +
pearl.c | 1 +
pegs.c | 1 +
puzzles.h | 26 ++++++++++++++++++++++
range.c | 1 +
rect.c | 1 +
samegame.c | 1 +
signpost.c | 1 +
singles.c | 1 +
sixteen.c | 1 +
slant.c | 1 +
solo.c | 21 ++++++++++++++++++
tents.c | 1 +
towers.c | 20 +++++++++++++++++
tracks.c | 1 +
twiddle.c | 1 +
undead.c | 21 ++++++++++++++++++
unequal.c | 20 +++++++++++++++++
unfinished/group.c | 1 +
unruly.c | 1 +
untangle.c | 1 +
45 files changed, 315 insertions(+)
More information about the tartarus-commits
mailing list