Skip to content

Error in findEnteringColumn #514

@miguel14

Description

@miguel14

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();
     }
    

    }

}
`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions