# Python3
import numpy as np
from scipy.optimize import linprog
# Objective function : minimise absolute total flux:
# v1*w1 + v2*w2 + v3*w3 + v4*w4 + v5*w5
reactions = np.ones(shape=5) # v
weights = np.ones(shape=5) # w
z = reactions * weights # objective function
# Subject to:
# 1. Steady state assumption: Nv = 0
N = [[1, -1, 1, 0, 0],
[0, 1, -1, -1, -1],
[0, 0, 0, 0, 1]]
# Rate of change for internal metabolites equals 0
N_rhs = [0, 0, 0]
# 2. Additional defined constraints:
# v4 = 1 and v3 = 0.5
constraints = [[0, 0, 0, 1, 0],
[0, 0, 1, 0, 0]]
constraints_rhs = [1, 0.5]
# Solve for optimum solution
linprog(c = z,
A_eq = N + constraints,
b_eq = N_rhs + constraints_rhs,
method = 'revised simplex')
# Solution: v1=1, v2=1.5, v3=0.5, v4=1, v5=0