Add support for quadratic objectives in convex QP problems#43
Merged
Add support for quadratic objectives in convex QP problems#43
Conversation
Implemented quadratic objective support for convex quadratic programming (QP) problems in HiGHS MCP server. The enhancement allows users to minimize quadratic objectives of the form: minimize c^T x + 0.5 x^T Q x, where Q must be positive semidefinite. Key features: - Support for both dense and sparse quadratic matrix formats - Validation to ensure Q is square and symmetric - Restriction to continuous variables only (no MIQP support) - Proper encoding to HiGHS LP format with quadratic terms - Comprehensive test coverage for various QP scenarios The implementation uses a discriminated union schema to provide type-safe separation between sparse and dense formats, ensuring proper validation and clear error messages. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
9 tasks
Updated the MCP tool description to explicitly mention quadratic programming limitations so LLMs understand the constraints: - QP only supports continuous variables (no MIQP) - Q matrix must be positive semidefinite (convex only) - Matrix values should be doubled for 0.5 factor Added test assertions to verify the description includes QP information.
Changed quadratic objectives from discriminated union to property-based
format consistent with constraint matrices:
Before (discriminated union):
{
format: 'dense',
matrix: [[...]]
}
After (property-based like constraints):
{
dense: [[...]] // OR
sparse: { rows: [...], cols: [...], values: [...], shape: [...] }
}
This provides a consistent API pattern across all matrix specifications
in the schema and aligns with existing constraint matrix design.
Updated all tests and documentation to reflect the new format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements support for quadratic programming (QP) problems in the HiGHS MCP server, enabling optimization of quadratic objectives of the form
minimize c^T x + 0.5 x^T Q x.Fixes #26
Changes
Schema Enhancement
QuadraticObjectiveSchemasupporting both dense and sparse matrix formatslinearcoefficients optional inObjectiveSchema(required if quadratic is not provided)Implementation
formatObjective()to generate HiGHS LP format quadratic terms using[ quadratic_terms ] / 2syntaxvariables.lengthinstead ofobjective.linear.lengthfor determining variable countTesting
tests/quadratic-objectives.test.ts)tests/integration/quadratic-simple.test.ts)Documentation
Key Areas for Review
Quadratic Term Format: The implementation follows HiGHS LP format for quadratic terms. Please verify the encoding in
encode.tslines 135-193, particularly:x1^2andx1 * x2Validation Logic: Check the schema refinements in
schemas.ts:Matrix Specification: The Q matrix values need to be doubled to account for the 0.5 factor in the objective. This is documented but may need emphasis.
Test Results
All tests pass including the new QP-specific tests:
The implementation is backward compatible - all existing LP and MIP functionality remains unchanged.