Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

graph/coloring: allow warm start for DsaturExact #1764

Merged
merged 1 commit into from
Jan 20, 2022

Conversation

kortschak
Copy link
Member

@kortschak kortschak commented Jan 20, 2022

This is a replay of #1705, now onto the merged coloring package. I had originally intended to wait until I had improved the base performance of the DsaturExact implementation before I applied this change, but I suspect that I won't have time to address that for a while (my initial investigations suggest that it's both subtle and extensive to improve the way that the color accounting is currently done), so rather than wait with a poorly performing exact coloring implementation I think this should go in, and the work to formally examine the impact of this change can happen after the base improvements are made with minor alterations of code added here.

The algorithmic addition is quite straightforward and I think the implications on run time are reasonably clear. I have some rough notes that I prepared a while back that I can make available to explain the behaviour (OOB since they are not public quality yet).

Please take a look.

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.
@codecov-commenter
Copy link

codecov-commenter commented Jan 20, 2022

Codecov Report

Merging #1764 (acbb2b9) into master (4536514) will increase coverage by 0.00%.
The diff coverage is 83.33%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1764   +/-   ##
=======================================
  Coverage   73.36%   73.37%           
=======================================
  Files         520      520           
  Lines       61341    61361   +20     
=======================================
+ Hits        45003    45021   +18     
- Misses      13803    13806    +3     
+ Partials     2535     2534    -1     
Impacted Files Coverage Δ
graph/coloring/coloring.go 90.33% <83.33%> (-0.03%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4536514...acbb2b9. Read the comment docs.

@kortschak
Copy link
Member Author

Here are the benchmarks. It looks horrifying until you look at the larger queens cases, and the sudoku problem. The variance on the times is very high due to the high impact of search path that is chosen, and the fact that it is partially randomly chosen.

old.benchnew.bench
time/opdelta
Coloring/empty/DsaturExact-86.67ns ± 2%6.01ns ± 1%−9.91%(p=0.000 n=10+9)
Coloring/singleton/DsaturExact-81.16µs ± 1%2.11µs ± 6%+81.59%(p=0.000 n=9+10)
Coloring/kite/DsaturExact-824.6µs ± 1%43.6µs ± 5%+76.92%(p=0.000 n=10+9)
Coloring/triangle+1/DsaturExact-814.6µs ± 1%23.9µs ± 3%+63.97%(p=0.000 n=10+9)
Coloring/bipartite_halves/DsaturExact-848.1µs ± 1%76.4µs ± 2%+58.94%(p=0.000 n=10+10)
Coloring/bipartite_alternating/DsaturExact-848.1µs ± 1%76.3µs ± 1%+58.66%(p=0.000 n=10+9)
Coloring/cubical/DsaturExact-847.9µs ± 2%77.7µs ± 3%+62.08%(p=0.000 n=9+9)
Coloring/HoG33106/DsaturExact-8107µs ± 1%175µs ± 7%+62.49%(p=0.000 n=9+10)
Coloring/HoG41237/DsaturExact-8323ms ± 2%330ms ± 1%+2.11%(p=0.002 n=9+8)
Coloring/exams/DsaturExact-837.2µs ± 1%62.9µs ± 2%+69.12%(p=0.000 n=9+10)
Coloring/exam_scheduler_1/DsaturExact-8135µs ± 1%275µs ±52%+103.38%(p=0.000 n=9+10)
Coloring/exam_scheduler_2/DsaturExact-867.3µs ± 2%114.5µs ± 2%+70.21%(p=0.000 n=10+9)
Coloring/Brélaz/DsaturExact-884.9µs ± 2%137.8µs ± 2%+62.38%(p=0.000 n=10+9)
Coloring/Lima_Carmo/DsaturExact-846.9µs ± 1%76.8µs ± 2%+63.88%(p=0.000 n=8+9)
Coloring/San_Segundo/DsaturExact-8193µs ± 4%259µs ± 2%+33.99%(p=0.000 n=8+10)
Coloring/tetrahedron/DsaturExact-817.1µs ± 2%33.5µs ± 4%+96.48%(p=0.000 n=9+9)
Coloring/triangle/DsaturExact-89.39µs ± 1%18.61µs ± 9%+98.21%(p=0.000 n=9+9)
Coloring/square/DsaturExact-816.0µs ± 2%26.1µs ± 2%+63.17%(p=0.000 n=10+9)
Coloring/cycle-5/DsaturExact-832.1µs ± 2%44.2µs ± 1%+37.85%(p=0.000 n=10+9)
Coloring/cycle-6/DsaturExact-826.4µs ± 2%43.1µs ± 1%+63.21%(p=0.000 n=10+8)
Coloring/wheel-5/DsaturExact-831.4µs ± 2%54.4µs ± 2%+73.39%(p=0.000 n=10+10)
Coloring/wheel-6/DsaturExact-859.9µs ± 2%86.9µs ± 1%+45.14%(p=0.000 n=10+10)
Coloring/wheel-7/DsaturExact-853.8µs ± 1%91.5µs ± 1%+69.94%(p=0.000 n=10+9)
Coloring/sudoku_board/DsaturExact-887.4ms ± 2%135.5ms ± 1%+54.96%(p=0.000 n=10+9)
Coloring/sudoku_problem/DsaturExact-810.3s ±68%7.3s ±130%~(p=0.165 n=10+10)
Coloring/cs_shc/DsaturExact-828.1µs ± 2%48.9µs ± 4%+73.64%(p=0.000 n=10+9)
Coloring/gis_hc/DsaturExact-824.3µs ± 2%43.1µs ± 8%+77.27%(p=0.000 n=9+10)
Coloring/gis_shc|rs_shc/DsaturExact-814.2µs ± 2%24.1µs ±11%+69.96%(p=0.000 n=9+10)
Coloring/lf_hc/DsaturExact-844.8µs ± 2%75.3µs ± 1%+67.95%(p=0.000 n=8+9)
Coloring/lf_shc/DsaturExact-824.6µs ± 1%40.3µs ± 2%+64.18%(p=0.000 n=8+9)
Coloring/lfi_hc/DsaturExact-8146µs ± 2%160µs ± 1%+9.47%(p=0.000 n=10+9)
Coloring/lfi_shc|slf_shc/DsaturExact-887.0µs ± 1%90.0µs ± 1%+3.50%(p=0.000 n=10+10)
Coloring/no_solo/DsaturExact-882.8µs ± 1%127.2µs ± 2%+53.63%(p=0.000 n=9+10)
Coloring/sl_hc/DsaturExact-8122µs ± 2%169µs ± 3%+38.09%(p=0.000 n=10+10)
Coloring/sl_shc/DsaturExact-835.3µs ± 1%59.5µs ± 2%+68.70%(p=0.000 n=10+10)
Coloring/slf_hc/DsaturExact-8103µs ± 2%115µs ± 2%+11.79%(p=0.000 n=10+9)
Coloring/sli_hc/DsaturExact-8195µs ± 2%271µs ± 1%+39.40%(p=0.000 n=10+9)
Coloring/sli_shc/DsaturExact-843.6µs ± 1%72.6µs ± 1%+66.72%(p=0.000 n=9+9)
Coloring/rsi_shc/DsaturExact-832.7µs ± 1%55.2µs ± 1%+68.63%(p=0.000 n=10+9)
Coloring/V_plus_not_in_A_cal/DsaturExact-848.8µs ± 1%77.6µs ± 2%+59.02%(p=0.000 n=10+10)
Coloring/queen5_5/DsaturExact-82.72ms ± 2%4.80ms ± 1%+76.24%(p=0.000 n=10+9)
Coloring/queen6_6/DsaturExact-8676ms ±34%276ms ±44%−59.17%(p=0.000 n=10+9)
Coloring/queen7_7/DsaturExact-84.09s ±87%1.55s ±116%−62.00%(p=0.022 n=9+10)

@vladimir-ch
Copy link
Member

vladimir-ch commented Jan 20, 2022

Almost all the other benchmarks are in the order of (tens of) µs, so I would put more weight on the larger problems where the warm up pays off. Are there other (generated) larger benchmark problems that we could add?

@kortschak
Copy link
Member Author

There are a bunch from where I got the queens graphs. Note that queens-8-8 takes a very long time with this implementation (either old or new) due to allocation inefficiency that I want to fix. I'm not particular fussed to add more bench marks. I think the result is sound.

@vladimir-ch
Copy link
Member

Agreed.

@kortschak kortschak merged commit d4eca1b into master Jan 20, 2022
@kortschak kortschak deleted the graph/warm_start_again branch January 20, 2022 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants