cancel
Showing results for 
Search instead for 
Did you mean: 

activiti-crystalball getting started

gromar
Champ in-the-making
Champ in-the-making
Hello.

as I promised in the following posts:
http://forums.activiti.org/en/viewtopic.php?f=6&t=6081&start=12
http://forums.activiti.org/en/viewtopic.php?f=6&t=5967&start=14

I created the first getting started for activiti-crystalball.

Topics covered:
- The First Simulation Run.
- Use simulation in design phase.
(BPM development cycle integration, development purposes reports, ….)

e.g. you can get report about your current test coverage:
[img]https://raw.github.com/gro-mar/activiti-crystalball/master/examples/src/test/resources/org/activiti/...[/img]

Topics not covered yet:
- Use simulation in deploy phase.
- :arrow: Use simulation for monitoring. click on the link. I would say this example will be nice one.
Use simulation for optimization.
17 REPLIES 17

gromar
Champ in-the-making
Champ in-the-making
After some time I've implemented simulation engine (In fact I took activiti process engine and bent it to the simulation engine). Simulation engine in the activiti-crystalball is able to execute simulation runs asynchronously and in parallel. To see the first example of usage please have a look on MonitoringTest. Test uses similar way to start simulation engine ans simulation instance as it is used for activiti process engine and process instances.

  SimulationEngine simulationEngine= SimulationEngineConfigurationImpl.createStandaloneSimulationEngineConfiguration().buildSimulationEngine();

  SimulationInstance simulationInstance = simulationEngine.getRuntimeService().startSimulationInstanceByKey("Monitor escalation", …..); 

Simulation experiment tries to answer question:
What is probability of escalation?
Finally answer is:
[img]https://raw.github.com/gro-mar/activiti-crystalball/master/examples/src/test/resources/org/activiti/...[/img]

Now I can continue in activiti-crystalball getting started. Crystalball is able to answer probability questions.

Questions:
Does anybody have any real use case where simulation can be applied?
How did the discussion about another simulation framework for activiti
http://forums.activiti.org/content/simulation-process-definition
http://sourceforge.net/p/bpm-accelerator/wiki/Home/

finished?

jbarrez
Star Contributor
Star Contributor
Which input params did you use to get to the 63%? How do you see users input that data?

Regarding the past discussions: no nothing has come out of that, unfortunately.

gromar
Champ in-the-making
Champ in-the-making
To answer questions I have to describe simulation instance more.

Simulation instance start javadoc:

/**
* Starts a new simulation instance
*
* @param name
* @param description
* @param author
* @param start
* @param end
* @param replication
* @param seed - pseudo random number generator seed.
* @param simulationConfigUrl - repository service is not copied form activiti engine - claspath resources are used.
* @return
*/
SimulationInstance startSimulationInstanceByKey(String name, String description, String author, Date start, Date end, int replication, Long seed, String simulationConfigUrl);

SimulationInstance configuration has two sources:
1. process definition (e.g. MortageDemo-1-monitoring.bpmn)

<serviceTask id="rejection_email" name="Send rejection e-mail" activiti:type="mail" sim:behavior="org.activiti.crystalball.simulator.delegate.Noop">
      <extensionElements>
        <activiti:field name="to" expression="to@domain"></activiti:field>
        <activiti:field name="from" expression="from@domain"></activiti:field>
        <activiti:field name="text">
          <activiti:expression><![CDATA[text]]></activiti:expression>
        </activiti:field>
      </extensionElements>
    </serviceTask>
sim:behavior="org.activiti.crystalball.simulator.delegate.Noop" (behavior can be set for user task too).
2. simulationConfigUrl - describes simulation engine behavior. (e.g. mortages-monitoring-h2-context.xml. Simulation configuration sets up simulation engine and simulation process engine - more description below.

MonitoringTest starts simulation instance with 11 simulation runs. Seed 7L takes care about getting always the same results from pseudo random number generator. RuntimeService.startSimulationInstanceByKey persists new SimulationInstance and its SimulationRuns(similar to ProcessInstance - in fact I took activiti process engine and I bent it to the simulation engine with different entities). Each simulation run is Job which is executed asynchronously in parallel (similar to the Job in the process engine).
Simulation run prepares environment (in this case makes copy of live process engine DB to the DB used by process engine (activiti 5.11)  used for simulation. Done by simulationRunHelper in mortages-monitoring-h2-context.xml. Following simulationRunHelper is used in  BasicSimulationTest config Simulator-context.xml

<bean id="simulationRunHelper" class="org.activiti.crystalball.simulator.impl.CopySimulationRunHelper">
  <constructor-arg index ="0" value="${tempDir:target}/basicSimulation.h2.db"/>
  <constructor-arg index ="1" value="${tempDir:target}/${simulationRunId:default}.h2.db"/>
</bean>
SimulationRun starts activiti process engine to simulate process instances execution. Process engine configuration:

<bean id="simProcessEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  <property name="dataSource" ref="simDataSource" />
  <property name="transactionManager" ref="simTransactionManager" />
  <property name="databaseSchemaUpdate" value="true" />
  <property name="jobExecutorActivate" value="false" />
  <property name="jobExecutor" ref="simDefaultJobExecutor"/>
  <property name="preParseListeners">
   <list>
    <bean class="org.activiti.crystalball.simulator.parse.SimulationBpmnParseListener"/>
   </list>
  </property>
  <property name="processEngineName" value="${simulationRunId:default}"/>
  <property name="deploymentResources">
   <list>
    <value>org/activiti/crystalball/examples/mortages/MortageDemo-1-monitoring.bpmn</value>
   </list>
  </property>
</bean>
   
<bean id="simDefaultJobExecutor" class="org.activiti.crystalball.simulator.processengine.jobexecutor.SimulationDefaultJobExecutor">
  <property name="waitTimeInMillis" value="300000"/>
</bean>
Simulation process engine has to use simDefaultJobExecutor which runs process jobs in the virtual simulation time - ability to simulate timers.

Answer:
In MonitoringTest case user behavior is described in  mortages-monitoring-h2-context.xml. It is possible to describe it in process definition too sim:behavior=.

<!–  User tasks executors                    –>     
    <bean id="userTaskExecutor" class="org.activiti.crystalball.simulator.executor.impl.RandomUserMapTaskExecutor">
       <constructor-arg index="0" value="300000"/> <!– from 5mins to 1100 sec  –>
       <constructor-arg index="1" value="1100000"/>
       <property name="taskVariablesMap">
        <map>
         <!– TASK preliminary_judgement possibilities –>
         <entry key="preliminary_judgement">
          <list>
           <map>
            <entry key="approved"><value type="java.lang.Boolean">True</value></entry>
           </map>
           <map>
            <entry key="approved"><value type="java.lang.Boolean">True</value></entry>
           </map>
          </list>
         </entry>
         <entry key="final_evaluation">
          <list>
           <map>
            <entry key="ok"><value type="java.lang.Boolean">True</value></entry>
           </map>
           <map>
            <entry key="ok"><value type="java.lang.Boolean">False</value></entry>
           </map>
          </list>
         </entry>
        </map>
       </property>
    </bean>

RandomUserMapTaskExecutor executes user task in uniform probability distribution from 5mins to 18min 20sec. in case of preliminary_judgement or final_evaluation we can set process variable change. User behavior can be played back from the process engine history too.

When 11 simulation runs are finished and SimulationRun results are stored in the DB, ProbabilityGraphGenerator generates process diagram

  ProbabilityGraphGenerator generator = new ProbabilityGraphGenerator();
  generator.generateGraph(simulationEngine.getRuntimeService(), simulationInstance, "mortagedemo-0:1:4", "mortagedemo-0", "activity_exists", System.getProperty("tempDir", "target") + "/monitoringTest.jpg");


Question:
Do you see any issues in this approach?
I would like to know your opinion.

jbarrez
Star Contributor
Star Contributor
Looks good. I do like the custom job executor which runs in virtual time, good idea.

One thing I think can be improved: do you mandate the Noop ServiceTask? It would be more useful if you allow to upload any process xml. BUT before you hand them to the simulation engine you swap all the classes with the Noop's (and similar for listeners on execution/task of course).

Another cool thing which every simulation effort must have is of course nice charts 😉

gromar
Champ in-the-making
Champ in-the-making
do you mandate the Noop ServiceTask?

org.activiti.crystalball.simulator.delegate.Noop is not mandatory for service tasks. Usage of simulation behavior depends on the simulation experiment. How realistic simulation experiment should be to reality? Do we want to use real serviceTasks in simulation - we do not need to use Noop. Do we want to play back execution - use org.activiti.crystalball.simulator.delegate.PlaybackCopyActivityBehavior. It really depends on the simulation experiment how far and realistic simulation should look like.

It would be more useful if you allow to upload any process xml. BUT before you hand them to the simulation engine you swap all the classes with the Noop's (and similar for listeners on execution/task of course)
Yes, it would be one possibility and can be used in the real application. On the other hand we can loose possibility to simulate some nodes in the process as real nodes (e.g. we can simulate load on mail server, or service calls).

I have the similar issue as swiderski.maciej in
http://forums.activiti.org/content/simulation-process-definition
http://sourceforge.net/p/bpm-accelerator/wiki/

practical application is missing.

In my opinion simulation can dramatically affect BPM.

You already helped me with the way how to show benefits of simulation.
Could you imagine way how to present contribution of simulation to the BPM solutions development?


jbarrez
Star Contributor
Star Contributor
I think the general way simulation is 'sold' is through cost analysis.

Meaning: you have process X and process Y. Both of them do the same thing, but they're modeled differently.
Simulation is then the tool you'd use to 'prove' that X is more efficient than Y.

That is why it is important to have charts, to see in a 1-1 fight which process is 'the best' 🙂

gromar
Champ in-the-making
Champ in-the-making
It makes sense.
I will try to prepare cost analysis example.

gromar
Champ in-the-making
Champ in-the-making
I prepared costs analysis example (visit https://github.com/gro-mar/activiti-crystalball/wiki/Getting-started#costs-analysis). Report is not so nice as the previous one, but can be processed further.

I hope that somebody will find it useful.

trademak
Star Contributor
Star Contributor
Thanks, that's looking already really useful. Looking forward to do some testing with it.

Best regards,