Skip to content

Instantly share code, notes, and snippets.

@dzolnai
Created January 17, 2017 18:27
Show Gist options
  • Save dzolnai/ab629bfdac78d1b52a291ace05069bac to your computer and use it in GitHub Desktop.
Save dzolnai/ab629bfdac78d1b52a291ace05069bac to your computer and use it in GitHub Desktop.
Simplex solver article - gist 3
Type solutionVectorType = new Type.Builder(renderScript, Element.F32(renderScript)).setX(script.get_MAX_COLS()).create();
Type resultSizeType = new Type.Builder(renderScript, Element.I32(renderScript)).create();
script.set_solution_vector(arrayAllocation);
script.set_result_size(resultSizeAllocation);
script.invoke_solve();
float[] solutionVector = new float[script.get_MAX_COLS()];
arrayAllocation.copyTo(solutionVector);
int[] resultSizeVector = new int[1];
resultSizeAllocation.copyTo(resultSizeVector);
// If the solution vector size is -1, no solution has been found.
if (resultSizeVector[0] <= 0) {
return null;
}
return Arrays.copyOf(solutionVector, resultSizeVector[0]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment