Solving

โš™๏ธ Solving with Qaekwy

Once you’ve built your model, it’s time to solve it! This guide will show you how to use Qaekwy’s solvers to find solutions to your problems.

1. Searchers: The Brains of the Operation

A searcher is the high-level algorithm that the solver uses to find a solution. Think of it as a detective with a particular style of solving mysteries.

Choosing the right searcher can make a huge difference in how fast you solve your problem. Qaekwy has a team of detectives for you to choose from:

  • DFS (Depth-First Search): The methodical detective. It explores one path as far as it can go before trying another. A good all-around choice.
  • BAB (Branch and Bound): The optimization expert. It’s great for finding the best solution (e.g., the cheapest or fastest).
  • LDS (Limited Discrepancy Search): The optimistic detective. It’s good when you have a hunch about where the solution might be.
  • PBS (Portfolio-Based Search): The team of detectives. It runs multiple search strategies at the same time, hoping that one of them will crack the case quickly. The searches are DFS, LDS, and RBS.

To set the searcher, use the set_searcher method on your modeller:

from qaekwy.model.searcher import SearcherType

modeller.set_searcher(SearcherType.DFS)

2. DirectEngine: The Power Behind the Throne

The engine is the “brain” that does the actual work of solving your problem. Qaekwy gives you a few different brains to choose from, depending on your needs.

  • DirectEngine: it connects to a Qaekwy solver engine running in the cloud, so you don’t have to install or run anything on your computer.

Here’s how to use the DirectEngine to solve your model:

from qaekwy.engine import DirectEngine

# Create a DirectEngine instance
engine = DirectEngine()

# Solve the model
solution_response = engine.model(modeller)

3. Cutoffs: Knowing When to Stop

For really hard problems, a full search could take days or even weeks. A cutoff is like setting an actions counter for your search.

Qaekwy has a bunch of different ways to set a time limit on your search:

  • CutoffConstant: Stop after a fixed number of steps.
  • CutoffFibonacci: The step limit increases like the Fibonacci sequence.
  • CutoffGeometric: The step limit grows exponentially.
  • CutoffLuby: A special sequence that’s good for some problems.
  • CutoffLinear: The step limit increases in a straight line.
  • CutoffRandom: A random step limit.

You can also combine cutoffs using Meta Cutoffs like MetaCutoffAppender, MetaCutoffMerger, and MetaCutoffRepeater.

To set a cutoff, use the set_cutoff method on your modeller:

from qaekwy.model.cutoff import CutoffConstant

# Stop searching after 1000 steps
modeller.set_cutoff(CutoffConstant(1000))