Skip to content
LIBRARY
Experimental.LinearMPCScheduler.md

Experimental.LinearMPCScheduler ​

Weights of the members of a controller bank for the current value of a scalar scheduling variable rho: with scheduling = Linear the hat-function weights of the two knots of rho_grid enclosing rho (linear interpolation, a single weight of 1 exactly at a knot), with Nearest a weight of 1 for the member whose knot is closest (the upper one halfway between two knots). rho is clamped to the grid, so outside it the boundary member is used. The weights sum to 1 and drive LinearMPCScheduledObserver and LinearMPCScheduledOptimizer; lmpc_bank_weights computes the same weights in Julia.

Usage ​

MPCComponents.Experimental.LinearMPCScheduler(g=rho_grid, gl=_lmpc_sched_left(rho_grid), gr=_lmpc_sched_right(rho_grid), ml=_lmpc_sched_midl(rho_grid), mr=_lmpc_sched_midr(rho_grid))

Parameters: ​

NameDescriptionUnitsDefault value
rho_gridKnots of the scheduling variable at which the members were built (strictly increasing)–
schedulingScheduling law–MPCScheduling.Linear()
NNumber of knots (derived)–size(rho_grid, 1)
nearestWhether the nearest member is selected instead of interpolating (derived)–_dyad_isa...ng.Nearest)

Connectors ​

  • rho - This connector represents a real signal as an input to a component (RealInput)

  • w - This connector represents a real signal as an output from a component (RealOutput)

Variables ​

NameDescriptionUnits
rho_cScheduling variable clamped to the grid–

Behavior ​

Behavior of this component cannot be rendered because it includes path variables.

Source ​

dyad
"""
Weights of the members of a controller bank for the current value of a scalar scheduling variable
`rho`: with `scheduling = Linear` the hat-function weights of the two knots of `rho_grid`
enclosing `rho` (linear interpolation, a single weight of 1 exactly at a knot), with `Nearest` a
weight of 1 for the member whose knot is closest (the upper one halfway between two knots). `rho`
is clamped to the grid, so outside it the boundary member is used. The weights sum to 1 and drive
`LinearMPCScheduledObserver` and `LinearMPCScheduledOptimizer`; `lmpc_bank_weights` computes the
same weights in Julia.
"""
component LinearMPCScheduler@[input clk extends Discrete]
  "Scheduling variable"
  rho = RealInput@[clk]() {
    "Dyad": {"placement": {"diagram": {"x1": -100, "y1": 450, "x2": 0, "y2": 550}}}
  }
  "Member weights (sum to 1)"
  w = [RealOutput@[clk]() for j in 1:N] {
    "Dyad": {"placement": {"diagram": {"x1": 1000, "y1": 450, "x2": 1100, "y2": 550}}}
  }
  "Knots of the scheduling variable at which the members were built (strictly increasing)"
  structural parameter rho_grid::Real[:]
  "Scheduling law"
  structural parameter scheduling::MPCScheduling = MPCScheduling.Linear()
  "Number of knots (derived)"
  final structural parameter N::Integer = size(rho_grid, 1)
  "Whether the nearest member is selected instead of interpolating (derived)"
  final structural parameter nearest::Boolean = case(scheduling, MPCScheduling.Nearest)
  "The knots"
  final parameter g::Real[N] = rho_grid
  "Left neighbour of each knot (a finite sentinel for the first)"
  final parameter gl::Real[N] = _lmpc_sched_left(rho_grid)
  "Right neighbour of each knot (a finite sentinel for the last)"
  final parameter gr::Real[N] = _lmpc_sched_right(rho_grid)
  "Lower edge of each nearest-member cell"
  final parameter ml::Real[N] = _lmpc_sched_midl(rho_grid)
  "Upper edge of each nearest-member cell"
  final parameter mr::Real[N] = _lmpc_sched_midr(rho_grid)
  "Scheduling variable clamped to the grid"
  variable rho_c::Real
relations
  rho_c = ifelse(rho < g[1], g[1], ifelse(rho > g[N], g[N], rho))
  if nearest
    for j in 1:N
      w[j] = ifelse(rho_c < ml[j], 0.0, ifelse(rho_c < mr[j], 1.0, 0.0))
    end
  else
    for j in 1:N
      w[j] = ifelse(rho_c < gl[j], 0.0, ifelse(rho_c < g[j], (rho_c - gl[j]) / (g[j] - gl[j]), ifelse(rho_c < gr[j], (gr[j] - rho_c) / (gr[j] - g[j]), 0.0)))
    end
  end
metadata {
  "Dyad": {
    "icons": {"default": "dyad://MPCComponents/LinearMPCScheduler.svg"},
    "doc": {"behavior": false}
  }
}
end
Flattened Source
dyad
"""
Weights of the members of a controller bank for the current value of a scalar scheduling variable
`rho`: with `scheduling = Linear` the hat-function weights of the two knots of `rho_grid`
enclosing `rho` (linear interpolation, a single weight of 1 exactly at a knot), with `Nearest` a
weight of 1 for the member whose knot is closest (the upper one halfway between two knots). `rho`
is clamped to the grid, so outside it the boundary member is used. The weights sum to 1 and drive
`LinearMPCScheduledObserver` and `LinearMPCScheduledOptimizer`; `lmpc_bank_weights` computes the
same weights in Julia.
"""
component LinearMPCScheduler
  "Scheduling variable"
  rho = RealInput@[clk]() {
    "Dyad": {"placement": {"diagram": {"x1": -100, "y1": 450, "x2": 0, "y2": 550}}}
  }
  "Member weights (sum to 1)"
  w = [RealOutput@[clk]() for j in 1:N] {
    "Dyad": {"placement": {"diagram": {"x1": 1000, "y1": 450, "x2": 1100, "y2": 550}}}
  }
  "Knots of the scheduling variable at which the members were built (strictly increasing)"
  structural parameter rho_grid::Real[:]
  "Scheduling law"
  structural parameter scheduling::MPCScheduling = MPCScheduling.Linear()
  "Number of knots (derived)"
  final structural parameter N::Integer = size(rho_grid, 1)
  "Whether the nearest member is selected instead of interpolating (derived)"
  final structural parameter nearest::Boolean = case(scheduling, MPCScheduling.Nearest)
  "The knots"
  final parameter g::Real[N] = rho_grid
  "Left neighbour of each knot (a finite sentinel for the first)"
  final parameter gl::Real[N] = _lmpc_sched_left(rho_grid)
  "Right neighbour of each knot (a finite sentinel for the last)"
  final parameter gr::Real[N] = _lmpc_sched_right(rho_grid)
  "Lower edge of each nearest-member cell"
  final parameter ml::Real[N] = _lmpc_sched_midl(rho_grid)
  "Upper edge of each nearest-member cell"
  final parameter mr::Real[N] = _lmpc_sched_midr(rho_grid)
  "Scheduling variable clamped to the grid"
  variable rho_c::Real
relations
  rho_c = ifelse(rho < g[1], g[1], ifelse(rho > g[N], g[N], rho))
  if nearest
    for j in 1:N
      w[j] = ifelse(rho_c < ml[j], 0.0, ifelse(rho_c < mr[j], 1.0, 0.0))
    end
  else
    for j in 1:N
      w[j] = ifelse(rho_c < gl[j], 0.0, ifelse(rho_c < g[j], (rho_c - gl[j]) / (g[j] - gl[j]), ifelse(rho_c < gr[j], (gr[j] - rho_c) / (gr[j] - g[j]), 0.0)))
    end
  end
metadata {
  "Dyad": {
    "icons": {"default": "dyad://MPCComponents/LinearMPCScheduler.svg"},
    "doc": {"behavior": false}
  }
}
end


Test Cases ​

No test cases defined.

  • Examples

  • Experiments

  • Analyses