user2627960
user2627960

Reputation: 1

"TypeError:_new_() take at least 2 arguments (1 given)"

I try to create the program generate the linear programming problem like

min cx
s.t. Ax=b
x>=0

but it occur the problem the program warn the message

"File"/tmp/tmpgX7_hI/___code___.py", line 3, in <module> class LP:"
"File"/tmp/tmpgX7_hI/___code___.py", line 4, in LP c=matrix()"
"TypeError: _new_() take at least 2 arguments (1 given)"

Which is my mistake and how should i fix it? Please!!!

Program
    class LP:
        c=matrix()
        A=matrix()
        b=matrix()
        def__init__(self,cvector,Amatrix,bvector):
            self.c=cvector
            self.A=Amatrix
            self.b=bvector
#----------------------------------------------------------------------
    import random 
    colc=[]colAmatrix=[]
    colb=[]
    LP_GEN=[]
    for m in range(2,5):
        for n in range(2,5):
            for k in range(2):
                c=matrix(1,n)
                for i in range(n):
                c[0,i]=random.randint(-50,50)
                b[0,i]=random.randint(-50,50)
                A[0,i]=random.randint(-50,50)
LP_GEN.append(LP(c,A,b))

Upvotes: 0

Views: 861

Answers (2)

zhangyangyu
zhangyangyu

Reputation: 8620

In your class definition, you use matrix(). But you have to pass at least one data to it. I think you may want:

class LP:
    def__init__(self,cvector,Amatrix,bvector):
        self.c=matrix(cvector)
        self.A=matrix(Amatrix)
        self.b=matrix(bvector)

Where cvector, Amatrix, bvector should be an array or a string. By the way, matrix(1, n) will also lead to an error.

Upvotes: 1

Moayad Mardini
Moayad Mardini

Reputation: 7341

The problem is how you are creating the instances of the matrix class. You're doing this:

c=matrix()

But it should be something like:

c=matrix(ARGUMENTS_HERE)

depending on the required arguments to create matrix.

Upvotes: 1

Related Questions