-
Notifications
You must be signed in to change notification settings - Fork 0
Updated matrix F in Palma Ratio Linearization #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR addresses three issues in the Palma ratio linearization implementation: standardizing vectorization indexing to column-major convention, correcting McCormick envelope RHS values, and fixing undefined variable references. The changes align the implementation with the mathematical formulation documented in Overleaf.
- Standardized all matrix indexing to column-major convention (
k = i + (j-1)*n) for consistency - Fixed McCormick envelope RHS values in the constraint vector
g(swapped envelope 2 and 3 values) - Corrected sorting constraint matrix
Tto have(n-1)rows instead ofnrows
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| test/test_matrix_f.jl | New comprehensive test file verifying matrix dimensions, permutation constraints, sorting behavior, McCormick envelopes, and full constraint system |
| src/implementation/palma_relaxation.jl | Updated both lin_palma() and lin_palma_w_grad_input() functions with column-major indexing, corrected T matrix dimensions, fixed McCormick RHS values, and added dimension assertions |
| script/relaxed_palma_ratio.jl | Applied same corrections as implementation file to maintain consistency in the test script |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
From the @copilot review, it looks like there was an inconsistency in
|
Key changes: - Add script/reformulation/load_shed_as_parameter.jl with new formulation where P_shed is a JuMP @expression (not @variable), eliminating equality constraints and simplifying the model structure - Add script/reformulation/validate_reformulation.jl with tests - Remove duplicate fairness functions from src/core/objective.jl (gini_index, jains_index, palma_ratio, alpha_fairness) that were causing precompilation errors due to method overwriting The reformulation preserves full dynamic sorting via permutation matrix optimization while using McCormick envelopes for bilinear terms and Charnes-Cooper transformation for the ratio objective. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
DiffOpt fix: - Increase regularization to 0.1 in MLD objective to keep pd variables interior, fixing sensitivity computation through KKT conditions - Add regularization parameter to objective_fairly_weighted_max_load_served Palma optimization fix: - Add Taylor expansion constraint linking pshed_new to weight changes - Fix objective from `Max, 0` to `Min, numerator_expr` (was maximizing zero!) - Add Charnes-Cooper denominator normalization constraint - Add trust region (±0.5) on weight changes for convergence stability - Relax y_pshed lower bound to allow Taylor expansion flexibility - Add MOI import and infeasibility handling - Fix return statement to return optimized weights Add diagnostic scripts: - script/reformulation/debug/ with Jacobian analysis tools - script/reformulation/test_bilevel_convergence.jl validates full pipeline Verified: Palma ratio decreases from 5.97 to 5.16 (13.6% improvement) over 5 bilevel iterations on ieee_13_aw test case. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The McCormick relaxation (relax_binary=true) produces degenerate solutions where the solver exploits loose envelopes to find objective=0. Binary permutation is required for correct results. Validated on IEEE 13-bus: NEW achieves 4.9% Palma improvement in 0.2s vs OLD's 3.8% in 3.6s. TODO: Investigate tighter McCormick cuts or alternative relaxations. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
awest32
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The functionality seems to be here. Thank you so much for doing this!
Matrix F Corrections for Palma Ratio Linearization
This PR suggests some changes to the constraint matrix F and related components in the Palma ratio linearization implementation. It attempts to resolve the bug mentioned in #3
I tried to align things with the mathematical formulation on the Overleaf. I used Claude Code Pro with the Opus 4.5 model to try to help.
Possible issues
I believe there are three possible issues in the current implementation:
A_longused undefined variableAIssue 1: Indexing Inconsistency
Problem
The original code mixed two different vectorization conventions for the permutation matrix:
A,AT,Tk = (i-1)*n + jA_row,A_colk = i + (j-1)*nThis caused the sorting constraint (using
T) to operate inconsistently with the permutation constraints (usingA_row,A_col).Example for n=3
For a permutation matrix entry
a_{i,j}:vec(a) = [a_{11}, a_{12}, a_{13}, a_{21}, a_{22}, a_{23}, a_{31}, a_{32}, a_{33}]vec(a) = [a_{11}, a_{21}, a_{31}, a_{12}, a_{22}, a_{32}, a_{13}, a_{23}, a_{33}]Suggested Fix
Standardized all matrices to use column-major indexing, as is standard in Julia/MATLAB convention:
The sorting matrix T was also updated to use column-major and now has dimension
(n-1) × n²instead ofn × n²:Issue 2: McCormick Envelope RHS Errors
Reference (Overleaf
main.texequations 19-22)The McCormick envelopes for the bilinear term
u_{ij} = a_{ij} · x_jwherea_{ij} ∈ {0,1}andx_j ∈ [0, P_j]:u_{ij} ≥ 0u_{ij} ≥ x̄_j · a_{ij} + x_j - x̄_ju_{ij} ≤ x̄_j · a_{ij}u_{ij} ≤ x_jConverting to F·y ≤ g·σ form
-I · u ≤ 0zeros(n²)-I · u + A_P · a + x_j · x ≤ PP_outI · u - A_P · a ≤ 0zeros(n²)I · u - x_j · x ≤ 0zeros(n²)Original Code
Fixed Code
Issue 3: A_long Variable Reference
Problem
Fix
Files Modified
src/implementation/palma_relaxation.jllin_palma()function (lines 14-145)lin_palma_w_grad_input()function (lines 160-348)script/relaxed_palma_ratio.jlDimension Changes
Due to the T matrix correction, the constraint system dimensions changed:
Added Verification
Dimension assertions were added to catch future dimension mismatches:
Trying to align with overleaf formulation
The corrected implementation now matches the Overleaf formulation (assuming it is still accurate):
Equations (5)-(6): Doubly stochastic constraints
A·1 = 1,Aᵀ·1 = 1are correctly implemented viaA_rowandA_colEquation (8): Sorting constraint
S_i ≤ S_{i+1}is implemented viaT · x_hat ≤ 0Equations (19)-(22): McCormick envelopes now have correct RHS values
Equations (31)-(34): Charnes-Cooper transformation
F·y ≤ g·σwith the currently written constraint structureTesting
I created a proof-of-concept test script
test/test_matrix_f.jlto verify:Test Results
Run the test with: