Skip to main content

Coords-NSGA2

License PyPI Python GitHub Tag Build Status

English | 中文

⚠️ Important Notice: This documentation and README files are AI-generated based on the source code analysis. While we strive for accuracy, there may be inconsistencies or issues. We are actively working to improve and verify all content. Please report any problems you encounter.

A Python library implementing a coordinate-based NSGA-II (Non-dominated Sorting Genetic Algorithm II) for multi-objective optimization. This library is specifically designed for optimizing coordinate point layouts, featuring specialized constraints, crossover, and mutation operators that work directly on coordinate points.

Features

  • Coordinate-focused optimization: Designed specifically for optimizing layouts of coordinate points
  • Variable point count support: Supports both fixed number of points and dynamic point count within a specified range
  • Multi-objective optimization: Supports 2 or more objective functions using NSGA-II algorithm
  • Flexible Objective/Constraint Definition: Supports defining multiple objectives/constraints either as a list of functions or as a single function returning a tuple/list of values, accommodating interdependencies between calculations
  • Parallel computation: Accelerate optimization with parallel processing for computationally intensive problems
  • Specialized constraints: Built-in support for point spacing, boundary limits, and custom constraints
  • Tailored genetic operators: Custom crossover and mutation operators that directly act on coordinate points
  • Flexible region definition: Support for both polygon and rectangular regions
  • Lightweight and extensible: Easy to customize operators and constraints
  • Progress tracking: Built-in progress bars and optimization history
  • Save/Load functionality: Save and restore optimization states

Installation

From PyPI

pip install coords-nsga2

From Source

git clone https://github.com/ZXF1001/coords-nsga2.git
cd coords-nsga2
pip install -e .

Quick Start

Here's a minimal example demonstrating how to run a coordinate-based NSGA-II optimization with multiple objectives:

import numpy as np
from scipy.spatial import distance
from coords_nsga2 import CoordsNSGA2, Problem
from coords_nsga2.spatial import region_from_points

# Define the optimization region
region = region_from_points([
    [0, 0],
    [1, 0],
    [2, 1],
    [1, 1],
])

# Define objective functions
def objective_1(coords):
    """Maximize sum of x and y coordinates"""
    return np.sum(coords[:, 0]) + np.sum(coords[:, 1])

def objective_2(coords):
    """Maximize spread of points"""
    return np.std(coords[:, 0]) + np.std(coords[:, 1])

# Define constraints
spacing = 0.05
def constraint_1(coords):
    """Minimum spacing between points"""
    dist_list = distance.pdist(coords)
    penalty_list = spacing - dist_list[dist_list < spacing]
    return np.sum(penalty_list)

# Setup the problem
problem = Problem(
    objectives=[objective_1, objective_2],  # Can be a list of functions, or a single function returning a tuple/list of values
    n_points=[10, 30],  # Can be fixed number or range [min, max]
    region=region,
    constraints=[constraint_1] # Can be a list of functions, or a single function returning a tuple/list of values
)

# Initialize the optimizer
optimizer = CoordsNSGA2(
    problem=problem,
    pop_size=20,
    prob_crs=0.5,
    prob_mut=0.1
)

# Run optimization
result = optimizer.run(1000)

# Visualize optimal layouts for each objective
optimizer.plot.optimal_coords(obj_indices=0)

# Access results
print(f"Result shape: {result.shape}")
print(f"Number of objectives: {len(optimizer.values_P)}")
print(f"Optimization history length: {len(optimizer.P_history)}")

Documentation

Complete documentation is available in the docs/ folder.

To start the documentation server locally:

mkdocs serve

To build the documentation:

mkdocs build

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the Apache-2.0 License - see the LICENSE file for details.

Citation

If you use this library in your research, please cite:

@software{Coords-NSGA2,
  title={Coords-NSGA2: A Python library for coordinate-based multi-objective optimization},
  author={Zhang, Xiaofeng},
  year={2025},
  url={https://github.com/ZXF1001/coords-nsga2}
}

Release files for coords-nsga2 2.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for coords-nsga2 2.7.0
File Size Uploaded
coords_nsga2-2.7.0.tar.gz 49.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for coords-nsga2 2.7.0
File Interpreter ABI Platform
coords_nsga2-2.7.0-py3-none-any.whl Python 3 none any Details

Total release size:78.4 kB

Release files / coords_nsga2-2.7.0.tar.gz

Download URL coords_nsga2-2.7.0.tar.gz
Size 49.8 kB
Tags Source
SHA-256 checksum
How to use checksums
2ce4113ac6f092b5a29a4976622cecfe2e58574370302e9ed82e28e17f6eaa71
BLAKE2b-256 checksum
How to use checksums
fe4864cbb95b8c38a29139edbafa2b945851f24b82eb4c322df975eea4b05536
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release files / coords_nsga2-2.7.0-py3-none-any.whl

Download URL coords_nsga2-2.7.0-py3-none-any.whl
Size 28.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aff34149098a019a0fae1d76f91cc2ac95210ca8093b6639a9cd7e47c7db6e17
BLAKE2b-256 checksum
How to use checksums
fae8ebf5b8ff97994760db19f7f4552f6ffef777ce1b2a20bbc1c49666b119d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

2.7.0 This release

2 release files

2.6.0

2 release files

2.5.0

2 release files

2.4.1

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page