1 Introduction

Today, organizations seek to take advantage of the benefits of proper supply chain management to maintain their position in the market, create a competitive advantage and reduce costs, and generally improve the efficiency of their supply chain. Decision-makers and managers may have strategies in place to stay alive in this condition, but the favorite result will only be achieved if an accurate and comprehensive plan is used. Therefore, a detailed network design and principled supply chain planning with all levels and units in mind to increase the efficiency of the entire supply chain seem necessary (Delgoshaei et al., 2021; Tirkolaee et al., 2022a, 2022b).

Return products management, on the other hand, is a complex issue that requires decision-making at the strategic and operational levels. Problems that need to be addressed at the strategic level include determining the type of facilities needed and their location, the volume of recyclables that can be controlled or planning the flow of recycling materials (Khalilpourazari et al., 2021; Rahbari et al., 2022). On the other hand, issues related to operational planning include issues such as the time interval between recycling collection times, the number and capacity of vehicles, the relevant routing issue, and the number of workers required. Despite the close relationship between these two types of decisions, their analysis and review are usually done separately. Strategic decisions often have to be answered through political and governmental issues, while operational decisions need to be considered at lower levels, such as at the municipal level. Therefore, issues related to recycling management should be considered in the case study of different types of products in different locations (Cheraghalipour et al., 2020; Tirkolaee et al., 2021).

Reverse logistics and closed-loop supply chains are some of the most important and vital aspects of any business and include the construction, distribution of services, and support for any type of product. In developed countries today, industrial, governmental, commercial, and service organizations focus on reverse logistics processes and supply chain, which play an important role in creating the true economic value of goods and services while supporting environmental considerations (Ranjbar & Mirzazadeh, 2019). This focus is now increasing in all markets, including the industrial and advanced technology, commercial and consumer products sectors. Recent literature has shown that today, product returns are not only costly but also a means of creating value. Examples include preserving the environment, providing core resources, and increasing customer value. That potential revenues are usually greater than the costs incurred to create the necessary measures for return channels (Krikke et al., 2013; R. Lotfi et al., 2022).

On the other hand, agricultural products are one of the most important elements of the food basket of the people of the world. Iran is one of the first countries in the world where agriculture has started. According to the statistics of the ‘Iranian Agricultural Jihad,’ about one-third of Iran’s land is agricultural, but due to poor soil and inadequate water distribution in most areas, only 12% of Iran’s land is cultivated (including gardens, vineyards, and agricultural lands). 63% of arable land is still intact. In Iran, 50–60% of the capacity and talent of the lands under agricultural operations (185,000 square kilometers) are used. Iran's arable land is estimated at sixteen million hectares, of which about half is irrigated and the other half is rainfed (Agriculture Jihad, 2016). The agricultural supply chain today has a very important role in supply chain issues because of its unique structures such as the significance of food features, climate change, price changes, and the importance of supply–demand. In the classification of these topics, products are divided into two categories of perishable and non-perishable (such as grain and dried products). Also, in terms of the life cycle, they are divided into two categories: agricultural and horticultural crops (Cheraghalipour et al., 2018).

In recent years, the importance of the issue of agricultural products has grown significantly with increasing demand from concerned customers for a healthy diet (Weber et al., 2015). This has made quality and availability two important issues in all months of the year (Paksoy et al., 2012). In the last 10 years alone, the agri-food industry in general and the fresh fruit sector, in particular, have been recognized and discussed in the supply chain as a key concept for competitiveness (Tsolakis et al., 2014). Numerous studies have addressed and covered the issue of agricultural supply chain issues; but in our research, we found a research gap in the reverse logistics of products, a big problem that causes a lot of damage to this chain every year. This problem, which is the decay of products, is covered in the reverse logistics section of our proposed network. Since a significant number of manufactured products in the stages of production, distribution, target markets, etc., are decayed and unusable, it is felt that to reduce the costs of these wastes and reuse them, it is necessary to develop and analyze a closed-loop supply chain network design model (Tirkolaee et al., 2022a, 2022b). It is very necessary and important to consider these concepts together.

In recent years, the design of the logistics network in the supply chain has become more important than in the past. Considering the issue from the perspective of several decision-makers, issues related to returned products, and the production of added value such as compost and biogas in the supply chain are of great importance today and have attracted the attention of many researchers. For this purpose, sufficient explanations will be provided in the present research. This study tries to develop a practical model for designing an agricultural supply chain network as much as possible, taking into account the limitations of the real world. Therefore, considering the waste and corrupted products in the agricultural supply chain, it will provide a network to collect these returns to reduce the costs of the chain and generate potential revenues from them. For this purpose, an eight-echelon network is designed for the agricultural supply chain. The suppliers are the first echelon. Farms are the second echelon to produce crops. In the third echelon, some DCs buy agricultural products from farms and send them to customers in the fourth echelon after processing. It should be noted that this network has been in operation for multiple periods, so in echelons 2–4, some of the products will become waste. These waste materials are transported to the fifth echelon for the depot, and according to management decisions, some of which are transferred to biogas production (echelon 7), and some are sent to the production of biological fertilizers (echelon 6). Finally, these biogas and biological fertilizers are sent to customers in the eighth echelon and the suppliers in the first echelon, respectively. Due to the computational complexity of the large-scale real-world problems, meta-heuristic algorithms are developed. Finally, various comparisons and analyses are performed to evaluate the model’s performance and the capabilities of the solution methods. The general purpose of this study is to present a bi-level programming model and evaluate the efficiency of the closed-loop agricultural supply chain network proposed in the case study; and the special purpose of this research is to achieve an efficient method for reuse of supply chain waste in the reverse logistics sector and return of this waste to the supply chain, which will add value to this waste. This is done by making compost and biogas. To this end, two goals such as minimizing total costs and maximizing total profits are considered.

Bi-level programming problems, in the simplest form, those mathematical models for the leader and the follower are linear and their decision variables are continuous, can be converted into a MIP problem. In this case, by using the Karush–Kuhn–Tucker (KKT) conditions, the follower model can transform into a series of constraints. Then, by placing them into the constraints of the leader, a nonlinear model is created. This nonlinearity is due to the constraints of the complementary slackness. By using binary variables, these terms can be linearized to create a Mixed Integer Programming (MIP) model (Shams Shemirani et al., 2021). But this model can only be solved in small sizes, and as the number of variables and constraints of followers increases, the number of binary variables also will increase. Computational experiences have indicated plenty of computational time will be needed. In the state that the possible values for the leader’s decision variables are discrete and the number of possible states for them is not high, we can identify the optimal solution using the KKT method. If the number of possible solutions is high for the leader, then the computational time of this method will be very long and time-consuming. Moreover, the Np-hardness of the bi-level programming problems is proved in (Ma, 2016; Talbi, 2013) which is the main reason for using these metaheuristics. Because there has not been an exact method that can identify the optimal solution for a variety of bi-level optimization problems in an acceptable time, designing a method that can identify optimal or near-optimal solutions in a short time is crucial. In this paper, using metaheuristic algorithm, and concepts of bi-level optimization, we introduce some nested bi-level algorithms that can find optimal or near-optimal solutions in a variety of bi-level optimization problems. Problems in which models of leader and follower can be solved using methods of LP, NLP, MIP, and MINLP in a relatively short time.

Compared with the traditional single-level programming models, the bi-level programming models have more advantages. The main advantages are that (1) the bi-level programming can be used to analyze two different and even conflict objectives at the same time in the decision-making process; (2) the multiple-criteria decision-making methods of bi-level programming can reflect the practical problem better, and (3) the bilevel programming methods can explicitly represent the mutual-action between the system managers and the customers (Sun et al., 2008).

Besides, given the location problem of distribution centers, where distributors seek to reduce the costs of their entire supply chain, and on the other hand, biogas production centers that seek to maximize profits from the sale of biogas, this issue is placed in a bi-level programming class. Obviously, it is appropriate that the bi-level programming model is adopted to describe this proposed problem. Here two decision-makers are managers of distribution centers and biogas production centers, each with separate goals for their levels. Therefore, by analyzing the results of this study, these two decision-makers benefit more, because they can understand the behaviors of other interconnected levels and use appropriate planning to achieve the goals and interests of their organization.

In this section, the introduction and generalities of the subject, including a brief statement of the problem, necessity, and goals, were stated. Section 2 describes the literature of the subject, and at the end of this section, research gaps are expressed. In the third section, the proposed problem and model formulation are explained. Section 4 represents the solution approach. The numerical examples are reported in Sect. 5. Sections 6 and 7 represent the computational results and conclusion, respectively.

2 Literature review

This section expresses the relevant concepts and reviews the research conducted in the field of the agricultural supply chain, multi-level programming, and agricultural waste. At the end of the section, the works are summarized and categorized in the form of tables to explain the research gaps.

2.1 Agricultural supply chain

The supply chain of agricultural products today has a very important role in supply chain issues due to its unique features such as the importance of food quality, the importance of supply–demand, climate change, and price changes. As a pioneer in this field, van Berlo (1993) measured activities associated with the vegetable processing supply chain, which included the stages of planting, harvesting, processing, and marketing, and used in a mathematical model using a goal programming approach. Their model included farmer decisions to reduce chain costs and did not include location decisions. After this research, the process of using operation research in agriculture continued. For example, Jolayemi (1996) planned agricultural planning for multi-regional harvests; Allen & Schuster (2004) estimated investment and harvest to reduce crop losses using a nonlinear model in vineyards. And Rantala (2004) provided a supply chain model for seedlings that sought to minimize production and transportation costs to meet customer needs. As progress in research gradually became more advanced, additional assumptions such as product quality and shipping process were considered. For example, Ferrer et al. (2008) developed a model for deciding on harvest per season, shipping process, processing of products, and packaging in the form of a mixed-integer model (MIP) for red grapes. Their model is designed only for post-harvest planning to meet customer demand and also takes into account the cost of harvesting and reducing the quality of the product.

The expansion of problems in the agricultural supply chain is taking place with an evolutionary trend so that recently Cheraghalipour et al. (2018) developed a multi-echelon network for the citrus supply chain and using several meta-heuristic algorithms attempt to balance the chain costs and customer demand. Also, in another study, Cheraghalipour et al. (2019) sought to create a bi-level network for the rice supply chain, which reduces the cost of the chain from the perspective of two decision-makers. They used nested evolutionary algorithms to solve their proposed problem and performed management insights and sensitivity analysis on specific parameters. In addition, Anderson & Monjardino (2019) considered a kind of discount in their formulation and tried to reduce the price of wheat by using the contact structure. They validated their structure using a case study in Australia and reported that the contract was closely related to manufacturers’ risk aversion. Also, Carvajal et al. (2019) used a robust programming method for the sugarcane sector in Colombia to optimize plant profits and make several tactical and strategic decisions.

In an article, Gardas et al. (2019) added value to the present data-based industry by identifying the challenges of the agricultural supply chain in India based on a careful review of the literature and the Delphi method. Therefore, laboratory and experimental decision-making methods were used to model the identified challenges, explore cause-and-effect interactions, and improve hierarchical configurations of challenges through interpretive structural modeling. The execution of this method led to the conclusion that two elements, namely limited integration into national agricultural markets and limited agricultural market infrastructure, are the most important factors. The integrated model obtained as a result of this study aims to guide agricultural policies and decision-makers to improve the performance of the agricultural supply chain in India. There are also some basic recommendations for improving the efficiency of agricultural supply chain management.

Recently, Dai & Liu (2020) conducted an in-depth study of the supply chain risk of large retail companies and then introduced the dock of agricultural supermarkets for the supply chain in the big data environment. In this study, big data was used to analyze the potential risk in the agricultural supply chain in large retail companies. From the aspects of production, processing, distribution, retail, and consumption, this research introduces new risks in the supply chain of agricultural supermarkets after the introduction of big data. In the second stage, qualitative analysis and quantitative calculation are combined to perform the risk assessment. Through experimental analysis, the ranking of all risk factors was obtained and the corresponding fuzzy assessment grade and risk assessment criteria were given. Through expert evaluation, a new risk rating was obtained, which is not much different from the results of the experimental analysis, and the experimental results were confirmed. Therefore, the development of this study is useful to avoid the risk of connecting the supply chain of agricultural supermarkets.

Yan et al. (2020) also proposed a way to coordinate an agricultural supply chain with tactical purchaser behavior in mind. According to the characteristics of the supply chain of agricultural products, the beneficial performance of consumers was provided and under the integrated chain, this study focuses on the effect of consumer behavior on decision-making in the supply chain. Therefore, it counts the tactical activities of strategic users as a risk aversion factor and examines the effect of user risk on supply chain decision-making. Also, two coordination contracts based on income sharing and wholesale prices are designed for decentralized decision-making in the agricultural supply chain. Finally, through numerical analysis, the sensitivity analysis of some of the main parameters in the model is performed.

2.2 Multi-level programming

Multi-level programming was first proposed by Bracken & McGill (1973, 1974a, 1974b) as a generalized mathematical programming model. Then, their different models were examined and used by researchers. But in recent years, these methods and applications have been studied more seriously and extensively. The main concept of the multi-level programming method is that the upper-level decision-maker determines his goal or decision and then demands the desired limit from each sub-level, which is calculated alone. Then, the lower-level decisions are presented and modified by the upper-level according to the profit or the total amount obtained. This process continues until a satisfactory solution is reached. In these types of issues, the upper-level decision-maker does not have the authority or ability to decide on all decision variables. The design of financial management networks, transportation, and production planning are among the issues in which this method is used (Behnia et al., 2019). The general model of multi-level programming can be presented as follows (Migdalas et al., 1998).

In relation (2), P1 is known as the first-level problem and is equivalent to the upper-level in the hierarchical structure. The decision-maker at this level controls the decision variable x1 and the objective function of his level to minimize f1. Similarly, Pk is the problem of the kth level and corresponds to the lowest level of the hierarchy. If the problem consists of only two lines, it is called a bi-level programming model. In this case, the decision-makers of the upper and lower levels are called leader and follower, respectively.

Leader–follower hierarchical decision-making problems were first raised by Stackelberg (1952), which he called bi-level programming problems. These issues have two levels that the first level decision-maker implements his decision on the second level, observes the reaction of the second level, and intends to optimize his objective function. The second-level decision-maker also observes the first-level decision and makes a logical decision to optimize its objective function.

$$\begin{gathered} \left( {P_{1} } \right) \, \left\{ {\begin{array}{*{20}c} {{\text{minimize}}\,\,f_{1} (x_{1} ,x_{2} ,...,x_{k} )\,\,\,\,\,\,\,\,\,\,\,\,} \\ {{\text{subject to }}g_{1} (x_{1} ,x_{2} ,...,x_{k} ) \le 0} \\ \end{array} } \right. \hfill \\ {\text{ where }}x_{2} {\text{ solves}} \hfill \\ \, \left( {P_{2} } \right) \, \left\{ {\begin{array}{*{20}c} {{\text{minimize}}\,f_{2} (x_{1} ,x_{2} ,...,x_{k} )\,\,\,\,\,\,\,\,\,\,\,\,\,} \\ {{\text{subject to }}g_{2} (x_{1} ,x_{2} ,...,x_{k} ) \le 0} \\ \end{array} } \right. \hfill \\ \, \vdots \hfill \\ {\text{ where }}x_{k} {\text{ solves}} \hfill \\ \, \,\,\,\,\,\,\,\,\,\,\,\,\, \, \left( {P_{k} } \right) \, \left\{ {\begin{array}{*{20}c} {{\text{minimize}}\,f_{k} (x_{1} ,x_{2} ,...,x_{k} )\,\,\,\,\,\,\,\,\,\,\,\,\,} \\ {{\text{subject}}\,{\text{to }}g_{k} (x_{1} ,x_{2} ,...,x_{k} ) \le 0} \\ \end{array} } \right. \hfill \\ \end{gathered}$$
(1)

In general, the following characteristics can be provided for a bi-level programming model:

  • Each decision-maker directly controls only certain variables.

  • Different levels of decision-making are influenced by the decisions and activities of other levels, but each is trying to optimize its own decisions.

  • Upper-level and lower-level decision-makers know each other’s level goals and constraints.

  • Lower-level is required to implement upper-level decisions and implementation of decisions is from top to bottom.

  • The goals and decision-making space of each level can be influenced by other level decisions.

The bi-level programming problem is an NP-hard problem (Bard, 1991). However, due to its many applications in practice, many methods have been proposed to solve it. Methods for solving this problem can be divided into five categories, which are presented in Table 1.

Table 1 Classification of different methods for solving multi-level programming problem

2.3 Agricultural waste

Pesticides and agricultural wastes are the most dangerous contaminants in water and soil that remain in the environment for years and cause irreparable damage to life. On the other hand, effluents from the agricultural sector are one of the most harmful sources of environmental pollutants that dangerously affect the health of the environment and, consequently, the quality of citizens’ life. Agricultural waste arises from production activities in the agricultural sector, which include waste, animal carcasses, and rotten agricultural products, pesticides, and chemical fertilizers (Chávez et al., 2018). According to statistics released by the FAO, about 30% of agricultural products worldwide are turned into waste, and the value of this volume of waste is estimated at $ 5 billion per year. Iran is known as one of the leading countries in the field of agricultural waste and has a high ranking compared to other countries in the same category. Waste from dates, figs, wheat, rice, wheat bran, barley bran, tomatoes, and legumes such as green pea, beans, corn, and other crops can be good sources for reproduction. Therefore, according to the mentioned importance, agricultural waste is an important and vital issue that must be addressed and prevented from entering the environment. Therefore, this study will consider the destruction of agricultural waste from the proposed supply chain by considering the production of biogas and compost. In the following, we will review some of the research conducted in the field of agricultural waste.

Xiong et al. (2020) in a study examined the possibility of consuming agricultural waste and synthetic macromolecules as sources of solid carbon and investigated the effects of improving nitrogenating through nominated agricultural wastes. The capacity of carbon release and disinfection performance of corn, peanut shell, worn rice, and other materials were systematically analyzed. The results showed that for each carbon source, the first-order kinetic equation is fundamentally monitored during the carbon emission process. Synthetic polymers are more suitable for nitrogen removal in groundwater filtration, while agricultural wastes are ideal carbon sources for secondary wastewater filtration. Also, Fareed et al. (2020) stated that every year, as a result of energy production activities, large amounts of agricultural waste ash are produced from crop residues. The disposal of soil and ash produced has serious environmental and health problems, which are primarily due to groundwater pollution. In addition, the unavailability of land for further evacuation is another major problem associated with it. Due to the problems related to agricultural waste ash, in their study, three types of nano-agricultural waste ash were used to modify the adhesive and asphalt mixture. Rice husk ash, sugarcane stem ash and wheat straw ash were first reduced to nanoscale using a mill. These samples were then mixed with asphalt connector in terms of joint weight. Then, all samples of modified adhesive were tested from different perspectives. From the results, it can be concluded that the combination of each of the nano-waste ashes in the adhesive and asphalt mixture is a sustainable and environmentally friendly method for its disposal.

In another study, Mo et al. (2020) investigated the use of solid agricultural waste in concrete production. According to them, the increase in construction activities has led to the rapid depletion of natural resources, especially aggregates used in the production of concrete. Also, a large amount of solid waste is produced from the agricultural industry, especially from the Southeast Asian region, such as palm and coconut shells. Therefore, their study investigated the feasibility of these wastes as a potential alternative to conventional aggregates in concrete. The durability of concretes, especially those containing recycled waste, is often investigated. Therefore, their article seriously examines the published findings on the durability properties of concrete containing these agricultural wastes. Moreover, Adebisi et al. (2020) observed that the production of silicon by conventional processes is complex and occurs at very high temperatures. Therefore, in their research, some agricultural wastes have been used to produce silicon in a very simple way. Agricultural waste is generated and disposed improperly in the environment, and this is an environmental challenge. Burning them produces gases that can affect the weather. The United Nations has called on all governments to work together to reduce climate change. On the other hand, the potential of Nigerian solar energy encourages investment in photovoltaic technology, which requires silicon, and their study aims to develop an alternative application for some agricultural wastes as potential sources of silicon.

Due to a large number of researches in this field, the following paragraph can be summarized. Heniegal et al. (2020) studied the properties of clay bricks containing refinery sludge and agricultural waste. Zhang et al. (2020) presented a study to maximize the use of agricultural waste in high-density polyethylene composites. Bhat et al. (2020) produced low-cost, catalyst-free, high-performance super-capacitors based on porous nano-carbons from agricultural waste. Kapoor et al. (2020) evaluated the value of agricultural waste for a biogas-based circular economy in India.

2.4 Research gaps

To provide a broader literature review to find the research gaps, a summary of some articles related to the agricultural supply chain is provided in Tables 2 and 3. For this purpose, articles published in international journals, library resources, and reputable scientific sites in different years until 2020 have been used to collect information. The Elsevier, Springer, Taylor & Francis, and John Wiley databases have also been selected as reliable and easier-to-access databases. Keywords including food supply chain, agricultural supply chain, perishable products, and fruit supply chain have been searched. For this purpose, 30 articles completely related to the subject of this research were selected and reviewed based on various factors to reveal the gaps.

Table 2 Comparison of studies in terms of approach, flow, layers, decision level, and variables
Table 3 Comparison of studies in terms of time horizon, products, capacity, case study and goals

Using the properties of Tables 2 and 3, we describe the gaps of the past researches. As it is shown in the table, 47% of these detailed research works used exact methods and then meta-heuristic algorithms with 40% took the second place of the used solution approach. However, simulation methods comprise only 13% of these studies. Therefore, exact and meta-heuristic algorithms have received more attention, which indicates the efficiency of these methods.

Also, 100% of these research works focused on forwarding flow, and only 7% of these research works considered both reverse flow and closed-loop mode. On the other hand, some layers of the network, such as recycling facilities, have only covered 7% of these research works. Therefore, these gaps, including close-loop, reverse logistics, and recycling facilities, need to be addressed in future works. In terms of the objective function, cost minimization covers 57% of these cases, which indicates the importance of this economic objective function. On the other hand, other important goals such as demand responsiveness and emission aspects have received very little attention. It is also evident that studies on apples and pears accounted for 20% of these studies, and other areas were less considered. Also, assumptions such as multi-product, bi-level, compost, and biogas with 30%, 3%, 7%, and 0% were less considered and should be covered. On the other hand, items such as strategic, planting, inventory, and multi-vehicle with 37%, 30%, 37%, and 7% received less attention, respectively, and should be covered. Therefore, the innovations of this research can be listed as follows.

  • Designing a new bi-level mathematical model for the closed-loop agricultural supply chain

  • Reuse of agricultural waste to produce compost and biogas

  • Introducing new, efficient, and effective nested hybrid metaheuristics for model analysis

  • Providing several numerical examples to validate the proposed model

3 Problem definition

In the desired supply chain, raw materials such as fertilizers and pesticides are supplied by various suppliers and delivered to farms. Farms send the final products to distribution centers (DCs) after production. Also, some of the products can be sent directly from the farms to the customer areas in the form of retail, which will be possible only for a limited period due to the lack of proper storage of these products by the manufacturers. An overview of the problem under study is shown in Fig. 1.

Fig. 1
figure 1

Scheme of the desired closed-loop agricultural supply chain network

Most agricultural products are stored in warehouses or, if necessary, in the cold stores of DCs and are sent to customer areas at different times. Depending on their type (fruits, vegetables, nuts, etc.), these products are damaged and corrupted in the sectors of farms, DCs, and customer areas (such as fruit and vegetable markets), and these corrupted values ​​are collected in inverse flow by the recycling depots. These wastes are sent from the recycling depot to the two sections for making biological fertilizers (compost) and the section for making biogas. The quantities of these shipments, depending on the type of waste materials, if they are not capable of producing biogas, are transferred to the biological fertilizer production department, and in practice, the quantities of these shipments are determined using a percentage coefficient. The corrupted products are transferred to the biogas production department and after the production of gas, this energy is sent to the applicants. Also, during the production of biogas, the obtained wastes are transferred to the production of biological fertilizers, so that after the production of natural fertilizers, these products are transferred to the suppliers of pesticides and agricultural fertilizers. Since various products and materials are needed to produce biogas, some of them can be covered by this proposed chain and the rest can be provided by other wastes of supply chains.

Biogas is a type of fuel gas that is a mixture of 65% methane (CH4) and 35% carbon dioxide (CO2). Biogas is a renewable energy source from agricultural products or animal manure. Biogas is the result of the fermentation process, which means the process of degrading organic matter using micro-organisms is known as anaerobic organisms. This process takes place in special tanks in which materials with heat and enzymes are decomposed in absence of oxygen. Biogas has several advantages:

  1. 1.

    Produces clean fuel.

  2. 2.

    These gases do not emit, so they do not cause pollution.

  3. 3.

    It is very efficient.

This product has another advantage because it produces scum and the remaining scum is used as biological fertilizer. However, biogas also has disadvantages:

  1. 1.

    Steals land and farms available to farmers to produce crops.

  2. 2.

    The cost of building biogas power plants is sometimes high.

Here, the closed loop mode is quite evident. In the middle part of Fig. 1, part of the recycled materials is delivered to the suppliers of the primary supply chain and part of them leave the primary chain and are transferred to the biogas production centers in the other supply chain. In this issue, it is assumed that initially, there are the number of DCs and recycling depots, and the status of other network facilities, including the reverse logistics sector in the network design process, is determined, and the location of facilities is considered. Decisions regarding the opening and closing of the facility may change during the course.

The problem can have two levels of decision-making. On one level, the main agricultural products are considered by one decision-maker and at the next level, the products of the stage of the reverse logistics will be considered by the second decision-maker. In summary, a bi-level programming model is proposed for the design of the closed-loop agricultural supply chain network (see Fig. 2). In this proposed model, decisions are made regarding the location and allocation of facilities, the amount of material and products flow between facilities in the supply chain, items related to strategies for selecting the type of vehicle, and other items.

Fig. 2
figure 2

Two main levels of proposed network in regards two DMs

Given the extent of the proposed problem and the use of the closed-loop network, strategic issues, and considering several goals in bi-level programming, modeling and problem solving will have their complexities and challenges. Multi-level supply chain network design problems are among the NP-hard problems (Cheraghalipour et al., 2019) and the problem described has different dimensions and complexities. Therefore, solving it in a reasonable time, especially in medium and large sizes, will face problems, and appropriate problem-solving methods must be developed. Depending on the mathematical model and structure of the problem, these solution methods can include nested bi-level meta-heuristic algorithms.

3.1 Assumptions

The main assumptions considered in this study are explained in detail above, but some of the other assumptions are as follows:

  1. The main focus of this research is on the development of a mathematical model for the closed loop agricultural supply chain and does not tend to its implementation phase. This research also seeks to optimize the proposed model in which in addition to agricultural products as the main products of the network, to produce two new products include biogas and compost by corrupted products to add value to the network.

  2. Since this network is a supply chain of several products, so the desired products can be different and do not refer only to a specific product. For example, several types of fruits and vegetables can be selected as products. Therefore, the proposed model can be used in various fields of agriculture.

  3. The supply chain network includes suppliers, farms, DCs, customers, and reverse logistics facilities.

  4. Customers’ locations are fixed and predefined.

  5. Facility capacity (supply, production, etc.) is limited.

  6. The problem is multi-period and multi-product.

  7. The initial inventory of all DCs in the first period is zero.

  8. The initial inventory is considered for suppliers in the first period.

  9. DCs and recycling depots include both existing and potential locations.

  10. Due to the perishability of products, the corruption rate is considered at three basic levels (farms, DCs, and customers).

  11. The transportation cost of products between network levels is based on the distance between points. It is assumed that several types of vehicles are available with certain capacities and costs.

  12. Only DCs can store the product.

  13. It is not possible to move the processed product between DCs.

3.2 Proposed model

This section introduces and describes the proposed mathematical model. For this purpose, first, the items required for modeling such as parameters, indices, and variables are described.

3.2.1 Indices

s = 1, 2, …, S

Index of suppliers

f = 1, 2, …, F

Index of farms

d = 1, 2, …, D

Index of existing and potential DCs

c = 1, 2, …, C

Index of customers

r = 1, 2, …, R

Index of existing and potential recycling depots

i = 1, 2, …, I

Index of compost production centers

j = 1, 2, …, J

Index of biogas centers

l = 1, 2, …, L

Index of biogas applicants

p = 1, 2, …, P

Index of agricultural products

m = 1, 2, …, M

Index of supplied raw materials

t = 1, 2, …, T

Index of periods

v = 1, 2, …, V

Index of vehicles

3.2.2 Parameters

\(rr_{mft}\)

Requested amount of raw material m by farm f in period t

\(\varphi\)

Impact coefficient of raw materials such as fertilizers and pesticides on a farm production

\(1 - \varphi\)

Impact coefficient of other criteria such as irrigation and weather conditions on a farm production

\(\alpha_{t}\)

Percentage of waste product in farms at period t

\(\beta_{t}\)

Percentage of waste product in DCs at period t

\(\gamma_{t}\)

Percentage of waste product in customer markets at period t

\(\omega_{1}\)

Weight assigned to allocate waste products to biogas centers

\(\omega_{2}\)

Weight assigned to allocate waste products to compost production centers

\(\theta\)

Coefficient for conversion of waste products to compost

\(fpcap_{pft}\)

Maximum capacity of farm f for producing product p in period t

\(sscap_{ms}\)

Initial supply capacity of supplier s for raw material m

\(dhcap_{dpt}\)

Holding capacity of DC d for product p in period t

\(dem_{pct}\)

Demand of product p by customer c in period t

\(bdem_{lt} \,\)

Demand of biogas by applicant l in period t

\(capr_{rt}\)

Maximum capacity of recycling depot r for storing products in period t

\(capb_{jt}\)

Maximum capacity of biogas center j for storing products in period t

\(capc_{it}\)

Maximum capacity of compost center i for storing products in period t

\(\delta\)

Coefficient for conversion of waste products to biogas in the liter

\(\mu\)

Percentage of reusable waste product in biogas centers for making compost

\(b\)

Big positive number

\(tcsf_{sfv}\)

Transportation cost of raw materials between supplier s and farm f by vehicle v

\(tcfd_{fdv}\)

Transportation cost of products between farm f and DC d by vehicle v

\(tcfc_{fcv}\)

Transportation cost of products between farm f and customer c by vehicle v

\(tcdc_{dcv}\)

Transportation cost of products between DC d and customer c by vehicle v

\(tcfr_{frv}\)

Transportation cost of products between farm f and recycling depot r by vehicle v

\(tcdr_{drv}\)

Transportation cost of products between DC d and recycling depot r by vehicle v

\(tccr_{crv}\)

Transportation cost of products between customer c and recycling depot r by vehicle v

\(fixr_{r}\)

Fixed cost of constructing potential recycling depot r

\(fixd_{d}\)

Fixed cost of constructing potential DC d

\(pc_{pf}\)

Production cost of product p in farm f

\(hc_{dp}\)

Inventory holding cost of product p in DC d

\(bc_{ms}\)

Buying cost of raw material m from supplier s

\(prg_{j}\)

Selling price of biogas by biogas center j

\(prc_{mi}\)

Selling price of raw material m by compost center i

\(tcrb_{rjv}\)

Transportation cost of products between recycling depots r and biogas center j by vehicle v

\(tcrv_{riv}\)

Transportation cost of products between recycling depots r and compost center i by vehicle v

\(tcvs_{isv}\)

Transportation cost of products between compost center i and supplier s by vehicle v

\(tcba_{jlv}\)

Transportation cost of products between biogas center j and applicant l by vehicle v

\(tcbv_{jiv}\)

Transportation cost of products between biogas center j and compost center i by vehicle v

\(pcg_{j}\)

Production cost of biogas in biogas center j

\(pcv_{mi}\)

Production cost of raw material m in compost center i

\(ihc_{ms}\)

Inventory holding cost of raw material m in supplier s

3.2.3 Decision variables

\(QSF_{msft}\)

Quantity of supplied raw material m by supplier s to farm f in period t

\(MQF_{pft}\)

Amount of produced agricultural product p by farm f in period t

\(QFD_{pfdt}\)

Quantity of shipped product p from farm f to DC d in period t

\(QFC_{pfct}\)

Quantity of shipped product p from farm f to customer c in period t

\(QDC_{pdct}\)

Quantity of shipped product p from DC d to customer c in period t

\(QFR_{pfrt}\)

Quantity of shipped waste product p from farm f to recycling depots r in period t

\(QDR_{pdrt}\)

Quantity of shipped waste product p from DC d to recycling depots r in period t

\(QCR_{pcrt}\)

Quantity of shipped waste product p from customer c to recycling depots r in period t

\(QRB_{rjt}\)

Quantity of shipped waste products from recycling depots r to biogas center j in period t

\(QRV_{rit}\)

Quantity of shipped waste products from recycling depots r to compost center i in period t

\(QVS_{mist}\)

Quantity of shipped compost (material m) from compost center i to supplier s in period t

\(QBA_{jlt}\)

Quantity of shipped biogas (liter) from biogas center j to biogas applicant l in period t

\(QBV_{jit}\)

Quantity of shipped waste products from biogas center j to compost center i in period t

\(X_{d}\)

Equal to 1, if DC d is constructed. Otherwise equal to 0

\(Y_{r}\)

Equal to 1, if recycling depots r is constructed. Otherwise equal to 0

\(IH_{dpt}\)

Inventoried product p in DC d at period t

\(ISS_{mst}\)

Inventoried capacity of supplier s for raw material m in period t

According to the mentioned properties and Fig. 1, two main levels of the designed network due to two expert insights, are exemplified in Fig. 2. Therefore, the proposed model is formulated as follows.

3.2.4 Upper-level model

$${\text{minimize}}\,Z_{{1}} {\text{ = Shipping}}\,{\text{costs + Construction costs + Production costs + Buying costs + Holding costs}}$$
(2)
$$\begin{gathered} {\text{Shipping}}{\text{ costs}} = \sum\limits_{m \in M} {\sum\limits_{f \in F} {\sum\limits_{s \in S} {\sum\limits_{t \in T} {\sum\limits_{v \in V} {QSF_{msft} \times tcsf_{sfv} } } } } } + \sum\limits_{p \in P} {\sum\limits_{f \in F} {\sum\limits_{d \in D} {\sum\limits_{t \in T} {\sum\limits_{v \in V} {QFD_{pfdt} \times tcfd_{fdv} } } } } } \hfill \\ \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\, + \sum\limits_{p \in P} {\sum\limits_{f \in F} {\sum\limits_{c \in C} {\sum\limits_{t \in T} {\sum\limits_{v \in V} {QFC_{pfct} \times tcfc_{fcv} } } } } } + \sum\limits_{p \in P} {\sum\limits_{d \in D} {\sum\limits_{c \in C} {\sum\limits_{t \in T} {\sum\limits_{v \in V} {QDC_{pdct} \times tcdc_{dcv} } } } } } \hfill \\ \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\, + \sum\limits_{p \in P} {\sum\limits_{f \in F} {\sum\limits_{r \in R} {\sum\limits_{t \in T} {\sum\limits_{v \in V} {QFR_{pfrt} \times tcfr_{frv} } } } } } + \sum\limits_{p \in P} {\sum\limits_{d \in D} {\sum\limits_{r \in R} {\sum\limits_{t \in T} {\sum\limits_{v \in V} {QDR_{pdrt} \times tcdr_{drv} } } } } } \hfill \\ \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\, + \sum\limits_{p \in P} {\sum\limits_{c \in C} {\sum\limits_{r \in R} {\sum\limits_{t \in T} {\sum\limits_{v \in V} {QCR_{pcrt} \times tccr_{crv} } } } } } \hfill \\ \end{gathered}$$
(3)
$${\text{Construction costs}} = \sum\limits_{d \in D} {fixd_{d} \times X_{d} + \sum\limits_{r \in R} {fixr_{r} \times Y_{r} } }$$
(4)
$${\text{Production costs}} = \sum\limits_{p \in p} {\sum\limits_{f \in F} {\sum\limits_{t \in T} {MQF_{pft} \times pc_{pf} } } }$$
(5)
$${\text{Holding costs}} = \sum\limits_{d \in D} {\sum\limits_{p \in P} {\sum\limits_{t \in T} {IH_{dpt} \times hc_{dp} } } } + \sum\limits_{m \in M} {\sum\limits_{t \in T} {\sum\limits_{s \in S} {ISS_{mst} \times ihc_{ms} } } }$$
(6)
$${\text{Buying costs}} = \sum\limits_{m \in M} {\sum\limits_{s \in S} {\sum\limits_{f \in F} {\sum\limits_{t \in T} {QSF_{msft} \times bc_{ms} } } } }$$
(7)

subject to

$$\sum\limits_{s \in S} {QSF_{msft} } \le rr_{mft} \,\,\,\,\,\,\,\,\,\,\forall m \in M,f \in F,t \in T$$
(8)
$$\sum\limits_{f \in F} {QSF_{msft} } \le ISS_{mst} \,\,\,\,\,\,\,\,\,\,\forall m \in M,s \in S,t \in T$$
(9)
$$MQF_{pft} = fpcap_{pft} \times \left( {\left( {1 - \varphi } \right) + \varphi \left( {\sum\limits_{m \in M} {\frac{{\sum\limits_{s \in S} {QSF_{msft} } }}{{rr_{mft} }}} } \right)} \right)\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall p \in P,f \in F,t \in T$$
(10)
$$MQF_{pft} \times \left( {1 - \alpha_{t} } \right) = \sum\limits_{d \in D} {QFD_{pfdt} } + \sum\limits_{c \in C} {QFC_{pfct} } \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall p \in P,f \in F,t \in T$$
(11)
$$\sum\limits_{p \in P} {\sum\limits_{f \in F} {\sum\limits_{t \in T} {QFD_{pfdt} } } } \le b \times X_{d} \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall d \in D$$
(12)
$$IH_{dp(t - 1)} + \sum\limits_{f \in F} {QFD_{pfdt} } = IH_{dpt} + \sum\limits_{c \in C} {QDC_{pdct} } + \sum\limits_{r \in R} {QDR_{pdrt} } \,\,\,\,\,\,\,\,\,\,\,\,\,\forall d \in D,p \in P,t \in T$$
(13)
$$IH_{dpt} \le dhcap_{dpt} \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall d \in D,p \in P,t \in T$$
(14)
$$\sum\limits_{d \in D} {QDC_{pdct} } + \sum\limits_{f \in F} {QFC_{pfct} } \le dem_{pct} \,\,\,\,\,\,\,\,\,\,\,\,\,\forall c \in C,p \in P,t \in T$$
(15)
$$\sum\limits_{r \in R} {QFR_{pfrt} } \le MQF_{pft} \times \alpha_{t} \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall p \in P,f \in F,t \in T$$
(16)
$$\sum\limits_{t \in T} {\sum\limits_{f \in F} {\sum\limits_{p \in P} {QFR_{pfrt} } } } \le b \times Y_{r} \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall r \in R$$
(17)
$$\sum\limits_{r \in R} {QDR_{pdrt} } \le \beta_{t} \times IH_{dp(t - 1)} \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall p \in P,d \in D,t \in T$$
(18)
$$\sum\limits_{p \in P} {\sum\limits_{d \in D} {\sum\limits_{t \in T} {QDR_{pdrt} } } } \le b \times Y_{r} \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall r \in R$$
(19)
$$\sum\limits_{r \in R} {QCR_{pcrt} } \le \gamma_{t} \times dem_{pct} \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall p \in P,c \in C,t \in T$$
(20)
$$\sum\limits_{p \in P} {\sum\limits_{c \in C} {\sum\limits_{t \in T} {QCR_{pcrt} } } } \le b \times Y_{r} \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall r \in R$$
(21)
$$\sum\limits_{f \in F} {\sum\limits_{p \in P} {QFR_{pfrt} } } + \sum\limits_{p \in P} {\sum\limits_{d \in D} {QDR_{pdrt} } } + \sum\limits_{p \in P} {\sum\limits_{c \in C} {QCR_{pcrt} } } \le capr_{rt} \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall r \in R,t \in T$$
(22)
$$ISS_{mst} = sscap_{ms} \,\,\,\,\,\,\,\,\,\forall t = 0,m \in M,s \in S$$
(23)
$$QSF_{msft} ,MQF_{pft} ,QFD_{pfdt} ,QFC_{pfct} ,QDC_{pdct} ,QFR_{pfrt} ,QDR_{pdrt} \ge 0\,\,\,\,\,\,\forall \,{\text{all}}\,{\text{sets}}$$
(24)
$$QCR_{pcrt} ,IH_{dpt} ,ISS_{mst} \ge 0\,\,\,\,\,\,\,\forall \,{\text{all}}\,{\text{sets}}$$
(25)
$$X_{d} ,Y_{r} \in \left\{ {0,1} \right\}\,\,\,\,\,\,\,\,\,\,\,\,\,\forall d \in D,r \in R$$
(26)

3.2.5 Lower-level model

$${\text{maximize}}\,Z_{2} = {\text{Income}} - {\text{costs}}$$
(27)
$${\text{Income}} = \sum\limits_{j \in J} {\sum\limits_{l \in L} {\sum\limits_{t \in T} {QBA_{jlt} \times prg_{j} } } } + \sum\limits_{m \in M} {\sum\limits_{i \in I} {\sum\limits_{s \in S} {\sum\limits_{t \in T} {QVS_{mist} \times prc_{mi} } } } }$$
(28)
$$\begin{gathered} {\text{Costs}} = \left( {\sum\limits_{r \in R} {\sum\limits_{j \in J} {\sum\limits_{t \in T} {\sum\limits_{v \in V} {QRB_{rjt} \times tcrb_{rjv} } } } } + \sum\limits_{r \in R} {\sum\limits_{i \in I} {\sum\limits_{t \in T} {\sum\limits_{v \in V} {QRV_{rit} \times tcrv_{riv} } } } } } \right. + \sum\limits_{m \in M} {\sum\limits_{i \in I} {\sum\limits_{t \in T} {\sum\limits_{s \in S} {\sum\limits_{v \in V} {QVS_{mist} \times tcvs_{isv} } } } } } \hfill \\ \,\,\,\,\,\,\,\,\,\,\,\,\, + \sum\limits_{j \in J} {\sum\limits_{l \in L} {\sum\limits_{t \in T} {\sum\limits_{v \in V} {QBA_{jlt} \times tcba_{jlv} } } } } \left. { + \sum\limits_{j \in J} {\sum\limits_{i \in I} {\sum\limits_{t \in T} {\sum\limits_{v \in V} {QBV_{jit} \times tcbv_{jiv} } } } } } \right) \hfill \\ \,\,\,\,\,\,\,\,\,\,\,\,\, + \left( {\sum\limits_{j \in J} {\sum\limits_{l \in L} {\sum\limits_{t \in T} {QBA_{jlt} \times pcg_{j} } } } + \sum\limits_{m \in M} {\sum\limits_{i \in I} {\sum\limits_{t \in T} {\sum\limits_{s \in S} {QVS_{mist} \times pcv_{mi} } } } } } \right) \hfill \\ \end{gathered}$$
(29)

subject to

$$\left( {\sum\limits_{p \in P} {\sum\limits_{f \in F} {QFR_{pfrt} } } + \sum\limits_{p \in P} {\sum\limits_{d \in D} {QDR_{pdrt} } } + \sum\limits_{p \in P} {\sum\limits_{c \in C} {QCR_{pcrt} } } } \right) \times \omega_{1} \ge \sum\limits_{j \in J} {QRB_{rjt} } \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall r \in R,t \in T$$
(30)
$$\sum\limits_{r \in R} {QRB_{rjt} \le capb_{jt} } \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall j \in J,t \in T$$
(31)
$$\left( {\sum\limits_{p \in P} {\sum\limits_{f \in F} {QFR_{pfrt} } } + \sum\limits_{p \in P} {\sum\limits_{d \in D} {QDR_{pdrt} } } + \sum\limits_{p \in P} {\sum\limits_{c \in C} {QCR_{pcrt} } } } \right) \times \omega_{2} \ge \sum\limits_{i \in I} {QRV_{rit} } \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall r \in R,t \in T$$
(32)
$$\sum\limits_{r \in R} {QRV_{rit} } + \sum\limits_{j \in J} {QBV_{jit} } \le capc_{it} \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall i \in I,t \in T$$
(33)
$$(\sum\limits_{r \in R} {QRV_{rit} } + \sum\limits_{j \in J} {QBV_{jit} } ) \times \theta = \sum\limits_{s \in S} {QVS_{mist} } \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall m = 1,i \in I,t \in T$$
(34)
$$ISS_{mst - 1} + \sum\limits_{i \in I} {QVS_{mist} } + SScap_{ms} = ISS_{mst} + \sum\limits_{f \in F} {QSF_{msft} } \,\,\,\,\,\,\,\,\,\,\,\,\,\forall m \in M,s \in S,t \in T$$
(35)
$$\sum\limits_{l \in L} {QBA_{jlt} } \le \sum\limits_{r \in R} {QRB_{rjt} } \times \delta \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall j \in J,t \in T$$
(36)
$$\sum\limits_{l \in L} {QBA_{jlt} } \le \,bdem_{lt} \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall j \in J,t \in T\,\,$$
(37)
$$\sum\limits_{i \in I} {QBV_{jit} } = \mu \times \sum\limits_{r \in R} {QRB_{rjt} } \,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\,\forall j \in J,t \in T$$
(38)
$$QRB_{rjt} ,QRV_{rit} ,QVS_{mist} ,QBA_{jlt} ,QBV_{jit} ,ISS_{mst} \ge 0\,\,\,\,\,\,\,\forall \,{\text{all}}\,{\text{sets}}$$
(39)

The objective function (2) attempts to minimize total costs of the upper-level consist of shipping costs presented in Eq. (3), construction costs presented in Eq. (4), production costs presented in Eq. (5), inventory holding costs presented in Eq. (6), and buying costs presented in Eq. (7).

Constraint (8) shows that the quantity of supplied raw materials by suppliers to farms in each period should be less than or equal to the requested amount of it by farms. Constraint (9) displays that the quantity of supplied raw materials by suppliers to farms in each period should be less than or equal to the supply capacity of suppliers. Equation (10) implies that the amount of produced agricultural products by farms in each period is related to the amount of supplied raw materials by suppliers. If this amount is less than the requested number of raw materials, it will hurt the production rate of the farms. Besides, if this amount is equal to the requested number of raw materials, it shows the full responsiveness of the demanded materials and the fraction value will be equal to 1. Therefore, the maximum capacity of farms for producing crops is multiplied with some coefficients. Here, (1-φ) shows the impact coefficient of some criteria such as irrigation and weather conditions on farm production, while φ represents the impact coefficient of raw materials (supplied by suppliers) such as fertilizers and pesticides on farm production. Equation (11) illustrates that the total agricultural products in farms minus the wasted amount can be shipped to both the DCs and customers. Restriction (12) indicates that transferring products to a potential DC is subject to its construction. Equation (13) calculates the inventory of products for DCs. This calculation is done in such a way that the inventory of the previous period plus the products received from the farms is equal to the inventory of the current period plus the products transferred from DCs to customers and recycling depots. Constraint (14) ensures that the inventoried products should be less than or equal to the holding capacity of DCs. Constraint (15) ensures that the sum of products shipped from farms and DCs is less than or equal to customers’ demand. Constraint (16) counts the number of waste products shipped from farms to recycling depots. Restriction (17) shows that transporting products to a potential recycling depot is subject to its construction. Constraint (18) calculates the number of waste products shipped from DCs to recycling depots. Constraint (19) displays that shipping products to a potential recycling depot are subject to its construction. Constraint (20) computes the number of waste products shipped from customers to recycling depots. Constraint (21) shows that distributing products to a potential recycling depot is subject to its construction. Constraint (22) shows that the summation of received products to each recycling depot should not be exceeded from its maximum capacity. Equation (23) shows the initial inventoried capacity of suppliers for raw materials in the first period. Moreover, the constraints (24) and (25) show the non-negativity decision variables used in upper-level, and constraint (26) represents the binary decision variables.

Besides, the objective function (27) seeks to maximize total profits of the lower-level using subtraction of incomes from the costs. To this end, Eq. (28) calculates the total income by selling manufactured biogas and compost to its applicants and suppliers. Equation (29) also calculates the total costs of lower-level consist of shipping costs between stages and production costs of biogas and compost.

Constraints (30) and (32) divide the waste products received in recycling depots between biogas and compost production centers, respectively. This work done using two weighting factors which consist of ω1 and ω2 whose sum is equal to 1. These two weighting factors are obtained by experts’ opinions. Constraint (31) shows that the summation of received products to each biogas center should not be exceeded from its maximum capacity. Also, constraint (33) shows that the summation of received products to each compost center should not be exceeded from its maximum capacity. Equation (34) shows the quantity of manufactured compost in compost centers that can be moved to suppliers. In this equality, the number of received waste products from recycling depots and biogas centers are mixed and using some procedure, the compost can be obtained. Therefore, these mixed waste products are multiplied by a conversion coefficient (conversion of waste products to compost), and the final amount of moved compost to suppliers is calculated.

Also, Eq. (35) calculates the inventoried capacity of suppliers for raw materials. To this end, inventory of the previous period plus the materials received from the compost centers and other sections is equal to the inventory of the current period plus the materials transferred from suppliers to farms. Besides, based on (Amirkhani et al., 2014), we know that compounds such as 50% water, 10% animal or human feces, and 40% rotten crops are needed to make biogas. Based on this research, 2 kg rotten crops by mixing other needed components (2.5 kg water and 0.5 kg feces) can release 1500-L biogas in 60 days, so 2 × (1500/60) = 50-L biogas release per day. Based on mentioned properties, δ = (1500/60) and in Eq. (36), this conversion coefficient is multiplied by waste products to calculate the amount of shipped biogas in liter to applicants. Constraint (37) shows that the summation of shipped biogas to applicants should not be exceeded by their demand. Equation (38) finds the number of waste products in biogas centers that can be reusable for making composts and transfers them to compost centers. Besides, the constraint (39) shows the non-negativity decision variables used in the follower level.

4 Solution method

This sector describes the suggested solution methods to solve the mentioned problem. To this end, first, the encoding and decoding process is presented and then some meta-heuristic algorithms such as Genetic Algorithm (GA) and Stochastic Fractal Search (SFS) are provided. The reasons for using the meta-heuristic algorithms are the nonlinear nature of the problem and the NP-hardness of the bi-level programming (Talbi, 2013). This information is existing in the following subsectors.

4.1 Encoding and decoding

One of the most important phases in using meta-heuristic algorithms is to describe the encoding–decoding process. There are different ways to encode a problem chromosome, each for a specific problem. Since the mechanism of operation of most algorithms is performed in a continuous environment, and also our problem requires sequencing for assignment to perform, so we use the priority-based encoding approach (Gen et al., 2006). We encourage the readers to follow (Lotfi & Tavakkoli-Moghaddam, 2013) for more information. So first we fill the genes of the chromosome with random numbers between (0, 1) and then we sort them according to priority and the position of each of which are integers and are selected as allocation sequence (see Figs. 3 and 4). For example, if the chromosome with random numbers is {0.2, 0.1, 0.4, 0.8, 0.3, 0.9, 0.5}, then the allocation sequence by sorting it is equal to {6, 7, 4, 2, 5, 1, 3}.

Fig. 3
figure 3

The chromosome with random numbers between (0, 1) for upper-level

Fig. 4
figure 4

The chromosome with random numbers between (0, 1) for lower-level

On the other hand, after encoding the problem and applying the algorithm operators to the problem chromosome, we need to calculate the variables and objective functions. Therefore, we need decoding procedures to convert the encoded problems to answers. To this end, the general form of these procedures is illustrated in Figs. 5 and 6.

Fig. 5
figure 5

Allocation procedure without inventory

Fig. 6
figure 6

Allocation procedure considering inventory

Figure 5 shows the allocation procedure without inventory for some sectors of chromosomes that not included inventory. Also, Fig. 6 shows the allocation procedure considering inventory for some sectors of chromosomes that included inventory. Moreover, it should be noted that the binary variable related to the opening facilities is shown in Fig. 5. This step may only apply to specific sectors of chromosomes such as sector two and sector four.

4.2 Genetic algorithm (GA)

This algorithm is proposed by John Holland (1975) and inspired by the genetic behavior of living organisms that can improve their physical condition through genetic mutations and inheritance from their parents. To this end, some random population is generated, and using two main operators (mutation and crossover), it seeks to improve the chromosome status and subsequently the state of the fitness function (Sang, 2021). Since the advent of this algorithm, various versions of it have been developed and it has also been effective in solving multi-level problems (Ma, 2016; Talbi, 2013). This algorithm is known as a model for various metaheuristic algorithms and in used in wide field of studies as a strong one such as in a joint order batching and picker routing problem (Yousefi Nejad Attari et al., 2021), location-inventory supply chain (Fathi et al., 2021), green supply chain (Gholizadeh & Fazlollahtabar, 2020), and others. Therefore, it is considered a strong and well-known algorithm in solving problems in this field, and we also use it to solve our proposed problem. It should be noted that all the algorithms used in this research are nested and among the main algorithm to calculate the high level, another lower-level algorithm is used. The pseudocode of nested bi-level GA is illustrated in Fig. 7.

Fig. 7
figure 7

Pseudo-code of the nested bi-level GA

Because the chromosome of this problem is filled with random numbers between (0, 1) and then an allocation sequence is obtained from the sort operator (using the gen’s priority), so all the chromosomes will be feasible. Besides, according to (Demirel et al., 2014; Maghsoudlou et al., 2016; Rostami et al., 2020), single-point and double-point crossovers along with swap, displacement, insertion, and reversion mutations operators were used. These operators are performed on random number vectors to avoid the creation of decimal numbers in the allocation sequence.

4.3 Stochastic fractal search (SFS)

This algorithm is inspired by the natural phenomena of growth and created using a mathematical concept called fractal. This algorithm was first presented by (Salimi, 2015). Like most algorithms, it is population-based and starts with a randomly generated initial population (Khalilpourazari et al., 2020). Due to a large number of formulas and concepts about this algorithm, readers are advised to refer to the mentioned source. In the following, the pseudo-code of this algorithm is presented (Fig. 8).

Fig. 8
figure 8

The pseudo-code of nested bi-level SFS

Because the chromosome of this problem is filled with random numbers between (0, 1) and then an allocation sequence is obtained from the sort operator (using the gen’s priority), so all the chromosomes will be feasible. Besides, all operators are performed on random number vectors to avoid the creation of decimal numbers in the allocation sequence.

4.4 Hybrid metaheuristics

Moreover, two hybrid metaheuristics based on SFS and GA are used to search for more appropriate answers. To this end, GA-SFS and SFS-GA are used that for example in GA-SFS, the genetic algorithm works on upper-level and stochastic fractal search works on lower-level. The opposite case is also established for SFS-GA. Since the descriptions for each algorithm are described separately, we will refrain from further explanations about these hybrid algorithms. It is important to note that here each algorithm (GA or SFS) is used only for a specific level and the other level uses a different algorithm.

5 Example

This section reports some generated examples to verify model performance and also adjusts the values of algorithm parameters. More information is presented in the following subsections.

5.1 Parameter setting

In this section, some numerical examples are generated randomly to set proposed model parameters. These generated examples are illustrated in Table 4, and also the values of periods and vehicles are fixed by 6 and 5, respectively, for all generated examples. It is necessary to consider several agricultural products, for example, several types of fruits and several types of raw materials supplied by suppliers, including pesticides, chemical fertilizers, and biological fertilizers. Moreover, according to experts in this field, values of 0.6 and 0.4 were adopted for ω1 and ω2, respectively. Finally, values of other parameters are reported in Table 5.

Table 4 Generation of twelve numerical examples in different dimensions
Table 5 Values of main parameters of model

Due to the lack of available information and momentary changes in the country under study, it is difficult to accurately state these values. Therefore, these numbers are close to the real world and the desired values can be changed for specific geographical areas.

5.2 Tuning parameters of algorithms

In this section, to calibrate the parameters of the applied algorithms, we have used the Taguchi method (Taguchi, 1986), which is one of the well-known methods in the design of experiments. According to the detailed information mentioned in the reference, this method uses some measures to reduce the number of experiments, therefore, we use a few experiment numbers instead of full factorial experiments. The important thing is that this method is only applicable to one objective function. Therefore, for single-objective mathematical models, it is sufficient to replace the value of the objective function of the model. Therefore, for multi-objective mathematical problems, a single value for the Taguchi method must be obtained using several types of standard multi-objective metrics. But this is a bi-level example, so according to (Kuo et al., 2015), only the upper-level objective is used to calibrate the algorithms in the Taguchi method. The statement ‘Smaller-the-Better’ is also chosen in the Taguchi method because the upper-level objective function is minimization.

To this end, it is initially desirable to report the values of the parameters of the used algorithms for different considered levels. These values are reached based on (Golshahi-Roudbaneh et al., 2017; Rahmati et al., 2013; Sarrafha et al., 2015) and illustrated in Table 6.

Table 6 Algorithm parameters range and defined levels

After setting the various levels of the algorithm parameters, it is time to run the Taguchi method using the Minitab software. After executing this method in the mentioned software, the orthogonal array L9 is selected for both algorithms. Moreover, after solving each algorithm during 30 executions, the average answer for each experiment is stored in the software. The orthogonal arrays along with resulted values of Z1 for GA and SFS are reported in Tables 7 and 8, respectively.

Table 7 The main results of Taguchi experiment for GA
Table 8 The main results of Taguchi experiment for SFS

As a result, using the analysis of these results by the Taguchi method, the selected values of the parameters are obtained by a tool called SN diagram. Therefore, the main effects plot of SN ratios for GA and SFS are illustrated in Figs. 9 and 10, respectively. Based on Fig. 9, it can be stated that values of 0.9, 0.1, 100, and 200 are selected for Pc, Pm, N-pop, and Max iteration, respectively. Also based on Fig. 10, it can be stated that values of 1, 150, and 300 are selected for MDN, N-pop, and Max iteration, respectively. These adjusted values are also applied for the two-hybrid algorithms.

Fig. 9
figure 9

The main effects plot for SN ratios of GA

Fig. 10
figure 10

The main effects plot for SN ratios of SFS

6 Results and discussion

6.1 Computational results

Finally, after setting the model parameters and adjusting the parameters of the algorithms, in this section, we will solve the generated examples. It should be noted that the examples are designed in small, medium, and large dimensions to further evaluate the performance of the algorithms. Also, to encode the algorithms, MATLAB software has been used and all the results have been executed under a personal computer with Windows 10 and a Core i5 CPU processor and 4 GB of RAM. To evaluate the performance of the algorithms, criteria such as the best value of the objective functions, the worst value of the objective functions, the mean of the objective functions, the CPU time, and normalized deviations (ND) have been used. The related formula to calculate ND is presented in Eq. (40).

$$ND = \frac{{\left| {Z_{1}^{\min } - Z_{1,i}^{*} } \right|}}{{Z_{1}^{\min } }} + \frac{{\left| {Z_{2}^{\max } - Z_{2,i}^{*} } \right|}}{{Z_{2}^{\max } }}$$
(40)

After executing each example using the proposed algorithms and extracting the values of mentioned criteria, we compare and analyze the results. These results are presented in Table 9 and the best value for each criterion is bolded in each example.

Table 9 The resulted computational results for twelve examples

To analyze the results of Table 9, some diagrams are used. For example, the comparison diagram of algorithms in terms of CPU time is presented in Fig. 11. Based on this figure, the SFS-SFS has the minimum execution time for all examples. Therefore, this algorithm is the best in terms of CPU time.

Fig. 11
figure 11

Comparison of algorithms based on CPU time

Also, from the perspective of the upper-level objective function, Fig. 12 illustrates these comparisons. Since this aim is minimization type, so the algorithm with the lowest value will be selected. As it turns out, SFS-GA has the best record in examples 1, 2, 3, 5, 6, 8, 10 and 12. The SFS-SFS has also gotten the best value in examples 4, 7, and 9.

Fig. 12
figure 12

Comparison of algorithms regarding leader-level objective

Moreover, Fig. 13 shows the assessment of algorithms in terms of the lower-level objective function. Since this objective function is a maximization type, so the algorithm with the highest value will be chosen. As is clear SFS-GA having the best performance in examples 1, 4, 5, 6, 8, 9, 10 and 12, while SFS-SFS has gotten the best value in examples 2, 7 and 11. Also, GA-SFS had the best performance in example 3.

Fig. 13
figure 13

Comparison of algorithms regarding follower-level objective

Furthermore, the normalized deviation is applied to review these results as shown in Fig. 14. This figure implies that the smallest deviations in almost all examples belong to SFS-GA.

Fig. 14
figure 14

Comparison of algorithms based on normalized deviation

After analyzing the results, we conclude that in some criteria, SFS-GA obtained better results and in others, SFS-SFS showed better performance. Therefore, to summarize, we must use a method that specifies only one algorithm for us as the best method. For this purpose, the displaced ideal solution (DIS) method (Pasandideh et al., 2015) has been used, the general structure of this method is summarized in Eqs. (41) and (42). In the mentioned method, in the first step, the value of Fi is obtained by averaging resulted values of twelve generated examples for each criterion, and then, the value of Fi* is determined using the lowest values for the criteria of the upper-level objective function and the highest values for the factors related to the lower-level objective function. The minimum amounts for ND and CPU time are also chosen. Finally, the values of Fi and Fi* are reported in Table 10.

Table 10 Calculation of Fi* and Fi values for DIS technique

Finally, we normalize the values of Table 10 using formula (41) and by summing the normal values, the direct distance for each method is calculated. It should be noted that the direct distance is calculated using formula (42) and the lower the direct distance value, the more desirable the answers of the mentioned algorithm than other algorithms. The normalized values and direct distances are presented in Table 11.

$$F_{i}^{N} = \frac{{F_{i} - F_{i}^{*} }}{{F_{i}^{*} }}$$
(41)
$$Direct\,distance = \sum\limits_{i} {F_{i}^{N} }$$
(42)
Table 11 The main results of DIS method

Finally, using the results of this method, we find that the proposed hybrid algorithm SFS-GA was selected as the best method to solve twelve generated examples among four proposed algorithms. This algorithm is selected because it has the least distance (0.047) from the ideal point. On the other hand, the SFS-SFS was selected as the second-best algorithm with a direct distance of 4.3665. It should be noted that the SFS-SFS especially in large size examples showed great in solving problems.

The results show that by using these analyses, better management in the real-world supply chain can be achieved and good results can be achieved in a reasonable time by using the proposed solution method. Therefore, by using these results, agricultural products can be allocated with proper planning, and also waste products can be used to make two new products that prevent both environmental pollution and produce clean fuel and useful biological fertilizers.

6.2 Sensitivity analysis

To further assess and analyze the performance of the suggested model in this section, sensitivity analysis is performed on some sensitive parameters of the model. The results are presented in Table 12. It should be noted that all these calculations were performed only for the first numerical example and the results were reported only for SFS-GA, which was selected as the best algorithm. To this end, five parameters that consist of product demand, biogas demand, farm capacity, ω1, and ω2 are chosen to change.

Table 12 Resulted values of sensitivity analysis

Using the analysis of the results of this table, it can be seen that changes in five parameters that consist of product demand, biogas demand, farm capacity, ω1, and ω2 cause changes in the number of objective functions as well as opened facilities. For instance, an increase in product demand can increase the total cost of the upper-level and slightly increase the objective function of the lower-level, which is a small increase due to the increase in the number of rotten products sent to the lower-level. On the other hand, increasing biogas demand only increases the lower level objective function. As well as increasing product demand and production capacity can also be opened additional facilities for storage. In addition, different changes are depicted for the two parameters ω1 and ω2, which according to experts’ opinions, the best value of 0.6 and 0.4 was selected for parameters ω1 and ω2, respectively. What is important is the use of these analyses to improve the status of the systems in question by managers and experts in the field.

7 Conclusion

Globalization and liberalization of trade in agricultural and food products have changed the structure of markets. Conventional traditional supply-based marketing systems for agricultural and food products have given way to coordinated and market-based supply chains. To succeed in meeting these challenges, it is necessary for businesses affiliated with the agricultural sector to apply the supply chain management approach in the process of converting inputs into inputs to deliver products to the market or end-users. On the other hand, issues related to rotten agricultural products have occupied the minds and attention of many systems. To this end, in this research, an eight-echelon agricultural supply chain was designed by seeing suppliers, farms, distributors, customers, recycling depots, biological fertilizers centers, biogas centers, and biogas applicants. Then, a mathematical model based on bi-level programming was formulated. The purpose of the upper-level of this proposed model was to minimize the total costs of the leader level, while the lower-level was to maximize the total profit achieved by the difference between the sales of follower level products and the total costs of this level. Since such problems had computational complexity, two meta-heuristic algorithms along with two hybrid algorithms were used to solve the proposed problem. Also, several numerical examples in different dimensions were generated to further explore the performance of these algorithms. On the other hand, to achieve the best performance of these algorithms, their parameters were first calibrated using the Taguchi method. Finally, the results were reported and showed the superiority of SFS-GA over other methods. Also, sensitivity analysis was executed on some parameters of the model, and using the results, several insights were reported. These gotten outcomes can be beneficial for agricultural managers and organizations. Like other research, this research has its limitations. For example, the values of the parameters, constraints, and conditions included in this model are related to the specific geographical location under study and may change in other areas. Therefore, the results obtained in this research for implementation in other areas and geographical areas should be reviewed. Another limitation is the high inflation and uncertainty in this geographical location, which causes the values of cost-related parameters to vary. As a final point, several guidelines for future studies are delivered as follow. Applying uncertainty in modeling problems such as robust programming, fuzzy sets, or stochastic programming can be useful and contribute to the complexity of the model and its proximity to the real world. Utilizing new metaheuristic and heuristic algorithms can lead to better answers and even reduce problem solving time. Considering green and sustainability aspects in modeling and integrating this SCM with other SCM can also be studied.