npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

group-planner

v0.2.0

Published

Partition competitors into groups by equipment, age, and gender

Readme

Group Planner

A TypeScript library for competitor partitioning algorithms, designed to be integrated into Next.js applications. Provides multiple algorithmic approaches to partition competitors into balanced subsets based on equipment class, age category, and gender preferences.

Features

  • Multiple Algorithm Approaches: Mixed Integer Programming (Greedy & HiGHS), K-means Clustering
  • Flexible Constraints: Configurable subset sizes (3-6 competitors, prefer 4). A target is never size 1 or 2.
  • Guardian Constraint Enforcement: Competitors must be in the same subset as their guardians
  • Multiple Optimization Criteria:
    • Even gender distribution within subsets
    • Age category homogeneity
    • Equipment class grouping or distribution
    • Guardian relationship handling
  • TypeScript Support: Full type safety and IntelliSense
  • Performance Optimized: Efficient algorithms suitable for up to 168 competitors

Installation

npm install group-planner

Quick Start

Usage

import { solve, type Competitor } from 'group-planner';

const competitors: Competitor[] = [
  { id: '001', equipmentClass: 'HB', ageCategory: 'J', gender: 'M' },
  { id: '002', equipmentClass: 'HB', ageCategory: 'J', gender: 'F' },
  { id: '003', equipmentClass: 'LB', ageCategory: 'A', gender: 'M' }, // Guardian
  { id: '004', equipmentClass: 'LB', ageCategory: 'A', gender: 'F' },
  { id: '005', equipmentClass: 'BBR', ageCategory: 'C', gender: 'M', guardianId: '003' }, // Must be with guardian 003
  // ... more competitors
];

// Auto-select best algorithm (default)
const result = await solve(competitors, {
  groupByEquipmentClass: true,
  preferredSubsetSize: 4,
});

// Or specify a particular algorithm
const mipResult = await solve(competitors, { algorithm: 'mip' });
const higgsResult = await solve(competitors, { algorithm: 'mip-lp' }); // HiGHS MIP solver
const clusteringResult = await solve(competitors, { algorithm: 'clustering' });

console.log(`Algorithm used: ${result.algorithmUsed}`);
console.log(`Score: ${result.result.score}`);
console.log(`Subsets:`, result.result.subsets);

Algorithm Comparison

If you want to compare all algorithms and see detailed results:

import { compareAlgorithms } from 'group-planner';

const { bestResult, allResults } = await compareAlgorithms(competitors, {
  groupByEquipmentClass: true,
  preferredSubsetSize: 4,
});

console.log(`Best algorithm: ${bestResult.algorithmUsed}`);
allResults.forEach(result => {
  console.log(`${result.algorithmUsed}: Score ${result.result.score} (${result.executionTime}ms)`);
});

Algorithm Approaches

1. Mixed Integer Programming (MIP)

Formulates the problem as an optimization problem with binary variables and constraints. Treats guardian families as atomic units that must be assigned together.

import { solveMIP } from 'group-planner';

const result = solveMIP(competitors, options);

2. K-means Clustering

Uses feature encoding and weighted distance metrics to cluster guardian families based on similarity, then adjusts clusters to meet size constraints while keeping families together.

import { solveClustering } from 'group-planner';

const result = solveClustering(competitors, options);

3. Branch-and-bound

Systematically searches the solution space by assigning guardian families (not individual competitors) to subsets, ensuring guardians and their dependents stay together.

// Branch-and-bound algorithm has been removed due to performance issues
// Use 'mip', 'mip-lp', or 'clustering' algorithms instead

Configuration Options

interface PartitionOptions {
  /** Prefer grouping competitors of same equipment class together vs distributing evenly */
  groupByEquipmentClass: boolean;
  /** Maximum number of subsets allowed (default: 28) */
  maxSubsets?: number;
  /** Minimum subset size. Below 3 is raised to 3 (default: 3) */
  minSubsetSize?: number;
  /** Maximum subset size (default: 6) */
  maxSubsetSize?: number;
  /** Preferred subset size (default: 4) */
  preferredSubsetSize?: number;
  /** Weight for same gender preference (default: 1.0) */
  genderWeight?: number;
  /** Weight for same age category preference (default: 1.0) */
  ageCategoryWeight?: number;
  /** Weight for equipment class grouping preference (default: 1.0) */
  equipmentClassWeight?: number;
  /** Extra weight for subsets that are exactly preferredSubsetSize (default: 0) */
  closedGroupWeight?: number;
  /** Host labels for bowstyle, age, and gender. Defaults to the built-in IFAA lists. */
  solutionSpace?: SolutionSpace;
}

Competitor Interface

interface Competitor {
  id: string;
  equipmentClass: string; // IFAA code, or any label listed in solutionSpace
  ageCategory: string;    // IFAA age code, or any label listed in solutionSpace
  gender: string;         // F, M, or any label listed in solutionSpace
  guardianId?: string;    // Reference to another competitor who is the guardian
}

Equipment Classes

  • HB: Heavy Bow
  • LB: Light Bow
  • TR: Traditional Recurve
  • BHR: Barebow Heavy Recurve
  • BBR: Barebow Basic Recurve
  • FSR: Freestyle Recurve
  • BBC: Barebow Compound
  • BL: Barebow Longbow
  • BU: Barebow Unlimited
  • FSC: Freestyle Compound
  • FU: Freestyle Unlimited

Age Groups

  • C: Children
  • J: Juniors
  • YA: Young Adults
  • A: Adults
  • V: Veterans
  • S: Seniors

Gender

  • F: Female
  • M: Male

Algorithm Selection

The library supports four algorithm options:

Algorithm Options

type Algorithm = 'mip' | 'clustering' | 'branch-and-bound' | 'auto';
  • 'auto' (default): Runs all three algorithms and returns the result with the highest score
  • 'mip': Mixed Integer Programming approach using greedy heuristic
  • 'clustering': K-means clustering with constraint adjustment
  • 'branch-and-bound': Systematic search with pruning

When to Use Each Algorithm

  • Auto: Best for production use when you want optimal results
  • MIP: Good balance of speed and quality, handles large datasets well
  • Clustering: Fast execution, good for real-time applications
  • Branch-and-bound: Most thorough search, best for smaller datasets (≤48 competitors)

Algorithm Performance Characteristics

| Algorithm | Speed | Quality | Max Competitors | Memory Usage | |-----------|-------|---------|-----------------|--------------| | MIP | Fast | High | 168 | Low | | Clustering | Fastest | Good | 168 | Low | | Branch-and-bound | Slow | Highest | ~48 | Medium | | Auto | Slow | Highest | 168 | Medium |

Result Structure

interface PartitionResult {
  subsets: Competitor[][];
  score: number;
  metadata: {
    totalCompetitors: number;
    totalSubsets: number;
    averageSubsetSize: number;
    scoreBreakdown: {
      sizeScore: number;
      closedGroupScore: number;
      genderScore: number;
      ageCategoryScore: number;
      equipmentClassScore: number;
    };
  };
}

Algorithm Selection

The library supports different algorithms via the algorithm option:

type Algorithm = 'mip' | 'mip-lp' | 'clustering' | 'auto';

// Available algorithms:
const mipResult = await solve(competitors, { algorithm: 'mip' });        // Greedy MIP solver
const higgsResult = await solve(competitors, { algorithm: 'mip-lp' });   // HiGHS MIP solver (WebAssembly)
const clusteringResult = await solve(competitors, { algorithm: 'clustering' }); // K-means clustering
const autoResult = await solve(competitors, { algorithm: 'auto' });     // Auto-select best (default)

Performance Guide

  • MIP (Greedy): Fast, good for most cases, handles all constraint types
  • MIP-LP (HiGHS): Most optimal results, slower, excellent constraint satisfaction
  • Clustering: Fast, good for large datasets, may need constraint post-processing
  • Auto: Runs all algorithms and returns the best result

Special Constraints

  • ≤112 competitors: When maxSubsetSize is omitted, maximum subset size is limited to 4. An explicit maxSubsetSize is kept.
  • Closed groups: Raise closedGroupWeight to prefer subsets of exactly preferredSubsetSize. Gender, age, and equipment weights still trade off inside that size.
  • No short targets: Subset size is at least 3. A leftover archer is not placed on a target of 1 or 2.
  • Guardian relationships: Automatically preserved across all algorithms
  • Maximum 28 subsets: Hard limit enforced by all algorithms

Guardian Constraints

The library automatically handles guardian relationships:

import { 
  createGuardianFamilies, 
  validateGuardianConstraints,
  validateCompetitors,
  EQUIPMENT_CLASSES,
  AGE_GROUPS 
} from 'group-planner';

// Validate competitor data before processing
const validation = validateCompetitors(competitors);
if (!validation.valid) {
  console.log('Validation errors:', validation.errors);
  return;
}

// View how competitors are grouped into families
const families = createGuardianFamilies(competitors);
console.log('Guardian families:', families);

// Validate that a solution respects guardian constraints
const guardianValidation = validateGuardianConstraints(competitors, subsets);
if (!guardianValidation.valid) {
  console.log('Guardian constraint violations:', guardianValidation.errors);
}

// Access available categories
console.log('Equipment classes:', EQUIPMENT_CLASSES);
console.log('Age groups:', AGE_GROUPS);

Examples

See src/example.ts for complete usage examples including:

  • Basic partitioning with all three algorithms
  • Guardian relationship handling and validation
  • Comparing equipment class grouping vs distribution strategies
  • Custom scoring weights

Development

Setup

npm install

Build

npm run build

Development Mode

npm run dev

Type Checking

npm run type-check

Algorithm Performance

  • MIP Solver: Fast greedy heuristic, good for large datasets
  • K-means Clustering: Balanced approach, handles feature similarity well
  • Branch-and-bound: Most thorough search, best for smaller datasets (<50 competitors)

Release

The package name group-planner is unscoped. prepublishOnly cleans and builds dist before publish:

npm test
npm publish

Installing from git runs prepare, which builds dist as well.

License

MIT