Equipment Manufacturing Sector¶
Purpose: The EquipmentManSector acts as the central logistics hub for heavy equipment on the Moon. Despite its name, its primary role in the current implementation is not manufacturing, but rather managing the inventory of critical assets like rovers and robots. It ensures that other sectors have the equipment they need to operate and expand by managing stock levels and orchestrating resupply missions from Earth.
Core Components:
EquipmentInventory: The heart of the sector, this class tracks the lifecycle of all equipment.physical_stock: The quantity of equipment physically present and available for allocation on the Moon.pending_orders: The quantity of equipment that has been requested from Earth but has not yet arrived.
EquipmentConfig: Holds theminimum_levelthreshold for a single equipment type. One is built per entry in theminimum_levelsconfig._equipment_backlog: Adequethat holds unfulfilled equipment requests from other sectors. If a request cannot be met due to insufficient stock, it remains in the backlog to be re-evaluated in a future step._event_buffer: A list that collectspayload_deliveredandequipment_requestevents as they arrive via the event bus. It is drained at the start of the next call tostep().
High-Level Flow¶
flowchart TD
A[Simulation step begins] --> B[Process buffered events]
B --> C{Event type}
C -->|payload_delivered| D[Add delivered equipment to physical stock]
D --> E[Reduce matching pending orders]
C -->|equipment_request| F[Add request to equipment backlog]
E --> G[Process equipment backlog]
F --> G
G --> H{Physical stock available?}
H -->|Enough stock| I[Publish equipment_allocated event]
I --> J[Remove allocated equipment from physical stock]
H -->|Partial stock| K[Publish partial equipment_allocated event]
K --> L[Keep outstanding quantity in backlog]
H -->|No stock| L
J --> M[Check resupply needs]
L --> M
M --> N[Sum outstanding backlog quantity per equipment type]
N --> O[Calculate effective stock: physical + pending]
O --> P[Target level: configured minimum + backlog demand]
P --> Q{Effective stock below target?}
Q -->|Yes| R[Add deficit to transport request payload]
R --> S[Increase pending orders immediately]
Q -->|No| T[No resupply needed]
S --> U{Any payload requested?}
T --> U
U -->|Yes| V[Publish transport_request event]
U -->|No| W[Step ends]
V --> W
Operational Cycle & Key Algorithms¶
The sector’s logic is event-driven and revolves around maintaining minimum stock levels. step() runs _process_buffered_events() (which itself calls _process_equipment_backlog() at the end) followed by _check_and_request_resupply(). The sector does not consume power: get_power_demand() returns a fixed 1.0 kW, and the allocated_power passed into step() is returned unchanged.
A. Event Processing (_process_buffered_events)
At the start of each step, the sector processes all events buffered since the last step by popping them off _event_buffer.
payload_delivered: When a resupply mission from Earth arrives, the sector updates its inventory:Increases
physical_stockwith the delivered items.Decreases
pending_ordersby the same amount, as the order is now fulfilled.
equipment_request: When another sector requests equipment, the request is appended to the_equipment_backlog.
B. Fulfilling Requests (_process_equipment_backlog / _fulfill_equipment_request)
The sector attempts to fulfill pending requests from its physical_stock, in backlog order (FIFO).
If stock is sufficient, it publishes an
equipment_allocatedevent (notifying the requesting sector) and deducts the items from its inventory.If stock is insufficient but non-zero, it allocates what it has (partial fulfillment), publishes
equipment_allocatedfor that smaller quantity, and re-queues the request with the outstanding quantity.If stock is zero, the full request is re-queued unchanged.
C. Proactive Resupply Logic (_check_and_request_resupply)
This is the core algorithm that prevents equipment shortages. For each equipment type with a configured EquipmentConfig:
Backlog demand: It first sums the outstanding
quantityacross every request still in_equipment_backlog, grouped byequipment_type.Effective stock:
physical_stock + pending_orders(see Equations below).Target level: the configured
minimum_levelplus that equipment type’s backlog demand, so a type with unmet requests is resupplied above its baseline minimum.Request resupply: If effective stock is below the target level, it calculates the deficit and immediately takes two actions:
Publishes a
transport_requestevent, asking theTransportationSectorto launch a resupply mission from Earth with the required equipment.Immediately increases its own
pending_ordersfor the requested amount. This is critical as it prevents the sector from sending duplicate resupply requests in subsequent steps for items that are already in transit.
A single
transport_requestevent (covering every deficient equipment type in that step) is only published if at least one type is below target.
Equations¶
Effective Stock:
Resupply Target & Order Quantity:
Configuration Options¶
The sector is configured in the world_system JSON file. You can set initial inventory levels and define the minimum stock thresholds that trigger the resupply logic. Equipment names are centralized in world_system_defs.py as EquipmentType.
"equipment_manufacturing": {
"sector_name": "equipment_manufacturing",
"resupply_origin": "Moon",
"resupply_destination": "Earth",
"initial_stocks": {
"Science_Rover_EQ": 2,
"Assembly_Robot_EQ": 1
},
"minimum_levels": {
"Science_Rover_EQ": 3,
"Assembly_Robot_EQ": 2,
"ISRU_Robot_EQ": 2
}
}
resupply_origin and resupply_destination default to the model’s environment_name (typically "Moon") and "Earth" respectively if omitted. Equipment types that appear in initial_stocks but have no entry in minimum_levels are tracked in physical stock but never trigger resupply.
State Persistence & Metrics¶
_apply_latest_state: On construction, ifconfig["latest_state"]is present, the sector restoressector_state,physical_stock,pending_orders, and the_equipment_backlogqueue from it (falling back to flattenedequipment_*keys for physical stock if noinventory_physical/physical_stockdict is found).get_metrics: Returnssector_state,inventory_physical,inventory_pending,backlog_queue, plus each physical stock item flattened asequipment_<item>for reporting.
TODO: Potential Improvements¶
[ ] Add Power Consumption:
get_power_demand()is hardcoded to1.0kW regardless of fleet size or activity; it does not yet model actual equipment handling/storage power draw.[ ] Add Manufacturing Capability: The sector currently only manages inventory and resupply; it does not manufacture equipment locally despite its name.
[ ] Backlog Starvation Handling: Partially-fulfilled requests are re-queued with no aging or priority, so an old low-priority request can sit behind newer ones indefinitely if stock stays scarce.