public class

KnapsackSolverImpl

extends Object
implements KnapsackSolver
java.lang.Object
   ↳ org.apache.helix.controller.strategy.knapsack.KnapsackSolverImpl

Class Overview

Implementation of KnapsackSolver

Based on the C++ knapsack solver in Google's or-tools package.

Summary

Public Constructors
KnapsackSolverImpl(String solverName)
Initialize a generic knapsack solver
KnapsackSolverImpl(KnapsackSolver.SolverType solverType, String solverName)
Initialize a specified knapsack solver
Public Methods
boolean bestSolutionContains(int itemId)
Check if an element was selected in the optimal solution
String getName()
Get the name of this solver
void init(ArrayList<Long> profits, ArrayList<ArrayList<Long>> weights, ArrayList<Long> capacities)
Initialize the solver
void setUseReduction(boolean useReduction)
Set whether a reduction should be used to prune paths early on
long solve()
Solve the knapsack problem
boolean useReduction()
Check if a reduction should be used to prune paths early on
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.helix.controller.strategy.knapsack.KnapsackSolver

Public Constructors

public KnapsackSolverImpl (String solverName)

Initialize a generic knapsack solver

Parameters
solverName the name of the solver

public KnapsackSolverImpl (KnapsackSolver.SolverType solverType, String solverName)

Initialize a specified knapsack solver

Parameters
solverType the type of solver
solverName the name of the solver

Public Methods

public boolean bestSolutionContains (int itemId)

Check if an element was selected in the optimal solution

Parameters
itemId the index of the element to check
Returns
  • true if the item is present, false otherwise

public String getName ()

Get the name of this solver

Returns
  • solver name

public void init (ArrayList<Long> profits, ArrayList<ArrayList<Long>> weights, ArrayList<Long> capacities)

Initialize the solver

Parameters
profits profit for each element if selected
weights cost of each element in each dimension
capacities maximum total weight in each dimension

public void setUseReduction (boolean useReduction)

Set whether a reduction should be used to prune paths early on

Parameters
useReduction true to enable, false to disable

public long solve ()

Solve the knapsack problem

Returns
  • the approximated optimal weight

public boolean useReduction ()

Check if a reduction should be used to prune paths early on

Returns
  • true if reduction enabled, false otherwise