-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.py
More file actions
47 lines (39 loc) · 1.5 KB
/
utils.py
File metadata and controls
47 lines (39 loc) · 1.5 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
# returns whether each element of each list is equal to the other
def equals(list1, list2):
if len(list1) != len(list2):
return False
for i, item in enumerate(list1):
if item != list2[i]:
return False
return True
# given a set of data that contains 3 or more variables,
# it returns a new set of data reduced to the first two.
def transform2D(data):
return {
"vars_c": transformArray(data["vars_c"]),
"A_ineq": transformMatrix2D(data["A_ineq"]),
"b_ineq": transformArray(data["b_ineq"]),
"A_eq": transformMatrix2D(data["A_eq"]),
"b_eq": transformArray(data["b_eq"]),
"bounds": data["bounds"][:2],
"ranges": data["ranges"][:2]
}
def transformMatrix2D(matrix):
if matrix is None: return None
return [item[:2] for item in matrix]
def transformArray(array):
if array is None: return None
return array[:2]
def message(ans):
msg = ""
if ans.success:
msg += f"El algoritmo de optimización de Simplex fue exitoso.\nEl punto mínimo de la función hallado fue {ans.fun} "
msg += f"que se obtuvo para el punto {ans.x}.\n"
else:
msg += "La optimización con el algoritmo Simplex no fue exitosa.\n"
if ans.status == 2:
msg += "El problema pudiera no tener solución factible.\n"
elif ans.status == 3:
msg += "El problema parece estar no acotado.\n"
msg += f"El número total de iteraciones realizadas fueron {ans.nit}."
return msg