OptaPlanner 7.32.0.Final version eggs - SolverManager the batch solving

Previous introduces OptaPlanner 7.32.0.Final version SolverManager asynchronous interface solution capabilities. This article deals continue to introduce another feature SolverManager - the bulk solving.

Applicable scene

In the daily planning system, solving a problem, in most cases, to allow time to run more limited, particularly in the scene in real-time high, allowing engine operation time is running out. Therefore, in this case, will, wait a moment, the need to obtain results from solving program after the start of the planning operation. But in some cases, when we encounter a problem when a large scale, the engine can not find the optimal solution relatively short period of time; and even in some cases, do not run long enough time, feasible solution could not be found. As for the reason, I can refer back to instructions on how-to articles OptaPlanner on NPC, NP-Hard scale of the problem.

Therefore, in some large-scale, time critical scenes, we can let the engine automatically calculate in their spare time. For example, in non-working hours (such as evenings, holidays, etc.) to start the engine of the problem more large-scale planning operations by means of regular jobs; work the next day, when you can get the operation result. Before publishing SolverManager, we can for different scenarios, to design appropriate timing of operating procedures, let the engine operation automatically. Of course, the problem with this method is asynchronous planning, requires a certain system design experience to design the architecture perfectly. The SolverManager Interface 7.32.0.Final releases, provides an easier way to achieve these needs.

SolverManager batch planning characteristics

Details about SolverManager interfaces, you should find different methods solve the Solver object, when a problem is solved using the method sovle SolverManager, in addition to solve the problem object as a parameter passed in the method, but also you need to pass a parameter as problemID . In fact, for this parameter is well understood, because SolverManager can simultaneously on multiple issues solution, there must be a way to identify different problems, after planning is complete, the caller also need to obtain the corresponding program by specifying identification number. , What are the requirements for the number of problems SolverManager simultaneously on multiple problems to solve? Its behavior is how to solve it?

SolverManager batch solving behavior

How many problems can be solved at the same time?

In fact, not only can achieve bulk SolverManager solve the problem, but can be achieved simultaneously on multiple parallel problem solving. By providing the parallelSolverCount SolverManager property, the number of engines may be provided at a batch operation, the problem can be solved in parallel. That is, when SolverManger solving operation starts, the number will be set parallelSolverCount loading problem solving spatially parallel operation. Usually parallelSolverCount value may be calculated based on the complexity of the CPU, memory and other computer resources, and the problem. If unable to determine this number, parallelSolverCount may be set to AUTO, the engine according to the specific circumstances, to automatically determine the number of parallel computing problems, usually, the number of parallel core is half of the number of CPU.

It is worth noting that a plurality of parallel computing problem here, with the solution process before multi-threaded computing (Multithreaded incremental solving) are the two concepts. Multi-threaded parallel computing, refers to the engine in solving a problem, a different subset of possible solutions will be divided into a plurality of threads simultaneously calculating (mainly performs computation constraints and heuristic scores). The bulk of the solution process SolverManager, parallelSolverCount attribute set is the number of engine problems when faced with multiple problems solved simultaneously. You can imagine that if the Multithreaded incremental solving also started up, so that the engine can use multiple CPU cores when solving a problem, in parallel to solve multiple problems. This issue dealt with the case is not so simple. So, unless you're complexity, CPU core and computing power of the problem is very clear, otherwise these two functions, or set to automatically better, according to engine operating conditions at the time of operation of computing resources dynamically and automatically determine the parallel solution of the number of questions, and each question the number of threads should start the process of solving. Experienced a single CPU multi-threaded programming friends should know, multithreading can improve resource utilization, but sometimes the number of threads of control is not good, but the performance is counterproductive, the simplest is the thread switching CPU will consume a certain Resources.

Batch solving role

In some less need for real-time planning, Solver does not need too frequent, when the operation takes longer, the batch solving can play a better role. Such as the need to do large-scale supply chain planning quarter or year, due to the large number of off-plan real problem space can be very large, it takes a long time to get the line relative to the optimal solution, even only feasible solution. Can be solved by way of a batch, so that engine operation in their spare time (for example at night, non-working day), thereby improving server resource utilization.

Basic Usage

The following example is an example of OptaPlanner user guide, we first make reference, there is no time to study SolverManager code in the sample program, temporarily do not know if there has been official SolverManager relevant code examples; if not, later on when I own try these features, one thing to write out to others.

public class TimeTableService {

    private SolverManager<TimeTable, Long> solverManager;

    // Returns immediately, call it for every dataset
    public void solveBatch(Long timeTableId) {
        solverManager.solve(timeTableId,
                // Called once, when solving starts
                this.findById,
                // Called once, when solving ends
                this.save);
    }

    public TimeTable findById(Long timeTableId) {...}

    public void save(TimeTable timeTable) {...}

}

 

The original is not easy, if you feel article helpful, welcome thumbs up, comment. Articles have omissions, welcome criticism.

This series of articles from time to time in the public serial number, please pay attention to the public number (APS make it possible) to receive timely, two-dimensional code:

http://weixin.qq.com/r/WjtFXSvE2HanrW8_925I  (Automatic Identification dimensional code)


To learn more about OptaPlanner application, please send email to: [email protected]
or discussion group to express your opinion: https://groups.google.com/forum/#!forum/optaplanner-cn
if We need to add a micro-channel (13,631,823,503) or QQ (12977379) real-time communication, but I am busy daily work, through micro letter, QQ and other tools may not be in-depth communication, more complex questions, suggestions or by mail discussion groups manner proposed. (Google mailing list discussion groups belonging to the domestic network may be difficult to access, the need to be resolved)

Guess you like

Origin www.cnblogs.com/kentzhang/p/12364917.html