public class

KnapsackStateImpl

extends Object
implements KnapsackState
java.lang.Object
   ↳ org.apache.helix.controller.strategy.knapsack.KnapsackStateImpl

Class Overview

Implementation of KnapsackState

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

Summary

Public Constructors
KnapsackStateImpl()
Initialize the knapsack state
Public Methods
int getNumberOfItems()
Get the current number of items in the knapsack
void init(int numberOfItems)
Initialize the knapsack with the number of items
boolean isBound(int id)
Check if an item is currently bound to the knapsack
boolean isIn(int id)
Check if an item is currently in the knapsack
boolean updateState(boolean revert, KnapsackAssignment assignment)
Update this state with an assignment
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.apache.helix.controller.strategy.knapsack.KnapsackState

Public Constructors

public KnapsackStateImpl ()

Initialize the knapsack state

Public Methods

public int getNumberOfItems ()

Get the current number of items in the knapsack

Returns
  • number of items

public void init (int numberOfItems)

Initialize the knapsack with the number of items

Parameters
numberOfItems the number of items

public boolean isBound (int id)

Check if an item is currently bound to the knapsack

Parameters
id the item id
Returns
  • true if bound, false otherwise

public boolean isIn (int id)

Check if an item is currently in the knapsack

Parameters
id the item id
Returns
  • true if inside, false otherwise

public boolean updateState (boolean revert, KnapsackAssignment assignment)

Update this state with an assignment

Parameters
revert true to revert to the previous state, false otherwise
assignment the assignment that was made
Returns
  • true on success, false on failure