-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathoptimization_egine.py
46 lines (38 loc) · 1.27 KB
/
optimization_egine.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
import pandas as pd
from gekko import GEKKO
m = GEKKO()
n = 5
budget = int(input('Enter campaign budget:'))
'''
A linear optimization won't be realistic; from a business point of view, we
will have our own constraints.
'''
combined = pd.read_csv('results/combined.csv', index_col=0)
channels = list(sorted(combined.index))
coeffs = combined['Mean'].tolist()
# Assign lower bound and upper bound as business constraints
x1 = m.Var(lb=100, ub=budget)
x2 = m.Var(lb=100, ub=budget)
x3 = m.Var(lb=100, ub=budget)
x4 = m.Var(lb=100, ub=budget)
x5 = m.Var(lb=100, ub=budget)
for i in range(n):
print(f'Channel {i + 1} should not exceed: ', end='')
z = int(input())
m.Equation(globals()['x' + str(i + 1)] <= z)
m.Equation(x1 + x2 + x3 + x4 + x5 <= budget)
m.Maximize(coeffs[0] * x1 + coeffs[1] * x2 + coeffs[2] * x3 + coeffs[3] * x4 +
coeffs[4] * x5)
m.solve(disp=False)
p1 = x1.value[0]
p2 = x2.value[0]
p3 = x3.value[0]
p4 = x4.value[0]
p5 = x5.value[0]
# Print the budget along with the channel names
print('Budgets:\n')
print(str(channels[0]) + ': ' + str(round(p1, 0)))
print(str(channels[1]) + ': ' + str(round(p2, 0)))
print(str(channels[2]) + ': ' + str(round(p3, 0)))
print(str(channels[3]) + ': ' + str(round(p4, 0)))
print(str(channels[4]) + ': ' + str(round(p5, 0)))