I am following a book that explains advanced linear programs. So far it's been good, but this example has me stumped on how to properly write the objective functions and constraints.
Below you'll find my attempt at coding the left coefficient but as you can see it doesn't seem correct.
My implementation so far is as follow
import pulp as lp
# data
r = 0.02
T = 2
J = 3
E = 6
K = {(1): 2, (2): 3, (3): 4, (4): 4, (5): 6, (6): 7}
C_j_t = {(1, 1): 2, (1, 2): 3, (2, 1): 4, (2, 2): 5, (3, 1): 6, (3, 2): 7}
F_j_e = {(1, 1): 2, (1, 2): 3, (2, 1): 4, (2, 2): 5, (3, 1): 6, (3, 2): 7}
I_j_e = {(1, 1): 2, (1, 2): 3, (2, 1): 4, (2, 2): 5, (3, 1): 6, (3, 2): 7}
# F_j_e = 1
prob = lp.LpProblem('Foobar Village Highway Problem', lp.LpMaximize)
X_j_t = lp.LpVariable.dicts("X",
[(j, t)
for j in range(1, J)
for t in range(1, T)],
cat='Continuous')
coef_left = {}
for t in range(1, T):
for j in range(1, J):
coef_left[(j, t)] = (1 + r)**-t * C_j_t[(j, t)]
pv = (1 + r)**-T
right_side = {}
for j in range(1, J):
for e in range(1, K[(j)]):
right_side[(j, e)] = pv * F_j_e[(j, e)] * I_j_e[(j, e)]
prob += lp.lpSum(coef_left[(j, t)] * X_j_t[(j, t)] + right_side[(j, e)]
for j in range(1, J)
for t in range(1, T)
for e in range(1, E))
prob.writeLP(r'8.2.1.lp')
# Solve
prob.solve()
I don't think this is correct or that I'm using the right methodology to code this complex objective an constraint.
it returns the following:
\* Foobar_Village_Highway_Problem *\
Maximize
OBJ: 3.92156862745 X_(1,_1) + 7.8431372549 X_(2,_1)
Subject To
Bounds
X_(1,_1) free
X_(2,_1) free
End