> On Nov 7, 2010, at 3:22 PM, Asier wrote:
> 
> > Perhaps I'm going to say something too obvious (or absolutely crazy). 
> > 
> > Has anyone used ruote as a rule engine? Something like drools, where you 
> > save your rules 
> > (=ruote process definition?) in an external resouce and use it each time is 
> > needed, f.i, 
> > for something like a "car customizer" where you can choose a combination of 
> > available 
> > components to customize your own car.
> > 
> > This rules will change over time (new models, new components), but allways 
> > keeping the 
> > previous rules and components. (I'll use this approach with ruote-kit)
> > 
> > Perhaps this is more the domain of something like drools, but I think ruote 
> > would fit very 
> > well here, but I can't see how

Hello Asier,

a question in a few words, still requiring a big answer, spreading lots of 
subjects.

---8<---
Ruote.process_definition 'car customization' do
  cursor do
    choice :select => 'car colour'
    choice :select => 'engine power'
    choice :select => 'doors count'
    rewind :if => '${f:selection_invalid}'
    choice :question => 'order or not ?'
    #...
  end
end
--->8---

Nice workflow, but what's its level ? there is only one person interacting with 
it... Rather a webflow or a "screenflow", interface flow.

Workflow engine ?

"do this, then that, with that other thing in parallel, when it's all done, do 
this if that previous step yielded something like that"

Rule engine ?

"if this condition is true do this, if that condition is false do that"

workflow definition :

---8<---
Ruote.process_definition 'document review' do
  cursor do
    author :task => 'revise document'
    reviewer :task => 'review'
    rewind :if => '${revision_needed}'
    publisher :task => 'publish'
  end
end
--->8---

ruleset (with rule engine implementation included) 
(https://gist.github.com/667236) :

---8<---
class RuleEngine
  def initialize
    @rules = []
  end
  def add(condition, action)
    @rules << [ condition, action ]
  end
  def rule(context)
    @rules.each do |condition, action|
      if condition.call(context)
        action.call(context)
        return true
      end
    end
    false
  end
end

#
# rule set

re = RuleEngine.new

re.add(
  lambda { |context|
    context['last_step'] == nil
  },
  lambda { |context|
    puts "author : please revise document"
    context['last_step'] = 'author'
  })
re.add(
  lambda { |context|
    context['last_step'] == 'author'
  },
  lambda { |context|
    puts "reviewer : please review document"
    context['last_step'] = 'reviewer'
  })
re.add(
  lambda { |context|
    context['revision_needed'] == true
  },
  lambda { |context|
    puts "author : please revise document"
    context['last_step'] = 'author'
  })
re.add(
  lambda { |context|
    context['last_step'] == 'reviewer'
  },
  lambda { |context|
    puts "publisher : please publish document"
    context['last_step'] = 'publisher'
  })

#
# example run

context = {}
re.rule(context)
re.rule(context)
context['revision_needed'] = true
re.rule(context)
re.rule(context)
context['revision_needed'] = false
re.rule(context)

   # => # author : please revise document
        # reviewer : please review document
        # author : please revise document
        # reviewer : please review document
        # publisher : please publish document
--->8---

which is equivalent to :

---8<---
def rule(context)

  if context['last_step'] == nil

    puts "author : please revise document"
    context['last_step'] = 'author'

  elsif context['last_step'] == 'author'

    puts "reviewer : please review document"
    context['last_step'] = 'reviewer'

  elsif context['revision_needed'] == true

    puts "author : please revise document"
    context['last_step'] = 'author'

  elsif context['last_step'] == 'reviewer'

    puts "publisher : please publish document"
    context['last_step'] = 'publisher'
  end
end

context = {}
rule(context)
rule(context)
context['revision_needed'] = true
rule(context)
rule(context)
context['revision_needed'] = false
rule(context)
--->8---

Note that with RuleEngine, you can insert new rules and reorder rules...

A look at wikipedia is worth the time :

  http://en.wikipedia.org/wiki/Rule_engine

Rools is a straightforward rule engine, like the RuleEngine above, each rule is 
checked in order until one matches.

Drools and Ruleby contain a RETE implementation :

  http://en.wikipedia.org/wiki/Rete_algorithm

quoting wikipedia :

  | A naïve implementation of an expert system might check each rule against
  | the known facts in the knowledge base, firing that rule if necessary, then
  | moving on to the next rule (and looping back to the first rule when
  | finished). For even moderate sized rules and facts knowledge-bases, this
  | naïve approach performs far too slowly. The Rete algorithm provides the
  | basis for a more efficient implementation.

Drools has all sorts of bells and whistles (and it's Java). It even has a 
Drools Flow which will replace jBpm soon as the "jboss workflow engine".


On Sun, Nov 07, 2010 at 05:29:23PM -0500, Cappelaere Patrice wrote:
> 
> I used Rools for business logic and integrated with Ruote for workflow 
> management.
> There are other rules engines you can use, Ruleby, Drools...
> This is a better approach than coding the logic in a participant.

There are various sorts of participants. Human and automated mostly. Human 
participants are mostly about placing some work on the work pile of a human 
(then presenting him with some form to fill, decision to take).

Automated participants can be divided between actions and decisions.

Action examples : send an email notification, create a new virtual machine, 
print an invoice ...

Decision examples : should the document undergo another revision ? Is the 
customer a premium customer or does his order deserve that status, even 
temporarily ?

Obviously, a rule engine can hide inside a decision participant. A rule engine 
could also wrap a human participant (there is a workitem for the role "floor 
manager", who is the floor manager for this week ?).

It all depends on the speed of change around your participants. Can rules be 
clearly defined ? Is it more advantageous to have a simple piece of Ruby code 
in an automated participant and swap it from time to time ?


I hope this doesn't confuse you. Best regards,

-- 
John Mettraux - http://jmettraux.wordpress.com

-- 
you received this message because you are subscribed to the "ruote users" group.
to post : send email to [email protected]
to unsubscribe : send email to [email protected]
more options : http://groups.google.com/group/openwferu-users?hl=en

Reply via email to