agent_urban_planning.DecisionEngine¶
- class DecisionEngine(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol every decision engine implements.
Implementations MUST provide
decide(). They MAY overridedecide_batch()for optimized population-level processing; otherwise the default implementation callsdecide()in a loop. They MAY overrideset_cache()to accept an optionalLLMCallCachefrom the market loop. The four canonical library engines (closed-form, hybrid, LLM, clusterized) all satisfy this protocol.Examples
>>> import agent_urban_planning as aup >>> # Any of the public engines can be used wherever >>> # `DecisionEngine` is required: >>> # engine: aup.DecisionEngine = aup.UtilityEngine(params)
- decide(agent, environment, zone_options, prices)[source]¶
Choose a location for one agent given the environment and current prices.
Implementations decide on the agent’s residence (and workplace, if joint) given the current state of the market. The choice is returned as a
LocationChoicecarrying both selected zones, the realized utility, and per-zone diagnostic utilities.- Parameters:
environment (
Environment) – TheEnvironmentin which the agent operates.zone_options (
list[str]) – Allowed residence (and, where joint, workplace) zones at this market step.prices (
dict[str,float]) – Mappingzone -> current priceseen by the agent.
- Return type:
- Returns:
A
LocationChoicedescribing the agent’s chosen (residence, workplace) pair and realized utility.
Examples
>>> import agent_urban_planning as aup >>> # engine = aup.UtilityEngine(params) >>> # choice = engine.decide(agent, env, zones, prices)
- decide_batch(agents, environment, zone_options, prices)[source]¶
Choose locations for many agents at once.
Default implementation loops over
decide()so legacy engines keep working. Override for optimized batching (e.g. async LLM calls or vectorized per-agent matrix evaluations).- Parameters:
agents (
list[Agent]) – List ofAgentinstances to decide for.environment (
Environment) – TheEnvironmentthey operate in.
- Return type:
- Returns:
List of
LocationChoice, one per input agent and in the same order.
Examples
>>> import agent_urban_planning as aup >>> # choices = engine.decide_batch(list(pop), env, zones, prices)
- set_cache(cache)[source]¶
Inject an optional cache from the market loop.
Engines that need not cache anything ignore the call (the default is no-op). LLM-backed engines typically wire the cache into their request layer here.
- Parameters:
cache – An
agent_urban_planning.llm.LLMCallCacheor compatible object.- Return type:
- Returns:
None.
Examples
>>> import agent_urban_planning as aup >>> # engine.set_cache(cache)