# Adding Model Constraints

Model constraints allow us to capture real-world limitations in our supply chain. These limitations might include production capacity, transportation restrictions, storage limits, etc.

By default, Cosmic Frog allows us to incorporate the following constraint types for Neo optimization models:

- Flow constraints
- Inventory constraints
- Production constraints
- Facility count constraints
- Flow count constraints
- Production count constraints
- Inventory count constraints

Each set of constraints has its own table in the Cosmic Frog data schema.

## Flow constraints

Flow Constraints introduce a limit on the amount of flow (product) that can pass between an origin/destination pair in our supply chain.

In the example below, we limit the number of pencils that the Ashland production site can ship to the Chicago customer to a maximum of 20 per period.

Note that we can adjust the unit of measure of our constraints as needed. For example, we might be interested in limiting the total weight of product shipped between locations, instead of the total count of product.

## Inventory constraints

Inventory constraints limit the amount of product that can be stored at a facility. They can represent both minimum and maximum inventory limits.

In the example below we limit the capacity of the Bakersfield distribution center such that it can hold at most 500 pens. We are also requiring that the DC stores at least 100 pencils.

## Production constraints

Production constraints limit the amount of product a supplier or a production facility can produce. Like inventory constraints, you can set both minimum and maximum production limits.

In the example below, the Memphis production can produce at most 250 pens in each period. Additionally, the Ashland site has a fixed production constraint, which requires it to always produce exactly 400 pencils in each period.

## Facility count constraints

Facility count constraints limit the number of facilities that can be used in a Cosmic Frog model. These constraints are often used in facility location and selection problems.

For many of the “count” constraints, we want to apply our constraint across a number of different supply chain elements (e.g. across all facilities). To do this, the group functionality of Cosmic Frog is particularly useful, and often necessary. For more detailed information on using groups in constraints, see Using Groups to Write Model Constraints.

In the following example we want to design a supply chain with exactly 2 facilities, and we want to know the optimal location of these 2 facilities. First, we set the status of candidate locations in our *Facilities* table to “consider”. Without making this change, our model will be forced to include all facilities where Status = “Include” in our network.

Then, we create a constraint requiring the model to select exactly 2 facilities from the “ProductionSites” group.

## Flow count constraints

Flow count constraints limit the *number *of flows of a particular product. Flow count constraints are particularly useful in problems where the available transportation resources are limited.

In the following example we are implementing a “single-sourced” rule where each customer is served by exactly one production site. For each customer (enumeration) we look across all production sites (aggregation) and set the flow count to be exactly 1.

## Production count constraints

Production count constraints allow us to manage the number of product types that are produced at different facilities.

In the example below we add two production count constraints. First, we require that only one production site produces pens. Second, we require that each production site makes at most one product from the “Products” group.

## Inventory count constraints

Inventory count constraints allow us to limit the number of product *types** *that are stored at our facilities. In the example below we require the Bakersfield DC to hold at most one type of product.