On-the-Fly Construction of Composite Events in Scenario-Based Modeling using Constraint Solvers

Guy Katz, Assaf Marron, Aviran Sadon, Gera Weiss

Introduction

Modeling complex reactive systems—those that must constantly respond to environmental stimuli—is a significant challenge in software engineering. Scenario-Based Programming (SBP) offers a solution by allowing developers to decompose system behavior into small, independent "scenarios." However, traditional SBP is often limited by its reliance on discrete event selection. This paper proposes a significant evolution: integrating modern constraint solvers directly into the SBP execution loop to handle multi-variable and continuous events.

The Challenge of Complex Reactive Systems

In traditional SBP, scenarios interact through a simple "request/block" mechanism. For example, one scenario might request to "add hot water" while another blocks that action if the temperature is too high. An execution engine interleaves these behaviors to produce a cohesive event log.

Traditional Scenario-Based Programming with discrete event selection.

While effective for simple logic, this discrete approach struggles with modern requirements like simultaneous actions (e.g., a drone climbing while turning) or continuous parameters (e.g., precise motor power levels). The "narrow interface" of discrete events cannot easily capture the richness of complex robotics or intricate software dependencies.

From Discrete Events to Logical Constraints

The authors' core innovation is replacing discrete event selection with on-the-fly constraint solving. Instead of requesting a specific event, each scenario contributes a logical constraint formula.

At every synchronization point:

  1. Formulas and Labels: Each scenario provides a formula (e.g., $v > 10$) and a label (such as "must" or "may").
  2. Global Composition: These individual formulas are combined according to global rules (e.g., ANDing "must" constraints).
  3. Constraint Solving: The resulting global formula is sent to a solver like Z3 (for SMT) or a MaxSAT solver.
  4. Composite Event Construction: The solver returns a variable assignment that satisfies all constraints, effectively "building" a composite event on the fly.
A scenario contributing a logical constraint formula for continuous variables.

This approach allows scenarios to collaboratively define the next state of the system, moving beyond a simple "pick one from a list" model.

Evaluation and Benchmarks

The methodology was implemented in MATLAB/Simulink and Python (using Z3) and evaluated against several complex modeling benchmarks:

  • Autonomous Drone: Managing simultaneous angular velocities.
  • Leader-Follower Rover: A robot tracking another while maintaining distance using continuous power variables.
  • Software Dependency Management: Solving package removal problems using MaxSAT.
  • Patrol Vehicle: Simulating a vehicle on a figure-eight path with complex speed constraints.

Key Insights

  • Collaborative Modularity: Scenarios can now influence variables they don't "own." A temperature control scenario can constrain a water flow variable without the flow logic needing to be aware of temperature.
  • Semantic Flexibility: By changing the solver or composition rules, the language can support "soft" constraints (MaxSAT), allowing the system to prioritize requests rather than failing on conflict.
  • Bridging Domains: This framework successfully bridges the gap between discrete logic and continuous control theory, preserving the modularity of scenario-based modeling while gaining the power of mathematical solvers.

Conclusion and Future Work

While this approach significantly increases expressiveness, it introduces new challenges. Invoking a solver at every step adds computational overhead, and the expanded state space makes formal verification more difficult. Future research will focus on optimizing solver performance for real-time systems and developing new model-checking techniques for constraint-based scenarios.

Summary updated

BibTeX
@inproceedings{katz2019fly,
  author = {Guy Katz and Assaf Marron and Aviran Sadon and Gera Weiss},
  title = {{On-the-Fly Construction of Composite Events in Scenario-Based Modeling using Constraint Solvers}},
  booktitle = {MODELSWARD},
  year = {2019},
  doi = {10.5220/0007573801430156},
}
Figure