Public Member Functions | Protected Attributes | Static Protected Attributes
DualCQKnP Class Reference

Solver of Continuous Quadratic Knapsack Problems (CQKnP) based on the standard formulation of the dual problem as a piecewise-convex problem in the unique multiplier of the knapsack constraint and the corresponding obvious dual-ascent approach. More...

#include <DualCQKnP.h>

+ Inheritance diagram for DualCQKnP:

List of all members.

Public Member Functions

 DualCQKnP (const bool sort=true, const double eps=1e-6)
 The most important operation for solving the CQKnP with a dual method is the sorting of the items for nondecreasing elements.
void SetSort (const bool WhchSrt=false)
 Allows to change the sorting procedures to be used in the next calls to SolveKNP(); see the comments to the constructor for details.

Protected Attributes

double * A
 vector of lower bounds
double * B
 vector of upper bounds
double * C
 vector of linear costs
double * D
 vector of quadratic costs
double McB
 volume value
bool sense
 sense of knapsack constraint
double LB
 lower bound on dual variable
double UB
 upper bound on dual variable
int * I
 optimal ordering
int nSort
 how many elements we have to sort
double * OV
 values upon which to order
double * XSol
 primal solution
double muStar
 optimal dual solution
bool WSort
 which sorting procedure is used
double OptVal
 The Optimal Value.
double DefEps
 precision required to construct the solution

Static Protected Attributes

static int * QSStck
 the stack to simulate recursive calls in QS
static int InstCntr
 number of active instances
static int maxvl
 max value of items

Detailed Description

Solver of Continuous Quadratic Knapsack Problems (CQKnP) based on the standard formulation of the dual problem as a piecewise-convex problem in the unique multiplier of the knapsack constraint and the corresponding obvious dual-ascent approach.

This class is restricted to instances where all items have strictly positive quadratic costs and finite bounds (both lower and upper).

Derives from CQKnpClass and therefore it mostly conforms to its interface, except for refusing to solve instances without the required characteristics.


Constructor & Destructor Documentation

DualCQKnP ( const bool  sort = true,
const double  eps = 1e-6 
)

The most important operation for solving the CQKnP with a dual method is the sorting of the items for nondecreasing elements.

2 * A[ i ] * D[ i ] + C[ i ] and 2 * B[ i ] * D[ i ] + C[ i ].

If the knapsack is a large one, this can be (relatively) time-consuming. Different sort procedures can be better in different situations, and the parameter 'sort' allows to decide which among the available sorting procedures has to be used. Possible values of this parameter are:

false Bubble Sort: this is O( n^2 ) on average, but it can be very fast - O( n ) - if reoptimizing from a previous problem where the order was not very different (e.g., only few costs have changed).

true [default] Quick Sort: this is O( n lg n ) on average and pretty efficient in practice, but can be very slow - O( n^2 ) - if the vector is already (almost) ordered, e.g. when reoptimizing from a previous problem where only few costs have changed.

The parameter Eps defines the precision required to construct the solution [default value is 1e-6].

The choices can be changed at any time with SetSort() and SetEps(), respectively [see below].


Member Function Documentation

void SetSort ( const bool  WhchSrt = false) [inline]

Allows to change the sorting procedures to be used in the next calls to SolveKNP(); see the comments to the constructor for details.

References DualCQKnP::WSort.