Solved

# Variable with Initial Value

• 2 replies
• 81 views

Hi everybod,

I have a quick question and hope you can help me.

I calculate in my model the optimal stock level depending on the period and szenario specific demand.
The inventory level is defined as follows: Inventory_PreviousPeriod + ProductionQuantity_CurrentPeriod (also a variable) - DeliveryQuantity_CurrentPeriod.

How is it possible to preset the variable stock for the first period to a fixed inital value (in this case the opening inventory)?

Best ragards, Hans

Hello Hans,

I typically do this by including the initial stock from a parameter and conditioning that this will only be added if the constraint is being applied for the first period.

Something like this:

Constraint c_balance {
IndexDomain: (i_period);
Definition:

(p_initialInventory | (i_period = 'period_1’)) + v_inventory(i_period - 1) + v_production(i_period) = v_delivery(i_period) + v_inventory(i_period)
}

Hence the “| (i_period = 'period_1’)" will only add the p_initialInventory parameter when i_periodo is ‘period_1’.

Best regards,

### 2 replies

Hu Luispinto,

This is exactly the kind of advice I was hoping for, you really helped me a lot.

Thanks again and best regards,

Hans

Userlevel 5
+6

Hello Hans,

I typically do this by including the initial stock from a parameter and conditioning that this will only be added if the constraint is being applied for the first period.

Something like this:

Constraint c_balance {
IndexDomain: (i_period);
Definition:

(p_initialInventory | (i_period = 'period_1’)) + v_inventory(i_period - 1) + v_production(i_period) = v_delivery(i_period) + v_inventory(i_period)
}

Hence the “| (i_period = 'period_1’)" will only add the p_initialInventory parameter when i_periodo is ‘period_1’.

Best regards,