/* AVAILABLE METHODS IN KP LIBRARY */ class KPF { public: /** * KPF constructor initializes the parameters of the given knapsack problem * * @param n number of items * @param weight array of weights of the items (can be either positive or negative) * @param profit array of profits of the items (can be either positive or negative) * @param C maximum weight capacity of the knapsack * @param B minimum profit threshold of the knapsack * */ KPF(long long n, long long* weight, long long* profit, long long C, long long B); /** * Finds which items need to either be excluded or included to fulfill the capacity and threshold constraints * * @param filter1 array of indexes of items that can be included, assumes filter1 is a (previously) allocated array of length 2*numberOfItems * @param filter0 array of indexes of items that can be excluded, assumes filter0 is a (previously) allocated array of length *numberOfItems * @param filteredAlreadyOne number of filtered items initially in filter1, and changed to the total number of items in filter1 * @param filteredAlreadyZero number of filtered items initially in filter0, and changed to the total number of items in filter0 * @param noCommit if true, filter automatically commits the items (set to false by default) * @return total number of filtered items, -1 if a feasible solution is not feasible */ long long filter( long long* filter1, long long* filter0, long long& filteredAlready1, long long& filteredAlready0, bool noCommit=true); /** * Changes the status of the given items to the new specified status * * @param filter array of indexes of items whose status must be changed * @param n total number of items whose status is being changed * @param newStatus array of the new statuses the corresponding items must be changed to {-1 = unkown, 0 = exclude, 1 = include} * @param dive if true, update does not allow changes of status to already set items (set to false by default) * @return true if all item statuses were updated successfully, flase otherwise */ bool update (long long* filter, long long n, char* newStatus, bool dive = false); /** * @return true iff the relaxed solution is integer */ bool upperBoundProfit(void); /** * @return lower bound on the weight for the current partial assignment */ double getLowerBoundWeight(void); /** * @return upper bound on the profit for the current partial assignment */ double getUpperBoundProfit(void); /** * @param t new threshold for the knapsack such that the gained protfit is greater or equal to this value */ void setNewThreshold(long long t); /** * @param c new capacity for the knapsack such that the accumulated weight is smaller or equal to this value */ void setNewCapacity(long long c); long long getTotalWeight(void); long long getTotalProfit(void); }; #endif