Skip to content

Commit 7b8b163

Browse files
now the simplified metered ramp is able to use two different flow eq: limited and unlimited
1 parent a43e9c2 commit 7b8b163

File tree

4 files changed

+59
-33
lines changed

4 files changed

+59
-33
lines changed

src/sym_metanet/blocks/origins.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -225,19 +225,28 @@ class SimplifiedMeteredOnRamp(MeteredOnRamp[VarType]):
225225
_actions = {"q"}
226226

227227
def __init__(
228-
self, capacity: Union[VarType, float], name: Optional[str] = None
228+
self,
229+
capacity: Union[VarType, float],
230+
flow_eq_type: Literal["limited", "unlimited"] = "limited",
231+
name: Optional[str] = None,
229232
) -> None:
230233
"""Instantiates a simplified on-ramp with the given capacity.
231234
232235
Parameters
233236
----------
234237
capacity : float or variable
235238
Capacity of the on-ramp, i.e., `C`.
239+
flow_eq_type : 'limited' or 'unlimited', optional
240+
Type of flow equation for the ramp. See
241+
`engine.origins.get_simplifiedramp_flow` for more details.
236242
name : str, optional
237243
Name of the on-ramp, by default None.
238244
"""
239-
super().__init__(capacity=capacity, name=name)
240-
del self.flow_eq_type
245+
super().__init__(
246+
capacity=capacity,
247+
flow_eq_type=flow_eq_type, # type: ignore[arg-type]
248+
name=name,
249+
)
241250

242251
def init_vars(
243252
self,
@@ -306,4 +315,5 @@ def get_flow( # type: ignore[override]
306315
rho_crit=link_down.rho_crit,
307316
rho_first=link_down.states["rho"][0],
308317
T=T,
318+
type=self.flow_eq_type, # type: ignore[arg-type]
309319
)

src/sym_metanet/engines/casadi.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,17 @@ def get_ramp_flow(
131131
@staticmethod
132132
def get_simplifiedramp_flow(
133133
qdes: VarType,
134-
d: VarType,
135-
w: VarType,
136-
C: VarType,
137-
rho_max: VarType,
138-
rho_first: VarType,
139-
rho_crit: VarType,
140-
T: VarType,
134+
d: VarType = None,
135+
w: VarType = None,
136+
C: VarType = None,
137+
rho_max: VarType = None,
138+
rho_first: VarType = None,
139+
rho_crit: VarType = None,
140+
T: VarType = None,
141+
type: Literal["limited", "unlimited"] = "limited",
141142
) -> VarType:
143+
if type == "unlimited":
144+
return qdes
142145
term2 = d + w / T
143146
term3 = C * cs.fmin(1, (rho_max - rho_first) / (rho_max - rho_crit))
144147
return cs.fmin(qdes, cs.fmin(term2, term3))

src/sym_metanet/engines/core.py

+22-14
Original file line numberDiff line numberDiff line change
@@ -311,37 +311,45 @@ def get_ramp_flow(
311311
@abstractmethod
312312
def get_simplifiedramp_flow(
313313
qdes,
314-
d,
315-
w,
316-
C,
317-
rho_max,
318-
rho_first,
319-
rho_crit,
320-
T,
314+
d=None,
315+
w=None,
316+
C=None,
317+
rho_max=None,
318+
rho_first=None,
319+
rho_crit=None,
320+
T=None,
321+
type: Literal["limited", "unlimited"] = "limited",
321322
):
322323
"""Computes the flows of a simplified ramp origin.
323324
324325
Parameters
325326
----------
326327
qdes
327328
Desired flow at the ramp.
328-
d
329+
d : optional
329330
Demand at the ramp.
330-
w
331+
w : optional
331332
Queue of the ramp.
332-
C
333+
C : optional
333334
Capacity of the ramp.
334-
rho_first
335+
rho_first : optional
335336
Density of the first segment of the link the ramp is attached to. To be
336337
provided only if `type=limited`.
337-
rho_max
338+
rho_max : optional
338339
Maximum density of the link the ramp is attached to. To be provided only if
339340
`type=limited`.
340-
rho_crit
341+
rho_crit : optional
341342
Critical density of the link the ramp is attached to. To be provided only if
342343
`type=limited`.
343-
T
344+
T : optional
344345
Sampling time.
346+
type : "limited" or "unlimited", optional
347+
Type of equation to compute the flow for a simplified metered ramp. By
348+
default, "limited" is selected, which means that the desired flow is limited
349+
according to the capacity, current demands, queues and densities of the ramp
350+
and its attached segment. This equation needs that all optional arguments
351+
are provided. Otherwise, "unlimited" makes sure that the desired flow is
352+
the actual flow of the ramp, which can cause negative queues though.
345353
346354
Returns
347355
-------

src/sym_metanet/engines/numpy.py

+14-9
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,21 @@ def get_ramp_flow(
123123
@staticmethod
124124
def get_simplifiedramp_flow(
125125
qdes: np.ndarray,
126-
d: np.ndarray,
127-
w: np.ndarray,
128-
C: np.ndarray,
129-
rho_max: np.ndarray,
130-
rho_first: np.ndarray,
131-
rho_crit: np.ndarray,
132-
T: np.ndarray,
126+
d: Optional[np.ndarray] = None,
127+
w: Optional[np.ndarray] = None,
128+
C: Optional[np.ndarray] = None,
129+
rho_max: Optional[np.ndarray] = None,
130+
rho_first: Optional[np.ndarray] = None,
131+
rho_crit: Optional[np.ndarray] = None,
132+
T: Optional[np.ndarray] = None,
133+
type: Literal["limited", "unlimited"] = "limited",
133134
) -> np.ndarray:
134-
term2 = d + w / T
135-
term3 = C * np.minimum(1, (rho_max - rho_first) / (rho_max - rho_crit))
135+
if type == "unlimited":
136+
return qdes
137+
term2 = d + w / T # type: ignore[operator]
138+
term3 = C * np.minimum(
139+
1, (rho_max - rho_first) / (rho_max - rho_crit) # type: ignore[operator]
140+
)
136141
return np.minimum(qdes, np.minimum(term2, term3))
137142

138143

0 commit comments

Comments
 (0)