27 releases (stable)
new 2.2.0 | Jan 1, 2025 |
---|---|
1.4.1 | Jan 1, 2025 |
1.3.2 | Nov 19, 2024 |
1.2.4 | Apr 29, 2024 |
0.1.3 | Nov 14, 2023 |
#108 in Math
1,512 downloads per month
1.5MB
1.5K
SLoC
Rust LP File Parser and Diff Tool
Overview
A robust Rust parser for Linear Programming (LP) files, built on the NOM parsing framework. This crate provides comprehensive support for parsing and analysing LP files according to major industry specifications.
Supported Specifications
Features
Core Functionality
-
Problem Definition
- Problem name and sense specification
- Single and multi-objective optimization support
- Comprehensive constraint handling
-
Variable Support
- Integer, general, bounded, free, semi-continuous variables
Advanced Features
-
LP File Comparison (
diff
feature)- Identify added, removed, and modified elements
- Useful for model version control and validation
-
Serialization (
serde
feature)- Full serialization support for all model structures
- Compatible with various data formats
- Enables integration with other tools and systems
Quick Start
Installation
Add to your Cargo.toml
:
[dependencies]
lp_parser_rs = "x.y.z"
Basic Usage
Clone and run with a sample file:
git clone https://github.com/dandxy89/lp_parser_rs.git
# Dissemble a single LP file
cargo run --bin lp_parser --release -- {{ /path/to/your/file.lp }}
# Compare two LP files (enabling the 'diff' feature)
cargo run --bin lp_parser --release --features diff -- {{ /path/to/your/file.lp }} {{ /path/to/your/other/file.lp }}
Using the library directly:
use lp_parser::{parser::parse_file, LpProblem};
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Parse LP file content
let content = parse_file(Path::new("problem.lp"))?;
// Parse into LP problem structure
let problem = LpProblem::parse(&content)?;
// Access problem components
println!("Problem name: {:?}", problem.name());
println!("Objective count: {}", problem.objective_count());
println!("Constraint count: {}", problem.constraint_count());
println!("Variable count: {}", problem.variable_count());
Ok(())
}
Enable Optional Features
[dependencies]
lp_parser_rs = { version = "x.y.z", features = ["serde", "diff"] }
Development
Testing
The project uses snapshot testing via insta
for reliable test management:
# Run all tests with all features enabled
cargo insta test --all-features
# Review snapshot changes
cargo insta review
Test Data Sources
The test suite includes data from various open-source projects:
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.