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

Optimize solving efficiency. #94

Open
wants to merge 54 commits into
base: dev
Choose a base branch
from

Conversation

BloodmageThalnos
Copy link

The logic solving process for some puzzles are significantly slow, especially the AIC process. I found that the data structure used for weaklinks was SortedSet<int>, which is costful when copying and accessing. Changing it to List<int> can save about 40% of time. Here is some experiment detail.

**Before switching to List<int>**
[Puzzle 1]
Global: 17753.5104ms
FindAIC: 16807.1923ms
FindSimpleContradictions: 9788.1093ms
FindNakedSingles: 6408.4519ms
FindNakedTuples: 2575.865ms
FindPointingTuples: 2152.4453ms
FindHiddenSingle: 1027.174ms
FindWings: 441.9736ms
FindDirectCellForcing: 424.5482ms
FindFishes: 373.8326ms
AddNewWeakLinks: 107.2984ms
SudokuSolver.Constraints.ThermometerConstraint: 40.5961ms

[Puzzle 2]
Global: 37277.418ms
FindAIC: 35803.2569ms
FindSimpleContradictions: 18268.3982ms
FindNakedSingles: 11468.6193ms
FindNakedTuples: 6376.9864ms
FindPointingTuples: 5103.6402ms
FindHiddenSingle: 2267.3987ms
FindDirectCellForcing: 983.7853ms
FindFishes: 811.8771ms
FindWings: 493.3857ms
AddNewWeakLinks: 142.1879ms
SudokuSolver.Constraints.ThermometerConstraint: 106.7276ms

**After switching to List<int>**
[Puzzle 1]
Global: 11995.1062ms
FindAIC: 11138.9596ms
FindSimpleContradictions: 6608.0917ms
FindNakedSingles: 3861.3857ms
FindNakedTuples: 1749.0708ms
FindPointingTuples: 1441.2341ms
FindHiddenSingle: 735.6207ms
FindDirectCellForcing: 539.7814ms
FindWings: 406.7448ms
FindFishes: 327.125ms
AddNewWeakLinks: 68.1765ms
SudokuSolver.Constraints.ThermometerConstraint: 41.1181ms

[Puzzle 2]
Global: 25083.0274ms
FindAIC: 23808.8689ms
FindSimpleContradictions: 12577.0124ms
FindNakedSingles: 6968.7097ms
FindNakedTuples: 4313.6901ms
FindPointingTuples: 3358.4323ms
FindHiddenSingle: 1601.7497ms
FindDirectCellForcing: 1257.6777ms
FindFishes: 705.0737ms
FindWings: 420.8716ms
SudokuSolver.Constraints.ThermometerConstraint: 101.4072ms
AddNewWeakLinks: 88.9675ms

F-puzzle strings of two puzzles:
N4IgzglgXgpiBcBOANCA5gJwgEwQbT1ADcBDAGwFc54AmVNCImAOwQBcMr7GWAFFgMYQyAWRIYA1mATMKZMgF9koBk2b9mQ0eKky5i5SFKVqAdm5r2nGBb6DhYydPiz5SlT3X3tTvW8OqdpoOOs6uBh5qGlqOui767uie0SG+8f6RQTGhfhFJUd6xYQkAusiE+VmpceGJgV7BPjUJAcmFOel59SlNxRlG5FQIABy2rPAcXJUN2Wm1rQWNRbl1bUsd85kz1X15xkPwAIxjVlPd7XOl5Vs9y52ri7PN/efrly9rT7sPVb0rC787ptprcNi0bhdnntBtQUNNTjYQZDvmUKvtqAA2E4TaxjUHvaEmBDmeE4s6fHb/CFvKE/bZ/e4A+lA8FImnfJn42mc5FUtlfFao6kCxnEGEIOH1BF43mi/mUuWvEXApUKlUUhnqx5q1mqzWs9HE7GTRF6lluIXy/UfbXWroa83222OulcjnCnU2wFg/qG+CjUkmmXsvlmn2KS1hgmu2Va73RnkhxUO8MxpNx5mpxPK3Up6ORvPcj12tM5r2ZhPFl2GP0kqVk02F90DIn+424q3VqtZ7v564tg6SzzSzs90eV8dFgfUAP1oOT5tRqdLxdN0Nr5PO1MlMogNgACxgGAAtgB7Y8wNhH/CgMgQZgwZwEEAAJQAzABhACsIFQ74/GK/q+AAsH6mEBL5fmBIA7okd4Pk+eCvhi0F/qYAEQehP5oR+wEwSUcH3o++BIS+KFvhBUEUX+oHUa+n54bBu7YBAYAkAARmQMDYGQp4MAI+C7iaAgkMwLHYCQV5gKeAAObAQKezBPgRQA==
N4IgzglgXgpiBcBOANCA5gJwgEwQbT1ADcBDAGwFc54AOVNCImAOwQBcMr7GWAFFgMYQyAWRIYA1mATMKZMgF9koBk2b9mQ0eKky5i5eh7rBwsZOnxZ8pcXJUEAdm5r2nGC76ntFvTcOqXppmOpbWBirGGlrmulb6tkZq0SG+8f6Ryd6xYQkBUdmhfooAusiEIKSU1ChJLG5cdSbBPnHhiYHNMUXpEU0prbkZ/YVp7flZLTnFHQVTPeOZQd1jeXbVCHRNDR4j86vDnQPTvQplFUejbWt7K9eHc3dDfZf79y+Pqe+zk08zE8svs8foDBv8ll0gTNzhDjgsbq8/qcAZCwcjYVdgSi4QcPr8oejbgTFpV7NRnNt4BxGojiTcqg54ABmTysKnuVk474wolokkM6gANlZO05mPBvJOJNpfIRn1lD3xCrxoKlcqVauGAs2IvZNPlmtK5QxbyxJqR0oN8MVqutKtRhpBDrtTq5ZslLsM2qQuupuxljp5Ac960ZFM6oo9uNd4sJwej2Njlo1Iaj30Tpol8e5xrT7uz+atCfNdJtzuLpI2PspfrFmbjRfToeoACZfRy8xLveHjJGC9Dc/2GymK0Pk7bR433d32/qR03O8OJwuxwkSmUQGwABYwDAAWwA9nuYGxd/hQGQIMwYJYCCAAEpMgDCAFYQKhH0/Be+HwAWJ+OD+94vgBIDrokl7XreeAPoKoEfo4X5AYhb4IU+v5gSUEFXje+AwfecFMkBIFER+/6kQ+z4YeBG7YBAYAkAARmQMDYGQB4MAI+Abn6AgkMwdHYCQp5gAeAAObAQAezC3lhQA

dclamage and others added 30 commits October 15, 2021 13:08
All tests pass.
Re-enabled fish logic.

All tests still pass.
…ich cannot repeat digits.

Known bug: SolveUniqueVariantFPuzzles takes longer. Will track this down.
Also includes fix for contradictions being enabled even when requested off if not human stepping.
Use of Visual Studio 2022 is highly recommended, especially for those previously using VS2019
 - VSCode / commandline API should still work, but make sure your commandline API is updated to .NET 6.0.x

C#10 features used:
 - Using implicit and global usings so that most files now do not list any using.
 - All namespaces now using the file scope format so that braces aren't required around the entire file.
 - New Json parser that uses compile-time code generation instead of reflection

Enabled link trimming
 - Significantly reduces the file size of the distribution
 - Required removing reflection:
  o The unused "plugin" system has been removed
  o Reflection is no longer used to locate constraints. They are now explicitly specified in ConstraintManager

Replaced Mono.Options with McMaster.Extensions.CommandLineUtils
 - Command-line options remain the same, but are now parsed by this library.
 - The hope here was that it's a maintained library and as such wouldn't have trim warning.
 - It does at the moment still have trim warnings, but the library appears to function properly anyway.
 - I liked the interface for this better so I'm sticking with it regardless.

Publishing ARM64 build for OSX

GitHub actions now deleted any PDBs before zipping up the release.
Refactored AIC logic to be in its own file/class.
Re-evaluate weak links during logical stepping.
Fixed text offset for single value xsums
dclamage and others added 23 commits November 25, 2021 01:27
…e single value is placed (only values within the cell are eliminated).

AICs now prefer shorter chains over number of candidates eliminated.
Added "digital root" cages which are specified as cosmetic cages in f-puzzles with value "DRN" where N is the digital root desired, like "DR2". This uses the multi-sum killer cage constraint to allow any sum which has the specified digital root, and also enforces non-repeat within the cage.
Currently no step solving but candidate logic is implemented.
Still need to add a few specific cases e.g. a group being ruled out by
sudoku rules.
Fixed an issue where the value index of a cell was used to get a group
index rather than the group being found from the index of the cell.
@dclamage
Copy link
Owner

I'm a little bit confused because you said you changed it to use List but your commit has: using WeaklinkType = SortedSet<int>;

@BloodmageThalnos
Copy link
Author

The previous commit was incidentally pushing the wrong testing version.

Re-pushed a fix. Sorry for the confusion.

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.

6 participants