Game.Simulation.Flow.Edge
Assembly: Game
Namespace: Game.Simulation.Flow
Type: struct
Base: System.ValueType
Summary:
Represents an edge in the flow network used by the simulation. An Edge stores a capacity, a direction (forward/backward/both/none), a committed (final) flow and a temporary flow used during augmentation/search algorithms. It also contains an Identifier used when computing minimum cuts. Utility methods compute capacity, residual capacity and oriented final flow and allow committing temporary flow into the final flow.
Fields
-
public int m_Capacity
Capacity of the edge (maximum flow the edge can carry in an allowed orientation). -
public FlowDirection m_Direction
Direction flags for the edge. Expected to be a bitmask (e.g., Forward, Backward, Both, None) that determines whether forward and/or backward flow is permitted. -
public int m_FinalFlow
Committed (final) flow value on this edge. Represents the flow that has been accepted/committed by the algorithm. -
public int m_TempFlow
Temporary flow used during search/augmentation before being committed. This is added to m_FinalFlow when FinalizeTempFlow is called. -
public Identifier m_CutElementId
Identifier used to tag or mark the edge when computing/minimizing network cuts (e.g., minimum s-t cut).
Properties
public int flow { get; }
Computed convenience property returning the current total flow on the edge (m_FinalFlow + m_TempFlow). Use this to get the effective flow considering both committed and temporary contributions.
Constructors
public Edge(int capacity, FlowDirection direction = FlowDirection.Both)
Initializes a new Edge with the given capacity and direction. m_FinalFlow and m_TempFlow are initialized to 0 and m_CutElementId is default-initialized.
Methods
-
public int GetCapacity(bool backwards)
Returns the edge's capacity if the requested orientation is allowed by m_Direction; otherwise returns 0. If backwards is true it checks the Backward bit, otherwise the Forward bit. -
public int GetResidualCapacity(bool backwards)
Computes the residual capacity for the requested orientation: - If m_Direction == FlowDirection.None returns 0.
- If backwards is true: residual = (backward allowed ? m_Capacity : 0) + flow. (Backward residual includes the current flow because sending flow back increases available capacity.)
-
If backwards is false: residual = (forward allowed ? m_Capacity : 0) - flow. (Forward residual subtracts the current flow from available capacity.) This method is used by flow algorithms to determine augmenting capacity along oriented edges.
-
public int GetFinalFlow(bool backwards)
Returns the oriented final (committed) flow: m_FinalFlow if not backwards, or -m_FinalFlow when viewed in the backward orientation. Useful when interpreting edge flow signs consistent with traversal direction. -
public void FinalizeTempFlow()
Commits the temporary flow into the final flow by adding m_TempFlow to m_FinalFlow and then zeroing m_TempFlow. Call this after successful augmentation steps to make temporary adjustments permanent.
Usage Example
// create a forward-capacity edge of 10 units
Edge e = new Edge(10, FlowDirection.Forward);
// propose a temporary augmentation of +3
e.m_TempFlow = 3;
// check residual capacity in forward direction
int residualForward = e.GetResidualCapacity(false); // = (capacity allowed ? 10 : 0) - flow
// commit the temporary augmentation
e.FinalizeTempFlow(); // m_FinalFlow becomes 3, m_TempFlow -> 0
// read effective flow
int currentFlow = e.flow; // 3
// read oriented final flow (backwards view)
int oriented = e.GetFinalFlow(true); // -3