Raymond Hettinger - Modern solvers: Problems well-defined are problems solved - PyCon 2019

PyCon 2019 · 63K views · 2019 · 47:15

Open on YouTube

Algorithms & data structuresPython, Ruby & scripting languagesLogic & formal methodstalk

Why Stack Overflow recommends it

Stack Overflow users link it when answering or building puzzle and constraint problems, pointing to its generic puzzle solver and SAT solver code as a starting point.

Recommended by 2 people across 2 different months, 2020 to 2023.

What it is

Raymond Hettinger's PyCon 2019 talk shows how to use solvers in Python: a generic tree-search puzzle framework, the PycoSAT SAT solver (with Sudoku and logic puzzles as examples), and a multi-armed bandit approach to rock-paper-scissors. It combines principles, working code and worked examples.

What people said

Strong rec Lukas S · 2022-04 · Stack Overflow · on “Finding the shortest path to solve colored water sorting games”

@MatsukaziIssy Hi, don't be sorry. I posted this here so somebody would read and comment on it. That was the intention :). Have you watched the presentation of the Generic Puzzle Solver [this video] that this is based on? It is a really great presentation and a good place to start understanding. Also if you have specific questions feel free to ask me in the comments. I am afraid I don't feel like anticipating your questions and answering them in case you might not understand i.e. adding a lot of comments to my code.

Recommends mapf · 2020-05 · Stack Overflow · on “Python: Find underlying sequence of word/strings based on list incomplete sequences”

Ok, I just couldn't stop thinking about this problem, and now I have finally found the solution I was looking for. This only works if your problem is in deed well-definied , meaning that a) there are no contradictions in your dataset, and b) that there is only one order that can be derived from it, with no room for ambiguity. Based on this assumption, I noticed that your problem looks very similar to a zebra, or Einstein puzzle [LINK] . I knew about this type of riddle, but it took me a very long time to figure out what it was actually called . At first, I thought you could tackle this type of problem by solving a system of linear equations, but soon I realized that it is not that simple. So

Cites physicalattraction · 2022-02 · Stack Overflow · on “Slow dnf to cnf in pycosat”

Question in short To have a proper input for pycosat [LINK] , is there a way to speed up calculation from dnf to cnf, or to circumvent it altogether? Question in detail I have been watching this video [this video] from Raymond Hettinger about modern solvers. I downloaded the code, and implemented a solver for the game Towers [LINK] in it. Below I share the code to do so. Example Tower puzzle (solved): 3 3 2 1 --------------- 3 | 2 1 3 4 | 1 3 | 1 3 4 2 | 2 2 | 3 4 2 1 | 3 1 | 4 2 1 3 | 2 --------------- 1 2 3 2 The problem I encounter is that the conversion from dnf to cnf takes forever. Let's say that you know there are 3 towers visible from a certain line of sight. This leads to 35 possible per

Cites Sebastian Wozny · 2023-07 · Stack Overflow · on “Combination Optimization in Python”

The problem description lends itself to solving with a Mixed-Integer-Linear Program (MIP) [LINK] . A convenient library for solving mixed integer problems is PuLP [LINK] that ships with the built-in Coin-OR suite [LINK] and in particular the integer solver CBC. We formulate a model that describes your problem: import pulp center_a_products = { 1: 8, 2: 4, 3: 12 } product_quantities = { 1: {1: 10, 2: 5, 3: 15}, 2: {1: 5, 2: 8, 3: 10}, 3: {1: 12, 2: 6, 3: 20} } problem = pulp.LpProblem("CenterSatisfactionProblem", pulp.LpMinimize) # Center vars are binary variables that we minimize in the objective. They indicate whether a center was visited or not center_vars = {center: pulp.LpVariable(f"Cent

Cites Sebastian Wozny · 2023-07 · Stack Overflow · on “Efficient random subsample of a Pandas DataFrame based on multiple columns target requirements”

The problem description lends itself to solving with a Mixed-Integer-Linear Program (MIP) [LINK] . A convenient library for solving mixed integer problems is PuLP [LINK] that ships with the built-in Coin-OR suite [LINK] and in particular the integer solver CBC. Note that I changed the data structure from the DataFrame in the example because the code gets really messy with your original DataFrame as lookups without index use a lot of .loc which I personally dislike :D data = { 'Polygon A': { 'Landcover 1': 10, 'Landcover 2': 15, 'Landcover 3': 20 }, 'Polygon B': { 'Landcover 1': 5, 'Landcover 2': 8, 'Landcover 3': 12 }, 'Polygon C': { 'Landcover 1': 7, 'Landcover 2': 4, 'Landcover 3': 9 }, 'P