This commit is contained in:
Alexander Munch-Hansen 2018-10-08 20:02:33 +02:00
parent 09e59b2028
commit 20c484809a

View File

@ -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 = [