Skip to content

Implement compact variable format#35

Merged
wspringer merged 1 commit intomainfrom
compact-variable-format-34
Jun 7, 2025
Merged

Implement compact variable format#35
wspringer merged 1 commit intomainfrom
compact-variable-format-34

Conversation

@wspringer
Copy link
Owner

Fixes #34

Summary

This PR implements a new compact variable format that replaces the verbose array-based approach with self-contained variable objects, addressing the verbosity issues identified in issue #34.

Key Changes

Breaking Change: New Variable Format

  • Old format (removed): Separate arrays for bounds, types, and names
  • New format: Array of self-contained variable objects with optional properties

Example Migration

// Before (verbose)
{
  "variables": {
    "bounds": [{"lower": 0, "upper": 100}],
    "types": ["continuous"], 
    "names": ["profit"]
  }
}

// After (compact)
{
  "variables": [
    {"name": "profit", "ub": 100}
  ]
}

Benefits

  • Eliminates array synchronization errors - no more mismatched array lengths
  • Reduces verbosity with smart defaults (lb=0, ub=+∞, type="cont")
  • Industry standard abbreviations - lb/ub for bounds, cont/int/bin for types
  • Self-contained - each variable object contains all its properties

Areas Requiring Verification

🔍 Schema Changes (src/schemas.ts)

  • New CompactVariableSchema with optional properties
  • Validation logic updated for array length checking
  • Please verify the smart defaults and validation rules are correct

🔍 Processing Logic (src/lp-format.ts, src/index.ts)

  • Updated to access variables[i].name instead of variables.names?.[i]
  • Smart defaults applied consistently
  • Please verify LP format generation works correctly

🔍 Test Coverage (src/index.test.ts)

  • All 29 tests updated to use new format
  • Error validation tests updated for new schema
  • Please verify test scenarios cover edge cases adequately

🔍 Documentation (README.md)

  • All examples updated to showcase compact format
  • Input schema documentation reflects new structure
  • Please verify examples are clear and accurate

🔍 Versioning (.changeset/compact-variable-format.md)

  • Marked as major breaking change for knope
  • Please verify changelog description is appropriate

Testing

✅ All 29 tests pass
✅ TypeScript compilation clean
✅ ESLint passes

This is a breaking change requiring a major version bump due to the incompatible API change.

@wspringer wspringer linked an issue Jun 7, 2025 that may be closed by this pull request
@wspringer wspringer merged commit 9402150 into main Jun 7, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve variable specification format for better usability

1 participant