Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in findEnteringColumn #514

Open
miguel14 opened this issue May 5, 2017 · 3 comments
Open

Error in findEnteringColumn #514

miguel14 opened this issue May 5, 2017 · 3 comments

Comments

@miguel14
Copy link

miguel14 commented May 5, 2017

I use your code, and this have issues when I run this program

Maximize p = x + y subject to 2x + y <= 4, x + 2y <= 3

I solve it changing findEnteringColumn function

`// finds the next entering column
private int findEnteringColumn(){
//float[] values = new float[cols];
//int location = 0;

    int count = 0; 
    for(int pos = 0; pos < cols-1; pos++){
        if(table[rows-1][pos] < 0){
            return pos;
            //System.out.println("negative value found");
            //count++;
        }
    }
    
    return -1; // This case never exist
    
    /*
    if(count > 1){
        for(int i = 0; i < cols-1; i++)
            values[i] = Math.abs(table[rows-1][i]);
        location = findLargestValue(values);
    } else location = count - 1;
   
    return location;
   */
}`

To validate I use this web https://www.zweigmedia.com/RealWorld/simplex.html

My complete code is here

`/*

  • To change this license header, choose License Headers in Project Properties.
  • To change this template file, choose Tools | Templates
  • and open the template in the editor.
    */
    package lp.LPObjects;

import lp.LPObjects.Simplex.ERROR;

/**

  • Use this class to test LP programs

  • @author Miguel Angel Ramos Valdovinos
    */
    public class prueba {

    public static void main(String[] args) {

     float[][] table = new float[3][6];
     
     
     table[0][0] = 2;
     table[0][1] = 1;
     table[0][2] = 1;
     table[0][3] = 0;
     table[0][4] = 0;
     table[0][5] = 4;
     
     table[1][0] = 1;
     table[1][1] = 2;
     table[1][2] = 0;
     table[1][3] = 1;
     table[1][4] = 0;
     table[1][5] = 3;
     
     table[2][0] = -1;
     table[2][1] = -1;
     table[2][2] = 0;
     table[2][3] = 0;
     table[2][4] = 1;
     table[2][5] = 0;
     
     Simplex solv = new Simplex(2, 5);
     solv.fillTable(table);
     solv.print();
     
     
     boolean cont = true;
     while (cont){
         ERROR res = solv.compute();
         if (res == ERROR.IS_OPTIMAL || res == ERROR.UNBOUNDED){
             cont = false;
         }
         solv.print();
     }
    

    }

}
`

@mik30s
Copy link
Contributor

mik30s commented May 7, 2017

Ok, I'll fix it up. Thanks

@MiKaminskas
Copy link

@miguel14 could you please again upload somethere your fix? All your links is broken :(

@miguel14
Copy link
Author

@MiKaminskas Hi, I found several bugs, so I better used the solver of CommonsMath3 of Apache. Sorry I delete the code.

http://commons.apache.org/proper/commons-math/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants