Skip to main content

Custom Weight Calculations  

Helix’s shortest path algorithms support sophisticated weight calculations that can reference properties from edges, source nodes, and destination nodes. This enables real-world routing scenarios where path costs depend on multiple factors and contexts.
Custom weights are available in both ShortestPathDijkstras and ShortestPathAStar.

Property Contexts

Property contexts allow you to reference different parts of the graph structure in your weight expressions:
All weight expressions must evaluate to non-negative values. Negative weights can cause incorrect results or infinite loops.

Context Reference Table

Edge Context: _::{property}

Access properties directly on the edge being evaluated:
Common use cases:
  • Distance-based routing
  • Bandwidth optimization
  • Cost minimization
  • Time-based routing

Source Node Context: _::FromN::{property}

Access properties from the node where the edge originates:
Common use cases:
  • Traffic-aware routing (avoid congested sources)
  • Elevation-based path planning
  • Load balancing (distribute from busy sources)
  • Source capacity constraints

Destination Node Context: _::ToN::{property}

Access properties from the node where the edge terminates:
Common use cases:
  • Popularity-weighted routing
  • Destination capacity management
  • Cost-aware pathfinding
  • Attraction-based navigation

Example 1: Time-decay routing with source context

Here’s how to run the query using the SDKs or curl

Example 2: Destination-aware routing with popularity weighting

Here’s how to run the query using the SDKs or curl

Example 3: Combining source and destination contexts

Here’s how to run the query using the SDKs or curl

Real-World Use Cases

Traffic-Aware Navigation

Cost Optimization

Load Balancing

Capacity Planning

Best Practices

1. Property Normalization

Ensure properties are on similar scales:

2. Avoid Division by Zero

Protect against zero denominators:

3. Index Key Properties

For best performance, index properties used in weight calculations:

4. Test Weight Distributions

Verify weights produce expected behavior:
  • Log sample weights during development
  • Ensure non-negative values
  • Check for reasonable ranges

Weight Expressions

Advanced mathematical weight calculations

ShortestPathDijkstras

Full Dijkstra algorithm documentation

Mathematical Functions

All available math functions

Overview

Compare all shortest path algorithms