# How do I model a machine that wears out?

A machine that wears out fails at about the same age, while a memoryless machine fails at any age. Weibull with a shape above 1 is the wear-out case. The script gives a press a Weibull uptime and an exponential one with the same 100-minute mean.

```python
from nagasim import build as nb


def breakdown_run(uptime):
    m = nb.Model(time_limit=2000, warmup=0)
    m.add_resource(name="Press")
    arrive = m.create(distribution=nb.Exponential(rate=0.5))
    arrive >> m.process(resource_name="Press", distribution=nb.Exponential(rate=1.0)) >> m.dispose()
    m.add_failure(name="Wear", resources=["Press"], uptime=uptime,
                  downtime={"distribution": "Constant", "dist_params": {"value": 20}})
    return m.run(replications=10, seed=1)


# Both uptimes average 100 minutes. Weibull shape 3 is wear-out: failures bunch around 100 minutes,
# while the exponential's scatter from almost 0 to over 400.
wear_out = {"distribution": "Weibull", "dist_params": {"scale": 112, "shape": 3}}
memoryless = {"distribution": "Exponential", "dist_params": {"rate": 0.01}}
for label, uptime in (("Weibull shape 3", wear_out), ("Exponential", memoryless)):
    results = breakdown_run(uptime)
    print(f"{label:<16} mean wait {results.kpi('resource/Press/Time in Queue Avg'):5.1f} minutes")

```

Save it as `recipe-weibull-wear-out.py` and run it with `python`. The script seeds itself, so the numbers below are the same on your machine.

```text
Weibull shape 3  mean wait   4.6 minutes
Exponential      mean wait   5.5 minutes

```

## How it works

1. `Weibull(scale, shape)` with `shape = 3` bunches failures around the mean; `shape = 1` is the exponential.
2. `add_failure` takes the uptime and downtime as distributions, so any family in the reference can drive a breakdown.
3. Both presses fail 100 minutes apart on average, and the regular failures cost a little less waiting.

## Elements used

- Distributions: [Weibull](../../reference/distributions/weibull.md), [Exponential](../../reference/distributions/exponential.md), [Constant](../../reference/distributions/constant.md).
- Blocks: [CREATE](../../reference/blocks/create.md), [PROCESS](../../reference/blocks/process.md), [DISPOSE](../../reference/blocks/dispose.md).
- Model-file sections: [`failures`](../../reference/model-file/failures.md).
- Python: [`Model`](../../reference/api/Model.md).

Back to all [recipes](index.md).
