-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.py
100 lines (64 loc) · 1.95 KB
/
examples.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import lippy as lp
# biblioteka za rjesavanje problema linearnog programiranja
# ------------------------------------------------------------
# PRIMJER
# funkcija cilja Z = 3x1 + 3x2 + 7x3
c_vektor = [3, 3, 7]
# ogranicenja
a_matrica = [
[1, 1, 1],
[1, 4, 0],
[0, 0.5, 3]]
b_vektor = [3, 5, 7]
gomory = lp.CuttingPlaneMethod(c_vektor, a_matrica, b_vektor)
rjesenje = gomory.solve()
# ispis rezultata
print()
print("Optimalne vrijednosti varijabli: ", rjesenje[0])
print("Vrijednost funkcije cilja: ", rjesenje[1])
# ------------------------------------------------------------
# PRIMJER (PREZENTACIJA)
# funkcija cilja Z = 7x1 + 9x2
c_vektor = [7, 9]
# ogranicenja
a_matrica = [[-1, 3],
[7, 1]]
b_vektor = [6, 35]
gomory = lp.CuttingPlaneMethod(c_vektor, a_matrica, b_vektor)
rjesenje = gomory.solve()
# ispis rezultata
print()
print("Optimalne vrijednosti varijabli: ", rjesenje[0])
print("Vrijednost funkcije cilja: ", rjesenje[1])
# ------------------------------------------------------------
# OPTIMIZACIJA KNJIZARE
# funkcija cilja Z = 5x1 + 6x2 + 8x3
c_vektor = [5, 6, 8]
# ogranicenja
a_matrica = [[12, 15, 20],
[0.5, 0.7, 1],
[-1, 0, 0],
[0, -1, 0],
[0, 0, -1]]
b_vektor = [2000, 100, -10, -5, -8]
gomory = lp.CuttingPlaneMethod(c_vektor, a_matrica, b_vektor)
rjesenje = gomory.solve()
# ispis rezultata
print()
print("Optimalan broj knjiga za svaku kategoriju: ", rjesenje[0])
print("Maksimalni profit: ", rjesenje[1])
# ------------------------------------------------------------
# PRIMJER 8.10 (Wolsey)
# funkcija cilja Z = 4x1 - x2
c_vektor = [4, -1]
# ogranicenja
a_matrica = [[7, -2],
[0, 1],
[2, -2]]
b_vektor = [14, 3, 3]
gomory = lp.CuttingPlaneMethod(c_vektor, a_matrica, b_vektor)
rjesenje = gomory.solve()
# ispis rezultata
print()
print("Optimalne vrijednosti varijabli: ", rjesenje[0])
print("Vrijednost funkcije cilja: ", rjesenje[1])