Class: Roby::EventConstraints::UnboundTaskPredicate::BinaryCommutativePredicate
- Inherits:
-
UnboundTaskPredicate
- Object
- UnboundTaskPredicate
- Roby::EventConstraints::UnboundTaskPredicate::BinaryCommutativePredicate
- 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.
Instance Attribute Summary collapse
-
#predicates ⇒ Object
readonly
Returns the value of attribute predicates.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #each_atomic_predicate(&block) ⇒ Object
- #explain_false(task) ⇒ Object
- #explain_static(task) ⇒ Object
- #explain_true(task) ⇒ Object
- #has_atomic_predicate?(pred) ⇒ Boolean
-
#initialize(left, right) ⇒ BinaryCommutativePredicate
constructor
A new instance of BinaryCommutativePredicate.
- #required_events ⇒ Object
Constructor Details
#initialize(left, right) ⇒ BinaryCommutativePredicate
Returns a new instance of BinaryCommutativePredicate.
563 564 565 566 |
# File 'lib/roby/event_constraints.rb', line 563 def initialize(left, right) @predicates = [left, right] super() end |
Instance Attribute Details
#predicates ⇒ Object (readonly)
Returns the value of attribute predicates.
561 562 563 |
# File 'lib/roby/event_constraints.rb', line 561 def predicates @predicates end |
Instance Method Details
#==(other) ⇒ Object
572 573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/roby/event_constraints.rb', line 572 def ==(other) other.kind_of?(self.class) && ( ( predicates[0] == other.predicates[0] && predicates[1] == other.predicates[1] ) || ( predicates[0] == other.predicates[1] && predicates[1] == other.predicates[0] ) ) end |
#each_atomic_predicate(&block) ⇒ Object
631 632 633 634 635 636 637 638 639 |
# File 'lib/roby/event_constraints.rb', line 631 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
598 599 600 601 602 603 604 605 606 607 608 609 |
# File 'lib/roby/event_constraints.rb', line 598 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
611 612 613 614 615 616 617 618 619 620 621 |
# File 'lib/roby/event_constraints.rb', line 611 def explain_static(task) return unless 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
586 587 588 589 590 591 592 593 594 595 596 |
# File 'lib/roby/event_constraints.rb', line 586 def explain_true(task) return unless 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
623 624 625 626 627 628 629 |
# File 'lib/roby/event_constraints.rb', line 623 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_events ⇒ Object
568 569 570 |
# File 'lib/roby/event_constraints.rb', line 568 def required_events predicates[0].required_events | predicates[1].required_events end |