Skip to content

[BUG] distribute_private_charging_demand: home branch books capacity to a stale charging_park_id #679

@joda9

Description

@joda9

Summary

In distribute_private_charging_demand
(edisgo/io/electromobility_import.py), the home branch discards the
return value of weighted_random_choice, so the subsequent
designated_charging_point_capacity_df bookkeeping uses a stale
charging_park_id (the one drawn for the last work car) for every home car.

Found while working on the performance refactor in #675 (which deliberately
preserves this behaviour to keep output identical; this issue tracks the actual
fix).

Where

edisgo/io/electromobility_import.py, distribute_private_charging_demand:

  • work branch (correct), ~line 885:
    charging_park_id = weighted_random_choice(...)   # return captured
    ...
    designated_charging_point_capacity_df.at[charging_park_id, ...] += charging_capacity
  • home branch (buggy), ~line 936:
    weighted_random_choice(...)                      # return discarded
    ...
    # charging_park_id is never assigned in the home loop -> stale value
    designated_charging_point_capacity_df.at[charging_park_id, ...] += charging_capacity

Destinations are processed in sorted order (0_work before 6_home), so
charging_park_id carries the last work car's park into the entire home loop.

Impact

  • The actual charging-point assignment written to charging_processes_df
    is still correct (it is set inside weighted_random_choice).
  • The capacity bookkeeping is wrong: all home cars' capacity is added to a
    single work charging park instead of their chosen home parks. Since
    designated_charging_point_capacity_df feeds back into combine_weights
    (capacity-based weighting), the "fuller park becomes less attractive"
    feedback is effectively disabled for home charging -> home cars are
    distributed without capacity feedback.
  • Edge case: a grid with home but no work charging would leave
    charging_park_id unassigned and raise NameError.

Suggested fix

Capture the return value in the home branch as well:

charging_park_id = weighted_random_choice(...)

Note this changes the resulting charging-point distribution (the weights, and
thus the stochastic draws, change), so it must be verified separately and is
intentionally not part of #675.

Part of #671.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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