0% found this document useful (0 votes)
12 views2 pages

Find Pivot Element in Matrix

This method finds the pivot element in a matrix for solving linear programs. It: 1. Finds the minimum value in the objective function row and saves its index. 2. Calculates the residuals of dividing each row element below the pivot by the pivot element. 3. Finds the minimum residual and saves the index of its row to identify the pivot element and row. 4. Returns the pivot element and its row and column indexes.

Uploaded by

john jd
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views2 pages

Find Pivot Element in Matrix

This method finds the pivot element in a matrix for solving linear programs. It: 1. Finds the minimum value in the objective function row and saves its index. 2. Calculates the residuals of dividing each row element below the pivot by the pivot element. 3. Finds the minimum residual and saves the index of its row to identify the pivot element and row. 4. Returns the pivot element and its row and column indexes.

Uploaded by

john jd
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

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

You might also like