An agent‑based modelling framework for the simulation of large‑scale consumer participation in electricity market ecosystems

The role of consumers as price-sensitive participants in electricity markets is considered essential to ensure efficient and secure operations of electricity systems. Yet the uncertain or unknown consequences of active market participation remain a large barrier for active consumer-side market participation. Simulations are a powerful tool to reduce this uncertainty by giving consumers an insight on the potential benefits and costs of market participation. However, the simulation setup must be adapted to each market context and each consumer market participation strategy. To simplify the simulation development process and improve the comparability of simulation results, this paper proposes a modular yet systematic electricity market modelling framework. The framework applies object-oriented programming concepts for business ecosystem modelling presented in previous works to develop an agent-based model of a consumer-centric electricity market ecosystem. The market ecosystem is represented by a multitude of interacting submarkets with their own logic. Within submarkets, context-independent and context-dependent elements are distinguished to provide model abstraction which can be adapted to different contexts. This framework is illustrated by applying it to three different submarkets in the Western Danish electricity market context: the Nordpool day-ahead market, the Nordpool intraday market, and the Frequency Containment Reserve market. The submarket role abstractions allow to benefit from the commonalities between the analysed submarkets during model implementation, while the role parametrisations allow to quickly adapt the roles to each market context. The implementation of the modelling framework in the Nordic context highlights the benefits of a modular approach in a liberalised and unbundled market context.


Introduction
In a liberalised market context, the role of system planning, scheduling and operations has been progressively decentralised, passing from a monopolistic system operator to a multitude of generation side and consumption side market participants, coordinated by market prices (Joskow 2022;Li et al. 2016). In a mature market with fair competition, market prices should therefore accurately reflect system needs, both for short-term operations and long-term investments (Roques and Finon 2017). Such market-driven system operations rely on price-responsive flexible demand, where consumers adapt their consumption based on how much they are willing to pay for power supply (Ma et al. 2017a(Ma et al. , 2018a). Yet until now, consumers largely remain passive market participants, not willing to adjust their consumption to system needs (Leinauer et al. 2022). Indeed, behavioural factors such as risk-willingness and innovation culture play an important role in implementing consumption-side flexibility (Alcázar-Ortega et al. 2015;Ma and Jørgensen 2018). Meanwhile, with the planned phase-out of dispatchable fossil-fuel power plants in many countries, demand-side participation in electricity markets is increasingly encouraged to improve the flexibility in the system (Billanes et al. 2018). This demand-side flexibility allows to avoid expensive reserve resources and helps increase the integration of renewables in the grid (Cecati et al. 2011).
To encourage consumer-side market participation, various electricity market models have been developed over the years to simulate potential benefits of market participation. In the context of market restructuring and role decentralisation brought by market liberalisation, agent-based modelling (ABM) has emerged as a popular modelling tool for electricity markets. Agent-based modelling (ABM) simulations are a type of simulation where autonomous agents can evolve in a predefined environment to pursue their own strategy while following basic preestablished rules (Ringler et al. 2016). Agents only access information from the environment in which they evolve through interactions with other agents (Wang and Paranjape 2017), and have limited knowledge of the overall state of the system (Baum et al. 2017). ABM simulations are therefore suited to represent decision making processes in electricity markets which are decentralised with incomplete information availability .
Modelling approaches focusing on participant's specific preferences and properties are particularly relevant for consumers, as operational risk-averseness, revenue uncertainty and reluctance to change have been identified as some of the key barriers for the uptake of consumer-side market participation (Leinauer et al. 2022;Alcázar-Ortega et al. 2015;Olsthoorn et al. 2015;Vaerbak et al. 2019). The specific success criteria of each consumer could result in different market participation strategies, depending on how well the market can satisfy these criteria (Fatras et al. 2022b). A particular challenge for consumers is to navigate the complexity of liberalised electricity markets, which are often composed of a series of interacting submarkets, each providing different services to the grid at different time resolutions, over different timespans, and with different participation requirements (Fatras et al. 2022b;Ma et al. 2019a). The properties and interactions between submarkets are also very context dependent. Overall, the diversity of submarkets on the market side and the differences in success criteria on the consumer side make it difficult for consumers to adopt systematic methods to easily evaluate market participation suitability. Evaluation tools must therefore be modular, in order to easily adapt the evaluation to different large-scale consumer types and market contexts, yet systematic, to streamline the evaluation process and improve the comparability of results.
To address this challenge, the following work aims to develop a systematic, modular and consumer-centric ABM framework to simulate consumer-side participation in electricity markets. Due to the large diversity of consumer types and behaviours, this study will only focus on large-scale electricity consumers, who are able to directly participate in the electricity market without market intermediaries. Large-scale consumers were identified to face the lowest implementation barriers due to preliminary experience with demand-side management, availability of ICT infrastructure, loads scheduled ahead of consumption time, less reliance on third-parties, and a more rational logic influenced to a greater extent by price signals (Shoreh et al. 2016;Samad and Kiliccote 2012;O'Connell et al. 2014).
The approach is considered consumer centric as it represents the electricity market from a consumer perspective, as an ecosystem of interacting submarkets in which the consumer can participate. The approach is systematic, as it identifies core contextindependent building blocks which provide the modelling blueprint, and it is modular, as it allows these building blocks to be assembled differently depending on the market context. The modular and systematic approach are based on object-oriented programming concepts, which are implemented through the Java-based Anylogic software. In this study, the developed framework is tested in the Western Danish electricity market (DK1) context by conceptually modelling consumer participation in three different submarkets: the day-ahead market, the intraday market, and the frequency containment reserve (FCR) market . These three submarkets have been chosen due to their differences in market properties, to test the modularity of the presented approach.
The presented modelling framework will facilitate and help standardise the development of simulations to evaluate consumer-side market participation suitability. The consumer-centric approach should increase consumers' understanding and confidence in model results by providing tailor-made solutions, while the modular approach should increase the comparability of results between different large-scale consumers, business models, and market contexts, which allows to evaluate the relative performance of obtained results.
The rest of this paper will first provide some background on the use of ABM in electricity markets. Then the general framework of the model is presented, with a stepby-step guide for model implementation. The developed framework is then applied to different submarkets in the Danish market context, and finally a discussion and conclusion provide further insights on the presented approach.

Impact of liberalisation on market structure
Electricity market liberalisation, a process started in the 90 s in many countries throughout the world, was implemented to improve the efficiency of system operations and investment by promoting fair competition (Wilson 2002). Competition was put in place by breaking down the monopoly of system operators: vertical unbundling was implemented to separate roles along the supply chain from generation to consumption, and horizontal unbundling was implemented to increase the number of actors within each step of the supply chain (which were suited to competition) (Joskow 2022). This unbundling process has led to a multiplication of actors within the electricity market and has transferred the responsibility of electricity system operations and investment from a centralised entity to competing actors cleared in the electricity market. As an electricity system has multiple requirements to fulfil, different market types, referred to here as submarkets according to the definition in Lopes (2018a), Stoft (2002), constitute the electricity market. Each of these submarkets represents a value chain which a large-scale consumer can decide to participate in or not. Efficient planning, scheduling and operations of the electricity system depend on active participation in each of these submarket types, and efficient coordination between the submarkets. Submarket interactions are what is referred to as market architecture in Lopes (2018a); Stoft (2002). Examples of submarket types found in the literature, without being exhaustive, are given in Table 1.
Each of these submarket types can consist of multiple submarkets, depending on the specific architecture of the electricity market. The overall system created by the different submarkets, the market participants, and the interactions between and amongst participants and submarkets is here referred to as an electricity market ecosystem. The market ecosystem is an extension of the business ecosystem concept presented in Ma (2019), where a business ecosystem is defined as a large number of interconnected participants depending on each other for mutual effectiveness and survival (Ma 2019;Iansiti and Levien 2002). In a market ecosystem, submarkets are represented as individual and interconnected entities in the system, despite not having an independent strategy or behaviour in the system. Such ecosystems reflect the complexity of liberalised markets, where access to market information depends on time, interactions, and the overall architecture of the market.

Existing models
Several ABM models focusing on electricity markets have emerged in recent years as a subbranch of agent-based computational economics. Some established electricity market ABM models in the literature are AMES (Agent-Based Modelling of Electricity Systems) for the bidding of generating companies (GenCos) in wholesale markets, used in Ref. Kiran et al. (2019) and El-Adaway et al. (2020); MASCEM (Multi-Agent Simulator Table 1 Submarket types found in liberalised electricity market contexts

Submarket type Description
Wholesale submarkets Direct electricity trading between generators and consumers, or between market intermediaries on either side, depending on the consumer's size and preferences Retail submarkets Contracts between the consumer and a market intermediary which purchases electricity in wholesale submarkets on behalf of the consumer Ancillary Service submarkets System balancing services provided by market participants and coordinated by the system operator during operation times to ensure overall balance between demand and supply at all times Congestion submarkets Load adjustment services provided by market participants to avoid congestions in the grid New capacity investment submarkets Investment in additional power generation capacity, usually over longer timescales Decarbonisation submarkets Submarkets to encourage the consumption of low-carbon power of Competitive Electricity Markets) (Pinto et al. 2014), designed to test the participation of market players in different markets and different contexts, used in Ref. Praça et al. (2019) and Pinto and Vale (2019); and PowerACE, designed to model the impact of renewable energy generators on electricity markets, used in Ref. Klein et al. (2019) and Fraunholz et al. (2021). Among these models, only MASCEM potentially allows to include consumer-side participants. Other existing models are MATREM (Multi-Agent Trading in Electricity Markets), which models generation-side and consumer-side participants bidding into exchange-based markets and bilateral contracts (Lopes 2018b), and more case-specific models, such as Ref. Etukudor et al. (2020),which focuses on local peer-to-peer markets with automated negotiation frameworks, or Ref. Zhang et al. (2019), which presents a novel two-stage trading mechanism for direct market participation of large-scale consumers. A typical application of such models is to aggregate market participants' bids and model their impact on market clearing, to provide a deeper understanding of the impact of market participation on market outcomes (Kühnlenz et al. 2018). This is referred to here as a market-centric approach, as results are particularly useful for market regulators implementing market regulation changes to improve market participation. Marketcentric models typically need to use small-scale case studies, such as the IEEE 30-bus system in Shafie- Khah and Catalão (2014), to keep the number of agents to a reasonable level. On the other side, other implementations of ABM focus on the demand response strategies with electricity market prices already provided, either as forecasts such as in Algarvio et al. (2016), scenarios in Golmohamadi et al. (2019), or historical data such as in Zheng et al. (2020). This is referred to here as a consumer-centric approach, as the impact of the consumer's actions on the overall market is considered less important. However, Ref. Shinde et al. (2021) notes that very few electricity market ABMs explicitly include the trading mechanisms and market rules during model setup, which makes it difficult to adapt the models to different submarket types or market contexts. In Ref. Shinde et al. (2021) demonstrates the importance of differences in submarket trading mechanisms by implementing an ABM approach in a continuous intraday market context. In this case, trading agents cannot implement established bid optimisation strategies developed for centrally cleared exchange markets and must instead implement heuristic learning strategies to adapt to continuously cleared bids with imperfect information about competitors' bids.

Electricity market ABM ontology
In Santos et al. (2016b), Santos et al. underline the importance of making electricity market ABM interoperable, in order to facilitate information exchange between models and compare different energy systems. Model interoperability requires a common ontology. Ontology is here understood based on the definition of Maedche and Staab as "a formal, explicit specification of a shared conceptualization" (Maedche and Staab 2001). Early attempts to create electricity market ontologies include ELMO, where a layered ontology based on geographical applicability range is applied in the Greek electricity market (Alexopoulos et al. 2009). Underlining that this ontology has not been generalised to other European electricity markets, and that it has not been developed specifically for ABM implementation, Ref. Santos et al. (2016a) proposes its own electricity market ontology (EMO), applied to the MASCEM electricity market ABM. EMO uses an upperlevel ontology common to all markets, from which market specific applications can be extended. EMO has since been extended and implemented in the EPEX market in Ref. Santos et al. (2017a), the Iberian market in Ref. Santos et al. (2018), and the Nordpool market in Ref. Santos et al. (2017b) The AiD-EM ontology is a more low-level ontology extending the EMO, developed to standardise the communication of market participants with electricity market models when implementing market participation strategies (Santos et al. 2021). The AiD-EM ontology therefore focuses more on the participant logic than the market operator logic. The Tools Control Center application ontology presented in Teixeira et al. (2020) pushes the decision support tool concept further by using semantics to allow co-simulation between heterogeneous simulation tools.
However, such approaches require a common agreement between models on the upper-level ontology, which can be hard to achieve in practice, and could lock future market designs into the framework of the upper-level ontology (Ma et al. 2019b). Moreover, each market context requires its specific lower-level ontology based on the upperlevel ontology, which limits the reusability of the developed models. In Ma et al. (2019b), Ma et al. conclude a review on existing ontologies for electricity market ABM with the need for more clarity in the ABM design methodology to ensure reproducibility. Moreover, despite existing electricity market ontologies, Lopes underlines in Lopes (2018a) the heterogeneity in description and representation of electricity markets software agents, and criticises the lack of framework for model results comparability.

Specificity of the presented approach
The diversity of electricity market ABM approaches presented above has created the need for increased standardisation to allow interoperability and comparability of model results. While extensive work has been done on describing market agents and their communication protocol in a standardised way, the modelling of the submarkets which these agents interact with lacks consistency and remains too context specific. Moreover, the modelling design steps are usually omitted, providing a description of the model components without explaining how they can be assembled into a model. This makes reusability and comparability of models in different market contexts difficult. The modelling framework outlined in this paper complements the existing work by proposing a systematic yet modular consumer-centric modelling approach of electricity markets. More specifically, the main contributions are the following: • An application of object-oriented programming concepts to electricity market architecture modelling by identifying commonalities and differences in electricity market ecosystems and representing market participants' interaction with such ecosystems. • A systematic model conceptualisation through context-independent market roles, role parametrisation, and predefined functions. The use of such building blocks simplifies model development and improves comparability of results in different market contexts. • A consumer-centric representation of electricity markets as an ecosystem of interacting submarkets which the consumer can choose to participate in. Each submarket has easily adaptable context-dependent parameters, which allows tailor-made solutions for consumers adapted to a specific electricity market ecosystem.
This one-to-many (consumer-to-submarkets) bidding approach taken in this study is a reversal of the many-to-one (consumers-to-market) bidding approach implemented in traditional agent-based models of electricity markets, as is summarised in Fig. 1. The focus is not on the impact of market participation strategies on market prices, as the many-to-one approach would do, but rather on which submarkets to participate in based on available submarket information.

Model framework.
The following framework follows the business ecosystem modelling process first presented in Ma (2019), which consists of three parts. Part I-"Business Ecosystem Architecture Development" and Part III-"Ecosystem simulation and reconfiguration" have both been applied to energy ecosystems with multiple cases, e.g., electric vehicle home charging Vaerbak et al. 2021), smart buildings (Ma et al. 2017b(Ma et al. , 2017c, and microgrids (Ma et al. 2019a(Ma et al. , 2018b. There the focus has been on the impact of distributed loads on the grid. In this paper, the work developed in Ma et al. (2021) and (Vaerbak et al. 2021) is adapted to the electricity market ecosystem context, more specifically from the point of view of a single large-scale consumer.

Model boundaries
Reference Ma (2019) uses the concept of Minimum Viable Ecosystem (MVE) to choose the ecosystem boundaries and identify the relevant stakeholders in the model accordingly. Ref. Vaerbak et al (2019) defines the MVE as "a completed ecosystem with minimum elements (actors, roles, and interactions), [which] still can serve the identified ecosystem boundary". The MVE therefore focuses on modelling the minimal amount of actors and interactions required for a stakeholder to obtain added value from a proposed business model. This is relevant when modelling electricity markets at a national or international scale, which are large business ecosystems involving many actors and which cannot be modelled in their entirety, both due to limited information access and limited computational capacity. The inaccuracies from the MVE simplification are compensated by data inputs from exogenous components. Exogenous components cannot be changed by simulation results, and therefore make the model less flexible for scenario exploration. The simpler the MVE, the more extensive and accurate the external database must be to compensate for the model's shortcomings.
In this study, actors and interactions included in the MVE are chosen based on the perspective of a single large-scale consumer participating in the electricity market. Market bids of generators and other consumers are not explicitly modelled. For this reason, market prices dependent on centralised clearing cannot be explicitly modelled, and historical prices and forecasts are used instead. This makes the consumer a price taker, as its actions do not influence clearing prices. This is acceptable if the consumer represents a negligible share of market transaction volumes. The reliance on historical data also implies that model results can only show what could have been gained from market participation in the past but cannot predict how much will be saved in the future. Historical market data could be replaced with market price forecasts based on future system assumptions to explore future scenarios, but this is not the focus of this study. In the following model, market price data is provided by a separate agent representing exogenous components.
Physical system properties such as network congestion, frequency stability and system imbalance are not modelled directly either. Instead, they are implicitly included in the data input from short-term balancing markets, whose market prices should reflect the physical state of the system. System operators in charge of grid operations, such as the Transmission System Operator (TSO) and Distribution System Operator (DSO), are therefore only included in the model for their roles as information provider to the market or as market operators for short-term balancing services. Data metering and administration roles are not included either.
Finally, market intermediaries such as retailers, aggregators, and independent balancing responsible parties (BRP) are also excluded from the model. Many large-scale consumers have the advantage of having large enough loads to directly participate in electricity markets without load aggregation (Fatras et al. 2022b;Samad and Kiliccote 2012;Howard et al. 2020). The modelled large-scale consumer is therefore assumed to be its own BRP. This avoids the reliance on third parties interfering in load scheduling, which was identified as an adoption barrier (Leinauer et al. 2022;Alcázar-Ortega et al. 2015), and allows to evaluate the benefits of direct market participation compared to traditional passive participation through retail contracts. As noted previously, market liberalisation has led to a large diversity of submarkets. The choice of submarkets to include in the model will depend on the evaluated consumer value chain, and on participation feasibility from a technical and regulatory point of view (Fatras et al. 2022b). As this is not the focus of this study, submarkets included in the case study will only be selected based on their suitability to illustrate the framework.

Model components
The presented modelling framework makes a distinction between context independent and context dependent model components. Certain actions must be executed in any market context to achieve the required electricity services. Examples of such actions are customer billing, market bidding, or bid clearing. Such context-independent actions are assigned to roles, which are responsibilities to be fulfilled by actors in the ecosystem, as defined in Ma et al. (2021) and ENTSO-E (2019). However, how these roles are implemented depends on which actors these roles are assigned to, and which other actors in the model they are influenced by. The context-dependent actors which roles are assigned to are defined as agents. This study therefore relies on the hypothesis that any electricity market can be modelled as a combination of context-independent roles which are adapted to a specific market context to create an overall market ecosystem.
The application of agents and roles in this work is based on the object-oriented programming (OOP) framework for agent-based modelling of energy business ecosystems presented in Vaerbak et al. (2021). The OOP approach couples data and methods together into objects (Liang 2018), making use of the abstraction provided by methods to implement them in different contexts. In this study, the methods are provided by predefined roles, the data is provided by the market context, and their combination creates the modelled electricity market ecosystem. The model framework in Vaerbak et al. (2021) and in this study are developed in Anylogic, a Java-based software with agentbased modelling features (Cenani 2021). OOP concepts in this section will therefore be referred to using Java programming language.

Roles
Roles correspond to Java Interfaces, which are abstract Classes providing a blueprint of the actions which that role fulfils. This blueprint defines the input format, output format, and methods corresponding to that role, while leaving the methods empty. The method body, referred to as logic, is only defined once the role is implemented by a specific agent. This basic context-independent definition of the methods which a role must fulfil relates to the OOP concept of abstraction. Abstraction simplifies the description of an object to its most defining characteristics, without giving details on the implementation of each characteristic. This role abstraction ensures consistency in model development by using the same methods, while providing modularity by adapting methods to the given context.
To provide further consistency in model development, the roles used in this framework are based to the largest extent possible on the Harmonised Electricity Market Role Model (HRM), developed by the European Network of Transmission System Operators-Electricity (ENTSO-E) to improve information exchange and comparability between different countries (ENTSO-E 2019). Since the HRM focuses on the wholesale and retail markets, its ontology is expanded here to fit the broader ecosystem of interacting submarkets presented in this study. Additionally, a role can include subroles, implying that an agent adopting that role also must implement the methods defined in these subroles. This follows the concept of inheritance in Java, where an interface (a role) "extends" another interface (a subrole). To keep track of the role which an interface is associated with, interfaces are referred to as I_Role, in line with the approach in Vaerbak et al. (2021), where "Role" is the name of the role which the interface is associated with. The relevant HRM roles and their corresponding adaptation to the consumer-centric approach in this study are summarised in Table 2.
To provide further consistency to role implementation, role parameters are defined as attributes in abstract classes of each role, which must be given a value upon role implementation. Examples of role parameters could be the scheduling frequency or the scheduling time resolution for a Scheduling Agent role. For agents responsible for market operations, these parameters are fixed and set by the Market Regulator role, as will be detailed in the section "Modelling submarkets".

Agents
Agents in an ecosystem correspond to Java objects, which are instances of Classes. The Classes define how the object should behave once it is instantiated in the model. An agent implements roles by providing context-depending logic to the empty interface methods. Multiple roles can be assigned to an agent, and conversely, multiple agents can be assigned the same role (Vaerbak et al. 2021). While classes in "strict" OOP only act upon request, agents in Anylogic are dynamic, with internal delays and scheduled events (Borshchev 2013). This provides the agents a certain level of autonomy representing independent decision making in a market context.
Here a distinction must be made between passive and active agents. Active agents have one or multiple success criteria they aim to fulfil, which will influence how the role is implemented to satisfy these criteria. For example, financial savings are a success criterion of an agent fulfilling the role of market bidder. The importance of this criteria will influence how much it is willing to bid in a given submarket at a given time. Active agents can adjust the logic of the roles based on how well the role outputs satisfy the agent's success criteria. This adjustment process as the agent interacts with its environment is generally called agent "learning".
On the other side, passive agents' role implementation is not influenced by the agent's strategy, and only depends on context-specific rules and properties. However, passive roles are not static in themselves, as their set of predetermined rules can be changed by an active agent, such as for example a market regulator. Changing such operation rules can influence the interaction dynamics between roles. For example, changing the bidding deadline of a specific submarket can cause participants to increase bidding in that submarket at the cost of other submarkets, as the changed bidding deadline is better aligned with participants' operational requirements. Following the Java OOP principle of encapsulation, methods and attributes implemented in agents are defined as either public or private. Private methods and attributes can only be accessed by the agent itself and represent information and decision logic only accessible to the agent. Public methods and attributes are visible and accessible to other agents and will be used in agent interactions, as will be explained next. This distinction between roles and agents is summarised in Fig. 2.

Interactions
An agent-based model relies on exchange of information between modelled agents to achieve an overall system behaviour. In the consumer-centric electricity market context, interactions occur between the consumer and the submarkets, but also between submarkets, and with the regulator and data-providers. As mentioned in the previous section, roles are differently distributed among agents depending on the market context. This implies that the information received by agents depends on the roles they are assigned to. On the other hand, the information received and emitted by roles only depends on the methods they must implement, which are context-independent. While the data type remains the same for a given role, the market context will determine whom this data is sent to, at what time, with what frequency, and in what format. For this reason, interactions in this model are again divided into context-independent and context-dependent components.
Context-independent components are based on communication between roles instead of agents, as implemented in Vaerbak et al. (2021). Such communication depends on methods defined in each role's interface, where the method declaration parameters specify the type of interface which can access that method. These context-independent communication methods are called flow methods, as they allow an exchange of flows between agents. Flows can be of different nature, representing exchange of information, data, monetary value, goods, or intangible value, as defined in Ma et al. (2021). In this study, data flows represent exogenous data, while information flows represent endogenous data. Role-based communication ensures role consistency in different market contexts, avoids to redefine the communication protocol for each agent adopting a new role, Fig. 2 Relationship between agents and roles and prevents agents from accessing information which their roles don't allow them to (Vaerbak et al. 2021). Flow methods are set as public to be able to call each other, but can only be called by roles with appropriate data access rights.
Context-dependent components adapt the role communications to the agents which each role is assigned to. In this study, this is done through methods called connection methods, which specify the address which flow methods must refer to when calling each other. When a role is assigned to another agent, only the agent mentioned in the connection method must be changed to adapt the model. Connection methods belong to the agent and are therefore defined as private. Connection methods are defined as either passive or active, depending on which role first gets in contact with the other role to start an interaction. In a hierarchical information flow structure, roles sending messages to a larger information aggregator are assigned active connections, while the information aggregator is set as passive. In case no hierarchy is defined, connections are set as passive or active randomly.

Model implementation
The actions of market participants included in the model are governed by a series of methods of different types. Role methods used to fulfil the role's purpose are defined as characteristic methods and are set as private, as they represent an agent's internal logic. Moreover, when implemented in an active agent, characteristic methods can call methods which are specific to the agent which the role is assigned to. Such agent-specific methods are set as private and defined as strategy methods, as they define the strategy implemented by the agent to achieve its success criteria. Together, the characteristic and strategy methods represent the internal methods of the agent. These internal methods are called by Anylogic Event functions, which are activated either cyclically at the specified time and frequency defined by the role's parameter values, or conditionally after receipt of a trigger message, depending on the role's characteristic functions.
These internal methods are complemented by agent interactions, each defined by the combination of a public flow method and a private connection method. These interactions methods are also called by Anylogic Event functions. Interactions methods are only called by Event functions in one of the two roles involved in the interaction, to avoid interaction redundancy. By convention, the role with the active connection method is also the one implementing the Event function to call the flow method. Role interactions within the same agent still use flow methods, but no connection methods, as all information is shared within the agent. Agents concentrating many roles therefore have a significant advantage in terms of informatic access, which can be used to study the impact of information access on market power. The different components of an agent implemented in the ecosystem are summarised in Table 3.

Modelling submarkets
The model components outlined above are very general and can be applied in different domains. The following section presents in more detail how this framework is implemented in an electricity market model.

Submarkets as agents
Submarkets in an electricity market ecosystem are designed to fulfil a specific set of roles to ensure satisfactory system operations. Each submarket is therefore considered as an agent which implements a set of roles. This is an extension of the ENTSO-E HRM, which considers Market Operator as a role without distinguishing between submarket types, and without specifying the actions to fulfil by the market operator. Submarket agents are passive agents, whose logic is determined by an external agent which these submarkets are assigned to. Submarkets are therefore usually subagents of a larger agent in the electricity market ecosystem, which itself can be passive or active. External agents such as market regulators can also have an influence on the submarket logic.
The roles assigned to a submarket depend on the submarket type. While submarket designs vary for each market context, certain submarket types are repeatedly found in different market contexts, as mentioned in the Background section on market liberalisation. As the case study presented in this work will focus on demand-response, the roles assigned to submarket types focusing on short-term operations are shown in more detail in Fig. 3.
The diagrams in Fig. 3 represent generic submarket types, without applying them to a specific market context. The roles assigned to each market type do not change much with context, as the market types are defined by these roles. The same applies for the roles which each submarket interacts with. An exception is the Data Provider role, which depends on the boundaries of the MVE and the internal logic of the submarkets. The Data Provider role could in some cases be internalised by submarkets. An example is a submarket cleared bilaterally instead of through an exchange, in which case external market price data is not available for the internal bid clearing logic. Figure 3 also shows that some subroles are common to all submarkets, such as Billing. This role requires a service quantity (energy or load in this case) and a service price (which can for example be fixed or per unit quantity), irrespective of the context. However, the time at which this information is provided and how the bill is calculated will depend on the specific rules of the submarket.

Submarket role standardisation
To further simplify the implementation of submarket agents in a given context, submarket method implementations for each role can be chosen from a predefined and standardised set of options. This assumption is based on the fact that individual components of market designs are often chosen from a limited set of real-life implementations. For example, market bidding mechanisms can be classified into bilateral and exchange-based market architecture, while market pricing mechanisms can be divided into pay-as-bid, pay-as-clear, or other existing auction mechanisms (Stoft 2002). Each of these market mechanisms is characterised by a specific algorithm. These algorithms correspond to predefined methods, which are stored in a class named F_Role, according to the submarket role's name. The predefined method chosen within F_Role depends on the market context and is determined by the role parameters assigned to the role once it is implemented in an agent. Role parameters are also used to implement the empty methods in a submarket's interface I_Role. For example, (Fatras et al. 2022b) describes different ancillary service submarkets in the Danish market context using four bidding parameters (bid resolution, bid frequency, bid deadline, minimum bid size) and five activation parameters (activation speed, activation symmetry, response duration, automatic activation, information exchange frequency). These parameters are needed to respectively implement the "Bid clearing" and "Reserve activation" roles shown for the ancillary service submarket in Fig. 3. Parameters are used both in characteristic methods, to determine how submarkets operate, but also in flow methods and Event functions, to determine how often, at what time, and in what format information is exchanged.

Fig. 3 Roles assigned to different submarket types
Role parameters are therefore both used to select the predefined methods in F_Role and to implement the empty methods in I_Role. Such role parameters are part of the role's "blueprint", but their value is context dependent. Unfortunately, Java interfaces do not allow to define empty attributes whose value can be assigned once the interface is implemented in an agent. Therefore, the method parameters cannot be defined in I_Role. Instead, a class named P_Role is defined for each role, where all relevant role parameters are defined. P_Role classes are implemented along with I_Role interfaces and F_Role classes when a role is implemented in an agent. The relationship between the different classes and interfaces assigned to a submarket agent is summarised in Fig. 4.
This definition of role interfaces and classes provides a structure when instantiating submarkets in a specific context. In a purely market-driven context, the agent implementing the submarket agent is passive: market outputs only depend on market rules, defined by an external and neutral Market Regulator role, and market inputs, provided by external market participants. Nonetheless, the outcome of passive submarkets can be influenced by indirect intervention of external stakeholders with vested interests in the submarket outcomes, as underlined in Fatras et al. (2022a). This level of indirect intervention depends on how many and which external agents the submarket is connected to. Alternatively, direct market intervention is possible in a context of incomplete market unbundling, where the market operator implementing a specific submarket can use it to its advantage to fulfil socio-political, economic, environmental or other success criteria.
Step-by-step model setup The above sections have described the different parts constituting the model and the object-oriented approach behind it. This final section of the model framework will explicitly summarise how to combine these different elements in a methodical way, to set up a model for a specific market context. The steps are summarised in the flowchart in Fig. 5.
Step 1: Defining the electricity market ecosystem 1.1: Identify submarkets where the consumer could participate from a technical and regulatory perspective. This requires a good understanding of the consumer's flexibility, operational constraints, and risk-willingness. Simultaneously, it requires an analysis of the different electricity submarkets within an ecosystem, to determine

Fig. 4 Submarket role classes and interfaces interactions
which market regulations would fit best with the consumer's properties. Such an approach is presented in Fatras et al. (2022b), but is not the focus of this study.

1.2.:
For the chosen submarkets, identify the key roles required to link the consumer to the submarkets. To remain within the scope of an MVE, only roles necessary for direct market participation should be included for a large-scale consumer. Roles representing inputs from exogenous factors must be included, to compensate for the model boundaries.

1.3.:
Identify the MVE agents associated with each submarket agent.

Fig. 5 Flowchart of modelling setup steps
Step 2: Defining the submarket roles The modelling steps outlined in step 2 assume the interfaces and classes belonging to a submarket role have not been defined yet. In case I_Role, F_Role and P_Role are already defined, step 2 can be ignored.
For each submarket role:

2.1.:
Identify the characteristic methods which must be fulfilled (without implementing them).

2.2.:
Identify the role interactions required to fulfil the characteristic methods. Define flow methods accordingly (without implementing them). A market ecosystem map can be generated based on all the identified role interactions.

2.3.:
Define the role interface I_Role based on the identified characteristic methods and flow methods.

2.4.:
Within the characteristic methods in I_Role, identify the methods which can be standardised through predefined methods and implement these predefined methods. These methods are stored in the role class F_Role.

2.5.:
Identify the role parameters required to implement both the predefined characteristic methods, the empty characteristic methods, and the flow methods, and store them in the role class P_Role. At this stage, role parameters are defined without being assigned specific values.
Step 3: Implementing the submarket roles 3.1.: Define the agent classes which the submarket roles belong to, including the agent's success criteria and strategy methods to implement the submarket roles. The role interfaces are implemented within these classes.
For each submarket role:

3.2.: Assign values to the method parameters in all
P_Role classes associated to the agent. In case the submarket is operated by a passive agent, parameter values are defined in the Market Regulator role (defined in the next section) and sent to each role through interaction methods. 3.3.: Implement the empty characteristic methods from I_Role, taking into account the success criteria of the agent to which they belong and parameters values assigned in P_Role.

3.4.:
Implement the flow methods within the role and the corresponding connection methods to allow role interactions with the correct agents.
Step 4: Implementing the market stakeholder roles Active and passive market stakeholders interacting with the submarkets in the MVE are defined and implemented in this last step.

4.1.:
Implement the Data Provider role with its corresponding agent based on available market data. Flow and connection methods are implemented based on the endogenous and exogenous inputs which the methods in the market ecosystem need.

4.2.:
Implement the Market Regulator role with its corresponding agent. Method parameters identified in P_Role for each role must be defined here as well, as the Market Regulator will initialise all roles at the simulation start by communicating the adequate parameter values. 4.3.: Implement the Imbalance Settlement Responsible role, if relevant. This concerns markets where participants directly bid in the submarkets and operate on a self-dispatch basis.

4.4.:
Define and implement the roles assigned to the Large-Scale Consumer agent. The agent must be assigned all roles required by the market ecosystem to ensure market participation. Role implementations must take into account the specific strategy of the large-scale consumer agent, based on the consumer's strategy and success criteria. As this is not the main focus of this study, this is not covered in more detail here.

Case study
The case study focuses on implementing the Western Denmark market ecosystem (DK1 synchronous area). The following section applies the presented framework to this context. The model framework is implemented for a large-scale consumer located in the DK1 synchronous area (Western Denmark), which is part of the Nordic electricity market. The Nordic electricity market is at an advanced stage of liberalisation, and therefore consists of a large range of submarkets which the consumer can bid in. As mentioned in the introduction, pre-modelling market screening steps should be applied to select the most relevant submarkets for a specific large-scale consumer. As this study does not specify a particular large-scale consumer type, submarkets are instead chosen based on their ability to illustrate the modularity of the developed approach. Therefore, this study focuses on the Nordpool Spot day-ahead market, the Nordpool Elbas intraday market, and the Frequency Containment Reserve (FCR) market. The day-ahead market allows producers and consumers to plan operation schedules a day in advance, based on cleared price-volume bids. The volumes traded on the dayahead market represent 80% of the region's electricity consumption (Agency et al. 2018). The day-ahead market is an exchange market cleared by the market operator Nordpool. Bids are submitted at noon for all 24 h of the next day, at an hourly resolution, and are cleared centrally at uniform price based on merit order (Energinet 2007). The day-ahead market operates on a self-dispatch basis, meaning that market participants are responsible for following the schedules cleared in the market. Deviations from the cleared schedule at dispatch time must be paid back to the Imbalance Settlement Responsible, which in Denmark is a role taken up by the national Transmission System Operator (TSO) Energinet.
The intraday market allows producers and consumers to adjust their operational schedules cleared in the day-ahead market by offering to buy or sell energy at a selfdetermined price (pay-as-bid price). Schedule adjustments can be required due to unexpected outages, changed production and consumption forecasts, or can be motivated by opportunistic market arbitrage. The intraday market is cleared on the Elbas exchange operated by Nordpool but consists of bilateral bid matching. Bidding and clearing occur continuously from day-ahead market clearing at 14:00 on the previous day up to one hour before consumption (Energinet 2007). Volumes traded on the intraday market are also taken into account when settling imbalances to pay to the Imbalance Settlement Responsible.
The FCR market is a primary reserve market to provide frequency stabilisation services to the grid. Market participants who clear bids agree to provide capacity to the TSO, which can activate this capacity by ramping energy production or consumption either up or down, depending on system needs. The TSO, which is the market operator for the FCR market, therefore also has a Reserve Activation role (a more general term for the Load Frequency Control Operator role defined in the ENTSO-E HRM). DK1 is part of the larger FCR cooperation spanning across western Europe, where TSOs pool the reserve bids in an exchange and clear them at uniform price based on merit order. Bids are sent to at 8:00 AM on the previous day for the next day, in four-hour blocks, and cleared at 8:30AM (Energinet 2022).
The analysed submarkets are thereby cleared sequentially, and market participants know clearing volumes and prices of upstream submarkets by the time they participate in the next submarket. However, uncertainty arises when participation strategies rely on coordinated bidding, where bidding in one submarket considers possible future prices in downstream submarkets. The time sequence (and thereby the information sequence) of the different submarkets is summarised in Fig. 6.

Results
The step-by-step model setup outlined in the model framework is here applied to the Danish market ecosystem presented in the Case Study.

Defining the Danish electricity market ecosystem
The roles and agents of the MVE corresponding to a large-scale consumer participating in the Danish day-ahead, intraday, and FCR submarkets are shown in Fig. 7, using the modified ENTSO-E HRM terminology.
The TSO agent has only been included for its role as FCR market operator and imbalance settlement responsible but is not acting as system operator in the MVE. On the consumer side, all the market intermediary roles, such as energy trader, scheduling agent, Fig. 6 Submarket participation timeline and balance responsible party, have been assigned to the large-scale consumer. The roles and agents identified in Fig. 7 are explained in more detailed in the next sections.

Defining the submarket roles
An ecosystem map is shown in Fig. 8 to illustrate the role interactions based on which the flow methods are defined for the different submarket roles. The roles are shown as circles, agents as rectangles, and interactions are coloured coded, following the convention outlined in Ma et al. (2021). Submarket interactions are done indirectly via the Data Provider, which sends information on clearing market prices at specific In sequential submarkets, the prices in one submarket are thereby influenced by prices in submarkets cleared ahead.
Based on the submarket descriptions in the previous sections and the ecosystem interactions shown in Fig. 8, the characteristic methods, flow methods, and role parameters are derived for the roles taken by the three analysed submarkets. The role abstraction principle is used to implement the same role to different submarkets.

Market operator
In Fig. 9, the interfaces and classes of the Market Operator role are shown using modified UML class diagrams. Events and connection methods are shown using simple method definitions. The parameters in the P_Role class are based on the market bidding parameters for short-term markets identified in Fatras et al. (2022b) and the market bidding mechanism types identified in Fatras et al. (2022a). The predefined bidding logic and clearing logic are also based on the market bidding mechanism classification given in Fatras et al. (2022a).

Billing agent
In Fig. 10, the interfaces and classes belonging to the Billing Agent role are shown using modified UML class diagrams. Events and connection methods belonging to the agent are shown using simple method definitions. The parameters in the P_Role class are based on the market settlement parameters found in the literature (Energinet 2019;NordPool: NordPool Settlement 2022). The billing logic translates the cleared bids received from the market operator into costs linked to every Energy Trader.

Reserve activation
In Fig. 11, the interfaces and classes belonging to the Reserve Activation role are shown using modified UML class diagrams. Events and connection methods are Fig. 9 Interfaces, classes and methods for Market Operator role implementation shown using simple method definitions. The parameters in the P_Role class are based on the market operational parameters for short-term markets identified in Fatras et al. (2022b). The reserve activation logic is assumed to be probabilistic based on historical data of capacity reserve activation.
The logic of the F_Role methods is not explicitly described in the above figures, in line with the abstraction level of this paper.

Implementing the submarket roles
The applicability of the approach to different submarket contexts is shown below by providing the P_Role parameter values required to set up the role methods and the Agent names required to set up the connection methods. Table 4 shows the implementation the Market Operator role in the three studied submarkets. Table 5 Fig. 10 Interfaces, classes and methods for Billing Agent role implementation Fig. 11 Interfaces, classes and methods for Reserve Activation role implementation shows the implementation of the Billing Agent role in the three studied submarkets. Table 6 shows the implementation of the Reserve Activation role in the FCR market.

Implementing the market stakeholder roles
This section provides more detail on the roles identified in Fig. 7 which are part of the MVE but do not belong to a submarket. The characteristic functions associated with these roles are not detailed here, as they are not the focus of this study.

Data provider
In the Danish context, the Data Provider role is implemented by the open data platform DataHub, which provides market participants access to consumption, market price, and other market operations data, depending on participants' information access rights. The role logic only consists of flow methods to receive and send data  Agents Connect_Market_ Operator Self Self Self

Connect_Energy_ Trader
Large-Scale Consumer Large-Scale Consumer Large-Scale Consumer and information. The Data Provider must therefore have a validation protocol to ensure data can only be accessed by allowed agents. As DataHub is a data platform, it behaves as a passive agent, without a personal strategy.

Market regulator
The Market Regulator role is assigned to the Danish Utility Regulator (DUR) agent in the unbundled Danish electricity market context. This agent is mainly active at simulation start through an initialisation Event which calls the flow methods sending the role parameter values to the different submarkets in the ecosystem. Since the DUR is an independent agent without vested interests in market participation, the Market Regulator does not interfere in market operations, except to penalise market participants not respecting market regulations. As the aim of this simulation is to test the impact of given market regulations on market participation, regulations are considered "static", and the Danish Utility Regulator is considered a passive agent.

Imbalance settlement responsible
The Imbalance Settlement Responsible role is taken up by Energinet, the Danish Transmission System Operator. Bid volumes cleared by the consumer in the dayahead and intraday market are added up and compared to the volumes at dispatch time, received from the Data Provider, to calculate the imbalances caused by the consumer (Energinet 2008). Volumes activated in the FCR market are not considered, as they are too small. The load imbalances are billed to the Balance Responsible Party at regulating power prices, which are provided at an hourly resolution by the Data Provider. In this model, the TSO implementing this role is considered a passive agent.

Large-scale consumer roles
In the consumer-centric electricity market MVE, the large-scale consumer takes on both the roles of electricity consumers and market intermediaries, as its size, equipment, and risk-willingness are considered acceptable to bid directly into submarkets. Following the ENTSO-E terminology, the large-scale consumer is a Consumer, Energy Trader, Balance Responsible Party and Scheduling Agent. Since the large-scale consumer is also providing frequency stabilisation services to the grid through participation in the FCR market, it is also a Balancing Service Provider. In terms of interactions with other agents, the Energy Trader will be the main source of interaction with Market Operators to offer and clear bids. The Consumer and Balance Responsible Party will mainly receive financial flows as bills for the charged or provided services. Finally, the Balancing Service Provider receives activation requests from the Reserve Activation role. Many interactions also occur between these roles, which depend on the internal strategy of the consumer, which is an active agent.

Balancing consistency and modularity
The application of the Market Operator and Billing Agent roles to the three submarkets have shown that the implementation process for different submarkets is streamlined by the abstraction and parametrisation provided by the presented framework. This present paper complements previous studies on electricity market ontologies by decomposing markets into their different submarkets, and in turn describing these submarkets by the different roles they must fulfil. The electricity market is described as an aggregation of standardised building blocks, creating an ecosystem influenced by the context in which this market is implemented. The distinction between context-independent and contextdependent elements of the market structure is thereby underlined, showing electricity markets present commonalities and variabilities. While the EMO presented in Refs. Santos et al. (2016a) and the ENTSO-E HRM in ENTSO-E (2019) standardise the different actors and their interactions within a market, the presented work standardises the different submarket types and their interactions within a market. However, the strong context-dependency of electricity market ecosystems prevents from having a completely automated model setup approach. For empty methods in role interfaces, the logic remains to be defined by the model developer. Predefined methods considerably reduce the modelling workload, as the method logic is chosen from a limited set of predefined options. Such predefined methods are a programmatic implementation of the market property categories identified in previous studies such as in Refs. Fatras et al. (2022aFatras et al. ( ), (2022b. This comes at the cost of model accuracy, as the predefined options cannot always perfectly reflect a given market context. When choosing methods to predefine in F_Role, a trade-off must be found between consistency and modularity. Assuming context-independent flow methods for role interactions also improves model setup consistency, at the cost of implementation rigidity. For example, the Market Operator role assumes interactions with a Data Provider role to obtain market price information. However, in the case of the intraday market, prices are cleared on a payas-bid basis, implying no central clearing price data is available. In this model, this was solved by making the intraday Market Operator get market price data from itself. The systematic role definition therefore introduces some redundant modelling steps. Nonetheless, this allows large-scale consumers to quickly test different business models, where agents take up different roles. In particular, this allows large-scale consumers to test direct market participation strategies, without passing through market intermediaries such as in Refs. Golmohamadi et al. (2019); Nehrir et al. (2018). This provides a greater sense of ownership and control of demand response solutions, which was identified as a critical element for demand-side market participation (Leinauer et al. 2022;Alcázar-Ortega et al. 2015).

Reliance on data
The simplification of the electricity market ecosystem to its Minimum Viable Ecosystem creates a significant reliance on input data to compensate for the exogenous factors not considered in the model. This is particularly important for submarkets with centralised clearing, as the price depends on market participants not included in the MVE. Therefore, market participation suitability can only be evaluated based on historical market prices, or on potential future market price forecasts, but cannot consider the impact of consumer strategy on market prices. This is a drawback of the price-taker consumercentric MVE approach compared to ABM models where market prices are calculated endogenously based on provided agent bids, such as in Refs. Algarvio et al. (2016); Rylatt et al. (2018); Steber et al. (2018).
As the boundaries of the model are expanded, more parts of the energy market could be directly modelled. This implies less dependence on fixed external data and allows to test more hypotheses by analysing the dynamics of the system. However, this comes at the cost of increased uncertainty, since assumptions must be taken in the model, which might make scenario results deviate from reality. For consumers hesitant to participate in electricity markets, a fine balance must therefore be found between giving new insights from scenario exploration and staying within plausible scenarios supported by real-life data.

Conclusion
The presented agent-based modelling approach proposes a framework and step-bystep methodology to model electricity markets in a flexible, yet consistent and simple way. The model is set up from a consumer's perspective by only including stakeholders directly interacting with the consumer in a Minimum Viable Ecosystem. The use of object-oriented programming concepts allows to differentiate between reusable contextindependent elements and context-specific stakeholder logic and agent interactions. The specificity of the market context is also provided by the data input to the model, which compensates for the simplifications taken during model setup. In general, the model framework aims to find a balance between consistency and accuracy, to provide consumers with simple yet insightful modelling tools for market participation evaluation.
The implementation of this framework in the Danish context has shown that different submarket types could be quickly modelled while only changing the values of a few parameters. The proposed approach can then be adapted to other market contexts around the world, as long as they have undergone some level of market unbundling, where system operations depend on the interactions between multiple stakeholders and submarkets. The submarket modelling would then change based on the assigned agent, the assigned market regulations, and the stakeholders allowed to interact with that submarket. Of particular interest when comparing different market contexts is the impact of market architecture on information access, and the influence of agents' market power on the submarket outputs.
In general, the presented approach complements existing studies on electricity market ABM by standardising the modelling of submarkets within the market, using object-oriented programming concepts of abstraction, encapsulation and inheritance to easily adapt the model to different market structures in unbundled market contexts. Modelling setup steps are also outlined to provide a design methodology for the electricity market model. This improves the comparability of results in different market contexts, which is important to avoid generalisations based on too contextspecific results.
The implementation of the model framework in this study has mainly focused on the overall model architecture and how to set up an electricity market ecosystem as an agent-based model. Future work will have to describe in more detail the logic of the consumer's roles when participating in this market ecosystem, with specific market participation strategies based on personal success criteria. A multi-criteria decision-making approach could be taken to consider the non-financial aspect of large-scale energy consumers' decision making process.