public static ArrayList<Double> findPivot2(ArrayList<ArrayList<Double>> M)
{
ArrayList<ArrayList<Double>> R = M;
//get the real pivot element:
ArrayList<Double> objZ = [Link](0);
//select the minimum value in the obj. function row:
// double minima1 = [Link](objZ).min().getAsDouble();
double minima1 = [Link](objZ);
[Link]("minima1 : " + minima1);
//save the index of that minimum element in a1 to target the index of
column for pivot seek:
int a1 = -1;
for (int k = 0; k < [Link](); k++)
{
if([Link](k) == minima1) a1 = k;
}
[Link]("a1 : " + a1);
/**
* the residus array is the where we store the results of dividing the
elements below and above
* the a1 element.
* then we store their indexes as well to target the index of row for pivot
seek.
*/
double [] residus = new double[[Link]() - 1];
int [] indexes = new int[[Link]() - 1];
for (int i = 1, j = 0; i < [Link](); i++, j++) {
[Link]("d : " + [Link](i).get(a1));
[Link]("D : " + [Link](i).get([Link](0).size() - 1));
//test if elements of the same column as pivot are positive (non-
negativity constraint)
/** since we are searching for minimal values to be stored in the
residus array
* we can't divide by negative number (solution irrealisable :>) nor 0
of course:
* so we take 1000000 for example as value so that we can ignore this
case explained above.
*/
if([Link](i).get(a1) <= 0) residus[j] = 1000000;
else{
residus[j] = [Link](i).get([Link](0).size() - 1) / [Link](i).get(a1);
}
indexes[j] = i;
}
//Debug stuffs
[Link]("Array: residus : ");
for (int i = 0; i < [Link]; i++) {
[Link](residus[i] + " ");
}
double minima2 = [Link](residus).min().getAsDouble();
[Link]("*************************");
//Save the index row in b1 variable
int b1 = -1;
// A little bug solved with hard coding (binarySearch() method didn't do
its job :>)
for (int k = 0; k < [Link]; k++)
{
if(residus[k] == minima2) b1 = k;
}
//We return the pivot element besides its i,j indexes
ArrayList<Double> returned = new ArrayList<>();
[Link]([Link](indexes[b1]).get(a1));
[Link]((double) indexes[b1]);
[Link]((double) a1);
return returned;
}