0

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.
Willy
  • 322
  • 1
  • 17
  • For one, the line were P is calculated fails since dimensions do not match, although they should do to the cumsum (i tried np.sum(X,axis=0 and got same error)? – Willy Nov 13 '17 at 21:44
  • Show reproducible code which we can run! Besides that: your algebra is broken, **cum**sum does not make any sense (read up what it is) and there is some strange numpy-usage. – sascha Nov 13 '17 at 22:35

0 Answers0