Constrained Markov Decision Process (CMDP)¶
masa.common.constraints.cmdp.CumulativeCost ¶
Bases: Constraint
CMDP-style cumulative cost constraint with a fixed budget.
The monitor keeps:
step_cost: the instantaneous cost \(c_t\),total: the accumulated cost \(C_T\).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cost_fn
|
CostFn
|
Mapping from a label set to a scalar cost. |
required |
budget
|
float
|
Episode budget \(B\). The episode is satisfied if
|
required |
Attributes:
| Name | Type | Description |
|---|---|---|
cost_fn |
The cost function |
|
budget |
Maximum allowed cumulative cost. |
|
total |
Running cumulative cost for the current episode. |
|
step_cost |
Cost at the most recent update. |
Source code in masa/common/constraints/cmdp.py
reset ¶
update ¶
Update costs from the current label set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
Iterable[str]
|
Iterable of atomic proposition strings for the current step. |
required |
Source code in masa/common/constraints/cmdp.py
satisfied ¶
Check whether the episode remains within budget.
Returns:
| Type | Description |
|---|---|
bool
|
|
episode_metric ¶
End-of-episode metrics.
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
A dict containing: |
Dict[str, float]
|
|
Dict[str, float]
|
|
Source code in masa/common/constraints/cmdp.py
step_metric ¶
Per-step metrics.
Returns:
| Type | Description |
|---|---|
Dict[str, float]
|
A dict containing: |
Dict[str, float]
|
|
Dict[str, float]
|
|
Dict[str, float]
|
|
Source code in masa/common/constraints/cmdp.py
masa.common.constraints.cmdp.CumulativeCostEnv ¶
Bases: BaseConstraintEnv
Gymnasium wrapper that attaches CumulativeCost to an environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
env
|
Env
|
Base environment (must be a |
required |
cost_fn
|
CostFn
|
Cost function mapping label sets to float cost. |
cost_fn
|
budget
|
float
|
Cumulative cost budget \(B\). |
20.0
|
**kw
|
Extra keyword arguments forwarded to |
{}
|