Skip to content

Generalize port routing with origin allow-list #19

Description

@Hackatro

Generalize origin routing and remove region from the agent layer

Problem

Region (bra/arg/usa) is hardcoded across three places that should be
region-agnostic:

  • Transport (transport.py, _move_split): Brazilian ports filter out
    non-BRA soy with hardcoded exclude_arg / exclude_usa flags. Logic is
    negative ("all except…") and leans on untyped getattr reads. Every new
    origin needs another exclude_* flag. (Raised in PR
    4-allow-for-conditional-events.)
  • Wholesaler agent (trader.py): derives bra/arg/usa_volume from
    volume_by_origin using hardcoded origin strings — location living in an agent.
  • Reporting (data_collector.py): the per-region CSV columns require those
    named attrs to exist on the agent, because Melodie's DataCollector records by
    attribute name.

volume_by_origin (keyed on farmer.origin) is already the region-agnostic
source of truth. Region is a routing + reporting dimension, not agent state.

Fix

  • Give each export port an explicit accepted_origins set (Santos/Paranagua →
    {"bra"}) and route only matching-origin volume from volume_by_origin.
    Drop the exclude_* params and getattr lookups.
  • Remove bra/arg/usa_volume and all origin string literals from trader.py.
    The agent keeps only volume_by_origin.
  • Move the origin→region-column projection into the reporting layer, computed
    from volume_by_origin. This is the only place region may live.
  • Keep the origin→region mapping in exactly one non-agent location.

Acceptance

  • No exclude_* flags in transport.py; routing driven by accepted_origins.
  • No region attrs or origin/region string literals in agents/*.py
    (grep clean: bra_volume|arg_volume|usa_volume,
    brazil_farms|argentina_farms|us_farms).
  • Transport reads volume_by_origin, never named attrs.
  • Per-region CSV columns produced by the reporting layer; names/order unchanged.
  • Origin→region mapping lives in exactly one non-agent location.
  • Adding a new producer origin needs no change to _move_split and no change
    to any agent file.
  • Full-run regression: all Result_Simulator_*.csv byte-identical to a
    pre-change baseline (Santos/Paranagua output unchanged).

Note

Branch 31-unify-farmer-trader-… merges first with the compatibility shim in
place (trader.py:140-144, plus the bra/arg/usa_volume attrs). This ticket
then pulls dev and removes that shim — deleting the three attrs, the origin
string literals, and the now-stale comment — as part of the work here.

Ref: transport.py:_move_split, trader.py, data_collector.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    improvementFor everything that improves an already existing feature.simulation logicFor everything related to the internal simulation logic

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions