Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Using Alf with Cameo Simulation Toolkit - Part 2: Modeling

168 views

Published on

Alf is an OMG-standard textual language with a familiar Java-like syntax, but it is designed specifically to be used in the context of graphical, executable UML and SysML models. This language is available for use in No Magic's Cameo Simulation Toolkit (CST) v18.5 to write expressions and behaviors in executable UML. This presentation follows on from "Using Alf with Cameo Simulation Toolkit - Part 1", covering the use of Alf for specifying behaviors in models of multiple, communicating objects, including synchronous operation calling and asynchronous signal sending.

Published in: Software
  • Be the first to comment

Using Alf with Cameo Simulation Toolkit - Part 2: Modeling

  1. 1. No Magic World Symposium, Allen TX Ed Seidewitz Model Driven Solutions, Inc. ● http://www.modeldriven.com ed-s@modeldriven.com ● @Seidewitz http://slideshare.net/seidewitz Copyright © 2018 Ed Seidewitz Using the Alf Action Language with Cameo Simulation Toolkit Part 2 – Modeling
  2. 2. Page 2 About me Ed Seidewitz Chief Technology Officier, Model Driven Solutions, Inc. ed-s@modeldriven.com ● @seidewitz • 30 years experience as a project manager, architect, developer and modeler • Involved with UML since version 0.8 • Developer of fUML and Alf Reference Implementations and MagicDraw Alf Plugin • Chair of the OMG fUML and Alf Revision Task Forces; member of the UML Revision Task Force Copyright © 2018 Ed Seidewitz
  3. 3. Page 3 Goals Part 1 – Basics (Sunday) • Learn the basics of the Alf action language for Executable UML. • Use the Alf Plugin for MagicDraw. • Practice using Alf with Cameo Simulation Toolkit. Part 2 – Modeling (Today) • Model simulations using the Alf action language. • Use Alf in class and state machine models in MagicDraw. • Creating and run simulations using Alf with Cameo Simulation Toolkit. Copyright © 2018 Ed Seidewitz
  4. 4. Page 4 Prerequisites (for Part 2) • Participant – Basic knowledge of class, activity and state machine modeling using MagicDraw – Some experience with model execution using Cameo Simulation Toolkit – Introductory understanding of using Alf in CST (e.g., from Part 1 of this tutorial) • System (for hands-on exercises) – MagicDraw 18.5 – Cameo Simulation Toolkit 18.5sp3 – Alf plugin 18.5 Install MagicDraw, CST and Alf Plugin on line or from USB stick Copyright © 2018 Ed Seidewitz
  5. 5. Page 5 5 Installing the Alf plugin Copyright © 2018 Ed Seidewitz Plugin documentation is available at: https://docs.nomagic.com/display/ALFP185/Alf+plugin Under Plugins (commercial), download / install the Alf plugin v18.5. Select Help ► Resource/Plugin Manager to open the Resource/ Plugin Manager window.  A new version will be available for the 19.0 release. Or click here to install from USB stick.
  6. 6. Page 6 Class Models Copyright © 2018 Ed Seidewitz
  7. 7. Page 7 Object creation and property access Copyright © 2018 Ed Seidewitz order = new Order(); order.product = aProduct; order.quantity = aQuantity; order.amount = aQuantity * aProduct.price; Create a new Order. Set the properties of the new order. aCustomer.orders->add(order); totalAmount = aCustomer.orders.amount-> reduce RealFunctions::'+' ?? 0.0; Add the new order to an existing customer. Navigate associations to compute total amount.  A reduce expression “inserts” a binary function into the elements of a sequence.  Properties must be public to be accessible. A property access
  8. 8. Page 8 Operations and methods Copyright © 2018 Ed Seidewitz this.product = product; this.quantity = quantity; return this.quantity * this.product.price; this.orders->add(order); return this.orders.getAmount()-> reduce RealFunctions::'+' ?? 0.0;  The behavior that implements an operation is called its method. An operation call
  9. 9. Page 9 Operation invocations Copyright © 2018 Ed Seidewitz order = new Order(aQuantity, aProduct); amount = order.getAmount(); aCustomer.addOrder(order); totalAmount = aCustomer.getTotalAmount(); A constructor can be used to create an object with initialization. A constructor operation has the standard Create stereotype applied.  Operation calls are synchronous invocations. The caller waits until the operation method execution completes.
  10. 10. Page 10 Hands On Address Book Copyright © 2018 Ed Seidewitz
  11. 11. Page 11 Create the Address Book project Copyright © 2018 Ed Seidewitz In the Alf folder, select the Alf template. Under Other, select Project from Template. Select File ► New Project to open the project creation window. Create an Address Book project.
  12. 12. Page 12 Create the Address Book class model Copyright © 2018 Ed Seidewitz Make sure these Entry attributes are public. Give this association end a multiplicity of *.
  13. 13. Page 13 Are you using SysML? Copyright © 2018 Ed Seidewitz  CST and Alf assume the use of the UML primitive types. But SysML provides primitive value types that are different than the UML primitive types. Value properties have to have value types, so String here is the SysML type. Remove the ValueProperty stereotype and change the type to the UML primitive type. ✗ ✗  This is resolved in v19.0 for both CST and Alf.
  14. 14. Page 14 Create Address Book and Entry operations Copyright © 2018 Ed Seidewitz Create a constructor operation in the usual way, and then apply the standard Create stereotype.
  15. 15. Page 15 Create the Entry constructor method Copyright © 2018 Ed Seidewitz Right click on the Entry operation and select Create Method ► Behavior to open this selection window. Choose either Activity or Opaque Behavior. Enter code in the Alf editor window to initialize an Entry.
  16. 16. Page 16 Create Address Book operation methods Copyright © 2018 Ed Seidewitz Create methods for the AddressBook operations, and then enter the Alf code shown for them.  A select expression is used to filter a sequence based on a condition. The index [1] ensures that at most one value is selected.  This expression will return either a single value or null, as required by the return multiplicity of 0..1.  The constructor operation is used when creating an instance of the Entry class.  The braces { } are required in if statement clauses in Alf.
  17. 17. Page 17 Test the Address Book model Copyright © 2018 Ed Seidewitz Create an AddressBookTest activity with the Alf code below.  The ?? (null-coalescing) operator is used here because get has return multiplicity 0..1 and the + operator requires argument multiplicity 1..1. Run the activity and see if it works!
  18. 18. Page 18 State Machine Models Copyright © 2018 Ed Seidewitz
  19. 19. Page 19 Classifier behaviors Copyright © 2018 Ed Seidewitz A signal reception declares the ability of instances of a class to handle a signal. A state machine can be attached to a class as a classifier behavior. The state machine reacts to signals that are sent to instances of its context class.
  20. 20. Page 20 Transition and state behaviors Copyright © 2018 Ed Seidewitz Alf can be used to define transition and state behaviors in state machines.
  21. 21. Page 21 Signal sending Copyright © 2018 Ed Seidewitz fan = new Fan(); fan.TurnOn(); fan.TurnOff(); A signal send has a similar syntax to operation calls, but referencing a signal reception, rather than an operation. The state machine starts running when an object is created.  A signal can only be sent using Alf to an object whose class has a reception declared for the signal.  Signal sends are asynchronous invocations. The sender continues immediately after the signal is sent.
  22. 22. Page 22 Hands On Heating Simulation Copyright © 2018 Ed Seidewitz
  23. 23. Page 23 Create the Heating Simulation project Copyright © 2018 Ed Seidewitz In the Alf folder, select the Alf template. Under Other, select Project from Template. Select File ► New Project to open the project creation window. Create a Heating Simulation project.
  24. 24. Page 24 Create the model package structure Copyright © 2018 Ed Seidewitz
  25. 25. Page 25 Create Environment and House classes Copyright © 2018 Ed Seidewitz Create three signals... …and use them to declare signal receptions. Make this attribute public. Make this association composite. Make this operation private. Give both association ends names.
  26. 26. Page 26 Create the Environment state machine Copyright © 2018 Ed Seidewitz
  27. 27. Page 27 Add triggers to transitions Copyright © 2018 Ed Seidewitz
  28. 28. Page 28 Create opaque behavior Copyright © 2018 Ed Seidewitz Under Effect, set the Behavior Type to Opaque Behavior.
  29. 29. Page 29 Add Alf code Copyright © 2018 Ed Seidewitz  A signal is sent by invoking the signal reception on the target object. Click on the transition to enter code for its effect behavior in the Alf editor window. Create an opaque behavior and add Alf code for this transition, too.
  30. 30. Page 30 Create the House state machine Copyright © 2018 Ed Seidewitz
  31. 31. Page 31 Create the cool method Copyright © 2018 Ed Seidewitz Right click on the cool operation and select Create Method ► Behavior to open the Behavior selection window. Enter the Alf code in the Alf editor window. Choose either Activity or Opaque Behavior.  The braces { } are required in if statement clauses in Alf.
  32. 32. Page 32 Coming in v19.0! Copyright © 2018 Ed Seidewitz Access event data in transition and state behaviors.
  33. 33. Page 33 Create an instance model Copyright © 2018 Ed Seidewitz Add a link for the Environment- House composite association. Be sure to create slots for both ends. Right click on the Environment instance and select Simulation ► Run to execute the model.
  34. 34. Page 34 Add a Heater class Copyright © 2018 Ed Seidewitz Add new signals. Add new reception. Add new operation. Make this attribute public. Make this association composite. Add new attribute.
  35. 35. Page 35 Update the House state machine Copyright © 2018 Ed Seidewitz Add a new transition triggered by the Heat signal with Alf code to call the heat operation. Create a method behavior for the heat operation.
  36. 36. Page 36 Create the Heater state machine Copyright © 2018 Ed Seidewitz
  37. 37. Page 37 Update the instance model Copyright © 2018 Ed Seidewitz Add a Heater instance and a link of the House-Heater composite association. Right click on the Environment instance and select Simulation ► Run to execute the model again.
  38. 38. Page 38 Add a Thermostat class Copyright © 2018 Ed Seidewitz Make this association composite. Add a new attribute. This association is not composite.
  39. 39. Page 39 Update the Heater state machine Copyright © 2018 Ed Seidewitz Use the isOn attribute to record which state the Heater is in.  There is no built-in way in Alf to determine what state a state machine is in.
  40. 40. Page 40 Create the monitor method Copyright © 2018 Ed Seidewitz
  41. 41. Page 41 Are you using SysML? Copyright © 2018 Ed Seidewitz Alf currently cannot be used to send a signal via a specified port.  To be resolved through further integration of Alf with composite structure semantics.
  42. 42. Page 42 Update the House state machine Copyright © 2018 Ed Seidewitz Double click on the running state (as a whole) to open its specification window. Under Entry, set the Behavior Type to Opaque Behavior. Click on just the entry behavior line and enter code in the Alf editor window.
  43. 43. Page 43 Update the instance model Copyright © 2018 Ed Seidewitz Add a Thermostat instance and links to the House and Heater instances. Right click on the Environment instance and select Simulation ► Run to execute the model again.

×