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

Optimize your problems using KIE Execution Server

Fri 18 August 2017
Avatar Matej Čimbora
Matej Čimbora

GitHub

OptaPlanner Workbench developer

KIE Server provides separation of execution environment from your client application, making it easy to use OptaPlanner outside Java ecosystem (e.g. .NET). In the 7 release stream, we worked to improve OptaPlanner/KIE Server integration. The new API is less verbose and more intuitive. Let’s take a closer look at its usage in more detail.

How a typical workflow looks like?

  1. Install your optimization app kjar to a maven repository accessible by the KIE Server. This step assumes the following conditions are met:

    • kmodule.xml file is located in META-INF folder of your project.

    • Project uses packaging type kjar.

    • kie-maven-plugin is configured for the project.

      <build>
        <plugins>
          <plugin>
            <groupId>org.kie</groupId>
            <artifactId>kie-maven-plugin</artifactId>
            <version>${version.org.kie}</version>
            <extensions>true</extensions>
          </plugin>
        </plugins>
      </build>
  2. Create a container (server unit of execution) wrapping the project. This example uses Java KIE Server client, which performs REST calls in the background.

    The following dependencies are required in your client application. Make sure to use version 7.0.0.Final, or later.

      <dependency>
        <groupId>org.kie.server</groupId>
        <artifactId>kie-server-api</artifactId>
      </dependency>
      <dependency>
        <groupId>org.kie.server</groupId>
        <artifactId>kie-server-client</artifactId>
      </dependency>

    Client and container creation:

      KieServicesConfiguration kieServicesConfiguration = new KieServicesConfigurationImpl(SERVER_URL, USERNAME, PASSWORD, CLIENT_TIMEOUT);
      KieServicesClient kieServicesClient = KieServicesFactory.newKieServicesClient(kieServicesConfiguration)
    
      // ReleaseId corresponds to groupId:artifactId:version (GAV) of the project installed in the first step
      ReleaseId releaseId = new ReleaseId("org.optaplanner", "kie-server-example", "1.0.0-SNAPSHOT");
      KieContainerResource containerResource = new KieContainerResource(CONTAINER_ID, releaseId);
      kieServicesClient.createContainer(CONTAINER_ID, containerResource);
  3. Create a solver within the container. A single container can hold multiple solvers, each of them having a unique identifier. This is useful if you want to try out different solver configurations.

    SolverServicesClient solverClient = kieServicesClient.getServicesClient(SolverServicesClient.class);
    solverClient.createSolver(CONTAINER_ID, SOLVER_ID, SOLVER_CONFIG_XML_PATH);
  4. Submit your optimization problem

    CloudBalance cloudBalance = loadPlanningSolution();
    solverClient.solvePlanningProblem(CONTAINER_ID, SOLVER_ID, cloudBalance);
  5. Check the solver state. At this point of time the best solution notifications are not supported yet on the client side, you need to periodically check the solver status/best solution.

      SolverInstance solver = solverClient.getSolver(CONTAINER_ID, SOLVER_ID);
      if (solver.getStatus() == SolverInstance.SolverStatus.SOLVING) {
        // continue
      } else {
        CloudBalance cloudBalance = (CloudBalance) solverClient.getSolverWithBestSolution(CONTAINER_ID, SOLVER_ID).getBestSolution()
        // process the solution
      }
  6. Once you are done with the optimization, terminate the solver.

      solverClient.terminateSolverEarly(CONTAINER_ID, SOLVER_ID);
  7. If you don’t plan to reuse the solver anymore, dispose it to free the resources on the server.

      solverClient.disposeSolver(CONTAINER_ID, SOLVER_ID);

New OptaPlanner REST API overview

The following table shows an overview of the new API introduced in version 7.0.0.Final. All solver action URLs are normally prefixed by container URL, e.g. http://${kie-server}/services/rest/server/containers/${container_id}, which is not included in the table to keep the output short.

Action Method URL suffix Payload

Register solver

PUT

solvers/${solver_id}

-

Get solver

GET

solvers/${solver_id}

SolverInstance object

Submit solution

POST

solvers/${solver_id}/state/solving

Solution object

Get best solution

GET

solvers/${solver_id}/bestsolution

SolverInstance object including the best solution

Terminate solver

POST

solvers/${solver_id}/state/terminating-early

-

Dispose solver

DELETE

solvers/${solver_id}

-

Where do I start?

Download KIE (Execution) Server.

Check KIE Server Integration chapter of OptaPlanner Workbench quickstart or OptaPlanner REST API documentation for more details on the API.

Optionally try out KIE Workbench, which integrates with the KIE Server. The following video demonstrates the process of setting up a Workbench example and optimizing it using the KIE Server.

Conclusion

KIE Server provides an alternative way of optimizing your constraint satisfaction problems. If you want to offload workload to cloud (possibly with a large amount of resources), or you use non-Java client, KIE Server is the right pick.


Permalink
 tagged as feature howto execution server

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
  • 8.35.0.Final released
    Fri 3 March 2023
Upcoming events
    Add event / Archive
Latest blog posts
  • 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
  • OptaPlanner deprecates score DRL
    Thu 26 May 2022
    Lukáš Petrovický
  • Real-time planning meets SolverManager
    Mon 7 March 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