diff --git a/h2/mbc.py b/h2/mbc.py index cf3ef5e..58e72a7 100644 --- a/h2/mbc.py +++ b/h2/mbc.py @@ -96,24 +96,45 @@ def solve_2dlp(c: Tuple[float, float], constraints: List[Tuple[Tuple[float, floa x1, x2 = -inf, -inf # TODO: something other than -inf (?) our_constraints = [] for (a1, a2), b in constraints: # TODO: random.shuffle() + + + + if not a1*x1 + a2*x2 <= b: - our_constraints.append(((a1, a2), b)) - - new_obj = c[0] + (b/a2 - a1/a2) - + print("rrgeerg"*30) constraint_for_1d = [] - for constraint in our_constraints: - (old_a1, old_a2), old_b = constraint - new_a1 = old_a1 + ((old_b/old_a2) - (old_a1/old_a2)) - constraint_for_1d.append((new_a1, old_b)) + # a_prime = a1 - (a2*a1)/a2 + # b_prime = b - (a2*b)/a2 + + # print("a,b prime", a_prime, b_prime) + # constraint_for_1d.append((a_prime, b_prime)) + + # Fix this + new_obj = c[0] - (c[1]*a1)/a2 + + for constraint in our_constraints: + (a_i1, a_i2), b_i = constraint + print("lel", a_i1, a_i2, b_i) + + a_prime = a_i1 - ((a_i2*a1)/a2) + b_prime = b_i - ((a_i2*b)/a2) + constraint_for_1d.append((a_prime, b_prime)) + + print("lal", a1, a2, b) + print(new_obj) + print(constraint_for_1d) x1 = solve_1dlp(new_obj, constraint_for_1d) x2 = ((b/a2) - (a1/a2))*x1 + + our_constraints.append(((a1, a2), b)) + + return x1, x2 -# TODO: assert solve_2dlp((-3, -2), [((-1, 3), 12), ((1, 1), 8), ((2, -1), 10)]) == (6, 2) +# assert solve_2dlp((-3, -2), [((-1, 3), 12), ((1, 1), 8), ((2, -1), 10)]) == (6, 2) c = (-3, -2) constraints = [