OptaPlanner logo
  • Download
  • Learn
    • Documentation
    • Videos

    • Use cases
    • Compatibility
    • Testimonials and case studies
  • Get help
  • Blog
  • Source
  • Team
  • Services
  • Star
  • T
  • L
  • F
  • YT
Fork me on GitHub

Is the search space of an optimization problem really that big?

Thu 27 March 2014
Avatar Geoffrey De Smet
Geoffrey De Smet

Twitter LinkedIn GitHub

OptaPlanner creator

Given a planning or optimization problem, how big is the search space? Can we hope to enumerate every possible solution, looking for the optimal solution? Let’s calculate the search space of a few use cases.

Use cases

searchSpaceSizeCalculationUseCases

We’ll look at these 3 use cases:

  • Cloud Balancing: Assign processes to computers. Each computer should have enough hardware capacity (CPU power, RAM, etc.) for all its processes. Use as few computers as possible to minimize the maintenance costs.

    • Model: The class Process has a planning variable computer of type class Computer. So every Process instance refers to the Computer instance to which it’s assigned.

  • Traveling Salesman Problem (TSP): Find the shortest path to visit every city.

    • Model: The class Visit has a planning variable previousVisit. All Visit instances together form a single linked list.

  • Course Scheduling: Assign lectures to periods and rooms. No teacher should have 2 lectures in the same period. No room should have 2 lectures in the same period. There are 6 more constraint types.

    • Model: The class Lecture has a planning variable period and a planning variable room.

What’s the search space for each of these use cases?

Base search space

Let’s first look at the number of combinations that each Solution model is able to represent, regardless if those Solutions are feasible or infeasible (= have broken hard constraints). Let’s call this the base search space.

searchSpaceSizeCalculation
  • Cloud Balancing: The base search space is the number of computers raised to the power of the number of processes.

  • Traveling Salesman Problem (TSP): The base search space is the factorial of the number of cities (= visits).

  • Course Scheduling: The base search space is the multiplication of the number of periods and rooms, raised to the power of the number of lectures.

The base search space is beyond gigantic. Let’s compare it to the minimal number of atoms in the known universe, which is 1080. In Cloud Balancing, the base search space is already bigger than that, for a small dataset of 100 computers and 300 processes. Not to mention the big datasets.

In the best case we can hope to enumerate 1020 combinations per year on modern hardware, so enumerating all combinations would take an insane amount of years. We don’t have years, we have seconds, maybe minutes or hours. Can we cut any corners?

Feasible search space

If we look at the course scheduling example, there is relatively little point in enumerating all solutions for which the first and the second lecture (A and B) are both in the same period and the same room. Regardless of the values of other lectures (C, etc.), the solution is infeasible and our business doesn’t want it. So let’s ignore those solutions.

How big is our search space if we discard all infeasible solutions? An infeasible solution is a solution that breaks at least 1 hard constraint.

feasibleSearchSpaceSizeCalculation
  • Cloud Balancing: The feasible search space is impossible to calculate. The capacity hard constraints are a form of bin packing, which is NP-complete. That implies that even the smartest computer scientists fail to calculate it in reasonable time for medium or big datasets.

  • Traveling Salesman Problem (TSP): There are no hard constraints which aren’t built-in into the model already. So, the feasible search space is the same as the base search space, n!.

  • Course Scheduling: We can successfully take into account 1 hard constraint: no room should have 2 lectures in the same period. In that case, the feasible search space is a number of digits less than the base search space. The other hard constraints are far more difficult (or impossible) to taken into account, especially because they can overlap.

Even if we were able to look at only the feasible solutions, it would still take an insane amount of years to enumerate all of them.

Pruned search space

Using feasibility as a threshold to check if we want to investigate a solution, is arbitrary (from a mathematical point of view):

  • There might not be any feasible solutions. The optimal solution might be infeasible. We still want to find it.

  • As soon as we know there is a solution of a certain score, we want to prune all solutions with a worse score from the search space. [1]

    • For example: as soon as we know there is a solution of score 0hard/-100soft, there is no point investigating partial solutions which already have a score of 0hard/-200soft (which is worse).

So instead of a using a Brute Force algorithm, shown here on the N queens use case (where to goal is to put n queens on a chessboard so they cannot attack each other):

bruteForceNQueens04 4

We can prune away the uninteresting search space, with the Branch And Bound algorithm:

depthFirstBranchAndBoundNQueens04 4
depthFirstBranchAndBoundNQueens04 5
depthFirstBranchAndBoundNQueens04 8

That’s pretty smart and it reduces the search space a lot.

Because it’s not practical to calculate the size of the pruned search space, let’s look at how both algorithms scale. First on N queens:

exhaustiveSearchScalabilityNQueens

Then on the Cloud Balancing use case:

exhaustiveSearchScalabilityCloudBalance

That’s bad. Even with Branch And Bound, we hit the wall at 8 computers and 24 processes. Although there are number of techniques to push that wall out further, these exhaustive algorithms don’t scale. Despite that the pruned search space is a lot smaller than the base search space, it’s still insanely large.

Conclusion

Yes, the search space of planning or optimization problems is unbelievably big. Exhaustive algorithms don’t scale. Instead, use the other algorithms in OptaPlanner, which do scale: heuristics and metaheuristics.


1. Presumes the use case only has negative constraints. Most use cases do, including all those shown in this article.

Permalink
 tagged as insight algorithm school timetabling

Comments

Visit our forum to comment
AtomNews feed
Don’t want to miss a single blog post?
Follow us on
  • T
  • L
  • F
Blog archive
Latest release
  • 9.44.0.Final released
    Wed 6 September 2023
Upcoming events
    Add event / Archive
Latest blog posts
  • Scaling Up Vehicle Routing Problem with planning list variable and Nearby Selector
    Thu 27 April 2023
    Anna Dupliak
  • OptaPlanner 9 has been released
    Mon 24 April 2023
    Radovan Synek
  • OptaPlanner 9 is coming
    Tue 21 February 2023
    Lukáš Petrovický
  • Farewell - a new lead
    Tue 15 November 2022
    Geoffrey De Smet
  • Run OptaPlanner workloads on OpenShift, part II
    Wed 9 November 2022
    Radovan Synek
  • Bavet - A faster score engine for OptaPlanner
    Tue 6 September 2022
    Geoffrey De Smet
  • Run OptaPlanner workloads on OpenShift, part I.
    Thu 9 June 2022
    Radovan Synek
  • Blog archive
Latest videos
  • The Vehicle Routing Problem
    Fri 23 September 2022
    Geoffrey De Smet
  • Introduction to OptaPlanner AI constraint solver
    Thu 25 August 2022
    Anna Dupliak
  • On schedule: Artificial Intelligence plans that meet expectations
    Sat 23 July 2022
    Geoffrey De Smet
  • Host your OptaPlanner app on OpenShift (Kubernetes)
    Mon 7 February 2022
    Geoffrey De Smet
  • OptaPlanner - A fast, easy-to-use, open source AI constraint solver for software developers
    Mon 31 January 2022
  • Order picking planning with OptaPlanner
    Fri 31 December 2021
    Anna Dupliak
  • AI lesson scheduling on Quarkus with OptaPlanner
    Thu 18 November 2021
    Geoffrey De Smet
  • Video archive

OptaPlanner is open. All dependencies of this project are available under the Apache Software License 2.0 or a compatible license. OptaPlanner is trademarked.

This website was built with JBake and is open source.

Community

  • Blog
  • Get Help
  • Team
  • Governance
  • Academic research

Code

  • Build from source
  • Issue tracker
  • Release notes
  • Upgrade recipes
  • Logo and branding
CC by 3.0 | Privacy Policy
Sponsored by Red Hat