C

MinimumCostFlow

Solves a minimum-cost flow problem.
Inheritance Hierarchy

Remarks

The minimum-cost flow problem is an optimization problem to find the cheapest possible way of sending a certain amount of flow through a network with capacities and costs.

There are three main ways of using this class, depending on how the problem to solve is stated. All variants require the maximumCapacities and costs.

  1. There can be minimumCapacities for edges as well as the maximumCapacities. In this variant supply is considered for defining supply/demand for nodes in the network, while source and sink are ignored.
  2. A source and sink node can be provided, in which case supply is ignored.
  3. As a third option, multiple nodes can have specific values for supply and demand configured via supply.

Other Flow Algorithms

yFiles for HTML supports another algorithm related to network flow:

  • MaximumFlow – solves a maximum flow problem where the largest possible flow through a network should be determined

Examples

Calculating a minimum cost flow of the graph
// prepare the minimum cost flow algorithm
const algorithm = new MinimumCostFlow({
  maximumCapacities,
  supply,
  costs,
})
// run the algorithm
const result = algorithm.run(graph)

// add labels indicating the actual flow
for (const edge of graph.edges) {
  graph.addLabel(edge, String(result.flow.get(edge)))
}

See Also

Developer's Guide

API

minimumCostFlow

Members

No filters for this type

Constructors

Parameters

Properties

Gets or sets a mapping for edge costs.
Edge costs influence how expensive it is to route part of the overall flow over that edge. The goal of this algorithm is to get as much flow through the overall graph while minimizing the total costs.
conversionfinal

See Also

Developer's Guide
Gets or sets a mapping for maximum capacities of edges.
The maximum capacity of an edge is the maximum possible flow over that edge.
conversionfinal

See Also

Developer's Guide
Gets or sets a mapping for the minimum capacities of edges.
conversionfinal

See Also

Developer's Guide
Gets or sets a single sink node.

If none is provided, the overall flow is calculated. In this case it is mandatory to provide a valid supply mapping.

If multiple are provided, the first valid sink node is used.

conversionfinal

See Also

Developer's Guide
Gets or sets a single source node.

If none is provided, the overall flow is calculated. In this case, it is mandatory to provide a valid supply mapping.

If multiple are provided, the first valid source node is used.

conversionfinal

See Also

Developer's Guide
Gets or sets the collection of edges which define a subset of the graph for the algorithms to work on.

If nothing is set, all edges of the graph will be processed.

If only the excludes are set, all edges in the graph except those provided in the excludes are processed.

Note that edges which start or end at nodes which are not in the subgraphNodes are automatically not considered by the algorithm.

ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithm.

The edges provided here must be part of the graph which is passed to the run method.
conversionfinal

Examples

Calculating a minimum cost flow of a subset of the graph
// prepare the minimum cost flow algorithm
const algorithm = new MinimumCostFlow({
  maximumCapacities,
  supply,
  costs,
  // Ignore edges without target arrow heads
  subgraphEdges: {
    excludes: (edge: IEdge): boolean =>
      edge.style instanceof PolylineEdgeStyle &&
      edge.style.targetArrow instanceof Arrow &&
      edge.style.targetArrow.type === ArrowType.NONE,
  },
})
// run the algorithm
const result = algorithm.run(graph)

// add labels indicating the actual flow
for (const edge of graph.edges) {
  graph.addLabel(edge, String(result.flow.get(edge)))
}
Gets or sets the collection of nodes which define a subset of the graph for the algorithms to work on.

If nothing is set, all nodes of the graph will be processed.

If only the excludes are set, all nodes in the graph except those provided in the excludes are processed.

ItemCollection<T> instances may be shared among algorithm instances and will be (re-)evaluated upon (re-)execution of the algorithm.

The nodes provided here must be part of the graph which is passed to the run method.
conversionfinal

Examples

Calculating a minimum cost flow of a subset of the graph
// prepare the minimum cost flow algorithm
const algorithm = new MinimumCostFlow({
  maximumCapacities,
  supply,
  costs,
  subgraphNodes: {
    // only consider elliptical nodes in the graph
    includes: (node: INode): boolean =>
      node.style instanceof ShapeNodeStyle &&
      node.style.shape === ShapeNodeShape.ELLIPSE,
    // but ignore the first node, regardless of its shape
    excludes: graph.nodes.first()!,
  },
})
// run the algorithm
const result = algorithm.run(graph)

// add labels indicating the actual flow
for (const edge of graph.edges) {
  graph.addLabel(edge, String(result.flow.get(edge)))
}
Gets or sets a mapping which provides the supply (or demand, if negative) for each node.

Nodes with a positive supply effectively act as additional sources, while nodes with a negative supply (demand) effectively act as additional sinks. However, both can appear anywhere in the network.

This value is ignored if both a source and sink node but no minimumCapacities are provided.

If no source or sink or neither of them are provided it is mandatory to provide a valid supply map.

conversionfinal

See Also

Developer's Guide

Methods

Solves the minimum-cost flow problem.
The result obtained from this algorithm is a snapshot which is no longer valid once the graph has changed, e.g. by adding or removing nodes or edges.
final

Parameters

graph: IGraph
The input graph to run the algorithm on.

Return Value

MinimumCostFlowResult
A MinimumCostFlowResult containing the flow for each edge and the total cost.

Throws

Exception ({ name: 'InvalidOperationError' })
If the algorithm can't create a valid result due to an invalid graph structure or wrongly configured properties.