# Supply Chain With Factory

This example demonstrates how to create an end-to-end supply chain involving a raw material supplier, a factory, and a warehouse. 

![alt text](img/img_six_node_sc.png)

## Creating Nodes

In this scenario, we create a supplier with a limited inventory capacity. A raw material needs to be created and provided to the supplier when it is created with finite inventory. This raw material is defined by several parameters, including ID, name, extraction quantity, extraction time, and cost. The supplier is designed to hold only a single type of raw material in its inventory and is responsible for mining it to maintain inventory levels to fill capacity.

```python
{% 
    include "../examples/py/sc_with_factory.py" 
    start="#create-sup-st"
    end="#create-sup-en"
%}
```

Creating a factory requires a product. A product and a factory can be created and configured as follows. 

```python
{% 
    include "../examples/py/sc_with_factory.py" 
    start="#create-fact-n-dis-st"
    end="#create-fact-n-dis-en"
%}
```

The factory's behavior is to produce products based on a replenishment policy. In this example, inventory will be replenished when the level drops below a threshold (s). Therefore, the factory will begin manufacturing products once the inventory falls below this level and increase it back up to its maximum capacity (S).

## Defining Links

Links represent the flow of products between nodes, with associated transportation costs and lead times.

```python
{% 
    include "../examples/py/sc_with_factory.py" 
    start="#linking-st"
    end="#linking-en"
%}
```

## Modeling Demand

Demand is generated at the distributor using deterministic arrival and quantity models.


```python
{% 
    include "../examples/py/sc_with_factory.py" 
    start="#dem-st"
    end="#dem-en"
%}
```

## Running the Simulation

Create the supply chain network and simulate it.

```python
{% 
    include "../examples/py/sc_with_factory.py" 
    start="#create-n-run-st"
    end="#create-n-run-en"
%}
```

## Review Results

Here is the simulation log generated by the network.

<div id="" style="overflow:scroll; height:600px;">
```
{% 
    include "../examples/py/sc_with_factory.py" 
    start="#out-st"
    end="#out-en"
%}
```
</div>
