Skip to content
DeepForgeby svx
All problems
HardOptimizationop-201

Gomory Cut Lite

Problem

Generate the coefficients of a Gomory fractional cut from a tableau row x_B = b - sum a_j x_j. Return [frac(b)] followed by frac(a_j) for every coefficient, where frac(v) = v - floor(v). The cut is sum frac(a_j) x_j >= frac(b).

Hint

Only the fractional parts enter the cut; integer coefficients contribute zero.

Test cases

case 1
in: [3.7,[1.2,-0.4,2]]
expected: [0.7000000000000002,0.19999999999999996,0.6,0]
case 2
in: [0.25,[0.5,-1.75]]
expected: [0.25,0.5,0.25]
case 3
in: [-2.3,[]]
expected: [0.7000000000000002]
Starter codePython
def gomory_cut(b, coeffs):
    # Your code here
    pass

3 test cases · run your code against them in the editor