Create and Manage Allocations
This example shows how to create and manage System Composer™ allocations.
An allocation establishes a directed relationship from architectural elements — components, ports, and connectors — in one model to architectural elements in another model. Resource-based allocation allows you to allocate functional architectural elements to logical architectural elements and logical architectural elements to physical architectural elements. Another common use case for allocations is to establish relationships from software components to hardware components to indicate a deployment strategy.
An allocation scenario contains a set of allocations between a source and a target model. Allocate between model elements within an allocation in an allocation scenario. The default allocation scenario is called
An allocation set consists of one or more allocation scenarios that describe various allocations between a source and a target model. Create an allocation set with allocation scenarios in the Allocation Editor.
This example uses the Tire Pressure Monitoring System (TPMS) project. To open the project, use this command:
Create a New Allocation Set
You can create an allocation set using the Allocation Editor. An allocation set is a collection of allocation relationships between two models: a source model, and a target model. The allocation set is stored as an
In this example,
TPMS_FunctionalArchitecture.slx is the source model and the
TPMS_LogicalArchitecture.slx is the target model.
To create an allocation set for these models, use this command.
allocSet = systemcomposer.allocation.createAllocationSet(... 'Functional2Logical', ...% Name of the allocation set 'TPMS_FunctionalArchitecture', ... % Source model 'TPMS_LogicalArchitecture' ... % Target model );
To see the allocation set, open the Allocation Editor by using the following command.
The Allocation Editor has three parts: the toolstrip, the browser pane, and the allocation matrix.
Use the toolstrip to create and manage allocation sets. For instance, you can use the New Allocation Set button to create a new allocation set between two models.
Use the Allocation Set Browser pane to browse and open existing allocation sets.
Use the allocation matrix to specify allocations between the source model elements in the first column and target model elements in the first row. You can create allocations programmatically or by double-clicking a cell in the matrix.
Create Allocations between Two Models
This example shows how to programmatically create allocations between two models in the TPMS project.
Get handles to the reporting functions in the functional architecture model.
functionalArch = systemcomposer.loadModel('TPMS_FunctionalArchitecture'); reportLevels = functionalArch.lookup('Path','TPMS_FunctionalArchitecture/Report Tire Pressure Levels'); reportLow = functionalArch.lookup('Path','TPMS_FunctionalArchitecture/Report Low Tire Pressure');
Get the handle to the TPMS reporting system component in the logical architecture model.
logicalArch = systemcomposer.loadModel('TPMS_LogicalArchitecture'); reportingSystem = logicalArch.lookup('Path','TPMS_LogicalArchitecture/TPMS Reporting System');
Create the allocations in the default scenario that is created.
defaultScenario = allocSet.getScenario('Scenario 1'); defaultScenario.allocate(reportLevels,reportingSystem); defaultScenario.allocate(reportLow,reportingSystem);
Optionally, you can delete the allocation between reporting low tire pressure and the reporting system.