smarts.sstudio.sstypes.condition module
- class smarts.sstudio.sstypes.condition.CompoundCondition(first_condition: Condition, second_condition: Condition, operator: ConditionOperator)[source]
This compounds multiple conditions.
- The following cases are notable
- CONJUNCTION (A AND B)
If both conditions evaluate TRUE the result is exclusively TRUE. Else if either condition evaluates EXPIRED the result will be EXPIRED. Else if either condition evaluates BEFORE the result will be BEFORE. Else FALSE
- DISJUNCTION (A OR B)
If either condition evaluates TRUE the result is exclusively TRUE. Else if either condition evaluates BEFORE then the result will be BEFORE. Else if both conditions evaluate EXPIRED then the result will be EXPIRED. Else FALSE
- IMPLICATION (A AND B or not A)
If the first condition evaluates not TRUE the result is exclusively TRUE. Else if the first condition evaluates TRUE and the second condition evaluates TRUE the result is exclusively TRUE. Else FALSE
- evaluate(**kwargs) ConditionState [source]
Used to evaluate if a condition is met.
- Returns:
The evaluation result of the condition.
- Return type:
- operator: ConditionOperator
The operator used to combine these conditions.
- property requires: ConditionRequires
Information that the condition requires to evaluate state.
- Returns:
The types of information this condition needs in order to evaluate.
- Return type:
- class smarts.sstudio.sstypes.condition.Condition[source]
This encompasses an expression to evaluate to a logical result.
- conjunction(other: Condition) CompoundCondition [source]
Resolve conditions as A AND B.
The bit AND operator has been overloaded to call this method. >>> condition = DependeeActorCondition(“leader”) >>> condition.evaluate(actor_ids={“leader”}) <ConditionState.TRUE: 4> >>> conjunction = condition & LiteralCondition(ConditionState.FALSE) >>> conjunction.evaluate(actor_ids={“leader”}) <ConditionState.FALSE: 0>
Note that the resolution has the priority EXPIRED > BEFORE > FALSE > TRUE. >>> conjunction = LiteralCondition(ConditionState.TRUE) & LiteralCondition(ConditionState.BEFORE) >>> conjunction.evaluate() <ConditionState.BEFORE: 1> >>> (conjunction & LiteralCondition(ConditionState.EXPIRED)).evaluate() <ConditionState.EXPIRED: 2>
- Returns:
A condition combining two conditions using an AND operation.
- Return type:
- disjunction(other: Condition) CompoundCondition [source]
Resolve conditions as A OR B.
The bit OR operator has been overloaded to call this method. >>> disjunction = LiteralCondition(ConditionState.TRUE) | LiteralCondition(ConditionState.BEFORE) >>> disjunction.evaluate() <ConditionState.TRUE: 4>
Note that the resolution has the priority TRUE > BEFORE > FALSE > EXPIRED. >>> disjunction = LiteralCondition(ConditionState.FALSE) | LiteralCondition(ConditionState.EXPIRED) >>> disjunction.evaluate() <ConditionState.FALSE: 0> >>> (disjunction | LiteralCondition(ConditionState.BEFORE)).evaluate() <ConditionState.BEFORE: 1>
- evaluate(**kwargs) ConditionState [source]
Used to evaluate if a condition is met.
- Returns:
The evaluation result of the condition.
- Return type:
- expire(time, expired_state=ConditionState.EXPIRED, relative: bool = False) ExpireTrigger [source]
This trigger evaluates to the expired state value after the given simulation time.
>>> trigger = LiteralCondition(ConditionState.TRUE).expire(20) >>> trigger.evaluate(time=10) <ConditionState.TRUE: 4> >>> trigger.evaluate(time=30) <ConditionState.EXPIRED: 2>
- Parameters:
time (float) – The simulation time when this trigger changes.
expired_state (ConditionState, optional) – The condition state to use when the simulation is after the given time. Defaults to ConditionState.EXPIRED.
relative (bool, optional) – If this trigger should resolve relative to the first evaluated time.
- Returns:
The resulting condition.
- Return type:
- implication(other: Condition) CompoundCondition [source]
Resolve conditions as A IMPLIES B. This is the same as A AND B OR NOT A.
- negation() NegatedCondition [source]
Negates this condition giving the opposite result on evaluation.
>>> condition_true = LiteralCondition(ConditionState.TRUE) >>> condition_true.evaluate() <ConditionState.TRUE: 4> >>> condition_false = condition_true.negation() >>> condition_false.evaluate() <ConditionState.FALSE: 0>
Note: This erases temporal values EXPIRED and BEFORE. >>> condition_before = LiteralCondition(ConditionState.BEFORE) >>> condition_before.negation().negation().evaluate() <ConditionState.FALSE: 0>
- Returns:
The wrapped condition.
- Return type:
- property requires: ConditionRequires
Information that the condition requires to evaluate state.
- Returns:
The types of information this condition needs in order to evaluate.
- Return type:
- trigger(delay_seconds: float, persistent: bool = False) ConditionTrigger [source]
Converts the condition to a trigger which becomes permanently TRUE after the first time the inner condition becomes TRUE.
>>> trigger = TimeWindowCondition(2, 5).trigger(delay_seconds=0) >>> trigger.evaluate(time=1) <ConditionState.BEFORE: 1> >>> trigger.evaluate(time=4) <ConditionState.TRUE: 4> >>> trigger.evaluate(time=90) <ConditionState.TRUE: 4>
>>> start_time = 5 >>> between_time = 10 >>> delay_seconds = 20 >>> trigger = LiteralCondition(ConditionState.TRUE).trigger(delay_seconds=delay_seconds) >>> trigger.evaluate(time=start_time) <ConditionState.BEFORE: 1> >>> trigger.evaluate(time=between_time) <ConditionState.BEFORE: 1> >>> trigger.evaluate(time=start_time + delay_seconds) <ConditionState.TRUE: 4> >>> trigger.evaluate(time=between_time) <ConditionState.BEFORE: 1>
- Parameters:
delay_seconds (float) – Applies the trigger after the delay has passed since the inner condition first TRUE. Defaults to False.
persistent (bool, optional) – Mixes the inner result with the trigger result using an AND operation.
- Returns:
A resulting condition.
- Return type:
- class smarts.sstudio.sstypes.condition.ConditionOperator(value)[source]
Represents logical operators between conditions.
- CONJUNCTION = 1
Evaluate true if both operands are true, otherwise false.
- DISJUNCTION = 2
Evaluate true if either operand is true, otherwise false.
- IMPLICATION = 3
Evaluate true if either the first operand is false, or both operands are true, otherwise false.
- class smarts.sstudio.sstypes.condition.ConditionRequires(value)[source]
This bitfield lays out the required information that a condition needs in order to evaluate.
- actor_ids = 8
- actor_states = 16
- agent_id = 1
- any_current_actor_state = 386
- any_mission_state = 3
- any_simulation_state = 92
- current_actor_road_status = 256
- current_actor_state = 128
- mission = 2
- none = 0
- road_map = 32
- simulation = 64
- time = 4
- class smarts.sstudio.sstypes.condition.ConditionTrigger(inner_condition: Condition, delay_seconds: float, untriggered_state: ConditionState = ConditionState.BEFORE, triggered_state: ConditionState = ConditionState.TRUE, persistent: bool = False)[source]
This condition is a trigger that assumes an untriggered constant state and then turns to the other state permanently on the inner condition becoming TRUE. There is also an option to delay response to the the inner condition by a number of seconds. This will convey an EXPIRED value immediately because that state means the inner value will never be TRUE.
This can be used to wait for some time after the inner condition has become TRUE to trigger. Note that the original condition may no longer be true by the time delay has expired.
This will never resolve TRUE on the first evaluate.
- delay_seconds: float
The number of seconds to delay for.
- evaluate(**kwargs) ConditionState [source]
Used to evaluate if a condition is met.
- Returns:
The evaluation result of the condition.
- Return type:
- persistent: bool = False
If the inner condition state is used in conjunction with the triggered state. (inner_condition_state & triggered_state)
- property requires: ConditionRequires
Information that the condition requires to evaluate state.
- Returns:
The types of information this condition needs in order to evaluate.
- Return type:
- triggered_state: ConditionState = 4
The state after the inner trigger condition and delay is resolved.
- untriggered_state: ConditionState = 1
The state before the inner trigger condition and delay is resolved.
- class smarts.sstudio.sstypes.condition.DependeeActorCondition(actor_id: str)[source]
This condition should be true if the given actor exists.
- actor_id: str
The id of an actor in the simulation that needs to exist for this condition to be true.
- evaluate(**kwargs) ConditionState [source]
Used to evaluate if a condition is met.
- Returns:
The evaluation result of the condition.
- Return type:
- property requires: ConditionRequires
Information that the condition requires to evaluate state.
- Returns:
The types of information this condition needs in order to evaluate.
- Return type:
- class smarts.sstudio.sstypes.condition.ExpireTrigger(inner_condition: Condition, time: float, expired_state: ConditionState = ConditionState.EXPIRED, relative: bool = False)[source]
This condition allows for expiration after a given time.
- evaluate(**kwargs) ConditionState [source]
Used to evaluate if a condition is met.
- Returns:
The evaluation result of the condition.
- Return type:
- expired_state: ConditionState = 2
The state value this trigger should have when it expires.
- relative: bool = False
If this should start relative to the first time evaluated.
- property requires: ConditionRequires
Information that the condition requires to evaluate state.
- Returns:
The types of information this condition needs in order to evaluate.
- Return type:
- time: float
The simulation time when this trigger becomes expired.
- class smarts.sstudio.sstypes.condition.LiteralCondition(literal: ConditionState)[source]
This condition evaluates as a literal without considering evaluation parameters.
- evaluate(**kwargs) ConditionState [source]
Used to evaluate if a condition is met.
- Returns:
The evaluation result of the condition.
- Return type:
- literal: ConditionState
The literal value of this condition.
- property requires: ConditionRequires
Information that the condition requires to evaluate state.
- Returns:
The types of information this condition needs in order to evaluate.
- Return type:
- class smarts.sstudio.sstypes.condition.NegatedCondition(inner_condition: Condition)[source]
This condition negates the inner condition to flip between TRUE and FALSE.
Note: This erases temporal values EXPIRED and BEFORE.
- evaluate(**kwargs) ConditionState [source]
Used to evaluate if a condition is met.
- Returns:
The evaluation result of the condition.
- Return type:
- property requires: ConditionRequires
Information that the condition requires to evaluate state.
- Returns:
The types of information this condition needs in order to evaluate.
- Return type:
- class smarts.sstudio.sstypes.condition.OffRoadCondition[source]
This condition is true if the subject is on road.
- evaluate(**kwargs) ConditionState [source]
Used to evaluate if a condition is met.
- Parameters:
actor_info – Information about the currently relevant actor.
- Returns:
The evaluation result of the condition.
- Return type:
- property requires: ConditionRequires
Information that the condition requires to evaluate state.
- Returns:
The types of information this condition needs in order to evaluate.
- Return type:
- class smarts.sstudio.sstypes.condition.SubjectCondition[source]
This condition assumes that there is a subject involved.
- evaluate(**kwargs) ConditionState [source]
Used to evaluate if a condition is met.
- Parameters:
actor_info – Information about the currently relevant actor.
- Returns:
The evaluation result of the condition.
- Return type:
- property requires: ConditionRequires
Information that the condition requires to evaluate state.
- Returns:
The types of information this condition needs in order to evaluate.
- Return type:
- class smarts.sstudio.sstypes.condition.TimeWindowCondition(start: float, end: float)[source]
This condition should be true in the given simulation time window.
- end: float
The ending simulation time as of which this condition becomes expired.
- evaluate(**kwargs) ConditionState [source]
Used to evaluate if a condition is met.
- Returns:
The evaluation result of the condition.
- Return type:
- property requires: ConditionRequires
Information that the condition requires to evaluate state.
- Returns:
The types of information this condition needs in order to evaluate.
- Return type:
- start: float
The starting simulation time before which this condition becomes false.
- class smarts.sstudio.sstypes.condition.VehicleSpeedCondition(low: float, high: float)[source]
This condition is true if the subject has a speed between low and high.
- evaluate(**kwargs) ConditionState [source]
Used to evaluate if a condition is met.
- Parameters:
actor_info – Information about the currently relevant actor.
- Returns:
The evaluation result of the condition.
- Return type:
- high: float
The highest speed allowed.
- classmethod loitering(abs_error=0.01)[source]
Generates a speed condition which assumes that the subject is stationary.
- low: float
The lowest speed allowed.
- property requires: ConditionRequires
Information that the condition requires to evaluate state.
- Returns:
The types of information this condition needs in order to evaluate.
- Return type:
- class smarts.sstudio.sstypes.condition.VehicleTypeCondition(vehicle_type: str)[source]
This condition is true if the subject is of the given vehicle types.
- evaluate(**kwargs) ConditionState [source]
Used to evaluate if a condition is met.
- Parameters:
actor_info – Information about the currently relevant actor.
- Returns:
The evaluation result of the condition.
- Return type:
- property requires: ConditionRequires
Information that the condition requires to evaluate state.
- Returns:
The types of information this condition needs in order to evaluate.
- Return type:
- vehicle_type: str