agents.base package

agents.base.Intermediary module

Superclass for any intermediary in the model (i.e. Plumber, EnergyAdvisor (EA)), but not for Houseowner Contains common methods to ensure basic functionality.

Authors:
class Intermediary(unique_id: int, model: Model, heating_preferences=None, known_hs=None, active_jobs: dict = None, completed_jobs: dict = None, max_concurrent_jobs: int = 1, active_jobs_counter: int = 0, hs_evaluation_params: list = None, hs_evaluation_params_rescale: list = None)[source]

Bases: Agent

A base class for intermediary agents like Plumbers and Energy Advisors.

This class provides common functionality for agents that interact with Houseowners to provide services. It manages the lifecycle of jobs (queuing, starting, and completing), evaluates heating systems based on a set of preferences, and shares knowledge and ratings with other agents.

Initialises an intermediary.

Parameters:
unique_id: int

ID of the intermediary.

model: MESA Model

An instance of MESA Model to contain the intermediary.

heating_preferences: Heating_preferences

Class containing weights for heating attribute evaluation.

known_hs: list

A list of heating systems the agent has learned about through information gathering or social interactions.

active_jobs: dict

Contains jobs that intermediary does.

completed_jobs: dict

Contains completed jobs for data gathering.

max_concurrent_jobs: int

Maximum number fo jobs the intermediary can do at the same time.

active_jobs_counter: int

Counts the number of jobs done currently.

hs_evaluation_params: list

List of heating attributes to be considered during evaluation.

hs_evaluation_params_rescale: list

List of heating attributes to be considered during evaluation, rescaled if less or more attributes are needed.

step() None[source]

Performs the common step for any intermediary.

Ensures that new subclasses perform basic actions without errors. Should be overridden in each subclass to include specific actions.

work()[source]

Two actions: 1. Transfers some jobs from service.job_queue to self.active_jobs. 2. Performs service-specific job. This happens only for jobs assigned for the current step.

training()[source]

Plumber/EA compatibility method Plumbers have their own training, while EA use this

update_attributes()[source]

Updates data tables for known technologies when dynamics values of the attributes are used. Synchronises own parameter table with that of the model.

begin_jobs(steps, service)[source]

Transfers some jobs from service.job_queue to self.active_jobs. Job completion is set to a step in the future. Number of jobs transfered depends on self.max_concurrent_jobs. Orders the service to begin the jobs.

Parameters:
steps: int

ID of the step to set the job duration. Normally, the current step.

service: Service

Service to begin the job.

check_job_completion(steps)[source]

Checks the self.active_jobs for jobs that should be finished at the given step.

Parameters:
steps: int

Step ID to check the job completion. Normally, the current step.

evaluate_system(system)[source]

Creates a heating system rating using heating system’s parameters and agent’s preferences.

Parameters:
system: Heating_system

The Heating_system object to be evaluated.

share_rating(agent)[source]

The intermediary shares the ratings of his known HS with a client

Parameters:
agent: Houseowner

A houseowner to share the ratings of known HS.

share_knowledge(agent)[source]

The intermediary shares the knowledge about their known heating systems with an agent. It also influences agent’s opinion on other known systems

Parameters:
counterpart: Houseowner

A houseowner to share the knowledge about known HS.

get_heating()[source]
get_trigger()[source]
get_stage_dynamics()[source]
get_class()[source]
get_system_age()[source]
get_opinion()[source]
get_satisfied_ratio()[source]
get_preferences()[source]
get_attributes()[source]
get_comprehensive_metrics()[source]
get_emissions()[source]
get_energy_demand()[source]
get_obstacles()[source]

agents.base.Job module

A module for defining job and service data structures.

This module provides the Job dataclass, which encapsulates all necessary information for a task to be performed by an intermediary agent for a houseowner. It also includes the IService interface for type hinting services.

Authors:
class IService[source]

Bases: object

Represents an interface for services offered by intermediary agents.

class Job(job_id: str, customer: Agent, service: IService, duration: int = 1)[source]

Bases: object

A data class representing a job to be performed by an intermediary.

Attributes:
job_idstr

A unique identifier for the job.

customerAgent

The agent (typically a Houseowner) who requested the job.

serviceIService

The service that is performing the job.

durationint, optional

The time (in simulation steps) required to complete the job.

job_id: str
customer: Agent
service: IService
duration: int = 1

agents.base.Service module

Defines base classes for services provided by intermediary agents.

This module contains the abstract Service class, which provides a template for services like consultations or installations. It manages a job queue and handles the basic job lifecycle. It also includes a concrete ConsultationService class that inherits from Service.

Authors:
class Service(intermediary=None, job_queue: deque = None)[source]

Bases: IService

An abstract base class for services offered by intermediary agents.

This class manages a queue of jobs, generates unique job IDs, and defines the interface for beginning, completing, and logging jobs. Subclasses must implement the begin_job method.

Attributes:
intermediaryIntermediary

The intermediary agent providing the service.

durationint

The default time in steps required to complete a job for this service.

job_counterint

A counter for the number of jobs queued for this service.

job_queuedeque

A queue of Job objects waiting to be processed.

Initializes a Service instance.

Parameters:
intermediaryIntermediary, optional

The intermediary agent providing the service.

job_queuedeque, optional

An initial queue of jobs. Defaults to an empty deque.

queue_job(houseowner)[source]

Adds a new job to the service’s queue for a given houseowner.

Also prevents duplicate jobs from the same houseowner from being added to the queue. It creates a Job object and appends to the job queue of the Service.

Parameters:
houseownerHouseowner

The houseowner agent requesting the service.

generate_id()[source]

Generates a unique ID for a new job.

Returns:
str

The formatted job ID, combining the intermediary ID, service name, and job counter.

abstractmethod begin_job()[source]

An abstract method to begin processing a job.

Subclasses must implement this method to define the specific actions taken when a job starts.

complete_job(job)[source]

Finalizes a job and logs its completion.

Records the details of the completed job in the model’s datacollector for later analysis. Usually supplemented by complete_job of a specific intermediary.

Parameters:
jobJob

The job that has been completed.

save_queue_length()[source]

Saves the current length of the job queue to the datacollector.

This method is used for data collection at each simulation step to track the workload of services.

class ConsultationService(intermediary=None, job_queue: deque = None)[source]

Bases: Service

A concrete implementation of a consultation service.

This class serves as a specific type of Service for consultations. It can be further subclassed or overridden to specify durations and behaviors for different intermediary types (e.g., Plumber, EnergyAdvisor).

Initializes a Service instance.

Parameters:
intermediaryIntermediary, optional

The intermediary agent providing the service.

job_queuedeque, optional

An initial queue of jobs. Defaults to an empty deque.

Module contents