GLPK模型无原始可行解求助:疑Stope_i约束表述有误
Hey there, let's dig into why your GLPK model is throwing that frustrating "No Primal Feasible Solution" error—you’re right to suspect those commented-out Stope_* constraints are the root cause. Let’s break this down step by step.
First, Let’s Confirm the Culprit
Your base model (with only the StopeB constraint active) should run fine—StopeB just limits each 2x2 block (since k=2, l=2) to have at most one active x[i,j] variable, which is totally feasible for binary 0/1 variables. The error hits as soon as you uncomment any of the Stope_i, Stope_j, Stope_ij, or Stope_im constraints, so those are definitely where we need to focus.
Why Those Constraints Break Feasibility
Let’s take the Stope_i constraint as an example (the same logic applies to the others):
subject to Stope_i{g in P, h in Q}: x[g,h] - sum{j in h+1..h+q} x[g,j] = 1;
Since q = l-1 = 1, this simplifies to:x[g,h] - x[g,h+1] = 1
Rearranged, that’s x[g,h] = 1 + x[g,h+1]. But x variables are binary (0 or 1)! If x[g,h+1] is 1, x[g,h] would need to be 2—which violates the <=1 bound on x. Even if x[g,h+1] is 0, this forces x[g,h] to be 1 for every g in P and h in Q—which would immediately conflict with the StopeB constraint (since multiple 1s would end up in the same 2x2 block).
The other constraints have identical issues:
Stope_jsimplifies tox[g,h] - x[g+1,h] = 1, requiringx[g,h] = 1 + x[g+1,h]—again impossible for binary variables.Stope_ijbecomesx[g,h] - x[g+1,h+1] = 1, same feasibility conflict.Stope_imuses an invalid index range: withl=2andm=8, whenh=7(part ofQwhich is1..7),h+l=9is way outside theJset (1..8)—this creates invalid variable references that break the model entirely.
Fixes to Get Your Model Feasible
1. Rewrite Constraints to Match Your Actual Business Logic
First, clarify what you’re trying to enforce with these Stope_* rules. For example:
- If you want to ensure the top-left cell of a block is only active if no other cells in that row/column are active, use an inequality instead of equality:
# Example: x[g,h] can only be 1 if x[g,h+1] is 0 subject to Stope_i{g in P, h in Q}: x[g,h] + x[g,h+1] <= 1; - If you need exactly one cell active per block, replace
StopeBwith an equality constraint:subject to StopeB{g in P, h in Q}: sum{i in g .. g+p, j in h..h+q} x[i,j] = 1;
2. Fix Invalid Index Ranges
For Stope_im, adjust the j range to stay within valid indices. For example, if you meant to reference cells to the right of the block, use:
subject to Stope_im{g in P, h in Q}: x[g,h] - sum{j in h+q+1..m} x[i,j] <= 0;
(Adjust the logic to match your intended rule—this example just ensures x[g,h] can’t be 1 if any cells to the right in the same row are active.)
3. Test Incrementally
Start with the working base model (only StopeB), then add one modified Stope_* constraint at a time. Run the model after each addition to catch feasibility issues early.
内容的提问来源于stack exchange,提问作者ayePete

