Class: Roby::EventConstraints::UnboundTaskPredicate::BinaryCommutativePredicate

Inherits:
Roby::EventConstraints::UnboundTaskPredicate show all
Defined in:
lib/roby/event_constraints.rb

Overview

Representation of a binary combination of predicates that is commutative. It is used to simplify expressions, especially for explanations.

Direct Known Subclasses

And, FollowedBy, NotFollowedBy, Or

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Roby::EventConstraints::UnboundTaskPredicate

#and, #compile, #evaluate, #negate, #or, #pretty_print, #to_unbound_task_predicate

Constructor Details

#initialize(left, right) ⇒ BinaryCommutativePredicate

Returns a new instance of BinaryCommutativePredicate.



476
477
478
# File 'lib/roby/event_constraints.rb', line 476

def initialize(left, right)
    @predicates = [left, right]
end

Instance Attribute Details

#predicatesObject (readonly)

Returns the value of attribute predicates.



475
476
477
# File 'lib/roby/event_constraints.rb', line 475

def predicates
  @predicates
end

Instance Method Details

#==(pred) ⇒ Object



482
483
484
485
486
# File 'lib/roby/event_constraints.rb', line 482

def ==(pred)
    pred.kind_of?(self.class) &&
        ((predicates[0] == pred.predicates[0] && predicates[1] == pred.predicates[1]) ||
        (predicates[0] == pred.predicates[1] && predicates[1] == pred.predicates[0]))
end

#each_atomic_predicate(&block) ⇒ Object



530
531
532
533
534
535
536
537
538
# File 'lib/roby/event_constraints.rb', line 530

def each_atomic_predicate(&block)
    2.times do |i|
        if predicates[i].kind_of?(self.class)
            predicates[i].each_atomic_predicate(&block)
        else
            yield(predicates[i])
        end
    end
end

#explain_false(task) ⇒ Object



499
500
501
502
503
504
505
506
507
508
509
# File 'lib/roby/event_constraints.rb', line 499

def explain_false(task)
    return if evaluate(task)

    reason0 = predicates[0].explain_false(task)
    reason1 = predicates[1].explain_false(task)
    if reason0 && reason1
        Explanation.new(false, self, [reason0, reason1])
    else
        reason0 || reason1
    end
end

#explain_static(task) ⇒ Object



510
511
512
513
514
515
516
517
518
519
520
# File 'lib/roby/event_constraints.rb', line 510

def explain_static(task)
    return if !static?(task)

    reason0 = predicates[0].explain_static(task)
    reason1 = predicates[1].explain_static(task)
    if reason0 && reason1
        Explanation.new(nil, self, [reason0, reason1])
    else
        reason0 || reason1
    end
end

#explain_true(task) ⇒ Object



488
489
490
491
492
493
494
495
496
497
498
# File 'lib/roby/event_constraints.rb', line 488

def explain_true(task)
    return if !evaluate(task)

    reason0 = predicates[0].explain_true(task)
    reason1 = predicates[1].explain_true(task)
    if reason0 && reason1
        Explanation.new(true, self, [reason0, reason1])
    else
        reason0 || reason1
    end
end

#has_atomic_predicate?(pred) ⇒ Boolean

Returns:

  • (Boolean)


522
523
524
525
526
527
528
# File 'lib/roby/event_constraints.rb', line 522

def has_atomic_predicate?(pred)
    pred = pred.to_unbound_task_predicate
    each_atomic_predicate do |p|
        return(true) if p == pred
    end
    false
end

#required_eventsObject



480
# File 'lib/roby/event_constraints.rb', line 480

def required_events; predicates[0].required_events | predicates[1].required_events end