class Roby::EventConstraints::UnboundTaskPredicate

Represents a temporal logic predicate that applies on the internal events of a single task. As the events are represented by their name, the predicate can be reused to be applied on different tasks.

Public Instance Methods

and(other_predicate) click to toggle source

Returns a predicate that is true if both self and other_predicate are true.

Because of the “and” semantic, the predicate is static if one of the two predicates is false and static, or if both predicates are static.

# File lib/roby/event_constraints.rb, line 175
def and(other_predicate)
    if self == other_predicate then self
    elsif other_predicate.kind_of?(UnboundTaskPredicate::False)
        other_predicate
    else
        And.new(self, other_predicate)
    end
end
compile() click to toggle source

Predicates are first represented as an AST using the subclasses of UnboundTaskPredicate, but are then compiled into code before being evaluated (for performance reasons).

This is the main call that performs this compilation

# File lib/roby/event_constraints.rb, line 245
            def compile
                prelude = required_events.map do |event_name|
                    "    task_event_#{event_name} = task.event(:#{event_name})\n" +
                    "    task_#{event_name} = task_event_#{event_name}.last"
                end.join("\n")

                compiled_predicate = CompiledPredicate.new
                eval <<-END, binding, __FILE__, __LINE__+1
def compiled_predicate.evaluate(task)
#{prelude}
    #{code}
end
                END
                @compiled_predicate = compiled_predicate
            end
evaluate(task) click to toggle source

Evaluates this predicate on task. It returns either true or false.

# File lib/roby/event_constraints.rb, line 263
def evaluate(task)
    compile if !@compiled_predicate || !@compiled_predicate.respond_to?(:evaluate)
    @compiled_predicate.evaluate(task)
end
explain_false(task) click to toggle source

Returns an Explanation object that explains why self is false. Note that it is valid only if evaluate(task) actually returned false (it will silently return an invalid explanation if evaluate(task) returns true).

# File lib/roby/event_constraints.rb, line 217
def explain_false(task); nil end
explain_static(task) click to toggle source

Returns an Explanation object that explains why self will not change its value anymore.

Note that it is valid only if static?(task) actually returned true (it will silently return an invalid explanation otherwise)

# File lib/roby/event_constraints.rb, line 224
def explain_static(task)
end
explain_true(task) click to toggle source

Returns an Explanation object that explains why self is true. Note that it is valid only if evaluate(task) actually returned true (it will silently return an invalid explanation if evaluate(task) returns false).

# File lib/roby/event_constraints.rb, line 211
def explain_true(task); nil end
negate() click to toggle source

Returns a predicate that is the negation of self

Because of the “not” semantic, the predicate is static if self is static.

# File lib/roby/event_constraints.rb, line 203
def negate
    Negate.new(self)
end
or(other_predicate) click to toggle source

Returns a predicate that is true if either or both of self and other_predicate are true.

Because of the “or” semantic, the predicate is static if one of the two predicates are true and static, or if both predicates are static.

# File lib/roby/event_constraints.rb, line 190
def or(other_predicate)
    if self == other_predicate then self
    elsif other_predicate.kind_of?(UnboundTaskPredicate::False)
        self
    else
        Or.new(self, other_predicate)
    end
end
pretty_print(pp) click to toggle source
# File lib/roby/event_constraints.rb, line 227
def pretty_print(pp)
    pp.text to_s
end
to_unbound_task_predicate() click to toggle source
# File lib/roby/event_constraints.rb, line 165
def to_unbound_task_predicate
    self
end