# Food Passports and Intelligent Food Recipes: The Data-Oriented Way of Producing Food
## 3 Results
### Procuring Ingredients and Regulating the Execution of Recipes  
The recipe needs now to be processed by the DRA, which needs to interpret it, procure its ingredients and control its execution. In the following text, the authors refer to the mock-up implementation provided in [[https://github.com/luferi/AROMA_Project](https://github.com/luferi/AROMA_Project)]([https://github.com/luferi/AROMA_Project](https://github.com/luferi/AROMA_Project)) (accessed on 1 January 2024). In said implementation, the DRA will continuously negotiate the procurement of ingredients with all the available SAs. It will preferably negotiate for the ideal quantities specified in the _DefaultRatio_ section of the recipe. Eventually, the suppliers will run out of supplies in the desired quantity and start refusing the procurement requests of the DRA. When this occurs, the DRA will start regulating the ratio of ingredients within the specified ranges and trigger re-negotiation. In parallel, for every successfully negotiated batch, the DRA will coordinate the execution of the defined flow of functions with the appropriate resources. The current implementation uses JADE [31], particularly version 4.6.0 [32] for implementing the agents, while the parsing of the AROMA DSL files uses the parse tree listener pattern documented in [33] and the interfaces automatically generated by ANTLR4 [30]. There are two main JADE behaviors within a DRA, running simultaneously. The first behavior handles, continuously and through negotiation, the procurement of ingredients for the recipes (Figures 4 and 5). In both diagrams, the FIPA Contract Net Protocol (CNET) [34] is considered. Successful negotiations (Figure 4) see many DRAs issuing a Call For Proposal (CFP) message to many SAs. On the CFP message, the desired products and properties are described. The SA will then evaluate whether they can supply accordingly to the CFP and issue a proposal in the form of a PROPOSE message, indicating the unit price of the procured ingredient. The DRAs process the different proposals and select the most appropriate one while rejecting all the others. In the case of the dynamic recipe, described in Listing 2, the mock-up implementation will initiate a CNET interaction for each ingredient in the recipe. Figure 4: Using the CNET Protocol for Ingredient Procurement. Certain protocol instances may fail due to the insufficient supply quantity on the suppliers side (Figure 5). In these circumstances, the DRA will recalculate the ingredient ratio, according to a specialized function that maintains the desired properties of the food being produced by a dynamic recipe, and will re-trigger negotiation for the recalculated ingredients. In certain cases, it may not be possible to recalculate the ratio, which causes the DRA to give up on the procurement process. For every successfully negotiated ingredient batch, the DRA then proceeds with the coordination of the resources described in the recipe flow. The actual interaction with the resources uses the FIPA Request Interactions Protocol [35]. At this point, the _Actions_ section in the Dynamic Recipe document (Listing 2, lines 89 to 115) is parsed using ANTLR4 and interpreted into JADE behaviors [16]. The mapping is as follows:  
* Sequence is interpreted as the JADE sequential behavior. * Parallel is interpreted as the JADE parallel behavior. * Repeat is interpreted as three main behaviors. A sequential behavior holds all the sub-flows of the repeat block, and a simple behavior evaluates the termination condition, both embedded into a finite state machine behavior, which, depending on the termination condition, evaluated as the terminator behavior, either re-runs the Repeat block, or terminates the finite state machine behavior. * Function invocations within resources are mapped into AchieveREInitiator behaviors, corresponding to the client-side communication of the FIPA Request Interaction protocol, whose responder side is implemented by the Resource Agents (RAs).