392 Commits

Author SHA1 Message Date
Sebastien Binet
ba05c1592d all: use go tool directive
Fixes #2021

Signed-off-by: Sebastien Binet <binet@cern.ch>
2025-10-03 09:16:48 +00:00
Schwarf
98271d5d64 graph/network: add Dinic maximum flow function 2025-08-30 19:35:24 +09:30
Nicolas Peugnet
43738f81c9 graph/network: add diameter example for Eccentricity 2025-03-28 05:40:58 +10:30
Nicolas Peugnet
844ab04bd4 graph/network: add test for eccentricity with digraphs 2025-03-26 21:50:27 +10:30
Nicolas Peugnet
6b50a8944e graph/network: add eccentricity measurement 2025-03-26 20:59:44 +10:30
Dan Kortschak
7f45d71405 graph/iterator: reflect the swiss map iterator shape 2025-03-11 05:06:05 +10:30
Dan Kortschak
3f7594a060 graph/formats/rdf: regenerate with new ragel version
Despite not showing a change in ragel -v output, the new version of
ragel (6.10-4 over 6.10-1 on my local machine) has a different output.
The differences appear to be incorrect in the new version, but will not
change the behaviour except for the reported lines in a panic or other
stack trace, so let's just go with what the new version has.
2025-02-01 22:18:04 +10:30
Dan Kortschak
bc349ecfab all: replace internal rand shim with math/rand/v2 2025-02-01 22:18:04 +10:30
Dan Kortschak
cf3307fa63 all: partially migrate to math/rand/v2
This is not intended to be a completed transition since it leaves the
libraries unusable to external client code, but rather as a step towards
use of math/rand/v2. This initial step allows repair of sequence change
failures without having to worry about API difference.
2025-02-01 22:18:04 +10:30
Oskar Haarklou Veileborg
ef1ae5e400 graph/path: improve performance of YenKShortestPaths
Add single-pair shortest path variant of Dijkstra. This variant can terminate
early when the target is reached, potentially make a large difference in
running time for Yen's k-shortest paths algorithm, as it makes many calls to
the shortest path subroutine.

The variant is also exposed for external use.
2025-01-15 07:04:43 +10:30
Dan Kortschak
f42c07e8cb all: fix typos 2025-01-01 08:26:48 +10:30
harpend
0dd167eaa3 graph/flow: add algorithm for finding intervals in flow graphs 2024-11-23 13:56:13 +10:30
Jonathan Bluett-Duncan
bdcda9a453 graph: use slices package for sorting and reversing slices 2024-08-17 08:41:18 +09:30
Dan Kortschak
2bef024c93 graph/iterator: improve reflect-based iterators
- use SetIterValue to reduce allocations
- use explicit stored iterator length

goos: linux
goarch: amd64
pkg: gonum.org/v1/gonum/graph/traverse
cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
                                    │  old.bench  │              new.bench              │
                                    │   sec/op    │   sec/op     vs base                │
WalkAllBreadthFirstGnp_10_tenth-8     3.575µ ± 2%   2.961µ ± 2%  -17.18% (p=0.000 n=20)
WalkAllBreadthFirstGnp_100_tenth-8    144.4µ ± 1%   132.4µ ± 1%   -8.33% (p=0.000 n=20)
WalkAllBreadthFirstGnp_1000_tenth-8   12.66m ± 2%   12.00m ± 2%   -5.20% (p=0.000 n=20)
WalkAllBreadthFirstGnp_10_half-8      8.415µ ± 1%   7.615µ ± 1%   -9.51% (p=0.000 n=20)
WalkAllBreadthFirstGnp_100_half-8     628.0µ ± 1%   580.7µ ± 1%   -7.54% (p=0.000 n=20)
WalkAllBreadthFirstGnp_1000_half-8    58.74m ± 1%   55.79m ± 2%   -5.03% (p=0.000 n=20)
WalkAllDepthFirstGnp_10_tenth-8       3.539µ ± 2%   2.956µ ± 1%  -16.49% (p=0.000 n=20)
WalkAllDepthFirstGnp_100_tenth-8      144.8µ ± 2%   135.5µ ± 1%   -6.40% (p=0.000 n=20)
WalkAllDepthFirstGnp_1000_tenth-8     12.40m ± 1%   12.02m ± 1%   -3.10% (p=0.000 n=20)
WalkAllDepthFirstGnp_10_half-8        8.210µ ± 1%   7.423µ ± 1%   -9.59% (p=0.000 n=20)
WalkAllDepthFirstGnp_100_half-8       625.8µ ± 1%   598.3µ ± 1%   -4.40% (p=0.000 n=20)
WalkAllDepthFirstGnp_1000_half-8      58.28m ± 1%   55.65m ± 1%   -4.52% (p=0.000 n=20)
geomean                               353.9µ        324.8µ        -8.21%

                                    │   old.bench   │              new.bench               │
                                    │     B/op      │     B/op       vs base               │
WalkAllBreadthFirstGnp_10_tenth-8      1.533Ki ± 0%    1.486Ki ± 0%  -3.06% (p=0.000 n=20)
WalkAllBreadthFirstGnp_100_tenth-8     29.58Ki ± 0%    29.61Ki ± 0%  +0.11% (p=0.000 n=20)
WalkAllBreadthFirstGnp_1000_tenth-8   1016.3Ki ± 0%   1016.4Ki ± 0%       ~ (p=0.199 n=20)
WalkAllBreadthFirstGnp_10_half-8       2.689Ki ± 0%    2.721Ki ± 0%  +1.16% (p=0.000 n=20)
WalkAllBreadthFirstGnp_100_half-8      61.44Ki ± 0%    61.47Ki ± 0%  +0.05% (p=0.000 n=20)
WalkAllBreadthFirstGnp_1000_half-8     4.036Mi ± 0%    4.036Mi ± 0%       ~ (p=0.080 n=20)
WalkAllDepthFirstGnp_10_tenth-8        1.533Ki ± 0%    1.486Ki ± 0%  -3.06% (p=0.000 n=20)
WalkAllDepthFirstGnp_100_tenth-8       29.58Ki ± 0%    29.61Ki ± 0%  +0.10% (p=0.000 n=20)
WalkAllDepthFirstGnp_1000_tenth-8      1.090Mi ± 1%    1.084Mi ± 1%       ~ (p=0.081 n=20)
WalkAllDepthFirstGnp_10_half-8         2.689Ki ± 0%    2.721Ki ± 0%  +1.16% (p=0.000 n=20)
WalkAllDepthFirstGnp_100_half-8        61.57Ki ± 0%    61.59Ki ± 0%  +0.04% (p=0.000 n=20)
WalkAllDepthFirstGnp_1000_half-8       6.279Mi ± 0%    6.167Mi ± 0%  -1.79% (p=0.000 n=20)
geomean                                58.77Ki         58.48Ki       -0.49%

                                    │  old.bench  │              new.bench              │
                                    │  allocs/op  │  allocs/op   vs base                │
WalkAllBreadthFirstGnp_10_tenth-8      27.00 ± 0%    17.00 ± 0%  -37.04% (p=0.000 n=20)
WalkAllBreadthFirstGnp_100_tenth-8    1.188k ± 0%   1.088k ± 0%   -8.42% (p=0.000 n=20)
WalkAllBreadthFirstGnp_1000_tenth-8   102.1k ± 0%   101.1k ± 0%   -0.98% (p=0.000 n=20)
WalkAllBreadthFirstGnp_10_half-8       70.00 ± 0%    60.00 ± 0%  -14.29% (p=0.000 n=20)
WalkAllBreadthFirstGnp_100_half-8     5.266k ± 0%   5.166k ± 0%   -1.90% (p=0.000 n=20)
WalkAllBreadthFirstGnp_1000_half-8    500.9k ± 0%   499.9k ± 0%   -0.20% (p=0.000 n=20)
WalkAllDepthFirstGnp_10_tenth-8        27.00 ± 0%    17.00 ± 0%  -37.04% (p=0.000 n=20)
WalkAllDepthFirstGnp_100_tenth-8      1.188k ± 0%   1.088k ± 0%   -8.42% (p=0.000 n=20)
WalkAllDepthFirstGnp_1000_tenth-8     102.1k ± 0%   101.1k ± 0%   -0.98% (p=0.000 n=20)
WalkAllDepthFirstGnp_10_half-8         70.00 ± 0%    60.00 ± 0%  -14.29% (p=0.000 n=20)
WalkAllDepthFirstGnp_100_half-8       5.266k ± 0%   5.166k ± 0%   -1.90% (p=0.000 n=20)
WalkAllDepthFirstGnp_1000_half-8      500.9k ± 0%   499.9k ± 0%   -0.20% (p=0.000 n=20)
geomean                               2.908k        2.572k       -11.54%
2024-05-24 20:49:39 +09:30
Dan Kortschak
f853624cb1 graph/iterator: allocate reflect map iterator inline 2024-05-17 20:05:25 +09:30
Jonathan Bluett-Duncan
fe73977b01 internal/order: move package from graph/internal/ordered and make function generic 2024-05-11 21:57:13 +09:30
Jonathan Bluett-Duncan
b94e4828e9 graph: replace custom reverse logic with slices.Reverse 2024-04-27 15:34:24 +09:30
Jonathan Bluett-Duncan
1f5b2b5b54 graph: add benchmarks for AllShortest.(All)Between 2024-04-27 15:34:24 +09:30
Jonathan Bluett-Duncan
1bc1de45aa graph: add benchmarks for topo.Sort(Stabilized) 2024-04-27 15:34:24 +09:30
Dan Kortschak
affaa34094 all: fix doc comments identified by staticcheck
All complaints in mathext/internal are ignored, and an unfortunate naming
of methods in spatial/{r2,r3} is now permanent.
2024-04-23 17:11:29 +09:30
Dan Kortschak
7bd265b283 graph: clean up and fix implicit graph example
The From method incorrectly returned nil for the empty case and node neighbour
expansion did not mark visited nodes. Fix these and exercise the corrected path
in the test. Also clean up the code structure.
2024-04-19 05:41:38 +09:30
Jonathan Bluett-Duncan
219257751c graph: merge set.Ints and set.Int64s into one generic set 2024-04-07 08:10:32 +09:30
Eng Zer Jun
e44948ca04 all: replace min/max helpers with min/max builtins 2024-04-06 20:24:32 +10:30
Jonathan Bluett-Duncan
8a2036b741 graph: replace ordered.Int64s with slices.Sort 2024-03-23 15:29:19 +10:30
Eng Zer Jun
db43f45c2b graph/path: do not keep duplicate paths in YenKShortestPaths
Previously the code did not ignore spur paths that had already been added into
the list of potential paths. This could cause the search to return duplicate
paths for certain graphs.
2023-11-08 14:12:31 +10:30
Eng Zer Jun
7d22d85fb1 graph: fix comment of exported elements
According to Comment Sentences at github.com/golang [1], it is a
convention to begin a comment with the name of the exported element.

[1]: https://github.com/golang/go/wiki/CodeReviewComments#comment-sentences

Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2023-09-23 11:30:23 +09:30
Jes Cok
bd727a9e14 all: fix typos 2023-07-16 13:37:17 +09:30
Dan Kortschak
9e7bb93637 graph/path: allow cost-based Yen shortest path calculation
This adds an additional constraint onto YenKShortestPaths to consider
the paths' cost as well as the number of paths, enabling search within a
constrained distance.
2023-06-26 19:49:09 +09:30
Dan Kortschak
258a51e069 graph/formats/dot/internal: regenerate with latest goccmack/gocc
Make use of go.mod to pin gocc version and go mod tidy.
2023-05-01 06:18:27 +09:30
Dan Kortschak
91a06ac64c graph/path: reduce allocations in path reconstructions
│   old.bench   │               new.bench               │
                                              │    sec/op     │    sec/op      vs base                │
ShortestAlts/AllTo_100×2|0.5(17)-8              12.380µ ±  9%   8.577µ ±   6%  -30.72% (p=0.000 n=10)
ShortestAlts/AllTo_1000×2|0.5(51)-8              74.87µ ± 17%   47.66µ ±   1%  -36.35% (p=0.000 n=10)
ShortestAlts/AllTo_100×4|0.25(53)-8              25.50µ ±  3%   15.35µ ±   3%  -39.82% (p=0.000 n=10)
ShortestAlts/AllTo_1000×4|0.25(574)-8            556.5µ ±  5%   279.2µ ±   4%  -49.83% (p=0.000 n=10)
ShortestAlts/AllTo_100×16|0.1(76)-8              35.79µ ±  9%   21.71µ ±   3%  -39.35% (p=0.000 n=10)
ShortestAlts/AllTo_1000×16|0.1(822)-8            851.8µ ±  6%   400.5µ ±   6%  -52.98% (p=0.000 n=10)
AllShortest/AllBetween_100×2|0.5(17)-8          12.482µ ±  6%   8.573µ ±   3%  -31.32% (p=0.000 n=10)
AllShortest/AllBetween_1000×2|0.5(51)-8          80.74µ ±  2%   52.90µ ±   4%  -34.48% (p=0.000 n=10)
AllShortest/AllBetween_100×4|0.25(53)-8          22.54µ ±  4%   16.17µ ±   4%  -28.26% (p=0.000 n=10)
AllShortest/AllBetween_1000×4|0.25(574)-8        543.8µ ±  3%   326.7µ ±   5%  -39.93% (p=0.000 n=10)
AllShortest/AllBetween_100×16|0.1(76)-8          31.21µ ±  1%   22.45µ ±   3%  -28.07% (p=0.000 n=10)
AllShortest/AllBetween_1000×16|0.1(822)-8        678.4µ ±  1%   402.5µ ±   3%  -40.67% (p=0.000 n=10)
ShortestAlts/AllToFunc_100×2|0.5(17)-8                          5.892µ ±   2%
ShortestAlts/AllToFunc_1000×2|0.5(51)-8                         40.81µ ±   2%
ShortestAlts/AllToFunc_100×4|0.25(53)-8                         9.178µ ±   2%
ShortestAlts/AllToFunc_1000×4|0.25(574)-8                       214.6µ ±   2%
ShortestAlts/AllToFunc_100×16|0.1(76)-8                         12.62µ ±   3%
ShortestAlts/AllToFunc_1000×16|0.1(822)-8                       310.7µ ±   3%
AllShortest/AllBetweenFunc_100×2|0.5(17)-8                      5.713µ ±   1%
AllShortest/AllBetweenFunc_1000×2|0.5(51)-8                     45.68µ ±   3%
AllShortest/AllBetweenFunc_100×4|0.25(53)-8                     9.775µ ±   1%
AllShortest/AllBetweenFunc_1000×4|0.25(574)-8                   245.2µ ±   5%
AllShortest/AllBetweenFunc_100×16|0.1(76)-8                     13.76µ ±   1%
AllShortest/AllBetweenFunc_1000×16|0.1(822)-8                   314.7µ ±   1%
geomean                                          82.87µ         43.03µ         -38.14%

                                              │   old.bench   │              new.bench               │
                                              │     B/op      │     B/op      vs base                │
ShortestAlts/AllTo_100×2|0.5(17)-8              14.148Ki ± 0%   9.727Ki ± 0%  -31.25% (p=0.000 n=10)
ShortestAlts/AllTo_1000×2|0.5(51)-8              189.8Ki ± 0%   127.5Ki ± 0%  -32.80% (p=0.000 n=10)
ShortestAlts/AllTo_100×4|0.25(53)-8              22.32Ki ± 0%   14.99Ki ± 0%  -32.83% (p=0.000 n=10)
ShortestAlts/AllTo_1000×4|0.25(574)-8           1272.9Ki ± 0%   681.9Ki ± 0%  -46.42% (p=0.000 n=10)
ShortestAlts/AllTo_100×16|0.1(76)-8              33.23Ki ± 0%   22.66Ki ± 0%  -31.79% (p=0.000 n=10)
ShortestAlts/AllTo_1000×16|0.1(822)-8           1799.9Ki ± 0%   953.2Ki ± 0%  -47.04% (p=0.000 n=10)
AllShortest/AllBetween_100×2|0.5(17)-8          13.039Ki ± 0%   8.617Ki ± 0%  -33.91% (p=0.000 n=10)
AllShortest/AllBetween_1000×2|0.5(51)-8          181.5Ki ± 0%   119.3Ki ± 0%  -34.29% (p=0.000 n=10)
AllShortest/AllBetween_100×4|0.25(53)-8          21.34Ki ± 0%   14.01Ki ± 0%  -34.35% (p=0.000 n=10)
AllShortest/AllBetween_1000×4|0.25(574)-8       1264.8Ki ± 0%   673.8Ki ± 0%  -46.72% (p=0.000 n=10)
AllShortest/AllBetween_100×16|0.1(76)-8          32.24Ki ± 0%   21.68Ki ± 0%  -32.76% (p=0.000 n=10)
AllShortest/AllBetween_1000×16|0.1(822)-8       1791.8Ki ± 0%   945.1Ki ± 0%  -47.25% (p=0.000 n=10)
ShortestAlts/AllToFunc_100×2|0.5(17)-8                          6.922Ki ± 0%
ShortestAlts/AllToFunc_1000×2|0.5(51)-8                         119.8Ki ± 0%
ShortestAlts/AllToFunc_100×4|0.25(53)-8                         9.531Ki ± 0%
ShortestAlts/AllToFunc_1000×4|0.25(574)-8                       611.1Ki ± 0%
ShortestAlts/AllToFunc_100×16|0.1(76)-8                         13.12Ki ± 0%
ShortestAlts/AllToFunc_1000×16|0.1(822)-8                       870.7Ki ± 0%
AllShortest/AllBetweenFunc_100×2|0.5(17)-8                      5.812Ki ± 0%
AllShortest/AllBetweenFunc_1000×2|0.5(51)-8                     111.5Ki ± 0%
AllShortest/AllBetweenFunc_100×4|0.25(53)-8                     8.547Ki ± 0%
AllShortest/AllBetweenFunc_1000×4|0.25(574)-8                   603.0Ki ± 0%
AllShortest/AllBetweenFunc_100×16|0.1(76)-8                     12.14Ki ± 0%
AllShortest/AllBetweenFunc_1000×16|0.1(822)-8                   862.6Ki ± 0%
geomean                                          126.5Ki        68.27Ki       -37.99%

                                              │  old.bench  │              new.bench              │
                                              │  allocs/op  │  allocs/op   vs base                │
ShortestAlts/AllTo_100×2|0.5(17)-8              141.00 ± 0%    94.00 ± 0%  -33.33% (p=0.000 n=10)
ShortestAlts/AllTo_1000×2|0.5(51)-8              420.0 ± 0%    269.0 ± 0%  -35.95% (p=0.000 n=10)
ShortestAlts/AllTo_100×4|0.25(53)-8              279.0 ± 0%    174.0 ± 0%  -37.63% (p=0.000 n=10)
ShortestAlts/AllTo_1000×4|0.25(574)-8           2.888k ± 0%   1.741k ± 0%  -39.72% (p=0.000 n=10)
ShortestAlts/AllTo_100×16|0.1(76)-8              395.0 ± 0%    244.0 ± 0%  -38.23% (p=0.000 n=10)
ShortestAlts/AllTo_1000×16|0.1(822)-8           4.128k ± 0%   2.485k ± 0%  -39.80% (p=0.000 n=10)
AllShortest/AllBetween_100×2|0.5(17)-8          136.00 ± 0%    89.00 ± 0%  -34.56% (p=0.000 n=10)
AllShortest/AllBetween_1000×2|0.5(51)-8          415.0 ± 0%    264.0 ± 0%  -36.39% (p=0.000 n=10)
AllShortest/AllBetween_100×4|0.25(53)-8          275.0 ± 0%    170.0 ± 0%  -38.18% (p=0.000 n=10)
AllShortest/AllBetween_1000×4|0.25(574)-8       2.884k ± 0%   1.737k ± 0%  -39.77% (p=0.000 n=10)
AllShortest/AllBetween_100×16|0.1(76)-8          391.0 ± 0%    240.0 ± 0%  -38.62% (p=0.000 n=10)
AllShortest/AllBetween_1000×16|0.1(822)-8       4.124k ± 0%   2.481k ± 0%  -39.84% (p=0.000 n=10)
ShortestAlts/AllToFunc_100×2|0.5(17)-8                         71.00 ± 0%
ShortestAlts/AllToFunc_1000×2|0.5(51)-8                        211.0 ± 0%
ShortestAlts/AllToFunc_100×4|0.25(53)-8                        114.0 ± 0%
ShortestAlts/AllToFunc_1000×4|0.25(574)-8                     1.156k ± 0%
ShortestAlts/AllToFunc_100×16|0.1(76)-8                        160.0 ± 0%
ShortestAlts/AllToFunc_1000×16|0.1(822)-8                     1.652k ± 0%
AllShortest/AllBetweenFunc_100×2|0.5(17)-8                     66.00 ± 0%
AllShortest/AllBetweenFunc_1000×2|0.5(51)-8                    206.0 ± 0%
AllShortest/AllBetweenFunc_100×4|0.25(53)-8                    110.0 ± 0%
AllShortest/AllBetweenFunc_1000×4|0.25(574)-8                 1.152k ± 0%
AllShortest/AllBetweenFunc_100×16|0.1(76)-8                    156.0 ± 0%
AllShortest/AllBetweenFunc_1000×16|0.1(822)-8                 1.648k ± 0%
geomean                                          649.3         336.5       -37.70%
2023-04-24 20:31:56 +09:30
Chris Nobody
45b800a8c6 all: add pkg.go.dev reference README badges
As discussed during the review of the immediately preceding changesets.
2023-03-16 06:40:50 +10:30
Chris Nobody
f040f6bd07 all: replace godoc.org README badges with godocs.io ones
The links have been redirecting to `pkg.go.dev` for a while now. In the
case of the main README, that made the badge a virtual duplicate of the
"go.dev reference" one.
2023-03-16 06:40:50 +10:30
Dan Kortschak
b7bed9533b graph/encoding/graphql: note requirement of dst parameter
The spanning tree walk sets nodes' IDs using the SetIDFromString method
so note that nodes returned by the destination's NewNode method must
satisfy StringIDSetter.
2023-01-17 06:39:27 +10:30
Dan Kortschak
d6b9d45e9e graph/path: fix yen k-shortest path with root cycles
Previously the code was not removing nodes on the root of the search
path, resulting in searches that could re-enter previously searched
nodes. In addition to this, the logic for making edges was incorrectly
marking both directions for digraphs and only one direction for
undirected graphs.

Finally, the range of nodes to include in the spur-node set was
off-by-one. This is now clarified by including the comment from the wiki
article since the pseudo-code is less clear than the English due to
choice of range indexing convention.
2023-01-17 06:39:13 +10:30
Dan Kortschak
98316cc24c graph/layout: regenerate isomap golden images for new lapack 2022-11-24 23:01:49 +01:00
Dan Kortschak
a4dda6a99c all: make tests pass when -count is greater than 1
Tests run repeatedly do not reinitialise state, meaning that a second run
of the tests will have leftover state from the previous run. This ensures
that repeated runs are identical with the exception of map iteration order.
2022-08-06 15:52:53 +09:30
Dan Kortschak
5f0141ca4c all: run gofmt and generate all packages
Changes made in dsp/fourier/internal/fftpack break the formatting used
there, so these are reverted. There will be complaints in CI.

[git-generate]
gofmt -w .
go generate gonum.org/v1/gonum/blas
go generate gonum.org/v1/gonum/blas/gonum
go generate gonum.org/v1/gonum/unit
go generate gonum.org/v1/gonum/unit/constant
go generate gonum.org/v1/gonum/graph/formats/dot
go generate gonum.org/v1/gonum/graph/formats/rdf
go generate gonum.org/v1/gonum/stat/card

git checkout -- dsp/fourier/internal/fftpack
2022-08-06 07:05:17 +09:30
Dan Kortschak
7509ddb1e3 ci,mod,graph/iterator: bump minimum version to go1.18 2022-08-06 07:05:17 +09:30
Dan Kortschak
a2c6f817bf ci: replace golangci-lint with staticcheck 2022-05-18 21:35:57 +09:30
Dan Kortschak
d8ad7756b6 all: fix spelling and typos 2022-03-14 21:32:06 +10:30
Sebastien Binet
7a7ecd314e all: bump x/tools@v0.1.9 and gonum/plot@v0.10.1 2022-03-13 09:58:39 +01:00
Dan Kortschak
09c7f513f8 graph/formats/rdf: add Repeat and Len methods 2022-03-04 14:26:53 +10:30
Dan Kortschak
d5f7a1db26 graph/formats/rdf: add Has{All,Any}{Out,In} query methods
These methods express queries that are currently able to be expressed
with a sequence of In, Out and And queries. However, the constructed
filter approach is potentially significantly more expensive and are
more complex to reason about. For example it is often possible to make
the following re-writes,

    p.Out(cond).In(cond).And(p) => p.HasAllOut(cond')

and

    p.In(cond).Out(cond).And(p) => p.HasAllIn(cond').

The expense comes when reaching out to a commonly connected node and then
coming back; the return traversal will generate a large set of fruitless
candidates that then need to be filtered via the conjunction. This saves
that fruitless effort.
2022-03-04 14:26:53 +10:30
Dan Kortschak
71b9fddc63 graph/coloring: dynamically determine test timeout for general case
Also don't fail, but do log. It would be nice if there were a testing
output option that always logged even without failure or -test.v, but
we have what we have.
2022-03-03 20:11:50 +10:30
Dan Kortschak
c65ee979e1 graph/coloring: prevent long running flakes from crashing the tests
It seems that it is sometimes possible for a bad search traversal to be chosen
resulting in very long run time. This causes the tests to crash due to the
test timeout, make the timeout softer and let other tests run when a long
failure happens.
2022-02-11 20:29:00 +10:30
Dan Kortschak
1f712d5ee0 graph/formats/rdf: add deduplication function 2022-02-09 20:37:52 +10:30
Dan Kortschak
820f2999af graph/formats/rdf: add a graph implementation and graph query language for RDF graphs
This is a very simplified version of a Gremlin-like language. The
simplification is in part forced by Go, but also reduces the level
of hiding complexity that is present in Gremlin.
2022-02-01 06:57:30 +10:30
Dan Kortschak
3593b1ee88 graph/formats/rdf: fix typo 2022-02-01 06:57:30 +10:30
Dan Kortschak
d4eca1bbc0 graph/coloring: allow warm start for DsaturExact
There is an optimisation that is available for the Dsatur recursive search
that takes advantage of the trivial observation that the colouring of a
maximum clique in the graph must be consistent with the colouring of the
graph and that a maximum clique will therefore constrain the colouring of
the graph. This means that if the maximum clique is first trivially coloured
the search can continue from there. However, if there are multiple co-equal
maximum cliques it is possible for a clique to be chosen that will force the
search down a pessimal search path, so we choose the clique to start from as
the clique with the least constraining effect on the rest of the graph. The
optimisation has the effect of excluding large sections of the search tree
with a small amount of initial work to assess the maximum cliques.

This change chooses the maximum clique with the lowest degree into the rest
of the graph and assigns colours to all its nodes and progresses from there.
2022-01-21 08:02:27 +10:30
Dan Kortschak
4536514e9f graph/coloring: add DIMACS queen test graphs
The graphs were obtained from https://mat.tepper.cmu.edu/COLOR/instances.html
and converted to graph6 using the following code:

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"

	"gonum.org/v1/gonum/graph/encoding/graph6"
	"gonum.org/v1/gonum/graph/simple"
)

func main() {
	g := simple.NewUndirectedGraph()
	sc := bufio.NewScanner(os.Stdin)
	for sc.Scan() {
		line := sc.Text()
		if len(line) == 0 || line[0] != 'e' {
			continue
		}
		f := strings.Fields(line)
		g.SetEdge(simple.Edge{F: node(f[1]), T: node(f[2])})
	}
	fmt.Printf("%q\n", graph6.Encode(g))
}

func node(s string) simple.Node {
	i, err := strconv.Atoi(s)
	if err != nil {
		panic(err)
	}
	return simple.Node(i)
}

To convert graphs (ASCII col format only), use `go run main.go < <input>.col'.
2022-01-20 17:30:35 +10:30