В этом примере показано, как создать несколько сценариев моделирования и использовать эти сценарии для оптимизации типов данных системы с фиксированной точкой.
Откройте модель. В этом примере выполняется оптимизация типов данных подсистемы контроллера. Модель настраивается так, чтобы использовать либо линейный, либо случайный ввод. Модель использует блок Assertion вместо того, чтобы использовать допуски сигнала для проверки численного поведения реализации с фиксированной точкой. Дополнительные сведения см. в разделе Указание поведенческих ограничений.
model = 'ex_controllerHarness';
open_system(model);

Создать Simulink.SimulationInput объект, содержащий различные сценарии. Для случайного ввода используйте как входные данные клина, так и четыре различных начальных значения.
si = Simulink.SimulationInput.empty(5, 0); % scan through 4 different seeds for the random input rng(1); seeds = randi(1e6, [1 4]); for sIndex = 1:length(seeds) si(sIndex) = Simulink.SimulationInput(model); si(sIndex) = si(sIndex).setVariable('SOURCE', 2); % SOURCE == 2 corresponds to the random input si(sIndex) = si(sIndex).setBlockParameter([model '/Random/uniformRandom'], 'Seed', num2str(seeds(sIndex))); % scan through the seeds si(sIndex) = si(sIndex).setUserString(sprintf('random_%i', seeds(sIndex))); end % setting SOURCE == 1 corresponds to the ramp input si(5) = Simulink.SimulationInput(model); si(5) = si(5).setVariable('SOURCE', 1); si(5) = si(5).setUserString('Ramp');
Чтобы задать параметры оптимизации, такие как количество итераций и метод для сбора диапазонов, используйте команду fxpOptimizationOptions объект. В этом примере для сбора диапазонов системы используется анализ производных диапазонов.
options = fxpOptimizationOptions('MaxIterations', 3e2, 'Patience', 50); options.AdvancedOptions.PerformNeighborhoodSearch = false; % use derived range analysis for range collection options.AdvancedOptions.UseDerivedRangeAnalysis = true
options =
fxpOptimizationOptions with properties:
MaxIterations: 300
MaxTime: 600
Patience: 50
Verbosity: High
AllowableWordLengths: [1x127 double]
ObjectiveFunction: BitWidthSum
UseParallel: 0
Advanced Options
AdvancedOptions: [1x1 DataTypeOptimization.AdvancedFxpOptimizationOptions]
Укажите входные объекты моделирования в качестве сценариев моделирования в дополнительных параметрах.
options.AdvancedOptions.SimulationScenarios = si;
Во время оптимизации программа извлекает диапазоны для всех сценариев моделирования, указанных в расширенных опциях. Программное обеспечение проверяет решения по каждому сценарию ввода моделирования.
result = fxpopt(model, [model '/Controller'], options)
+ Starting data type optimization...
+ Checking for unsupported constructs.
+ Preprocessing
+ Modeling the optimization problem
- Constructing decision variables
+ Running the optimization solver
- Evaluating new solution: cost 496, does not meet the behavioral constraints.
- Evaluating new solution: cost 976, does not meet the behavioral constraints.
- Evaluating new solution: cost 1936, meets the behavioral constraints.
- Updated best found solution, cost: 1936
+ Optimization has finished.
+ Fixed-point implementation that satisfies the behavioral constraints found. The best found solution is applied on the model.
- Total cost: 1936
- Use the explore method of the result to explore the implementation.
result =
OptimizationResult with properties:
Model: 'ex_controllerHarness'
SystemUnderDesign: 'ex_controllerHarness/Controller'
FinalOutcome: 'Fixed-point implementation that satisfies the behavioral constraints found. The best found solution is applied on the model.'
OptimizationOptions: [1x1 fxpOptimizationOptions]
Solutions: [1x1 DataTypeOptimization.OptimizationSolution]
Можно исследовать каждое решение в сравнении с каждым определенным сценарием моделирования. Изучите наилучшее найденное решение и просмотрите его с помощью входных данных моделирования пандуса. Вход клина является сценарием моделирования пять.
solutionIndex = 1; % get the best found solution scenarioIndex = 5; % get the 5th scenario (ramp) solution = explore(result, solutionIndex, scenarioIndex);