Skip to content

CartoDB/workflows-extension-territory-planning

Repository files navigation

Territory Planning Extension Package

Description

An extension package for CARTO Workflows that provides comprehensive territory planning and location allocation optimization capabilities. This package enables users to solve complex spatial optimization problems by creating balanced territorial boundaries, or finding optimal facility locations, allocating demand points to facilities, and managing territorial constraints while minimizing costs or maximizing coverage.

Components

1. Facilities Preparation

Prepares facility data for location allocation optimization. Handles three types of facilities:

  • Candidate facilities: Potential locations that could be opened based on optimization strategy
  • Required facilities: Mandatory locations that are always activated regardless of strategy
  • Competitor facilities: Existing competitor locations that influence demand allocation

Supports advanced features like facility grouping, capacity constraints (min/max), and opening costs.

📖 Documentation

2. Demand Points Preparation

Prepares customer or demand point data for the optimization process. Processes locations that require service allocation such as customers, delivery addresses, or service points and optionally handles demand values for capacity-based optimization.

📖 Documentation

3. Cost Matrix Preparation

Prepares cost data (such as travel distance, travel time, or transportation costs) that define the assignment cost between each facility and demand point. Includes optional cost transformations (linear, power, exponential) to model different cost relationships and validates data integrity to ensure complete cost coverage.

📖 Documentation

4. Constraints Definition

Adds constraint definitions for location allocation that control facility-demand point relationships:

  • Required relationships: Required facility-demand point assignments that must be maintained
  • Forbidden relationships: Prohibited facility-demand point assignments that must be avoided

Helps enforce business rules and regulatory requirements in the optimization process.

📖 Documentation

5. Location-Allocation

The main optimization component that performs territory planning using advanced location allocation algorithms. Supports multiple optimization strategies:

  • Minimize total cost: Reduces overall system costs
  • Minimize maximum cost: Reduces worst-case assignment costs
  • Maximize coverage: Maximizes demand point coverage within distance limits

Includes comprehensive parameter controls for facilities limits, capacity constraints, competitor influence, demand satisfaction, and solver performance tuning.

📖 Documentation

Important

It is mandatory to use the Prepare components in advance, to ensure correct formatting of input sources.

6. Territory Balancing

An advanced spatial optimization component that splits a gridified area (H3 or Quadbin cells only) into a set of optimal, continuous territories. This component ensures balance according to a specified business metric while maintaining internal similarity within each territory.

📖 Documentation | 🚀 CloudRun Deployment

Building the extension

To build the extension, follow these steps:

  1. Install the required dependencies:

    pip install -r requirements.txt
    
  2. Package the extension:

    python carto_extension.py package
    

This will create a packaged version of the extension that can be installed in your CARTO Workflows.

Deploying the Cloud Run service

Territory Balancing is deployed as a scalable microservice for handling large spatial datasets. Follow the steps in here to deploy.

Running the tests

To run the extension tests, follow these steps:

  1. Set up environment configuration: Create a .env file from the template and configure your database connection settings.

  2. Install the required dependencies:

    pip install -r requirements.txt
    
  3. Run the test suite:

    python carto_extension.py pytest
    

Warning

Special setup required for Location-Allocation tests: Due to component dependencies, you may encounter errors when testing the locationallocation component.

Recommended workflow:

  1. First, run the constraints component tests in normal mode
  2. Copy the output table name into constraints.ndjson
  3. Switch the constraints test to skip mode in its configuration
  4. Run the complete test suite together

This ensures the required constraint tables exist before testing the location allocation optimization.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •