Inventorymodel : an R Package for Centralized Inventory Problems by

Inventory management of goods is an integral part of logistics systems; common to various economic sectors such as industry, agriculture and trade; and independent of production volume. In general, as companies seek to minimize economic losses, studies on problems of multi-agent inventory have increased in recent years. A multi-agent inventory problem is a situation in which several agents face individual inventory problems and agree to coordinate their orders with the objective of reducing their costs. The R package Inventorymodel allows the determination of both the optimal policy for some inventory situations with deterministic demands and the allocation of costs from a game-theoretic perspective. The required calculations may be computed for any number of agents although the computational complexity of this class of problems when the involved agents enlarge is not reduced. In this work, the different possibilities that the package offers are described and some examples of usage are also demonstrated.


Introduction
Often, once a product is chosen to be acquired, the seller advises that he or she does not have a unit of that product in stock.Probably, this vendor has not managed the storage of this commodity efficiently since the possibility of not being able to satisfy the demand for a product in time leads to shortages.Specific techniques may prevent situations such as this, allowing for reduction in economic losses associated with the lack of products.
Inventory is defined as the amount of goods stored by a company at a moment of time, which represents a capital investment for the purchase and maintenance of the product in stock.Each company desires having the proper inventory level to meet the needs of customers, and so they would prefer to handle it optimally.Inventory theory focuses on the design and optimization of production systems to minimize economic losses due to product shortages.However, this implies the existence of extra costs associated with different assumptions imposed on the model with an influence on the overall cost of the procedure.The consideration of the holding cost or variable cost for the transportation of a new order from a supplier to the warehouse are examples, among others, of new conditions to take into account in the models.Generally, this study focuses on a single product with fixed characteristics that companies need.Moreover, it presents new inventory situations in which a customer can switch to another supplier to get the desired product or an analogous product with similar properties.So, in an inventory system, the following must be considered: • An agent that wants to organize its inventory of a certain commodity.
• A deterministic demand for a product that this agent needs over a fixed period of time.
• The agent satisfies its demand through an external provider.
• In some circumstances, the agent can consider the possibility of not fulfilling all the demand in time, that is, a shortage of the good is allowed.
The main goal entails determining the optimal amount of product to request and the moment in which it is requested.The balance between quantity and the number of orders is essential.Not following the optimal policy implies that fewer orders than necessary are placed or that they are placed more frequently than usual, and hence the cost of the procedure increases.
Usually, we talk about inventory management for a single company, with a single decision determining the amount required depending on the demand or, for instance, the moment in which that order must be placed.Although individually, such inventory models totally ignore the decisions made by other agents in the same circumstances, it is possible to consider situations wherein they cooperate.Sometimes, in order to obtain savings, it is possible to consider the joint action of several individuals who, independently, would face situations of inventory management of a product as described.
In a centralized inventory problem, several agents who face individual inventory problems decide to coordinate their orders to reduce costs.The determination of the optimal level of inventory involves: (a) formulation of an appropriate mathematical model that describes the situation of inventory (shortages, transportation costs, holding costs, etc.), (b) identification of the optimal policy under the cooperation of a group of individuals, and (c) allocation of the incurred costs among the involved agents by using, for instance, game theoretic procedures.
The R Journal Vol.10/1, July 2018 ISSN 2073-4859 The analysis of cooperative multi-agent inventory problems has received much attention in recent years.The most basic models, the Economic Order Quantity (EOQ) model and the Economic Production Quantity (EPQ) model, are introduced in Meca et al. (2003) for the cooperative case, using the Share the Ordering Costs rule (SOC rule) as a procedure to obtain allocations with interesting properties.However, other inventory problems have been treated in the literature under this approach, including those detailed below.In Fiestras-Janeiro et al  Nagarajan and Sošić (2008), Dror andHartman (2011), andFiestras-Janeiro et al. (2011) are examples of some recent surveys in this field.
This paper describes the R package Inventorymodel and its capabilities for determining the optimal policies in the mentioned inventory models under a game-theoretic approach.For each of them, an allocation procedure is implemented to share the collaborating costs.This package can be very useful when the number of involved agents increases due to the computational complexity of the calculus of all possible groups considerably increases.
The remainder of this paper is organized as follows.First, we introduce some game theoretic notations used in this class of problems.Then, we present the different inventory models included in the Inventorymodel package, describing, for each, the optimal policy and appropriate allocation rule for the collaborating costs.Usage of the package is illustrated through the analysis of different examples considered in the literature.

Preliminaries on game theory
In this section, we introduce some necessary theoretical game terminology.
The cost games correspond to one of the most important classes of cooperative games.They are necessary for analysing those cost situations where n agents collaborate.Its definition is based on the concept of coalition.In what follows, if N := {1, ..., n} denotes the set of agents which cooperate, a coalition of N is a subset S ⊆ N with s := |S| elements.Following González-Díaz et al. (2010), a cost game is a pair (N, c), where N is the set of players and c is a characteristic function, a map from 2 N to R satisfying that c(∅) = 0. Usually, c(S) represents the cost of the collaboration of the players in the coalition S, for every S ⊆ N.
In this class of situations, some natural properties to verify are the following.We say that (N, c) is subadditive if, for each S, T ⊆ N, with S ∩ T = ∅, it satisfies c(S) + c(T) ≥ c(S ∪ T).Subadditivity implies that agents in S ∪ T do have economic incentives to collaborate with respect to the cooperation of the groups S and T independently.As consequence, the formation of coalition N is profitable.A game (N, c) is concave if, for all i ∈ N and for all S ⊂ T ⊆ N \ {i}, it satisfies c(S ∪ {i}) − c(S) ≥ c(T ∪ {i}) − c(T).Under concavity, players will have more incentive to join the coalition with a lower cost to contribute.
When a set of N agents cooperate, an important issue is the definition of procedures to allocate the cost c(N) obtained by collaborating among the involved agents.Below, we introduce two of the most important classes of allocations in this context according to different criteria in order to define the new allocation rules.The first approach focuses on the equanimity of allocations between players that cooperate.The Shapley value, introduced in Shapley (1953), is an example of a rule defined under this criteria to distribute c(N).The Shapley value of (N, c), Φ(N, c), is defined for each i ∈ N by: where Π(N) denotes the set of permutations of N, P σ i := {j ∈ N : σ(j) < σ(i)} denotes the predecessors of agent i by a permutation σ, and m σ i (c) := c(P σ i ∪ i) − c(P σ i ) for each σ ∈ Π(N).The Shapley value assigns to each i ∈ N its expected value if an agreement is reached, and each agent has to pay its contribution in the costs to the indicated set of predecessors.It is assumed that the arrival order is random and all orders are equally likely.
The second criteria is represented by the stability of the allocations.The core of (N, c), as in Gillies The R Journal Vol.10/1, July 2018 ISSN 2073ISSN -4859 (1953)), is the following set of payoff vectors for the members of N: , and for each non empty coalition S ⊂ N, ∑ i∈S x i ≤ c(S) .
It is said that the core allocations are stable in the sense that abandoning N and acting independently represents no improvement (in terms of gains) to coalition S, with S ⊂ N.This is due the fact that agents in S will pay more, when N does not form, than in those situations where its members act jointly with the rest of agents in N \ S. The study of the core of a game (N, c) and its cardinality become a complex issue in game theory since the number of associated constraints increases when n enlarges.For this reason, the definition of rules whose allocations are stable is a main goal in this class of problems.Under the verification of some properties of (N, c), it is easy to study the core.In particular, if the cost game is concave, the Shapley value of (N, c) is an element of this set, and when (N, c) is subadditive, C(N, c) is a non-empty set.

Centralized inventory problems
The Inventorymodel package includes functions to obtain the optimal policy in this class of situations.
In particular, different scenarios with deterministic demands are considered: for example, shortages can be allowed, transportation costs can be taken into account by assuming that agents are in a line or a general route, or different costs of product during shortages are allowed.
Depending on the considered assumptions, different parameters should be selected for modelling the problem among those described below.If a set of agents N cooperate to place joint orders, we can distinguish the following parameters: • a > 0, the fixed part of the ordering cost that is independent of the size of a new order, • a i > 0, the variable part of the ordering cost that depends on the distance between i and the supplier, • d i > 0, the deterministic demand of the product of agent i, • h i > 0, a holding cost by unit of a product stored in the own warehouse, • b i > 0, the shortage cost per item and per time unit, • K i > 0, the capacity of the warehouse of agent i.
This section introduces the different inventory models included in our package, which are dealt with in the literature by considering several assumptions about them. 1

The EOQ and EPQ models under cooperation
The EOQ model under cooperation, introduced in Meca et al. (2003), establishes the optimal policy for an agent i ∈ N to satisfy its demand of a product.This model supposes a fixed ordering cost, a > 0, and, for each i ∈ N, a deterministic demand of d i > 0 units of product per time unit and a holding cost by unit, h i > 0. For this model, it is assumed that shortages are not allowed.
If Q i denotes the required size of the order to satisfy d i , the time between two consecutive orders (length of the cycle) is Q i /d i .If only one agent acts, we deal with a basic EOQ problem, a well-known problem in operations research.The optimal policy is simple in this case: once the stock runs out, this agent places a new order.When a group of agents S ⊆ N decides to cooperate, instead of ordering independently, it applies for a unique joint order.Moreover, all agents should order at the same time, and thus the lengths of the individual cycles coincide as well (this is, Q i /d i = Q j /d j for each pair of agents i, j ∈ S).In addition, if we define the number of orders per time unit by m i = d i /Q i , in the cooperative case we have that m i = m j for each i, j ∈ S. Therefore, it is easy to check that the average cost per cycle is Using optimization techniques, (1) takes its minimum value at for each i ∈ S. Hence, 1 To simplify the description of the different inventory models contained in this package, we only consider the cooperative case when the formation of a certain group S ⊆ N is assumed.Moreover, this generalizes the case where a single agent i ∈ N acts, by taking S = {i}.
The R Journal Vol.10/1, July 2018 ISSN 2073-4859 we can associate a cost game (N, c), where c(S) where denotes the optimal number of orders per time unit for each i ∈ S.
The EPQ model under cooperation is introduced by Meca et al. (2003) by adding the following assumptions to those for the the EOQ model: • Each agent i of group S faces the possibility of not fulfilling its demand on time by incurring a level of shortage of β i units.The cost by shortage unit is b i > 0.
• Once the agents order, in a unit of time, agent i obtains r i units of the product, and the replacement rate of agent i with r i > d i .
When an agent acts individually, the optimal policy is simple as well: once the stock runs out and the maximum level of shortage is reached, this agent places a new order.Following Meca et al. (2003), when a group S ⊆ N is formed, its members apply for new joint orders.The average cost per cycle is ) and . With the appropriate calculations, we can associate a cost game (N, c) to the EPQ model by defining, for each where denotes the optimal number of orders per time unit for each i ∈ S.
The cooperative inventory cost situations defined in this section are denoted by (N, a, m).The class of the obtained games is called inventory games, verifying that for each S ⊆ N, c(S) = 2a ∑ j∈S m * j 2 and also c 2 (S) = ∑ i∈S c({i}) 2 .
The SOC rule, introduced by Meca et al. (2003), establishes proportional allocations in situations such as detailed.Let (N, a, m) be a situation of inventory as defined, and let (N, c) be the associated cost game.When N cooperate, the SOC rule σ proposes to each agent i ∈ N a core allocation that includes a part of the fixed order cost (proportional to m 2 i ), a part of the holding costs and, in the EPQ model, a part relative to shortages.Hence, when N cooperates, for each i ∈ N, while , the stability of the allocations is ensured.It is remarkable that the calculation of σ i (N, c) does not require the determination, in a explicit way, of the complete characteristic function of (N, c).

The inventory transportation systems
An inventory transportation system is an inventory situation wherein agents face a basic EOQ model.As Fiestras-Janeiro et al. (2012) propose, the cost of a new order has two components: the first is common to all and the second is proportional to the distance between the supplier and the agent.
Let N := {1, . . ., n} be the set of agents.We consider as parameters the fixed ordering cost, a > 0, and for each i ∈ N, the variable ordering cost, a i > 0; the deterministic demand of the product, d i > 0; and the holding cost by unit stored by the agent i, h i > 0. Let (N, a, {a i , d i , h i } i∈N ) be an inventory transportation system.The formation of a group S ⊆ N implies that, instead of ordering independently, agents apply for a unique joint order.As we mention, all agents have to order at same time, and thus the lengths of the individual cycles are equal.In addition, in this model, we assume the following: • All agents are in a same route.If S places a new order, the ordering cost is equal to, first, a and, second, the maximal distance a S between the agents in S and the supplier.So, a S := max{a i : The R Journal Vol.10/1, July 2018 ISSN 2073-4859 i ∈ S}.
• The supplier allows the formation of ordering coalitions.Given S ⊆ N, the cost of a new order of S is a + a S , although in some specific order, an agent in S may not buy the product.
According to Fiestras-Janeiro et al. ( 2012), the average cost per cycle is determined by After some algebraic calculation, when S ⊆ N is formed, the optimal size of the order for i ∈ S is , which is the optimal number of orders per time unit m * S : . So, for an inventory transportation system, we can define a cost game (N, c) for S ⊆ N by Fiestras-Janeiro et al. ( 2012) propose the line-rule L(N, c) as the procedure to share the collaborating costs.This rule assigns to each i ∈ N where Π L (N, c) denotes the set of permutations of N that reverse the order given by the distances from the agents to the supplier.Formally, So, this rule can be seen as a variation of the Shapley value for cost games.It requires less computational effort than the original, and Fiestras-Janeiro et al. ( 2012) prove that it is an element of the core of the game using the subadditivity character of (N, c) under these assumptions.

The inventory problems with no-holding costs and without shortages
A basic EOQ system without holding costs is a model with a deterministic demand, no holding costs, and a limited capacity of the warehouses and shortages are not allowed.Let N := {1, . . ., n} be the set of agents.Following Fiestras-Janeiro et al. ( 2014), the parameters associated with each i ∈ N in these systems are the fixed ordering cost, a > 0; the deterministic demand of the product of agent i, d i > 0; and the capacity of the warehouse of i, K i > 0.
We denote these systems by (N, a, {d i , K i } i∈N ).The optimal policy of a group S ⊆ N is very simple.When a group of agents S is formed, the length of a joint cycle is min j∈S {K j /d j } and its associated cost per time unit is Thus, we can associate with every basic EOQ system without holding costs and with general transportation costs (N, a, A, {d i , K i } i∈N ) the cost game (N, c) which is given for all S ⊆ N by Notice that the obtained cost game can be seen as an airport game (see Littlechild and Owen (1973), for details).For it, the Shapley value is an excellent rule with stable allocations.Moreover, there is a simple procedure to obtain it.By ordering in a non-decreasing order, the ratio d i /K i for all i ∈ N, the expression of the Shapley value for agent i ∈ N, Φ i (N, c), is Below, we describe an inventory system with costs for transporting a new order.
A basic EOQ system without holding costs and with transportation costs is an inventory situation introduced by Fiestras-Janeiro et al. (2014), where agents face a basic EOQ model.Let N := {1, . . ., n} be the set of agents.For each i ∈ N, the following parameters are considered: the fixed part of the ordering cost, a > 0; the variable part of the ordering cost, a i > 0; the deterministic demand of the product of i, d i > 0; and the capacity of the warehouse of i, K i > 0.
The R Journal Vol.10/1, July 2018 ISSN 2073-4859 These models are denoted by (N, a, {a i , d i , K i } i∈N ).The formation of a group S ⊆ N implies that agents in S place a unique joint order instead of independent orders.All of them have to order at the same time, and thus the lengths of the individual cycles are equal.In addition, we consider the following two assumptions imposed on the inventory transportation systems (see Fiestras-Janeiro et al. (2012), for instance): • All agents are in the same route.When a group S is formed, the ordering cost is equal to, first, a fixed value a and, second, the maximal distance a S of agents in S to the supplier.Thus, a S := max{a i : i ∈ S}.
• The supplier allows the formation of ordering coalitions.Given S ⊆ N, the cost of a new order of S is a + a S , regardless of whether an agent in S does not buy the product.
The optimal policy of a group S ⊆ N in this context is simple.When agents in S place joint orders, since shortages are not allowed, the length of a cycle is min j∈S {K j /d j } and the minimum joint cost per time unit is cost of a cycle length of a cycle Thus, we can associate with basic EOQ system without holding costs and with transportation costs (N, a, {a i , d i , K i } i∈N ) the cost game (N, c), which is given for all S ⊆ N by For each system (N, a, {a i , d i , K i } i∈N ), the two-lines rule assigns the cost allocation TL(N, c) := (TL(N, c)) i∈N .Following Fiestras-Janeiro et al. (2014), it belongs to the core of (N, c) and is given, for each i ∈ N, by where Π 1 (N, c) and Π 2 (N, c) are the following sets: It is composed of permutations that reverse the order given by the transportation costs.
• Π 2 (N, c) := {σ ∈ Π(N) : , for all i, j ∈ N}.This contains the permutations that reverse the order given by the ratio of demand/capacity.In some circumstances, it is certainly restrictive to consider that agents are located in the same route.For instance, they can be located in a circular route or other types of graphs, and that a S := A(S) for each S ⊆ N and for a general function A. So, A is a general map to assign the variable part of the transportation cost of a group S that depends on the distance of a member of S to the supplier.In addition, we consider as parameters the fixed part of ordering cost, a > 0, the deterministic demand of the product of i, d i > 0, and the capacity of the warehouse of i, K i > 0.
Thus, this model is denoted by (N, a, A, {d i , K i } i∈N ).The optimal policy of a group S ⊆ N is easy to obtain.Since holding costs are irrelevant, when the agents in S place joint orders, the length of a cycle is min j∈S {K j /d j }, and then the minimum joint cost per time unit is cost of a cycle length of a cycle = a + A(S) Thus, we can associate with every basic EOQ system without holding costs and with general transportation costs (N, a, A, {d i , K i } i∈N ) the cost game (N, c), which is given by, for all S ⊆ N, c(S) Notice that for each S ⊆ N, c(S) can be written as the sum of two terms.Therefore, c(S) := c a (S) + c b (S), with c a (S) = a max j∈S { where Π n (N) := {σ ∈ Π(N) satisfying, for all i ∈ {1, . . ., n − 1}, that } denotes the set of permutations that reverse the order of the ratios {d i /K i } i∈N .Saavedra-Nieves et al. ( 2018) prove that if the game (N, c b ) is subadditive and the function A is submodular2 , the proposed rule is in the core of (N, c).

The inventory problems with no-holding costs and shortages
An EOQ system without holding costs and shortages, introduced in the reference Fiestras-Janeiro et al. ( 2015), is a multi-agent situation, where each agent faces a continuous review inventory problem with no-holding costs, with shortages and with a limited capacity warehouse.The parameters associated with each i ∈ N are the fixed part of the ordering cost, a > 0; the shortage cost per item and per time unit, b i > 0; the demand of the product of i, d i > 0; and the capacity of the warehouse of i, K i > 0. This model is denoted by (N, a, {b i , d i , K i } i∈N ).As shortages are allowed, the optimal policy changes.When agent i reaches the maximum shortage level, agent i places a new order of size K i + β i , where β i is the level of shortages for i.So, the length of the cycle is , and the length of the period with shortages is . When a group S ⊆ N cooperates, we assume that its members place joint orders, and thus: 1 where x i and x j denote the number of orders per time unit for each agent i, j ∈ N. Hence, the average cost per cycle for a coalition S is a + ∑ i∈S b i , and the average cost by time unit is Denoting by x the common number of orders per time unit under cooperation, we have for all i ∈ S, and the average cost per time unit can be written as: The calculus of the optimal policy in this problem consists of calculating the minima of C S (x).Fiestras-Janeiro et al. (2015) propose an iterative algorithm to obtain this value.So, once it is applied, C S (x) reaches its minimum value as follows: (14) Thus, we can associate with every system as described the cost game (N, c) which is given, for all S ⊆ N, by c(S) := C S (x * S ).When agents in N cooperate, the authors propose a procedure to share the collaborating costs which ensures that the obtained allocation is in the core of (N, c).The G-rule proposes The stable character of the allocations can be justified by the fact of ∑ i∈S G i (c) ≤ c(S) for all S ⊂ N and ∑ i∈N G i (c) = c(N) (for details, see Fiestras-Janeiro et al. (2015)).
The previous model considers that the initial product and shortages have the same price by a unit of commodity.In some situations, the latter cost may be significantly smaller than the initial cost, as when shortages are produced by the same agent.Saavedra-Nieves et al. (2018a) justify and analyse this new inventory situation.
An EOQ problem without holding costs and with two acquisition costs is a multi-agent inventory model wherein each agent faces a continuous-review inventory problem involving the same commodity.In this case, the considered parameters are the fixed part of the ordering cost, a > 0; the shortage cost per unit and per time unit, b i > 0; the demand of the product of i, d i > 0; and the capacity of the warehouse of i, K i > 0. Additionally: • c 1 > 0, the acquisition cost of one unit of the purchased commodity, • c 2 > 0, the acquisition cost of one unit of the produced commodity, with c 2 < c 1 .
We denote this class of situations by (N, a, c 1 , c 2 , {b i , d i , K i } i∈N ).In an analogous way to the model studied in Fiestras-Janeiro et al. (2015), the inventory optimal policy varies when shortages are allowed.If agent i reaches the maximum shortage level, agent i places an order of size K i + β i , with β i the level of shortages for i.The length of the cycle is given by and the length of the period with shortages is . When a coalition S is formed, it verifies the following: where x i and x j denote the number of orders per time unit for each agent i, j ∈ S. Hence, the average + c 2 max{β i , 0} and the average cost by time unit is Taking x for all i ∈ S, we have for each x > 0: Authors propose another iterative procedure to obtain the optimal inventory policy with the calculus of the minima of C S (x).So, the minimum value of C S (x) is where A cost game (N, c) can be associated with every system as proposed.It is given by c(S) := C S (x * S ) for all S ⊆ N. When agents in N cooperate in (N, a, c 1 , c 2 , {b i , d i , K i } i∈N ), the GR-rule allocates, for i ∈ N: In order to summarize the assumptions on the described models in this section, Table 1 relates them with the associated cost game and the allocation rule proposed for each case.

Inventorymodel in practice
This section presents an overview of the structure of the package.Inventorymodel is a tool for calculating the optimal policy in several inventory situations and for allocating the collaboration costs among the agents involved in the process.This software helps the user to determine faster the optimal policy when the number of agents increases.Remark that these functions only automatize the required operations for the calculus of the optimal costs under theses scenarios although the computational complexity still maintains. 3rdering costs Variable ordering costs Holding costs Shortages Table 1: Summary of assumptions, cost games, and allocations rules.
Inventorymodel package includes several functions that enable users to determine the optimal inventory policy for the inventory models decribed in previous section.Moreover, auxiliary functions are implemented to obtain some intermediate values in the calculation.This package has as dependencies e1071 and GameTheoryAllocation packages of which takes some functions in its calculations.The last one, in a primitive version, includes some generic functions related to game-theoretic concepts.The functions incorporated in the package are briefly described in Table 2.

Function Description coalitions
Function to obtain all possible coalitions with n players.

EOQ
Function to calculate the optimal policy and costs in an EOQ model (2).

EOQcoo
Function to calculate the optimal policy and associated cost game in an EOQ model when n agents cooperate (2).

EPQ
Function to calculate the optimal policy and costs in an EPQ model (4).

EPQcoo
Function to calculate the optimal policy and associated cost game in an EPQ model when n agents cooperate (4).inventorygames Function to determine the associated cost game in an EOQ (2) or an EPQ (4) model.inventorymodelfunction Main function to obtain the optimal policy by selecting any model and its parameters.linerule Function to obtain the line-rule allocation (7) for an inventory transportation system (6) when a coalition N is formed .linerulecoalitional Function to obtain the line-rule allocation (7) for an inventory transportation system (6) for each possible coalition.marginal_contribution_mean Intermediate auxiliary function to calculate the mean of the marginal contributions for a set of permutations.mct Function to obtain the costs in a basic EOQ system without holding costs and with transportation cost (10).mfoc Function to obtain the associated costs in a fixed order cost model (8).mwhc Function to obtain the associated costs in a model without holding costs (14).mwhc2c Function to obtain the associated costs in a model without holding costs and with two different costs of a product ( 16).mwhcct Function to obtain the associated costs in a basic EOQ system without holding costs and with a general transportation cost (12).shapley_mfoc Function to calculate the Shapley value (9) for the associated game in a fixed order cost model ( 8).

SOC
Function to obtain the allocation proposed by the SOC rule (5) under an EOQ/EPQ model, see ( 2) and (4).

STI
Function to obtain the optimal orders and associated cost in inventory transportation systems (6).

STIcoo
Function to obtain the optimal orders and associated cost when n agents are cooperating in the inventory transportation system (6).twolines Function to calculate the allocation proposed by the two-lines rule (11) in a basic EOQ system without holding costs and with transportation cost (10).Users can obtain the optimal inventory policy in each case by introducing the associated parameters to each model in the corresponding function.Table 3 describes the different options to define the inventory models included in Inventorymodel.However, not all of the mentioned options are necessary since only some of them are specific for each inventory situation.Additionally, the function coalitions takes, as a unique argument, the integer variable n (the number of involved agents) to calculate all possible subsets of the set of N. The auxiliary function marginal_contribution_mean allows the calculation of the average of the marginal contribution vectors for some indicated permutations.Therefore, it only needs as arguments a matrix with the permutations to study (permute) and a vector that contains the characteristic function with associated cost values for each possible coalition in a set of agents N (costs).

Examples of application
Several examples of application of the Inventorymodel package are used to illustrate its performance in the different contexts considered.After installing the package from CRAN, as an initial step a user should load the package in the R Console: > library("Inventorymodel") Below, in order to illustrate the performance of those functions which determine the optimal order and the associated cost game, we consider examples extracted from the references.In this situations, The R Journal Vol.Optimal shortages 1 2 3 0.000000 0.000000 0.000000 9.359019 0.000000 0.000000 0.000000 9.054699 0.000000 0.000000 0.000000 6.172134 5.310381 7.455973 0.000000 5.654318 0.000000 4.918359 0.000000 6.700683 4.151265 The output is a list which contains as a first element a data frame with optimal orders and the associated costs, and a data frame where the optimal shortages by agent are depicted for the different coalitions.
The calculation of the SOC rule (5) in the abovementioned example for the EOQ problem completes this evaluation.To conclude, we use the SOC function to obtain this allocation (as a numeric vector).

The inventory transportation systems in R
To evaluate the performance of the inventory transportation systems in R, we consider the example depicted in Fiestras-Janeiro et al. (2012).Let N = {1, 2, 3} be a set of three involved agents, with a = 200 as the fixed cost of a new order.The remainder of the data are detailed in Table 6 The function STIcoo allows the determination of the optimal policy for each possible S ⊆ N in this inventory situation.Its result is shown below in terms of the number of orders and its associated costs (6).

The inventory problems with no-holding costs and shortages in R
The EOQ system without holding costs and shortages in R is evaluated using the example taken from Fiestras-Janeiro et al. (2015).In that case, a = 180, and the rest of the necessary data in the model are given in Table 10.
The R Journal Vol.10/1, July 2018 ISSN 2073-4859 All examples dealt with in this section can be evaluated with inventorymodelfunction by introducing, for each case, the corresponding character chain for the associated model and its parameters (see Table 3

Computing time
To illustrate the time required by the different functions in the R package Inventorymodel, we performed the following simulations with artificial data.We generated, according to a uniform distribution, 100 samples of the involved parameters in the functions included in the package for values of n from 3 to 10.
For each sample, we evaluate the available functions.All the computations included in this paper have been performed on a personal computer with Intel(R) Core(TM) i5-4210U and 8 GB of memory using a single 2.40GHz CPU processor.The results of the evaluations for all samples are depicted in Tables 12 and 13, where the values are reported in seconds.EOQcoo 0.00 0.00 0.00 0.00 0.00 0.00 0.02 0.00 EPQcoo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 STIcoo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.04 mfoc 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 mct 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.01 mwhc 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.01 mwhc2c 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 mwhcct 0.00 0.00 0.00 0.00 0.00 0.02 0.00 0.01 We can observe that the runtime is mainly affected by the number of agents.As we expected, as the procedure is based on the subsets of N, the dimension of the characteristic function determines the runtime required for its calculation.In view of Tables 12 and 13, it is easy to check that when n increases, the computing time increases too.However, in most of cases, it does not exceed ten seconds of running time for all computation.Only in seven situations the computing time is bigger (without exceeding a minute).

Conclusions
This paper discusses the implementation in R of several procedures to calculate the optimal policy in different inventory situations from using game theory results.Mechanisms to allocate the collaborating costs among the agents have been incorporated as well.Thus, the Inventorymodel package provides R users a set of functions to determine the optimal costs in different situations defined in the literature: with holding costs, with costs by the transport of a new order, with shortages, and with different prices of a unit of purchased and produced products.When the number of agents increases, these calculations become computationally more complicated since that the number of possible groups of agents considerably enlarges.Future research and development plans for forthcoming versions of the package include the addition of new inventory models that can be dealt with in the framework presented above and the inclusion of alternative procedures in order to reduce the computational complexity present in this class of problems.
Below, the assumption of a general transportation cost function is introduced in the previous model.Saavedra-Nieves et al. (2018) analyse the EOQ systems without holding costs and with general transportation costs, a generalization of the basic model with transportation costs proposed inFiestras- Janeiro et al. (2014).
and c b (S) = A(S) max j∈S { d j K j } for each S ⊆ N.For every system as the proposed, Saavedra-Nieves et al. (2018) introduce the following allocation.
.8571 For this class of problems, when N agents cooperate, the allocation proposed by the two-lines rule (11) for the dealt example is obtained by the function twolines: > twolines(n = 3, a = 400, av = c(300, 500, 200), d = c(2, 2, 5), K = c(9, 8, 7)) MCT model Cooperative case Two-lines rule [1] 0.0000 219.6429 423.2143 4 . (2012), the inventory transportation systems are defined as a new approach of the EOQ problem when individual transportation costs by a new order are taken into account.The line-rule allows us to allocate the costs generated by the joint order in these situations.This model is generalized in Saavedra-Nieves et al. (2018), where a general function of transportation costs is considered and an extension of the line-rule is proposed.Fiestras-Janeiro et al. (2014) describe two EOQ models with no holding costs: a basic model and a model with transportation costs.The Shapley value and the two-lines rule are the chosen allocation procedures for sharing costs in this class of situations.Fiestras-Janeiro et al. (2015) introduce a cooperative multi-agent inventory model, where the holding costs are negligible and shortages are allowed.Saavedra-Nieves et al. (2018a) introduce a variant of the previous model by considering that shortages are cheaper than the original product.For these models, two rules are proposed to allocate the collaborating costs.Apart from those mentioned above,

Table 2 :
Summary of functions in the Inventorymodel package.
The R Journal Vol.10/1, July 2018 ISSN 2073-4859 Table4summarizes the required arguments in the specific function associated with each inventory model.Examples of usage for the implemented functions are described in the next section.The possible values are "EOQ" (EOQ), "EPQ" (EPQ), "STI"(the inventory transportation systems), "FOC" (the fixed order cost model), "MCT" (the basic EOQ system without holding costs and with transportation cost), "MWHC" (the model without holding costs and shortages), "MWHC2" (the model without holding costs and two acquisition costs), and "MWHCCT" (the EOQ system without holding costs and with general transportation costs).nAnintegerspecifying the number of agents involved in the inventory model.It corresponds to the cardinality of the set N. aA real number that indicates the fixed cost per new order.avAvector of dimension n that contains, in each component, the transportation costs associated with each agent i ∈ N. dA vector of dimension n that contains, in each component, the deterministic demands per time unit associated with each agent i ∈ N. hA vector of dimension n that indicates, in each component, the holding costs per product unit associated with each agent i ∈ N. mA vector of dimension n that indicates, in each component, the number of orders m i associated with each agent i ∈ N.These values are necessary only when information about demands is unknown.rAvector of dimension n that contains, in each component, the replacement rate of a product associated with each agent i ∈ N in a EPQ model.In general, it verifies r i > d i .KA vector of dimension n that details, in each component, the warehouse capacity of the product associated with each agent i ∈ N. bA vector of dimension n that details, in each component, the cost by shortage unit of the product associated with each agent i ∈ N. c1A real value with the acquisition cost of one unit of the purchased commodity.c2Areal value with the acquisition cost of one unit of the produced commodity.cooperation A variable that indicates if cooperation is considered.If it exists, cooperation=1, else cooperation=0.allocation A variable that indicates if the defined allocation in each case is required.If it exists, allocation=1, else allocation=0.

Table 3 :
Summary of arguments for functions in the Inventorymodel package.

Table 6 :
. Distances to the supplier, demands, and individual holding costs.

Table 9 :
Transportation costs function A for each S ⊆ N.

Table 13 :
User time (in seconds) for 100 computations using Inventorymodel and for several values of n.