TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Send+more=money and how to use forward-checking in search

24 pointsby SoylentOrangealmost 4 years ago

4 comments

lamchobalmost 4 years ago
The general method presented here is Constraint Programming (CP), a sibling of SAT and ILP. In CP, you can formulate constraints over variables. Search is then performed branch-n-bound style. A variable is assigned, then constraints check if the assignment is legal and remove non-solutions from the other variable&#x27;s domains.<p>If anyone is interested: An accessible python module for this is python-constraint. Gecode is a powerful, modern C++ CP Framework.
评论 #27904805 未加载
评论 #27907333 未加载
评论 #27909375 未加载
petercooperalmost 4 years ago
Fun! It&#x27;s beside the point of the article, but am I misinterpreting &quot;There are 2 valid solutions&quot; or is it <i>at least</i> 2 valid solutions? The first two solutions I came up with weren&#x27;t the same as the author&#x27;s but passed the checker (e.g. 7534+0825=08359)
评论 #27904870 未加载
评论 #27914920 未加载
评论 #27905933 未加载
akudhaalmost 4 years ago
How hard would it be to write a program that can <i>create</i> such puzzles, given a set of few thousand valid English (or some other language) words?
评论 #27907196 未加载
评论 #27905573 未加载
dragontameralmost 4 years ago
FC is one of the &quot;cheapest&quot; checks.<p>&quot;Maintaining Arc Consistency&quot; is actually asymptotically equivalent (in the same O(n^2) complexity class as FC), but textbooks only list AC3 typically (which is suboptimal but pretty easy to understand. I&#x27;d compare it to &quot;insertion sort&quot;). AC4 is difficult to program and understand (especially difficult to extend beyond binary constraints), but worst-case asymptotically optimal.<p>Today: there&#x27;s AC2001, a simple extension to AC3, which has best-case attributes similar to AC3 but is worst-case asymptotically optimal. Its also &quot;obvious&quot; how to extend into GAC (aka: the GAC2001 algorithm) to handle non-binary constraints.<p>This is an NP-complete problem, so there&#x27;s really no way to know if FC, MAC (with AC2001), or even Path-consistency (a consistency level above MAC) is optimal. I guess the rule of thumb is that if there&#x27;s &quot;lots of solutions&quot; out there, then you want to spend less time checking: and maybe FC is better.<p>If there are &quot;very very few solutions&quot;, then MAC (and even Path-consistency) may be superior. A stronger check leads to cutting more of the search tree away, but requires a bigger-and-bigger preprocessor at every step.<p>The textbooks I&#x27;ve read seem to default to FC. But given the discovery of AC2001, I think the modern default probably should be MAC using AC2001.<p>----------------<p>Or in the &quot;Sudoku terms&quot;, how long do you want to spend searching the tree, vs how long do you want to spend proving that the current search isn&#x27;t &quot;hopeless&quot; ??<p>The longer you ensure that your &quot;current choice&quot; is &quot;not hopeless&quot;, the longer your best-case search takes. The less time you spend on checking for &quot;hopelessness&quot;, the longer the worst-case search takes (because you&#x27;ll run into more hopeless situations but still spend tons of time searching through it).<p>FC, MAC (aka 2-consistency), Path Consistency (aka 3-consistency), and 4-Consistency, 5-consistency, 6-consistency... you can arbitrarily spend as much time as you like on checking for hopelessness. If you have 99-variables (like the 99-locations in Sudoku), checking for 99-consistency is equivalent to solving the puzzle in every possible way (If multiple solutions are possible, 99-consistency would find them all!!!). As such, 100-consistency cannot exist if you only have 99-variables, so 99-consistency is the limit on Sudoku.<p>Your &quot;Big O&quot; is something like (O(d^k)), where d is the size of domains (9 in Sudoku), and k is the consistency level you&#x27;re aiming for. So O(9^2-ish) is what you&#x27;re looking at for FC and MAC. O(9^99) is what you&#x27;re looking at for 99-consistency. So aiming for higher levels of consistency scales poorly to say the least... and textbooks only briefly mention Path (3-consistency) and k-consistency in passing.<p>In practice, if you&#x27;re in fact trying to &quot;find all solutions&quot;, the brute force 99-variable == 99-consistency is suboptimal. In practice, you might find a 55-consistency relationship that&#x27;s backtrack free (exponentially faster than 99-consistency), but this involves solving some rather nasty graph problems. Its absolutely worth the tradeoff but there be dragons here. (Finding the optimal ordering of variables means solving for the minimum-induced width of an induced graph of the variables, which is an NP-complete problem)<p>--------<p>There&#x27;s also DAC: Directional Arc Consistency. Which is &quot;more consistent&quot; than FC but &quot;less consistent&quot; than full Arc Consistency (aka: MAC&#x2F;Maintaining Arc Consistency). A naive implementation of DAC will be asymptotically optimal.<p>Needless to say: researchers have spent a lot of time looking at various &quot;consistency&quot; benchmarks for these backtracking problems.
评论 #27908768 未加载