Aggregate planning with inventory I am lost in formulating a mathematical model for my linear integer program. My problem is; how to include inventory and backlogging.

The following is given:


1100 units can be produced each month
Unit production cost = \$7
Inventory unit cost = \$2
Annual expense = \$10.000
Sales unit price \$12
We have given the demand for 12 month and need to plan for 12 month
If demand is not met in one month, it will be transferred to next month (backlogging)
All demand should be met in the end of the year
The sum of all demand = 12.345 unit


We want to maximize the profit

\begin{align}
\max \sum_{i=1}^{12} x_i 12 - 10.000-\sum_{i=1}^{12} x_i 7 - \sum_{i=1}^{12} y_i 2
\end{align}
where $x_i$ is the amount produced each month, for i=1,...,12 and $y_i$ is the amount of inventory each month. I have defined the following constraints:

\begin{align}
x_i \leq 1100 \\
\sum_{i=1}^{12} x_i = 12345
\end{align}

So if we have $d_i\geq x_i$ we backlog the demand, and if $x_i \geq d_i$ we put it in inventory. 
\begin{align}
if: d_i \geq x_i : b_i = d_i-x_i+b_{i+1} \\
if: x_i \geq d_i : y_i = x_i - d_i + y_{i-1}
\end{align}
where $b_i$ is the amount backlogged and $d_i$ is the demand. 

But this is not correct, since the inventory constraint should be smaller if we take some of it to meet the demand that exceeds the amount we can produce (if we have something backlogged), and if we have some inventory, then we don't need to backlog it. I really hope that someone can help me formulate it correctly.
Your objective-function seems to only concern inventory (that's the only variable aspect of your problem). Indeed $\sum x_i =12345$ is constant, your profit, excluding inventory cost, will be $5$ times this in any case ($12 - 7$). Your objective can be written more simply as $\min \sum y_i$

$b_i=\max\{0, d_i-x_i-y_{i-1}\}$ and $y_i=\max\{0, x_i+y_{i-1}-d_i\}$ should be the additional constraints.
If production + previous inventory is not enough to satisfy demand, you get a backlog at period $i$ and inventory at $i$ is what remains after satisfying the current demand with the current production + previous inventory.  

So $b_i\geq d_i-x_i-y_{i-1}$ and $y_i\geq x_i+y_{i-1}-d_i$ should do. 

Since $y_i$ are to be minimized, these variables would equal their lowest feasible bound ($0$ or the difference above).

You will just pay $\$2$ for every unit you produce above demand on a given period. However, from an inventory management point of view, the cost of inventory in your model seems unusually simplistic. A more realistic cost for inventory would consider a holding/carrying cost (cost of holding one unit of inventory for one unit of time) and an ordering cost (cost of ordering raw material or components). The difficulty of inventory problems is typically determining when and how much to order to find the best trade-off between these two costs.

PS. It may make sense at the aggregate level, and intermediate-planning time horizon, to make such a simplification regarding inventory costs. However, aggregate planning and inventory management are two strategic problems in their own rights, over two different time-horizons. They cannot be easily solved by one simple, integrated model (mostly because of different levels of uncertainty in demand over the two time-horizons and at the aggregate vs individual level).