OptaPlanner notes 1

1.1 What is OptaPlanner

Every organization faces a planning problem: providing limited, constrained resources (employees, assets, time, and money) for a product or service. OptaPlanner is used to optimize this kind of planning to achieve more business with fewer resources. This is called Constraint Satisfaction Programming (which is part of the discipline of operations research).

OptaPlanner is a lightweight, embeddable constraint satisfaction problem solving engine that optimizes planning problems. Scenarios it is applicable to include:

  • Employee shift scheduling: Schedule shifts for nurses, mechanics, etc.
  • Agenda Scheduling: Schedule meetings, appointments, maintenance work, advertising, etc.
  • Scheduling in education: arranging subjects, courses, examinations, academic conferences, etc.
  • Vehicle Routing: Utilize known mapping tools to plan vehicle routes transporting cargo and/or passengers that can pass through multiple destinations.
  • Packing problems: How to load items using crates, trucks, ships, and storage warehouses, or how to package information across computer resources in cloud computing.
  • Workshop operation scheduling: automobile assembly line planning, machine queue planning, labor task planning, etc.
  • Cut Stock: Minimize waste when cutting paper, steel, carpet and more.
  • Sports Scheduling: Plan game and training schedules for football leagues, baseball leagues.
  • Financial optimization: portfolio optimization, risk diversification, etc.

Insert image description here

1.2 What is a planning problem?

Insert image description here

Planning problems have an optimal solution based on limited resources and specific rules. The optimal solution can be any number of transactions, for example:

  • profit maximization
  • Minimize environmental impact
  • Maximize employee and customer satisfaction

The ability to achieve these goals depends on the amount of resources available, such as:

  • Number of personnel
  • time
  • Budget
  • Physical assets (machinery, vehicles, computers, buildings, etc.)

Specific limitations associated with these resources must also be considered, such as the number of hours a person can work, their ability to use certain machines, or compatibility between devices.

OptaPlanner can help Java programmers solve constraint satisfaction problems efficiently. It uses very efficient score calculations that combine optimization heuristics and metaheuristics.

1.2.1 Is the planning problem NP-Complete or NP-Hard?

NP-Hard problems are problems that cannot be solved in polynomial time. These problems are often very difficult because their solution requires significant computational resources. Examples of NP-Hard problems include the traveling salesman problem, the divide and conquer problem, etc.
The NP-Complete problem refers to a problem that can be solved in polynomial time but can be solved during the solution process of the NP-Hard problem. The solution of these problems is usually faster than the solution of NP-Hard problems, but still requires significant computing resources. Examples of NP-Complete problems include complete knapsack problems, branch and bound problems, etc.

All the scenarios mentioned above may be NP-Complete or NP-Hard, that is to say:

  • It's easy to verify a given solution to a problem in a reasonable amount of time.
  • There is no magic bullet to find the best solution to a problem in a reasonable amount of time. (At least, the smartest computer scientists in the world haven't discovered such a panacea yet. But if they find a solution that works for one NP-Complete problem, it will work for every NP-Complete problem.)

This means that solving the problem may be more difficult than you expect because commonly used techniques are insufficient to solve the problem:

  • Brute force algorithms (even clever variants) will take a lot of time
  • Fast algorithms (such as in a bin-packing problem where the largest items are put in first) will yield solutions that are far from the optimal solution.

By using advanced optimization algorithms, OptaPlanner can find near-optimal solutions to such planning problems in a reasonable amount of time.

1.2.2 Planning problems have constraints (hard constraints or soft constraints)

Typically, planning problems have at least two levels of constraints:

  • An absolutely indestructible (negative) hard constraint. (For example, a teacher cannot teach two different classes at the same time.)
  • A (negative) soft constraint that should not be violated if it can be avoided. (Example: A teacher does not like teaching on Friday afternoons.)

Positive constraints may also exist for some problems:

  • (positive) soft constraints that should be satisfied if possible. (For example, a teacher prefers to teach on Monday mornings.)

Some basic problems (such as the N-Queens problem) only have hard constraints. Some problems have three or more levels of constraints, such as hard, medium, and soft constraints.
These constraints define the score calculation (also called the fitness function) of the planning problem. Each solution to a planning problem can be rated with a score. In OptaPlanner, score constraints are written in an object-oriented language (such as Java code). Such code is easy to write, flexible and extensible.

1.2.3 There is a huge search space for planning problems

There are many solutions to planning problems. These solutions can be divided into the following categories:

  • A possible solution that does not consider whether any constraints are violated . Planning problems tend to have a large number of such worthless solutions.
  • A feasible solution that does not violate any negative hard constraints . Feasible solutions are often relative to the number of possible solutions. Sometimes there is no feasible solution. Every feasible solution is a possible solution
  • The optimal solution with the highest score . Planning problems have at least one optimal solution. This is true even when there is no feasible solution and the best solution is not feasible.
  • The best solution with the highest score found within a given time . The optimal solution may be feasible, and if time is available, it is the best solution.

Counterintuitively, even if the data set is small, the number of possible solutions is huge (if calculated correctly). As you can see in the examples, most cases have more possible solutions than the number of atoms in the known universe (10^80). Since there is no magic bullet for finding an optimal solution, any implementation must evaluate a subset of possible solutions.

OptaPlanner supports a variety of optimization algorithms and can effectively handle a large number of possible solutions. Depending on the use case, some optimization algorithms will perform better than others, but it's impossible to tell ahead of time. Using OptaPlanner, you can easily switch optimization algorithms with just a few lines of XML or code to modify the solver configuration.

Guess you like

Origin blog.csdn.net/zhoudingding/article/details/132248254