I'm trying to solve for the ideal matrix X in the following linear program setup:
X = N by T matrix which is our variable. For simplicity, let's set N to 4 and T to 3.
X_column_sum = 1 by T matrix where each column value is the sum of all values of the corresponding column in X
R = N by 1 matrix with randomly determined values
G = constant (let's set to 100 for simplicity)
d = 1 by T matrix whose values take in the range [0, G-1]
P = 1 by T matrix equal to X_column_sum + d
C = X dotted with P
I want to minimize the sum of the entries of C, while preserving the following constraints:
- all values in X have to be >= 0
- the sum of all values in each corresponding row of X have to be at least equal to the corresponding value in R
I tried the following code using cvxpy in python, but to no avail:
from cvxpy import *
X = Variable(N,T)
G = 100
d = np.random.randn(1, T)
d *= G-1
X_column_sum = cumsum(X,axis=0)
P = cost_matrix_cars + d
R = matrix([[10]]*N) # all set to 10 for testing
objective = Minimize(sum_entries(X@P)) #think this is good
constraints = [0 <= X, cumsum(X,axis=0) >= R]
prob = Problem(objective, constraints)
print("Optimal value", prob.solve())
print("Optimal X is",x.value ) # A numpy matrix.