2

I have the following code:

import numpy as np
import cvxpy as cp
import math
import sys

def solve05( p, a ):
    m,n,ids,inv,k = 0,len(p),{},{},0
    for i in range(n):
        for j in range(n):
            ids[(i,j)] = k
            inv[k] = (i,j)
            k = k+1
    # Problem data
    A = np.zeros((2*n,n*n+n))
    D = np.zeros((2*n,n*n+n))
    b = np.zeros(2*n)
    B = np.zeros(2*n)
    c = np.zeros(2*n)
    for j in range(n):
        for i in range(n):
            idx = ids[(i,j)]
            A[j,idx] = 1
        b[j] = 1
    for i in range(n):
        for j in range(n):
            idx = ids[(i,j)]
            A[i+n,idx] = p[j]
        A[i+n,n*n+i] = -1
        b[i+n] = p[i]
    # Construct the problem
    x = cp.Variable(n*n+n)
    print("M = ",A)
    print("b = ",b)
    CF = 1e3
    print("Now scaling M by ",CF)
    A = A*CF
    print(A)
    b = b*CF
    constraints = [0 <= x, A*x == b]
    pex = x[n*n]+x[n*n+1]+x[n*n+2]+1
    constraints.append(x[n*n] <= a[0]*CF)
    constraints.append(x[n*n+1] <= a[1]*CF)
    constraints.append(x[n*n+2] <= a[2]*CF)
    constraints.append(x[n*n] >= 0.01)
    constraints.append(x[n*n+1] >= 0.01)
    constraints.append(x[n*n+2] >= 0.01)
    ex = pex.__pow__(-1)
    print("Dummy variables: ",x[n*n],x[n*n+1],x[n*n+2])
    print("Objective function: ",ex)
    print("[should be convex] Curvature: ",ex.curvature)
    objective = cp.Minimize(ex)
    prob = cp.Problem(objective,constraints)
    result = prob.solve(verbose=True)
    print('problem state: ', prob.status)
    alpha = np.zeros((n,n))
    for i in range(n):
        for j in range(n):
            alpha[i,j] = x.value[ids[(i,j)]]
    dummy = [x.value[j] for j in range(n*n,n*n+n)]
    return (x,alpha)


if __name__ == '__main__':
    p = [0.0005,0.0001,0.0007]
    a = [900,500,700]
    n = len(a)
    (sl,alpha) = solve05(p,a)
    for row in alpha:
        for x in row:
            print("%.4f " % (x), end=" "),
        print("")

It fails with "Problem UNFEASIBLE" verdict, and I am eager to know why. Is there any way to know more? I am not a convex programming expert, so any comments on why this is a bad model is appreciated. I have also tried scaling the problem, because I thought some numerical instability may be what is causing problems, but alas.

Ilonpilaaja
  • 1,169
  • 2
  • 15
  • 26

1 Answers1

0

The answer ecos+cvxpy was giving is correct. The problem is unfeasible, which can be shown by summing up all the equations and observing that the LHS is some quantity F, whereas the RHS is F+e, for some e > 0.

Ilonpilaaja
  • 1,169
  • 2
  • 15
  • 26