Code Monkey home page Code Monkey logo

computer-based-optimization-techniques's Introduction

Revised simplex

To find the inverse of intermediate matrices, two approaches are used with time compexities O(n) and O(n2) respectively.

Libraries used

  • time
  • sympy (sub-modules)

SymPy is a Python library for symbolic mathematics. Since a number of variables are used (x1, x2...) this library provides efficient way of interpreting the variales for computation. It supports formatted matrix printing, easy interpretation of matrices, its inverse and sub-matrices.

The time is started after all the libraries are imported and before the function definition. It is stopped at the end of the program after some interations. The overall time is interpreted in milli-seconds as it is an interpretable scale for such computations.

How the input is taken?

The input file can be viewed here.

The text under '***' is viewed as comment and it represents the format of the input with some examples (along with solutions). The code checks for the type of the problem (i.e., minimisation or maximisation) and then computes the result.

The problem to be solved has to be appended below the final '***'. And it should contain the type of the problem and the constraints.

Once the file is read, it checks for the lines below the final '***' and then converts that into matrices form by a library linear_eq_to_matrix on which computations are performed. This library takes input in the form of equations and converts them into matrices of coefficients.

Output

With the help of SymPy, the output is formatted in matrix form.

When the input is taken as:

Maximize: z = 5x1+4x2

s.t.

6x1 + 4x2 ≤ 24

x1 + 2x2 ≤ 6

-x1 + x2 ≤ 1

x2 ≤ 2

The matrices A, b, c are printed as:

The output and intermediate matrix after each iteration is printed:

Time complexity

When we found the inverse using both the functions on the same matrix. The following results were obtained:

  • Elementary method:
def inverse1(mat,entering,leaving):
    
    dim = mat.shape[0]
    
    X = mat.row(leaving)/mat.row(leaving)[entering]
    mat.row_del(leaving)
    mat = mat.row_insert(leaving,X)
    
    for j in range(dim):
        if(leaving!=j):
            con=mat.row(j)[entering]
            X = mat.row(j)-mat.row(leaving)*con
            mat.row_del(j)
            mat = mat.row_insert(j,X)
            
    return mat

The execution time was 0.9977817 ms

  • Gauss Jordan method:
def inverse2(A):
    
    size = A.shape[0]
    
    B = eye(size)
    
    for x in range(0,size):
        V = B*A.col(x)
        W = V*1
        item = V[x]
        for y in range(0,size):
            if item != 0:
                if y == x:
                    W[y] = 1/item
                else:
                    W[y] =- V[y]/item
                    
        T = B*1
        T.row_del(x)
        T = T*1
        B = T.row_insert(x,zeros(1,size)) + (W*B.row(x))
        
    return B

The execution time was 3.027201 ms

i.e., Elementary method is ~3.1 times faster.

Justification - In elementary method, we used a single for loop whereas in gauss jordan method we used two for loops. (O(n) vs O(n2))

computer-based-optimization-techniques's People

Contributors

nitin-bommi avatar tarunsunny3 avatar yashi1011 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

computer-based-optimization-techniques's Issues

Formatting the project

Remove unnecessary files and text. Only 2 files are important. If all the changes to the code are done, I will format it.

Background operations done!

I have completed coding the background operations.
We still have to format the output, print the optimal values, read from files.

File input is done

File input along with checking unbounded condition have been included along with some sample examples in the input file named input1.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.