Abstract
Marketplaces bring together products from multiple providers and automatically manage orders that involve several suppliers. We document the use of Answer Set Programming to automatically choose products from various warehouses within a marketplace network to fulfill a specified order. The proposed solution seamlessly adapts to various objective functions utilized at different stages of order management, leading to cost savings for customers and simplifying logistics for both the marketplace and its suppliers.
Introduction
E-commerce has revolutionized the retail landscape, establishing the Internet as the primary platform for purchasing a wide range of goods [27]. Numerous recent studies address computational challenges associated with e-commerce logistics [11, 31]. In its early stages, e-commerce primarily centered around business-to-consumer (B2C) transactions, with a primary focus on online stores promoting and selling their own products. Nowadays, marketplaces of varying scales and catering to diverse commercial sectors are emerging, elevating e-commerce to a more lucrative level [25]. Indeed, a marketplace offers a unified perspective on products sold by various suppliers and housed in different warehouses. This capability empowers end-users to fulfill orders that might be impractical through any single supplier alone. The marketplace assumes the responsibility of coordinating the affiliated suppliers to ensure the provision of products requested in a customer’s order. Furthermore, the marketplace platform manages the business-to-consumer (B2C) transaction linked to an order and subsequently handles the business-to-business (B2B) transactions with the suppliers. This simplifies a crucial financial aspect of online sales.
Building a profitable marketplace platform poses various challenges, primarily attributed to the growing complexity of the supply chain. Despite the challenges, marketplaces are gaining widespread popularity, and as of 2022, they represented more than half of the total global e-commerce sales. Considering the substantial financial stakes, optimizing the distribution chain can result in noteworthy cost savings. Primarily, a marketplace must monitor the inventory of multiple suppliers to enable end-users to create valid and eligible orders. Considering that the same product may be offered by different suppliers, an eligible order can be fulfilled by shipping products from various suppliers. Hence, a sensible criterion is needed to determine which suppliers should be engaged in handling an eligible order. Determining the objective function is crucial. One option is to minimize end-user expenses, prioritizing cost-effectiveness. Alternatively, streamlining the logistic processes within the marketplace could be the focus. Additionally, considering the logistic aspects for suppliers is another important consideration. The choice depends on the overarching objectives and priorities of the marketplace.
In this article, which extends our previous work [6] presented at the 26th International Symposium on Practical Aspects of Declarative Languages (PADL24), we consider the setting of the oliveru.comoliveru.com marketplace and some of its logistic problems. In the examined marketplace, suppliers showcase products with prices that have been mutually agreed upon with the platform. Every supplier ensures synchronization of their warehouse inventory with the marketplace platform, allowing end-users to assemble eligible orders. Furthermore, each supplier provides the option to waive shipping fees if the total cost of the products to be shipped meets a specified threshold, a threshold determined by the respective supplier. To enhance the marketplace’s appeal to end-users, the total cost of a composed order is minimized by strategically distributing the order among suppliers with lower shipping fees. This approach aims to capitalize on available opportunities for free shipping whenever possible. The total cost is continuously updated with each addition or removal of a product to ensure a seamless user experience. Consequently, the optimization task needs to be accomplished with minimal computational effort to maintain a pleasant user experience. Prior to finalizing the order, the platform verifies the estimated cost and provides the end-user with information regarding the number of shipments required to distribute the requested products. This information is derived by tackling a slightly more intricate combinatorial problem. It selects, among solutions with the same minimum cost, those that streamline the marketplace logistics to the greatest extent possible. This involves opting for solutions that minimize the number of involved suppliers. After the end-user has paid for the order, the platform engages a broader combinatorial problem. The objective is to further optimize and streamline the logistics of the involved suppliers, specifically by minimizing the number of warehouse–product pairs involved in the process. This way, the marketplace platform provides benefits to both end-users and suppliers, contributing to the overall success of its business.
The combinatorial problems tackled by the examined marketplace are formally defined and addressed through Answer Set Programming (ASP) specifications (see [21, 24]. ASP has demonstrated success in numerous planning and scheduling applications, as evidenced by studies such as [13, 17]. Its effectiveness is attributed to a rich set of linguistic constructs that facilitate the representation of intricate knowledge. Additionally, the availability of efficient engines for automated reasoning, as highlighted in [5, 16], contributes to its utility. Actually, a small fragment of ASP is sufficient to empower the proposed specifications. The problem prototyping was accomplished using ASP CHEF [4], a straightforward and user-friendly web application for analyzing answer sets. It is specifically designed to facilitate the creation of pipelines of operations over sequences of interpretations. An experiment, conducted to evaluate the quality of the developed specifications, compares solutions obtained using ASP with those obtained through a greedy algorithm. ASP not only yields significantly superior performance but also offers the flexibility to uniformly address all three combinatorial tasks of interest. The experiment is further elaborated by incorporating an alternative solution implemented using MINIZINC [29]. MINIZINC is a solver-agnostic modeling language designed for defining and solving combinatorial satisfaction and optimization problems.
The remainder of this article is structured as follows. Section 2 introduces the required background on ASP. Section 3 formalizes the analyzed problem (Section 3.1), its complexity (Section 3.2), and how to address it in ASP (Section 3.3). After that, Section 4 reports on the implementation of the proposed solution and its empirical assessment: the ASP implementation is described in Section 4.1; the greedy algorithm used as baseline is reported in Section 4.2; the empirical assessment is detailed in Section 4.3; an additional comparison with an alternative implementation in MINIZINC is given in Section 4.4. Finally, Section 5 discusses recent literature regarding e-commerce marketplaces, and Section 6 concludes the article.
Background
We adopt a restricted syntax in which aggregates solely appear in (weak) constraints, and all other rules take the form of choice rules aimed at selecting exactly one atom. The language fragment is associated with decision tasks in the complexity class
A constant is any natural number in
A (rule) body is a conjunction of atoms, intervals and aggregates. An (exactly-one) choice rule has the form
Variables of different rules are distinct (even if they share the same string representation). Global variables of a rule are those occurring in at least one atom of its body and those on the left-hand-side of an interval of its body. Global variables are (virtually) expanded by substituting them with constants, in all possible ways. Any remaining (local) variable inside an aggregate of the form (1) or in a head of a choice rule of the form (2) is safe if it occurs in at least one atom or left-hand-side of an interval in conj. Any remaining variable in weak constraints (in squared brackets) is unsafe. Only programs with safe variables are considered here. An expression (term, atom, interval, and so on) is ground if all its terms are constants. Let expand(E) be the set obtained by expanding an expression E.
An interpretation I is a set of ground atoms. Variable-free terms are interpreted independently by the chosen interpretation as follows: I (c) = c if
This section starts by formalizing the problem introduced in Section 1 (see Section 3.1) and shows its
Problem formalization
The input includes the following elements: a set P of products, i.e., the integer interval [1 . . |P|]; a set W of warehouses, i.e., the integer interval [1 . . |W|]; a function a function a function a function
a function
The goal is to select the requested amount of products from warehouses (i.e., computing a function
Note that (8) involves warehouse 3 without reaching the threshold for waiving its shipping fee, while (9)–(11) benefit from completely free shipping. Additionally, (10)–(11) also minimize the number of warehouses involved. Finally, (11) also minimizes the number of warehouse–product pairs involved. ■
We provide a reduction from Partial Weighted MaxSat [12], hence establishing

Gadgets used in the reduction from PARTIAL WEIGHTED MAXSAT:
Let ∞ be the ∑
j
w (x
j
) + 1 (an integer larger than the sum of all weights). We fix functionproduct_request to the constant 1, and function shipping free threshold to the constant n + 2. We associate each variable x
j
with products P
x
j
, P+x
j
, and each clause γ
i
with one product P
γ
i
. Variable x
j
is also associated with three warehouses, namely W
x
j
, W¬x
j
and W+x
j
. Let
There is a one-to-many mapping from assignments satisfying Γ and selections with shipping cost smaller than ∞. Let I : vars (Γ) → {0, 1} satisfy Γ. We select P x j from W x j if I (x j ) =1, and from W¬x j otherwise, obtaining in any case free shipping from the used warehouse. Since I satisfies Γ, for each γ i there is (at least one) ℓ ∈ γ i such that I (ℓ) =1; we select P γ i from Wℓ (for one of such ℓ). Finally, we select P+x j from W x j if I (x j ) =1 (as W x j is already used), or from W+x j otherwise (paying the shipping fee w (x j ). We have that the total shipping cost is ∑ j w (x j ) · (1 - I (x j )).
To complete the proof, we observe that any assignment not satisfying Γ maps to a selection using both W
x
j
and W¬x
j
for at least one j: Let γ
i
be unsatisfied by I. Product P
γ
i
must be selected from some Wℓ such that ℓ ∈ γ
i
, but since I (ℓ) =0 we also use
■
Given the formalization of the problem presented in Section 3.1, it is natural to develop an ASP encoding for the computation of optimal solutions for instances of the problem. Products in P and warehouses in W are identified by constants. The input is encoded by the following facts:
The encoding of the instance from Example 5 is shown in Fig. 2. The output is encoded by facts

ASP representation of the instance from Example 5
The code snippet presented in Fig. 3 encapsulates the necessary conditions. Specifically, it relies on the @-term

ASP encoding to select products from warehouses
This section provides a few details on the implementation of a prototype addressing the computational tasks formalized in Section 3, and its empirical assessment. Specifically, the main development steps are summarized in Section 4.1, which also describes some technical details of the implementation and its prototyping in ASP CHEF [4]. After that, Section 4.3 delves into the experimental design, outlining the objective and metrics guiding our evaluation. The conducted experiments aim to assess the performance and efficacy of the proposed method using a greedy algorithm as baseline (introduced in Section 4.2). Finally, Section 4.4 presents an alternative implementation of our formalization in MINIZINC [23], and extends the empirical analysis accordingly.
ASP implementation
The ASP encodings presented in Section 3.3 were fast prototyped creating a recipe with ASP CHEF [4]. Figure 4 shows the interface of ASP CHEF and the first ingredients of a recipe addressing the marketplace logic tasks analyzed in this article. (Recipe and Example 5 available on https://asp-chef.alviano.net/s/marketplace@IA2024https://asp-chef.alviano.net/s/marketplace@IA2024.) The window is split in two columns, where input and output are placed on the right panel and the recipe on the left panel. Below is a brief description of the recipe shown in Fig. 4.

First eight ingredients of an ASP CHEF recipe stacking solutions for the three marketplace logistic tasks analyzed in this article. The instance in input is the one introduced in Example 5.
are used to produce facts representing the products and warehouses in the given instance using the values provided in the first row of the CSV.

A snippet of code to produce a table representation of input instances

Stacked representation provided by ASP CHEF of the input (a) and solutions (b)–(d) for the instance from Example 5.
Before the last visualization,
Sub-optimal solutions of the problem formalized in Section 3.1 can be obtained by Algorithm 1. It is a greedy algorithm that iteratively selects a warehouse maximizing the number of requested products available within its supplies. This process continues until all requested products are covered by the selection. In more detail, the algorithm constructs a select function with the signature Each warehouse is assigned a utility value, which is the number of requested products available within its supplies (lines 2–3). A warehouse w with the maximum utility is selected (line 4), and the maximum quantity of requested products is taken from w (lines 6–10). If no new products are covered by w, the algorithm terminates, reporting the inconsistency of the input instance (line 5).
Note that each warehouse is selected at most once, given that its product supply is updated by line 9, rendering its utility value 0 for the next iteration.
Algorithm 1 finds an admissible solution if one exists, but cannot guarantee its optimality, as shown by the above example. For another example, consider a trivial instance with only one unit of product 1, whose cost is 1. Product 1 is available in warehouses 1 and 2, whose thresholds are respectively 1 and 2. The algorithm cannot distinguish between 1 and 2, so it possibly selects warehouse 2, failing to obtain free shipping (which is instead possible if warehouse 1 is selected). For yet another example, consider an instance with one unit of product 1 and one unit of product 2, whose costs is 1. Product 1 is available in warehouse 1, and product 2 is available in warehouse 2; both warehouses have threshold 1. There is a third warehouse with both products, whose threshold is 3 (unreachable), and the algorithm eventually selects this third warehouse, failing to obtain free shipping (which is instead possible if warehouses 1 and 2 are selected). Moreover, the algorithm cannot guarantee the inclusion of a minimal number of warehouses or pairs of warehouse–product in the computed solution. Consequently, the more sophisticated objective functions defined in Section 3.1 are beyond its capabilities. Nonetheless, it can serve as a baseline for more sophisticated algorithms.
Empirical assessment
The most common scenario for the oliveru.comoliveru.com marketplace involves end-users purchasing no more than 10 different products, typically with a single unit per product. However, for the experiment, much larger instances were generated. These instances included a random number of products ranging from 1 to 20, each with a random multiplicity in the range of 1 to 20. The number of warehouses was randomly chosen between 1 and 20, and the available products within each warehouse were randomly selected from the range of 1 to 20. A total of 10000 instances were generated for the experiment. The generated instances were processed using CLINGO (version 5.6.2) with the activation of the unsatisfiable core analysis algorithm K [3] along with reiterated geometric search unsatisfiable core shrinking [2] (command line:
The experimental results are presented in Fig. 7. Firstly, it is observed that the greedy algorithm completes in less than 0.01 seconds for all tested instances, while running the ASP encodings Π$, Π$W, Π$WP takes approximately 0.04s, 0.05s, and 0.07s on average, respectively. Furthermore, 804 out of the 10,000 generated instances do not have feasible solutions, and their statistics are depicted on the rightmost positions in the plots. It is noteworthy that CLINGO identifies the inconsistency with negligible effort. The other plots in Fig. 7 quantify the quality of the computed solutions. Concerning the shipping cost, all ASP encodings yield the same result, and thus, we focus on Π$. Interestingly, the shipping cost is frequently 0, indicating that shipping fees are correctly waived when feasible. Regarding the number of warehouses involved, Π$W and Π$WP yield the same result. Hence, we focus on Π$ and Π$W, along with the greedy algorithm. It is evident that the greedy algorithm prioritizes minimizing the number of warehouses involved rather than minimizing the resulting shipping cost. Nevertheless, activating the weak constraint of level 2 significantly reduces the number of warehouses involved, aligning them with the small number obtained by the greedy algorithm while maintaining the minimum shipping cost. A similar observation is applicable to the number of warehouse–product pairs involved in the process. The greedy algorithm performs well, and ASP slightly improves upon this baseline by activating the weak constraint of level 1 (i.e., program Π$WP).

Experimental results comparing the greedy algorithm and CLINGO running algorithm K (bar plots with instance number of the x-axis).
We ran CLINGO a second time without activating the unsatisfiable core analysis, that is, using the default configuration of the solver [15]. In this case, CLINGO implements a linear search sat-unsat that iteratively improves the latest computed solution by imposing a constraint on the admissible value of the objective function, until the unsatisfiability of the processed instance is proved (witnessing that the latest computed solution is optimal). The results are shown in Fig. 8. It can be observed that algorithm K is usually faster than the default configuration on the tested instances. The gap between the two settings is more evident for program Π$WP (Fig. 8b), for which the default configuration leads to 2373 timeouts. Even if we have not registered any timeout for programs Π$W and Π$ (Fig. 8a), we note that the performance of CLINGO is improved in around 48% of the tested instances, and worsened in around 36% of the cases; algorithm K provides a more sensible particular gain on program Π$ (5808 times faster than the default configuration, and only 1175 times providing some negligible overhead). All in all, we conclude that running CLINGO with its default configuration is not aligned with the requirements of the marketplace.

Execution time of CLINGO using its default configuration or algorithm K; time bounded to 3 seconds in (b). For Π$ and Π$W, the result is mixed but in favor of algorithm K: in (a) the majority of points is above the dashed line, and specifically the number of wins is 5808 vs 1175 (Π$) and 3789 vs 2474 (Π$W) in favor of K. The result is more uniform and in favor of K for Π$WP, as shown in (b), even if there are some exceptions: the number of wins is 8226 vs 534 in favor of K.
Constraint Satisfaction is a Knowledge Representation and Reasoning (KRR) formalism at the core of many applications in Artificial Intelligence [30]. A (finite-domain) Constraint Satisfaction Problem (CSP) can be expressed in the following form: Given a set of variables, together with a finite set of possible values that can be assigned to each variable, and a list of constraints, find values of the variables that satisfy every constraint [8]. Many combinatorial problems, such as scheduling, timetabling and resource allocation, can be formulated as CSPs. Some of these problems involve an objective function to minimize or maximize, leading to the definition of Constraint Satisfaction and Optimization Problem (CSOP). MINIZINC is a solver-agnostic modeling language for defining and solving CSPs and CSOPs. MINIZINC provides a solver-independent modeling language that is supported by several constraint-programming solvers, mixed integer programming solvers, SAT and SAT modulo theories solvers, and hybrid solvers [29]. In MINIZINC, the declarative specification for a problem is encoded in a file that takes the name of model file (or simply model). A typical model file includes the following elements: directives to define the format of the instances of the addressed problem, that is, the parameters of the problem; statements to define the search space, that is, variables and their domains; one solving instruction, possibly paired with an objective function. Instances of a problem are then written in files that take the name of data files. A data file contains assignments for all parameters of the associated problem.
The MINIZINC model

A MINIZINC model (referred to as

MINIZINC data file for the instance from Example 5 and model
To the best of our knowledge, MINIZINC does not support any syntactic construct to specify multi-level optimization. A simple and common strategy to address multi-level optimization in MINIZINC is by first obtaining the optimum value of the top level with one model, and then use such an optimum value in a second model targeting solutions that optimize the next level. The process is reiterated until there are no more levels to optimize. Following such a strategy, we defined the MINIZINC model

Lines 1–25 of model

Lines 1–50 of model
We ran the three MINIZINC models on the instances used in Section 4.3, on the same machine we ran the other experiments, using OR-TOOLS as backend (https://github.com/google/or-toolshttps://github.com/google/or-tools). All instances are solved by MINIZINC, which obtained the same optimal values of CLINGO. Our analysis is then focused on the execution time of the two solvers, which is summarized in Fig. 13. In the plots, the execution time of model

Execution time of CLINGO and MINIZINC; time bounded to 3 seconds in (a); time bounded to 1 second in (b). CLINGO is faster than MINIZINC with a few exceptions (16 wins and 9 draws) for the task of minimizing the shipping cost; in (b) the majority of points are above the dashed line.
A different view on the experimental results is given by the plots in Fig. 14. In the plots, instances are sorted by increasing the number of warehouses, products, and requested products. The whisker plots report data on the execution time of CLINGO (running K) and MINIZINC (minimum, maximum, median, lower and upper quartiles). As a general comment, execution time tends to increase with such parameters, as expected. The benefits of CLINGO are consistently spread across various groups of instances, despite MINIZINC displaying a more gradual increase in execution time for the basic objective function in our benchmark. Notably, for this specific objective function, the quartiles of MINIZINC are also more closely clustered compared to those of CLINGO. On the other hand, the fastest execution time obtained by MINIZINC is always above the upper quartile of CLINGO (in all plots).

Execution time of CLINGO and MINIZINC with instances sorted according to different criteria (whisker plots reporting minimum, lower quartile, median, upper quartile and maximum values).
The paper relates to literature which already studied the E-commerce Marketplace optimization of retail chain. Dutta et al. [14] study the need for sustainable practices in Indian E-commerce by proposing a multi-objective logistics model. It optimizes cost, environmental impact, and social responsibility in the reverse logistics network, considering various facilities and technologies. The efficiency of the E-commerce marketplace is a relevant topic from an economic and environmental point of view. Zhang and Ma [31] investigate the possibility of the supplier and the platform reaching a consensus on the implementation of the e-commerce marketplace channel through the integration of a logistics service strategy. The study identifies the significant impact of logistics service levels on consumers’ channel preferences. While suppliers are generally inclined to embrace the marketplace channel and its associated logistics responsibilities, the platform’s benefit depends on the effectiveness of logistics service or commission rates. However, the authors do not consider any specific optimization in the delivery and logistic of the solution. Qin et al. [26] analyze the dynamics of logistics service sharing within e-commerce platforms, where the platform extends marketplace services to sellers in addition to its retailing function. The study conducts a strategic and economic analysis of this sharing arrangement. Results indicate that the outcome of logistics service sharing hinges on factors such as the service level of third-party logistics service providers (TPLPs) and the market potential. Kumar and Mahapatra [19] leverage the Rain Optimization Algorithm (ROA) designed by Moazzeni and Kamehchi [22] and addresses the challenge of item deterioration in inventory management, focusing on non-instantaneous items. Specifically, this research incorporates a multi-warehouse setup, with one owned warehouse and others rented, each with limited storage capacity. The primary objective is to determine retailers’ replenishment policies that maximize total profit for each item while minimizing overall costs.
The order splitting problem (also known as split delivery) means that multi-item orders are split into several suborders fulfilled by multiple warehouses separately. The suborders are packed in different packages and delivered with multiple shipments. Order splitting is becoming particularly prominent for large-scale online retailers with the multi-item order feature. The problem of split orders in retail is of particular relevance in the E-commerce Marketplace due to the nature of the business model itself. It has become a great challenge to online retailers for fulfilling multi-item orders in a multi-warehouse storage network. A split order entails additional cost for the retailed that certainly are reflected on the cost of the goods. Zhang et al. [32] presents a multi-warehouse package consolidation approach aimed at consolidating multiple suborders’ stock-keeping units (SKUs) through transshipments among warehouses. They propose a combined multi-commodity network flow model and an enhanced logic-based Bender’s decomposition algorithm to effectively generate schemes for the multi-warehouse package consolidation problem. Lei, Jasin and Sinha [20] consider a multi-period joint pricing and fulfillment (JPF) problem where an e-commerce sells multiple products to customers coming from multiple demand locations and demands are fulfilled in real-time through multiple fulfillment centers. They propose a tractable deterministic approximation for the problem to maximize the total expected profits. Catalán and Fisher [11] introduce the problem of assigning stock-keeping units to distribution centers to minimize split orders. Specifically, the research investigates the problem of shipping products from different suppliers and demonstrates the NP-hardness of the problem. The authors then focus on developing several heuristics mainly taking into account the average number of shipments per order and the workload distribution across suppliers, hence deviating from the objective functions of the marketplace considered in this paper. Nonetheless, extensions of the ASP specifications presented here to accommodate workload balancing and fair distribution of sales represent interesting aspects to explore.
Conclusion
ASP demonstrated effectiveness in resolving the combinatorial problems associated with the analyzed platform, particularly for instances of anticipated size corresponding to the volume of business managed by the marketplace. In addition to computational efficiency, the ASP specification presented in Section 3.3 offers a consistent solution to the three combinatorial problems under consideration. This solution is contingent on the activation of specific weak constraints. Interestingly, the standard algorithm used by CLINGO to address combinatorial optimization is not sufficient to cope with the more sophisticated objective function that also minimizes the logistic effort for suppliers. This is due to the uncontrolled improvements provided by linear search sat-unsat: the algorithm may proceed with small improvements even if currently far from optimality. Moreover, the constraint enforced by linear search sat-unsat involves all weak constraints, leading to an expensive computation that makes particularly challenging to prove optimality of the last computed solution. The observed inefficiency was quickly fixed by switching to the unsatisfiable core analysis algorithm K with reiterated geometric search unsatisfiable core shrinking. Within this algorithm, the search directly targets optimality, actually building a proof of optimality during the whole search rather than as a final step. (We refer [1, 3] for details on the algorithm.) The assignment of products generated for delivery from each warehouse can be further optimized in the realm of in-warehouse logistics. For instance, in an automated warehouse scenario, there would be a necessity to compute a collision-free schedule of robot movements and actions to efficiently deliver all the required products (we refer [28] for details).
Acknowledgment
This work was partially supported by Italian Ministry of University and Research (MUR) under PRIN project PRODE “Probabilistic declarative process mining”, CUP H53D23003420006 under PNRR project FAIR “Future AI Research”, CUP H23C22000860006, under PNRR project Tech4You “Technologies for climate change adaptation and quality of life improvement”, CUP H23C22000370006, and under PNRR project SERICS “SEcurity and RIghts in the CyberSpace”, CUP H73C22000880001; by Italian Ministry of Health (MSAL) under POS projects CAL.HUB.RIA (CUP H53C22000800006) and RADIOAMICA (CUP H53C22000650006); by Italian Ministry of Enterprises and Made in Italy under project STROKE 5.0 (CUP B29J23000430005); by the LAIA lab (part of the SILA labs) and by GNCS-INdAM.
Disclaimer
The contents of this document represents the views of the authors only and are their sole responsibility; it cannot be considered to reflect the views of the European Commission and/or the Joint Research Centre (JRC), or any other body of the European Union. The European Commission and JRC do not accept any responsibility for use that may be made of the information it contains.
Footnotes
https://asp-chef.alviano.net/s/marketplace-show-astable@AI2024
