Tuesday, May 14, 2013

Creating your own Drools and jBPM Persistence with Infinispan


Original post here by me:

Hello and welcome to a post in which I intend to show you how to create your own implementation of drools and jBPM persistence. I’ve worked on an infinispan based persistence scheme for drools objects and I learnt a lot in the process. It’s my intention to give you a few pointers if you wish to do something of the sort.

Why?

If you’re reading this, you probably already have a “why” to redefine the persistence scheme that drools uses, but it’s good to go over some good reasons to do something like this. The most important thing is that you might consider the JPA persistence scheme designed for drools doesn’t meet your needs for one or more reasons. Some of the most common I’ve found are these:
The given model is not enough for my design: Current objects created to persist the drools components (sessions, process instances, work items and so on) currently are as small as possible to allow the best performance on the database, and most of the operational data is stored in byte arrays mapped to blob objects. This scheme is enough for the drools and jBPM runtime to function, but it might not be enough for your domain. You might want to keep the runtime information in a scheme that is easier to query from outside tools, and to do that you would need to enrich the data model, and even create one of your own.
The persistence I’m using is not compatible with JPA: There are a lot of persistence implementations out there that no longer use databases as we once knew (distributed caches, key value storages, NoSQL databases) and the model usually needs extra mappings and special treatment when persisting in such storages. To do so, sometimes JPA is not our cup of tea
I need to load special entities from different sources every time a drools component is loaded: When we have complex objects and/or external databases, sometimes we want new models to relate in a special way to the objects we have. Maybe we want to make sure our sessions are binded to our model in a special way because it makes sense to our business model. To do so we would have to alter the model

How?

In order to make our own persistence scheme for our sessions, we need to understand clearly how the JPA scheme is built, to use it as a template to build our own. This class diagram shows how the JPA persistence scheme for the knowledge session is implemented:

Looks complicated, right? Don’t worry. We’ll go step by step to understand how it works.
First of all, you can see that we have two implementations of the StatefulKnowledgeSession (or KieSession, if you’re using Drools 6). The one that does all the “drools magic” is StatefulKnoweldgeSessionImpl, and the one we will be using is CommandBasedStatefulKnowledgeSession. It has nothing to do with persistence, but it helps a lot with it by surrounding every method call with a command object and deriving its execution to a command service. So, for example, if you call the fireAllRules method to this type of session, it will create a FireAllRulesCommand object and give it to another class to execute.
This command based implementation allows us to do exactly the thing we need to implement persistence on a drools environment: It lets us implement actions before and after every method call done to the session. That’s where the SingleSessionCommandService class comes in handy: This command service contains a StatefulKnowledgeSessionImpl and a PersistenceContextManager. Every time a command has to be executed, this class creates or loads a SessionInfo object and tells the persistence context to save it with all the state of the StatefulKnowledgeSessionImpl.
That’s the most complicated part: the one that implements the session persistence. Persistence of pretty much everything else is done easily through a set of given interfaces that provide methods to implement how to load everything else related to a session (process instances, work items and signals). As long as you create a proper manager and its factory, you can delegate on them to store anything to anywhere (or do anything you want, for that matter).

So, after seeing all the components, it’s a good time to start thinking of how to create our own implementation. For this example, we’ve created an Infinispan based persistence scheme and we will show you all the steps we took to do it.

Step 1: (re)define the model
Most of the time when we want to persist drools objects in our way, we might want to do it with a gist of your own. Even if we don’t wish to change the model, we might need to add special annotations to the model to work with your storage framework. Another reason might be that you want to store all facts in a special way to cross-query them with some other legacy system. You can literally do this redefinition any way you want, as long as you understand that whatever model you create, the persistence scheme will serialize and deserialize it every time you call a method on the knowledge session, so always try to keep it simple.
Here’s the model we created for this case:
Nothing too fancy, just a flattened model for all things drools related. We weren’t too imaginative with this model, because we just wanted to show you that you can change it if you want to.
One thing to notice in this model is that we are still saving all the internal data of these objects pretty much the same way as it is stored for the JPA persistence. The only difference is that  JPA stores it in a Blob, and we store it in a Base64 encrypted string. If you wish to change the way that byte array is generated and read, you have to create your own implementations of these interfaces:
  • org.kie.api.marshalling.Marshaller for knowledge sessions
  • org.jbpm.marshalling.impl.ProcessInstanceMarshaller for process instances
But providing an example of that would take way too much time and perhaps even a whole book to explain, so we’ll skip it :)

Step 2: Implementing the PersistenceContext
For some cases, redefining the PersistenceContext and the PersistenceContextManager would be enough to implement all your persistence requirements. The PersistenceContext is an object in charge of persisting work items and session objects by implementing methods to persist them, query them by ID and removing them from a particular storage implementation. The PersistenceContextManager is in charge of creating the PersistenceContext, either once for all the application or on a per-command basis. The comand service will use it to persist the session and its objects when needed.
In our case we implemented a PersistenceContext and a PersistenceContextManager using an Infinispan cache as storage. The different PersistenceContextManager instances will have access to all configuration objects through the Environment variable. We’ve used the already defined keys in Environment to store our Infinispan related objects:
  • EnvironmentName.ENTITY_MANAGER_FACTORY is used to store an Infinispan based CacheManager
  • EnvironmentName.APP_SCOPED_ENTITY_MANAGER and EnvironmentName.CMD_SCOPED_ENTITY_MANAGER will point to an Infinispan Cache object.
You can see that code here:


At this point we have some very important steps to redefining our drools persistence. Now we need to know how to configure our knowledge sessions to work with this components.

Step 3: Creating managers for our work items, process instances and signals

Now that we have our persistence contexts, we need to teach the session how to use them properly. The knowledge session has a few managers that can be configured that allow you to modify or alter the default behaviour. These managers are:
org.kie.api.runtime.process.WorkItemManager: It manages when a work item is executed, connects it with the proper handler, and notifies the process instance when the work item is completed.
org.jbpm.process.instance.event.SignalManager: It manages when a signal is sent to or from a process. Since process instances might be passivated, it needs to
org.jbpm.process.instance.ProcessInstanceManager: It manages the actions to be taken when a process instance is created, started, modified or completed.

JPA implementation of these interfaces already work with a persistence context manager, so most of the times you won’t need to extend them. However, with Infinispan, we have to make sure the process instance is persisted more often than with JPA, so we had to implement them differently.
Once you have these instances, you will need to create a factory for each type of manager.The interface names are the same, except with the suffix “Factory”. Each receives a knowledge session as parameter, from which you can get the Environment object and all other configurations.

Step 4: Configuring the knowledge session

Now that we have our different managers created, we will need to tell our knowledge sessions to use them. To do so you need to create a CommandBasedStatefulKnowledgeSession instance with a SingleSessionCommandService instance. The SingleSessionCommandService, as its name describes, is a class to execute commands against one session at a time. SingleSessionCommandService’s constructor receives all parameters needed to create a proper session and execute commands against it in a way that it becomes persistent. Those parameters are:

  • KieBase: the knowledge base with the knowledge definitions for our session runtime.
  • KieSessionConfiguration: Where we configure the manager factories to create and dispose of work items, process instances and signals.
  • Environment: A bag of variables for any other purpose, where we will configure our persistence context mananager objects.
  • sessionId (optional): If present, this parameter looks for an already existing session in the storage. Otherwise, it creates a new one.

Also, in our example, we’re using Infinispan, which is not a reference based storage, but a value based storage. This means that once you say to infinispan to store a value, it will store a copy of it and not the actual object. Some things in drools persistence are managed to be stored through reference based storages, meaning you can tell the framework to persist an object, change its attributes, and see those changes stored in the database after committing the transaction. With infinispan, this wouldn’t happen, so you have to implement an update of the cache values after the command execution is finished. Luckily for us, the SingleSessionCommandService allows us to do this by implementing an Interceptor.
Interceptors are basically your own command service to wrap the default one. You can tell each command to add more behaviour before or after each execution. Here’s a couple of diagrams to explain how it works:

As you can see, the SingleSessionCommandService allows for a command service instance to actually invoke the command’s execute method. And thanks to the interceptor extension of the command service, we can add as many as we want in chain, allowing us to have something like the next sequence diagram executing every time a command needs execution:

In our case, we created a couple of these interceptors and added them to the SingleSessionCommandService. One makes sure any changes done to a session object are stored after finishing the command. The other one allows us to do the same with process instance objects.

Overall, this is how we need to create our knowledge sessions at this point to actually use infinispan as a persistence scheme:

Complicated, right? Don’t worry. There’s yet another couple of classes to make it easier to configure.

Step 4: Creating our own initiation service

Yes, we could write that ton of code every time we want to create our own customized persistent knowledge sessions. It’s a free world (for the most part). But you can also wrap this implementation in a single class with two exposed methods:
  • One to create a new session
  • One to load a previously existing session
And creates all the configuration internally, merging it whenever you wish to change one or more things. Drools provides an interface to serve as a contract for this called org.kie.api.persistence.jpa.KieStoreServices
We created our own implementation of this interface and also a static class to access it, called InfinispanKnowledgeService. This allows us to be able to create the session like this:


Conclusion

Drools persistence can seem complicated to understand and to get working, let alone to implement it in your own way. However, I hope this shows a bit of demystification to those who need to implement drools persistence in a special way, or were even wondering if it is possible to do so in any other way than JPA.
Also, if you wish to see the modifications done to make it work, see these three pull requests:
A feature request to add this features to Drools is specified in this JIRA ticket. Feel free to upvote it if you wish to have it as part of the core drools project!

Tuesday, May 07, 2013

London JBUG May Event - What's new in Drools 6.0 (22nd May 2013)

http://www.c2b2.co.uk/london_jbug_may_2013


London JBUG May Event - What's new in Drools 6.0

WHENWHEREHOW TO REGISTER?
Wednesday
22nd of May 2013
6pm-8:30pm
Skills Matter eXchange
116-120 Goswell Road
London, EC1V 7DP
Fill in the form at the bottom 
of the page!
If you are interested in attending the future JBUG events please join JBUG on Meetup

Presentation

Drools 6.0 introduces new approaches for authoring, building, deploying and utilising rules. Using convention and configuration, over programmatic apis, in an effort to simplify the experience for end users.
This talk, presented by Mark Proctor - Platform Architect at Red Hat - will take users through the new web based IDE (built with UberFire) for authoring and deploying rules, and then utilising them on the client side. It will also introduce the other new 6.0 features, including our new lazy rule engine algorithm. Ideally attendees will have a basic understanding of Drools and rule engines.

Speaker 

Mark Proctor received his B.Eng in Engineer Science and Technology and then his M.Sc. in Business and Information Systems; both from Brunel University, West London. His M.Sc. thesis was in the field of Genetic Algorithms; which is where he discovered his interest for anything AI related.
For the last 10 years Mark's focus has been on developing knowledge engineering systems in java, while working for Red Hat as Platform Architect. Mark is the co-founder of the Drools project, the leading Java expert system tool, and as Platform Architect he is responsible for all technologies related to rules, processes, events, ontologies and intelligent agents at Red Hat.

Agenda

18:00 - 18:15 - Coffee, Welcome and Networking 
18:15 - 19:30 - 'What's new in Drools 6.0' by Mark Proctor 
19:30 - 19:50 - Lightning Talks / Problem Solving Sessions
'Hands off my data! How to use Off-Heap Memory from Java and keep the latencies down' lightning talk will be presented by Jaromir Hamala
19:50 - 20:30 - Beer, Pizza and Networking
‘Problem Solving’ Sessions
Following your suggestions, we’re introducing the new Problem Solving panel sessions which give you an opportunity to discuss various JBoss-related problems you may want to share and discuss with the rest of the JBUG members. If you want to ask others for help and advice, discuss the issues, listen to suggestions and find the solutions – let us know! Email your topic to jbug@c2b2.co.uk and we will be more than happy to add your session to the agenda.
 

Lightning Talks

We are also opening up the floor to anyone using JBoss who has a tale to share. We are looking for a number of lightning talks 5 - 10 minutes in length where you can share your experiences, problems or wonderful solutions with the rest of the community. This is a huge opportunity to develop new or hone existing speaking skills!
If you are interested, please send the title of your talk to jbug@c2b2.co.uk .

Monday, May 06, 2013

Drools and jBPM talks at JUDCon:2013 United States


In Boston in June?  Meet some of the leaders of the Drools and jBPM teams!   Mark Proctor and Edson Tirelli will be be speaking this June at JBoss User and Developer Conference.  Take advantage of meeting Mark and Edson there.  It is a great opportunity to share your ideas and implementations.

Admission tickets get you into three separate events: Red Hat Developer Exchange, JBoss User Developer Conference (JUDCon) and CamelOne.  The events will be held in Boston Sunday June 9th - Tuesday June 11th.  



The activities start Sunday evening June 9th with the JUDCon, CamelOne and Red Hat Exchange reception. Then Monday and Tuesday, there will be 3 tracks of sessions, and 2 workshop tracks as well. The evening will also include a JBoss Core Developer panel, a live recording of the JBoss Community Asylum, and yes, beer.

The JBoss Users and Developers Conferences are developer gatherings held around the Globe to give JBoss users the chance to talk to and collaborate with Java contributors and core developers. The core JBoss developers, along with the open source community, create and support the projects that drive innovation and help lead development in standards bodies like the Java Community Process, the Apache Software Foundation, OASIS, W3C and other open standards organizations. Many of these projects become the upstream for Red Hat JBoss products.

3 tracks and 33 sessions will cover topics including:
  • Java and Java EE App Development
  • Mobile Development
  • Drools, jBPM, Fuse, ActiveMQ, Infinispan 
  • and many more
6 workshops providing hands-on labs covering:
  • Ceylon taught by Gavin King and Stephane Epardaud
  • Infinispan and JBoss Data Grid cross-datacenter replication
  • CDI, Forge and Errai
  • and many more.
JUDCon:2013 Boston Agenda



CamelOne is designed specifically for professionals using open source integration and messaging solutions in the enterprise and will feature a combination of keynote presentations, educational sessions and networking events that will enable attendees to meet, learn and share ideas with open source integration experts.

Founders, committers and users of Apache Camel, ServiceMix, ActiveMQ and CXF enjoyed a great Meet and Greet in the Exhibit Hall from 6:30 to 8:30. Stop by and mingle with your community over hors d’oeuvres and drinks!

CamelOne Agenda


Red Hat Connect Developer Exchange is heading back to Boston. You won't want to miss this one-day event where you can learn more about Red Hat developer tools and technologies. From gcc to Java to scripting languages, from traditional models to devops--You'll get the chance to connect with fellow developers, share real-world challenges, and solve mutual problems through collaboration.

5 tracks and 25 sessions will cover important topics, including:
• Programming on OpenShift Online PaaS
• OpenShift Enterprise and Java
• Languages and tools for mission-critical development
• Get more out of Red Hat Enterprise Linux tools

Red Hat Developer Exchange Agenda:


Friday, May 03, 2013

IntelliFest Oct 2013 - San Diego


Keynote Speakers:
  • Dr. Ernest Friedman-Hill (Jess) 
  • Dr. Daniel Miranker (Treat, Leaps, Venus)
  • Dr. Ellen Voorhees (Information Retrieval, National Institute of Standards and Technology, NIST)

International Conference
on Reasoning Technologies

October 7-11 • Bahia Resort Hotel

San Diego, CA • USA

IntelliFest returns to the charming Bahia Hotel for 2013! Join us for a full program featuring:

  • Single track technical conference for software and IT developers, programmers, engineers, and architects in the applied AI and rule-based domains.
  • Welcoming Reception on Sunday, October 6.
  • Technical Vertical Day on Monday, October 7.
  • Two days of boot camps on Monday, October 7 and Friday October 11!
  • Main Conference, Tuesday, October 8 through Thursday, October 10
  • AM plenary sessions with guest keynotes each day!
  • Hands-on, mini-camps all during the PM sessions of the main conference!

Topics include but are not limited to:

  • Reasoning About Big Data AI and Cloud Computing
  • AI and the Semantic Web
  • Emerging Standards
  • Latest News in Rule Engines
  • … and much more!

Wednesday, May 01, 2013

Google Summer of Code 2013

JBoss is participating in the Google Summer of Code 2013 program, which means that students can work on their favourite open-source project during the summer and get ultimate glory and a nice paycheck in return.
Google Summer of Code is a global program that offers students stipends to write code for open source projects. We have worked with the open source community to identify and fund exciting projects for the upcoming summer.
JBoss has created a list of possible ideas you can take a look at, but you can always propose us your own ideas as well !

For Drools & jBPM, we've added a few ideas to the list, but there is a Wiki page with over 10 possible jBPM proposals available here, including:
  • jBPM on android
  • Integrating jBPM with your own preferred project(s)
  • Realtime Collaborative Editor for Drools Decision Tables using GWT and Errai OT/EC
  • jBPM performance on steroids
  • Document management system
  • Mobile client(s) for jBPM
  • From BPEL to BPMN2
  • Social BPM using jBPM
  • Process mining for jBPM
  • jBPM and Drools for access control
  • jBPM and Drools for clinical decision support

The deadline for student applications is May 3rd, 19:00 UTC, so if you're interested but didn't submit anything yet, you'll need to be fast!

Monday, April 29, 2013

Try the jBPM Console NG (Beta)! (for developers)


Hi everyone out there! This is another post about the jBPM Console NG. After 6 months of heavy work I'm happy to be writing this post for the developers community to try it out. On this post I will be explaining how to build the application from the sources. The main idea behind this is to know how to set up your environment and modify the application while your testing it. You will basically learn all you need to know to contribute with the project.

Introduction

The jBPM Console NG aims to provide a Task & Process Management collaborative environment to facilitate the adoption of the BPM Suite in a company. Downloading the sources and compiling the application will allow you to try the application and modify it in the case that you want to extend it or fix bugs. The application is under the Apache License V2 so it can be used and modified according with this license.

Working with the Source Code

The first step in order to get everything running is to get the source code using GIT. This are the things that you need to have installed in your computer in order to proceed:
  • JDK 6
  • Maven 3.x
  • Git
  • Any IDE (Eclipse, IntelliJ, Netbeans) with the maven plugin installed
  • JBoss Application Server 7.1.1 (optional)
Once you get all these tools installed we can proceed to get the source code from the github repository:
In order to get a "Clone" of the repository to work you must from the terminal:
git clone https://github.com/droolsjbpm/jbpm-console-ng.git

Once it's done, you can compile the source code, here you have two alternatives:
1) Compile the project for development purposes with:
mvn clean install

2) Compile the project to generate the distribution wars for JBoss and Tomcat + the documentation
mvn clean install -PfullProfile

Sit back and relax! The first time that you do this step Maven requires to download tons of libraries, so you will need to wait.

Running the application in Hosted Mode

Once the project is compiled, the jbpm-console-ng-showcase can be executed in what GWT calls "Hosted Mode" (also known as Developer Mode)
In order to start up the application in hosted mode you should do the following:
1) The jBPM Console NG Showcase contains the final application distribution code:
cd jbpm-console-ng-showcase/

2) Run in hosted mode using the GWT Maven Plugin
mvn gwt:run

This will start up a Jetty + the GWT Development Mode screen which will allow you to copy the URL where the application is hosted for you to try it:
GWT Hosted Mode
GWT Hosted Mode
Copying the URL (http://127.0.0.1:8888/org.jbpm.console.ng.jBPMShowcase/jBPM.html?gwt.codesvr=127.0.0.1:9997) into your browser (For hosted mode you need to have the GWT plugin installed in your browser, don't worry it's automatically installed if you don't have it) will open the application. I strongly recommend to use Firefox for development mode or Chrome (usually slower), because for developing we scope the compilations to work on FF and Chrome (gecko browsers).

Running the application in JBoss AS  7

Now if you want to deploy the application on JBoss, you need to go the the second compilation option (-PfullProfile) which will take some extra time to compile the application for all the browsers and all the languages (English, Spanish, etc.). In order to deploy the application to your jboss as 7 instance you will need to move the war file generated inside the jbpm-console-ng/jbpm-console-ng-distribution-wars/target/jbpm-console-ng-jboss-as7.war into the <jboss-as>/standalone/deployments directory and then rename the war file to jbpm-console-ng.war. The name of the application will be used as the root context for the application.
For the JBoss you also need to do some configurations for the users and roles. Inside the jBPM Console NG you will need to have set up the users that will be available for your installation. Those are handle by JBoss Security Domains. In order to set up the security domains, you need to do the following:
1) Edit the <jboss_as>/configuration/standalone.xml and add a new security domain:

<security-domain name="jbpm-console-ng" cache-type="default">
 <authentication>
   <login-module code="UsersRoles" flag="required">
     <module-option name="usersProperties"   value="${jboss.server.config.dir}/users.properties"/>
     <module-option name="rolesProperties" value="${jboss.server.config.dir}/roles.properties"/>
     </login-module>
   </authentication>
</security-domain>

2) add the users.properties and roles.properties files
content of the user.properties file:
maciek=Merck
salaboy=salaboy
katy=katy
john=john
content of the roles.properties file:

maciek=jbpm-console-user,kie-user,analyst,HR,PM,Reviewer
salaboy=jbpm-console-user,user,analyst,PM,IT,Reviewer
katy=jbpm-console-user,HR
john=jbpm-console-user,Accounting
The only requirement for the roles file is to include the jbpm-console-user role for all the users.
Note that this is the simplest way of configuring a security domain, but you can go for more advanced options, like configuring the security domain to use an LDAP server or a Database to authenticate your users and roles. (https://docs.jboss.org/author/display/AS7/Security+subsystem+configuration)
Then you are ready to go, you can start jboss with:
1) Go into the bin directory:
cd <jboss-as>/bin/
2) Start the application server:
./standalone.sh

On Openshift

In order to deploy the application into openshift you need to obviously have an openshift account. Once you set up your account you will need to do almost the same configurations as in the JBoss Application. In the openshift git repository that you clone, you will have a specific dir to apply this configuration:
.openshift/config
There you will find the standalone.xml file and you can place the users.properties and roles.properties files.
So in the standalone.xml file you will need to configure the security domains as we did before and add the users.property and roles.properties files.
Besides this configuration you will need to set up a system property for storing the knowledge repository:

<system-properties>
  <property name="org.kie.nio.git.dir" value="~/jbossas-7/tmp/data"/>
</system-properties>

The Application

Now you are ready to use the application, so if you point your browser to the URL provided by the hosted mode or to http://localhost:8080/jbpm-console-ng/ you will be able to access the login form.
As you will see, before entering the application you will need to provide your credentials. Once you are in the application is divided in:
Cycle
Cycle
In the Authoring section you will be able to access to the Process Designer to model your business processes. The Process Management section will allow you to list the available Business Processes and Start new instances, and also monitor those instances. The Work Section will enable you to access the Task Lists (Calendar and Grid View)  to work on the tasks assigned to you. In order to use the BAM section you will need to deploy the BAM dashboard application but I will describe that in a future post.
Feel free to try it out and write a comment back if you find something wrong.

Contributions

Your feedback means a lot, but if you want to contribute, you can fork the jbpm-console-ng repository in github: https://github.com/droolsjbpm/jbpm-console-ng/
I will appreciate if you can test the Task Lists and Process Management screens and write feedback in this post, so I can iteratively improve what we have. I will be writing another post to describe the screens and also to list a set of small tasks that you can contribute back.

Friday, April 05, 2013

Score DRL: faster and easier in OptaPlanner

For OptaPlanner (= Drools Planner) 6.0.0.Beta1, I 've replaced the ConstraintOccurrence with the much more elegant ConstraintMatch system. The result is that your score DRL files are:
  • much faster
  • easier to read and write
  • far less error-prone, because they make it a lot harder to cause score corruption
Let's look at the results first, before we look at the code readability improvements.

Faster

"Show me the benchmarks!"

The average calculate count - which is the number of scores OptaPlanner calculates per second - has risen dramatically.
  • N queens: +39% calc count for 256 queens
  • Cloud balance: +27% calc count on average
  • Vehicle routing: +40% calc count on average
  • Course scheduling: +20% calc count on average
  • Exam scheduling: +23% calc count on average
  • Nurse rostering: +7% calc count on average

However, this doesn't necessarily imply a dramatic improvement in result, especially if the old result is already (near) optimal. It means you can get the exact same result in far less time. But - as with all other performance improvements - gives no promise for significantly better results in the same time. It does helps when scaling out.
  • Cloud balance: +0.58% feasible soft score on average in 5 minutes
  • Vehicle routing: +0.14% feasible soft score on average in 5 minutes
  • Course scheduling: +2.28% feasible soft score on average in 7 minutes
  • Exam scheduling: +0.53% feasible soft score on average in 7 minutes
Several of the 30 Vehicle routing datasets were already solved optimally in 5 minutes, so these drag the average down, despite the high vehicle routing speedup.

All benchmarks use the exact same Drools and OptaPlanner version, so these numbers show only the improvements of the ConstraintMatch change. There are several other improvements in 6.0.

How does the average calculate count scale?

Here are a some charts comparing the old ConstraintOccurrence with new ConstraintMatch. The new ConstraintMatch's current implementation hasn't been fully optimized, so it's sometimes referred to being in "slow" mode (even though it's faster).

CloudBalance:

Vehicle routing:

Course scheduling:

Exam rostering:


Easier

"Show me the code!"

For starters, the accumulateHardScore and accumulateSoftScore rules are removed. Less boilerplate :) Next, each of the score rule's RHS (= then side) is simpler:

Before:
    rule "conflictingLecturesSameCourseInSamePeriod"
        when
            ...
        then
            insertLogical(new IntConstraintOccurrence("conflictingLecturesSameCourseInSamePeriod", ConstraintType.HARD,
                    -1,
                    $leftLecture, $rightLecture));
    end


After:
    rule "conflictingLecturesSameCourseInSamePeriod"
        when
            ...
        then
            scoreHolder.addHardConstraintMatch(kcontext, -1);
    end


Notice that you don't need to repeat the ruleName or the causes (the lectures) no more. OptaPlanner figures out it itself through the kcontext variable. Drools automatically exposes the kcontext variable in the RHS, so you don't need any extra code for it. Also, the limited ConstraintType enum has been replaced by a Score type specific method, to allow OptaPlanner to better support multilevel score types, for example HardMediumSoftScore and BendableScore.

You also no longer need to hack the API's to get a list of all ConstraintOcurrence's: the ConstraintMatch objects (and their totals per constraint) are available directly on the ScoreDirector API.

Thursday, March 21, 2013

Drools Planner renames to OptaPlanner: Announcing www.optaplanner.org

We’re proud to announce the rename Drools Planner to OptaPlanner starting with version 6.0.0.Beta1. We’re also happy to unveil its new website: www.optaplanner.org.

OptaPlanner optimizes business resource usage. Every organization faces planning problems: provide products or services with a limited set of constrained resources (employees, assets, time and money). OptaPlanner optimizes such planning to do more business with less resources. Typical use cases include vehicle routing, employee rostering and equipment scheduling.

OptaPlanner is a lightweight, embeddable planning engine written in Java™. It helps normal Java™ programmers solve constraint satisfaction problems efficiently. Under the hood, it combines optimization heuristics and metaheuristics with very efficient score calculation.

OptaPlanner is open source software, released under the Apache Software License. It is 100% pure Java™, runs on the JVM and is available in the Maven Central Repository too.

For more information, visit the new website:

 

Why change the name?


OptaPlanner is the new name for Drools Planner. OptaPlanner is now standalone, but can still be optionally combined with the Drools rule engine for a powerful declarative approach to planning optimization.

  • OptaPlanner has graduated from the Drools project to become a top-level JBoss Community project.
    • OptaPlanner is not a fork of Drools Planner. We simply renamed it.
    • OptaPlanner (the planning engine) joins its siblings Drools (the rule engine) and jBPM (the workflow engine) in the KIE group.
  • Our commitment to Drools hasn't changed.
    • The efficient Drools rule engine is still the recommended way to do score calculation.
    • Alternative score calculation options, such as pure Java calculation (no Drools), also remain fully supported.

 

How will this affect your business?


From a business point of view, there's little or no change:

  • The mission remains unchanged:
    • We're still 100% committed to put business resource optimization in the hands of normal Java developers.
  • The license remains unchanged (Apache Software License 2.0). It's still the same open source license.
  • The release lifecycle remains unchanged: OptaPlanner is still released at the same time as Drools and jBPM.
  • Red Hat is considering support subscription offerings for OptaPlanner as part of its BRMS and BPM platforms.
    • A Tech Preview of OptaPlanner is targeted for BRMS 6.0.

 

What has changed?


  • The website has changed to http://www.optaplanner.org
  • The distributions artifacts have changed name:
    • Jar names changes:
      • drools-planner-core-*.jar is now optaplanner-core-*.jar
      • drools-planner-benchmark-*.jar is now optaplanner-benchmark-*.jar
    • Maven identification groupId's and artifactId's changes:
      • groupId org.drools.planner is now org.optaplanner
      • artifactId drools-planner-core is now optaplanner-core
      • artifactId drools-planner-benchmark is now optaplanner-benchmark
    • As usual, for more information see the Upgrade Recipe in the download zip.
  • The API's namespace has changed. As usual, see the upgrade recipe on how to deal with this efficiently.
    • Starting from 6.1.0.Final, OptaPlanner will have a 100% backwards compatible API.
  • OptaPlanner gets its own IRC channels on Freenode: #optaplanner and #optaplanner-dev