-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimplexEx.py
More file actions
66 lines (55 loc) · 1.78 KB
/
simplexEx.py
File metadata and controls
66 lines (55 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from ..simplex.simplex_method import simplex_algorithm
from ..simplex.utils import equals
from manim import *
class SimplexExample(Scene):
def construct(self):
points = self.linear_problem()
# creating coordinate axes
ax = Axes(
x_range=[0, 5],
y_range=[0, 5]
)
line1 = ax.plot(lambda x : (3 - x), color=BLUE_C)
line2 = ax.plot(lambda x : (4 - x) / 2, color=BLUE_C)
line3 = ax.plot(lambda x : 1 + x, color=BLUE_C)
self.add(ax)
self.wait()
self.add(line1)
self.wait()
self.add(line2)
self.wait()
self.add(line3)
last = None
for point in points:
self.wait()
p = ax.coords_to_point(point[0], point[1])
dot = Dot(point=p, color=YELLOW)
l1 = ax.get_vertical_line(p)
l2 = ax.get_horizontal_line(p)
self.add(dot, l1, l2)
self.wait()
if not last is None:
arrow = Arrow(last, dot, buff=0)
self.add(arrow)
self.wait()
last = dot
dot = Dot(point=last.get_center(), color=RED)
self.add(dot)
self.wait(duration=3)
def linear_problem(self):
data = {
"vars_c" : [-2, -3],
"A_ineq" : [[1, 1], [1, 2], [-1, 1]],
"b_ineq" : [3, 4, 1],
"A_eq" : None,
"b_eq" : None,
"bounds" : ((0, None), (0, None))
}
results, _ = simplex_algorithm(data)
points = [step.x for step in results]
ans = [points[0]]
for i in range(1, len(points)):
if equals(points[i], points[i - 1]):
continue
ans.append(points[i])
return ans