Use a TreeSet instead of an ArrayList when dropping columns after phase 1 of the simplex solver to improve performance.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/math/trunk@1367227 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ebc0d3d309
commit
107d7f3ea8
|
@ -26,6 +26,7 @@ import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
|
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
|
||||||
import org.apache.commons.math3.linear.MatrixUtils;
|
import org.apache.commons.math3.linear.MatrixUtils;
|
||||||
|
@ -333,7 +334,7 @@ class SimplexTableau implements Serializable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Integer> columnsToDrop = new ArrayList<Integer>();
|
Set<Integer> columnsToDrop = new TreeSet<Integer>();
|
||||||
columnsToDrop.add(0);
|
columnsToDrop.add(0);
|
||||||
|
|
||||||
// positive cost non-artificial variables
|
// positive cost non-artificial variables
|
||||||
|
@ -362,8 +363,10 @@ class SimplexTableau implements Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = columnsToDrop.size() - 1; i >= 0; i--) {
|
// remove the columns in reverse order so the indices are correct
|
||||||
columnLabels.remove((int) columnsToDrop.get(i));
|
Integer[] drop = columnsToDrop.toArray(new Integer[columnsToDrop.size()]);
|
||||||
|
for (int i = drop.length - 1; i >= 0; i--) {
|
||||||
|
columnLabels.remove((int) drop[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.tableau = new Array2DRowRealMatrix(matrix);
|
this.tableau = new Array2DRowRealMatrix(matrix);
|
||||||
|
|
Loading…
Reference in New Issue