Skip to content

Instantly share code, notes, and snippets.

@htrajan
Created February 12, 2018 22:27
Show Gist options
  • Select an option

  • Save htrajan/52ca0f62fa882eafdd08bfd985d0ecfa to your computer and use it in GitHub Desktop.

Select an option

Save htrajan/52ca0f62fa882eafdd08bfd985d0ecfa to your computer and use it in GitHub Desktop.
Binary Home Searching
@Inject BinarySearchSolver solver;
...
Function<Double, Affordability> affordabilityFn ...; // our mapping function that takes a number and returns an affordability
Function<Affordability, Boolean> manageableTargetTest = affordability -> affordability.getOrdinal() <= MANAGEABLE.getOrdinal();
double maxManageablePrice = solver.solveForMaxValuePassingTargetTest(
lowerBound,
upperBound,
tolerance, // how close our upper and lower bounds should be to stop searching
affordabilityFn,
manageableTargetTest,
maxSearchIterations);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment