Toggle navigation OptaPlanner logo
  • Home
  • Download
  • Learn
    • Documentation
    • Videos
    • Slides
    • Training
    • Use cases
    • Compatibility
    • Testimonials and case studies
  • Get help
  • Source
  • Team
  • Services
  • Star
  • @OptaPlanner
  • Fb
Fork me on GitHub
  • Visualize the score and the constraints
  • Does A.I. include constraint solvers?

Optimize your problems using KIE Execution Server

Fri 18 August 2017

Avatar Matej Čimbora

Matej Čimbora


GitHub

Ex 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.


Comments Permalink
 tagged as feature howto execution server

Comments

Visit our forum to comment
  • Visualize the score and the constraints
  • Does A.I. include constraint solvers?
Atom News feed
Don't want to miss a single blog post?
Follow us on
  • T
  • Fb
Blog archive
Latest release
  • 8.3.0.Final released
    Fri 5 March 2021
Upcoming events
  • KIE Live
    Worldwide - Tue 9 March 2021
    • Testing your constraints with OptaPlanner by Lukáš Petrovický, Karina Varela, Alex Porcelli
  • Javaland
    Worldwide - Tue 16 March 2021
    • AI on Quarkus: I love it when an OptaPlan comes together by Geoffrey De Smet
  • Red Hat Webinar
    Worldwide - Wed 24 March 2021
    • AI planning: Top 3 use cases and benefits by Ronald Meuwsen, Geoffrey De Smet
  • SouJava MOTU
    Worldwide - Thu 15 April 2021
    • Planejamento de Recursos com OptaPlanner by Karina Varela, Otávio Santana
Add event / Archive
Latest blog posts
  • Optimizing COVID-19 vaccination appointment scheduling
    Thu 4 March 2021
     Paul Brown
  • How much faster is Java 15?
    Tue 26 January 2021
     Michal Tomčo
  • Solve the facility location problem
    Fri 9 October 2020
     Jiří Locker
  • OptaPlanner Week 2020 recordings
    Mon 7 September 2020
     Geoffrey De Smet
  • Let’s OptaPlan your jBPM tasks (part 1) - Integrating the two worlds
    Fri 3 July 2020
     Walter Medvedeo
  • AI versus Covid-19: How Java helps nurses and doctors in this fight
    Fri 8 May 2020
     Christopher Chianelli
  • Workflow processes with AI scheduling
    Tue 5 May 2020
     Christopher Chianelli
Blog archive
Latest videos
  • YT Maintenance scheduling
    Wed 24 February 2021
     Julian Cui
  • YT Vaccination appointment scheduling
    Wed 3 February 2021
     Geoffrey De Smet
  • YT Shadow variables
    Tue 19 January 2021
     Geoffrey De Smet
  • YT Domain modeling and design patterns
    Tue 17 November 2020
     Geoffrey De Smet
  • YT Quarkus insights: AI constraint solving
    Tue 20 October 2020
     Geoffrey De Smet
  • YT AI in kotlin
    Wed 23 September 2020
     Geoffrey De Smet
  • YT Planning agility: continuous planning, real-time planning and more
    Thu 3 September 2020
     Geoffrey De Smet
Video archive

KIE projects

  • Drools rule engine
  • OptaPlanner constraint solver
  • jBPM workflow engine

Community

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

Code

  • Build from source
  • Submit a bug
  • License (Apache-2.0)
  • Release notes
  • Upgrade recipes
Sponsored by
Red Hat
More coder content at
Red Hat Developers
© Copyright 2006-2021, Red Hat, Inc. or third-party contributors - Privacy statement - Terms of use - Website info