7#ifndef LIMBO_SOLVERS_MULTIKNAPSACKLAGRELAX_H
8#define LIMBO_SOLVERS_MULTIKNAPSACKLAGRELAX_H
26template <
typename T,
typename V>
28template <
typename T,
typename V>
30template <
typename T,
typename V>
32template <
typename T,
typename V>
65template <
typename T,
typename V>
114 m_bestObj = std::numeric_limits<coefficient_value_type>::max();
144 return solve(updater, scaler, searcher);
183 std::ostream&
printObjCoef(std::ostream& os = std::cout)
const;
196 std::ostream&
printConstraint(std::ostream& os, std::string
const& name)
const;
202 template <
typename TT>
203 void printArray(
unsigned int n, TT
const* array,
bool nonzeroFlag)
const;
219 return constr.
sense() !=
'=';
244 bool operator()(variable_type
const& v1, variable_type
const& v2)
const
267 void scale(scaler_type* scaler);
298 template <
typename TT,
typename VV>
299 void bMinusAx(matrix_type
const& A, VV
const* x, TT
const* b, TT* y)
const;
331template <
typename T,
typename V>
336template <
typename T,
typename V>
341template <
typename T,
typename V>
346template <
typename T,
typename V>
351template <
typename T,
typename V>
356template <
typename T,
typename V>
361template <
typename T,
typename V>
364 unsigned int result = 0;
371template <
typename T,
typename V>
421template <
typename T,
typename V>
454template <
typename T,
typename V>
457 bool defaultUpdater =
false;
458 bool defaultScaler =
false;
459 bool defaultSearcher =
false;
464 defaultUpdater =
true;
470 defaultScaler =
true;
473 if (searcher == NULL)
476 defaultSearcher =
true;
508template <
typename T,
typename V>
518#ifdef DEBUG_MULTIKNAPSACKLAGRELAX
522 std::ofstream out (buf);
535template <
typename T,
typename V>
541 for (
unsigned int i = 0, ie =
m_model->constraints().size(); i < ie; ++i)
550template <
typename T,
typename V>
554 for (
unsigned int i = 0, ie =
m_model->constraints().size(); i < ie; ++i)
559template <
typename T,
typename V>
565 for (
typename std::vector<term_type>::const_iterator it =
m_model->objective().terms().begin(), ite =
m_model->objective().terms().end(); it != ite; ++it)
566 m_vObjCoef[it->variable().id()] += it->coefficient();
570 for (
unsigned int ie =
m_model->numVariables(); i < ie; ++i)
572 variable_type var (i);
573 variable_value_type lowerBound =
m_model->variableLowerBound(var);
574 variable_value_type upperBound =
m_model->variableUpperBound(var);
575 if (lowerBound == upperBound)
576 m_model->setVariableSolution(var, lowerBound);
582 for (
unsigned int ie =
m_model->constraints().size(); i < ie; ++i)
590 m_vSlackness =
new coefficient_value_type [numCapacityConstraints];
595 m_model->constraints().at(*it).normalize(
'<');
608#ifdef DEBUG_MULTIKNAPSACKLAGRELAX
611 constraint_type
const& constr =
m_model->constraints()[*it];
623 constraint_type
const& constr =
m_model->constraints()[*it];
624 for (
typename std::vector<typename constraint_type::term_type>::const_iterator itt = constr.
expression().
terms().begin(), itte = constr.
expression().
terms().end(); itt != itte; ++itt, ++i)
626#ifdef DEBUG_MULTIKNAPSACKLAGRELAX
638 constraint_type
const& constr =
m_model->constraints()[*it];
646 unsigned int numGroupElements = 0;
647 for (std::vector<unsigned int>::iterator it = bound, ite =
m_vConstraintPartition.end(); it != ite; ++it, ++i)
649 constraint_type
const& constr =
m_model->constraints()[*it];
658 for (std::vector<unsigned int>::iterator it = bound, ite =
m_vConstraintPartition.end(); it != ite; ++it, ++i)
660 constraint_type
const& constr =
m_model->constraints()[*it];
661#ifdef DEBUG_MULTIKNAPSACKLAGRELAX
664 expression_type
const& expr = constr.
expression();
666 for (
typename std::vector<term_type>::const_iterator itt = expr.
terms().begin(), itte = expr.
terms().end(); itt != itte; ++itt, ++j)
672template <
typename T,
typename V>
691 for (
typename std::vector<term_type>::const_iterator it =
m_model->objective().terms().begin(), ite =
m_model->objective().terms().end(); it != ite; ++it)
692 m_vObjCoef[it->variable().id()] += it->coefficient();
701template <
typename T,
typename V>
706 variable_value_type* vVariableSol = &
m_model->variableSolutions()[0];
710 variable_type
const* variable;
713 std::fill(vVariableSol, vVariableSol+
m_model->numVariables(), 0);
716 variableGroupBegin = variableGroupEnd;
719 variable = std::min_element(variableGroupBegin, variableGroupEnd, helper);
720 vVariableSol[variable->
id()] = 1;
727template <
typename T,
typename V>
733template <
typename T,
typename V>
738 for (
unsigned int i = 0, ie =
m_model->numVariables(); i < ie; ++i)
742template <
typename T,
typename V>
745 bool feasibleFlag =
true;
746 bool convergeFlag =
true;
759 convergeFlag = feasibleFlag =
false;
762 else if (multiplier*slackness != 0)
764 convergeFlag =
false;
771 coefficient_value_type obj =
m_model->evaluateObjective();
784template <
typename T,
typename V>
789 else if (
m_bestObj != std::numeric_limits<coefficient_value_type>::max())
797 return searcher->operator()(updater);
801template <
typename T,
typename V>
802template <
typename TT,
typename VV>
807 AxPlusy((coefficient_value_type)-1, A, x, y);
810template <
typename T,
typename V>
813 std::ofstream out (filename.c_str());
823template <
typename T,
typename V>
826 os << __func__ <<
" iteration " <<
m_iter <<
"\n";
829 os <<
"[" << i <<
"]";
833 if (
m_model->variableSolution(*variable) == 1)
834 os <<
" *" <<
m_model->variableName(*variable) <<
"*";
836 os <<
" " <<
m_model->variableName(*variable);
842template <
typename T,
typename V>
845 std::ofstream out (filename.c_str());
855template <
typename T,
typename V>
858 os << __func__ <<
" iteration " <<
m_iter <<
"\n";
859 os <<
"lagrangian objective = " <<
m_lagObj <<
"\n";
860 os <<
"objective = " <<
m_model->evaluateObjective() <<
"\n";
861 for (
unsigned int i = 0, ie =
m_model->numVariables(); i < ie; ++i)
865template <
typename T,
typename V>
868 std::ofstream out (filename.c_str());
878template <
typename T,
typename V>
881 os << __func__ <<
" iteration " <<
m_iter <<
"\n";
888template <
typename T,
typename V>
893 constraint_type
const& constr = this->
m_model->constraints()[i];
894 if (
m_model->constraintName(constr) == name)
896 os <<
"constraint " << name <<
": rhs = " << constr.
rightHandSide() <<
"\n";
897 for (
typename std::vector<term_type>::const_iterator it = constr.
expression().
terms().begin(), ite = constr.
expression().
terms().end(); it != ite; ++it)
898 os <<
m_model->variableName(it->variable()) <<
": " <<
m_model->variableSolution(it->variable()) <<
"*" << it->coefficient() <<
"\n";
903template <
typename T,
typename V>
904template <
typename TT>
907 limboPrint(kNONE,
"array of length %u = {", n);
908 for (
unsigned int i = 0; i < n; ++i)
916 limboPrint(kNONE,
"%u:%g", i, (
double)array[i]);
977 ,
m_iter(std::numeric_limits<unsigned int>::
max())
993 this->base_type::operator=(rhs);
1026 value_type const* multiplier = vLagMultiplier;
1027 value_type* newMultiplier = vNewLagMultiplier;
1028 for (
unsigned int i = 0; i < n; ++i)
1067template <
typename T,
typename V>
1107template <
typename T,
typename V>
1135 value_type result = std::numeric_limits<value_type>::max();
1136 for (
typename std::vector<term_type>::const_iterator it = expr.
terms().begin(), ite = expr.
terms().end(); it != ite; ++it)
1137 result = std::min(result, it->coefficient());
1155template <
typename T,
typename V>
1183 for (
typename std::vector<term_type>::const_iterator it = expr.
terms().begin(), ite = expr.
terms().end(); it != ite; ++it)
1184 result += it->coefficient()*it->coefficient();
1185 return sqrt(result/expr.
terms().size());
1199template <
typename T,
typename V>
1269 return m_solver->solveSubproblems(updater, beginIter, endIter);
1300template <
typename T,
typename V>
1374 unsigned int numNegativeSlacksPrev = std::numeric_limits<unsigned int>::max();
1375 unsigned int numNegativeSlacks = std::numeric_limits<unsigned int>::max();
1377 std::vector<bool> vVariableProcess (this->
m_model->numVariables(),
false);
1379 std::vector<VariableMoveCost> vVariableMoveCost;
1383 largeCost += (*it > 0)? *it : 0;
1386 vVariableProcess.assign(this->
m_model->numVariables(),
false);
1388 numNegativeSlacksPrev = numNegativeSlacks;
1389 numNegativeSlacks = 0;
1404 for (
typename std::vector<VariableMoveCost>::const_iterator it = vVariableMoveCost.begin(), ite = vVariableMoveCost.end(); it != ite; ++it)
1410 this->
m_vObjCoef[it->variable.id()] = largeCost;
1412 slackness += it->capacity;
1414 vVariableProcess[it->variable.id()] =
true;
1419 ++numNegativeSlacks;
1422 if (numNegativeSlacks == 0)
1426 }
while (numNegativeSlacks && numNegativeSlacks*(1+
m_convergeRatio) < numNegativeSlacksPrev);
1437 for (
unsigned int i = 0; i < this->
m_numGroups; ++i)
1441 for (; it != ite; ++it)
1454 vVariableMoveCost.clear();
1456 for (
typename std::vector<term_type>::const_iterator it = constr.
expression().
terms().begin(), ite = constr.
expression().
terms().end(); it != ite; ++it, ++j)
1459 if (this->
m_model->variableSolution(it->variable()) && !vVariableProcess[it->variable().id()])
1466 for (; itv != itve; ++itv)
1468 if (it->variable() != *itv)
1470 moveCost = std::min(moveCost, this->
m_vObjCoef[itv->
id()]-this->m_vObjCoef[it->variable().id()]);
1474 vVariableMoveCost.push_back(
VariableMoveCost(it->variable(), moveCost, it->coefficient()));
1486template <
typename T,
typename V>
1578 std::vector<VariableMoveCost> vVariableMoveCost;
1580 std::vector<unsigned int> vNegativeSlackConstr;
1587 vNegativeSlackConstr.push_back(i);
1594 for (std::vector<unsigned int>::const_iterator it = vNegativeSlackConstr.begin(), ite = vNegativeSlackConstr.end(); it != ite; ++it)
1601 vVariableMoveCost.clear();
1604 typename std::vector<VariableMoveCost>::const_iterator itm = std::min_element(vVariableMoveCost.begin(), vVariableMoveCost.end(),
CompareVariableMoveCost());
1608 if (itm->moveCost != std::numeric_limits<coefficient_value_type>::max())
1612 this->
m_model->setVariableSolution(var, 0);
1613 for (std::vector<std::pair<unsigned int, unsigned int> >::const_iterator itc = this->
m_mVariable2Constr[var.
id()].begin(), itce = this->m_mVariable2Constr[var.
id()].end(); itc != itce; ++itc)
1623 this->
m_model->setVariableSolution(targetVar, 1);
1624 for (std::vector<std::pair<unsigned int, unsigned int> >::const_iterator itc = this->
m_mVariable2Constr[targetVar.
id()].begin(), itce = this->m_mVariable2Constr[targetVar.
id()].end(); itc != itce; ++itc)
1638 for (std::vector<unsigned int>::const_iterator it = vNegativeSlackConstr.begin(), ite = vNegativeSlackConstr.end(); it != ite; ++it)
1657 for (
typename std::vector<term_type>::const_iterator it = constr.
expression().
terms().begin(), ite = constr.
expression().
terms().end(); it != ite; ++it, ++j)
1662 for (
typename std::vector<term_type>::const_iterator it = this->
m_model->objective().terms().begin(), ite = this->m_model->objective().terms().end(); it != ite; ++it)
1671 vVariableMoveCost.clear();
1673 for (
typename std::vector<term_type>::const_iterator it = constr.
expression().
terms().begin(), ite = constr.
expression().
terms().end(); it != ite; ++it, ++j)
1677 if (this->
m_model->variableSolution(var))
1685 for (; itv != itve; ++itv)
1690 bool enoughCapacityFlag =
true;
1691 for (std::vector<std::pair<unsigned int, unsigned int> >::const_iterator itc = this->
m_mVariable2Constr[itv->
id()].begin(), itce = this->m_mVariable2Constr[itv->
id()].end(); itc != itce; ++itc)
1695 if (slackness < coeff)
1697 enoughCapacityFlag =
false;
1701 if (!enoughCapacityFlag)
1704 if (moveCost > targetCost)
1706 moveCost = targetCost;
1724template <
typename T,
typename V>
#define limboAssert(condition)
custom assertion without message
#define limboStaticAssert(condition)
compile time assertion
numerical functions for linear algebra
Basic utilities such as variables and linear expressions in solvers.
Base heuristic to search for feasible solutions.
unsigned int *const & m_vVariableGroupBeginIndex
std::vector< unsigned int > const & m_vConstraintPartition
coefficient_value_type *& m_vLagMultiplier
FeasibleSearcher(solver_type *solver)
constructor
matrix_type const & m_constrMatrix
model_type *const & m_model
coefficient_value_type & m_objConstant
model_type::expression_type expression_type
unsigned int & m_maxIters
model_type::variable_type variable_type
SolverProperty solveSubproblems(updater_type *updater, unsigned int beginIter, unsigned int endIter)
kernel lagrangian iterations
solver_type::updater_type updater_type
coefficient_value_type & m_lagObj
model_type::coefficient_value_type coefficient_value_type
variable_type *const & m_vGroupedVariable
virtual SolverProperty operator()(updater_type *)
API to search for feasible solutions.
unsigned int const & m_numGroups
coefficient_value_type *& m_vObjCoef
virtual ~FeasibleSearcher()
destructor
std::vector< coefficient_value_type > const & m_vScalingFactor
model_type::variable_value_type variable_value_type
std::vector< variable_value_type > & m_vBestVariableSol
coefficient_value_type *const & m_vConstrRhs
coefficient_value_type *& m_vSlackness
coefficient_value_type & m_bestObj
model_type::term_type term_type
void computeSlackness()
compute slackness in an iteration
solver_type::matrix_type matrix_type
model_type::constraint_type constraint_type
MultiKnapsackLagRelax< coefficient_value_type, variable_value_type > solver_type
LinearModel< coefficient_value_type, variable_value_type > model_type
Scaling scheme with default L2 norm scaling.
base_type::model_type model_type
model type
base_type::term_type term_type
term type
base_type::value_type value_type
value type
value_type operator()(constraint_type const &constr) const
API to compute scaling factor for constraints using L2 norm.
L2NormScaler()
constructor
~L2NormScaler()
destructor
value_type operator()(expression_type const &expr) const
API to compute scaling factor for expression using L2 norm.
ProblemScaler< T, V > base_type
base type
base_type::expression_type expression_type
expression type
base_type::constraint_type constraint_type
constraint type
A base helper function object to update lagrangian multipliers using subgradient descent....
coefficient_value_type value_type
virtual value_type operator()(unsigned int iter, value_type multiplier, value_type slackness)=0
API to update lagrangian multiplier.
virtual ~LagMultiplierUpdater()
destructor
virtual void operator()(unsigned int iter, unsigned int n, value_type const *vSlackness, value_type const *vLagMultiplier, value_type *vNewLagMultiplier)=0
API to update lagrangian multiplier using subgradient descent.
LagMultiplierUpdater()
constructor
coefficient_value_type rightHandSide() const
expression_type const & expression() const
std::vector< term_type > const & terms() const
model to describe an optimization problem
V variable_value_type
V variable.
VariableProperty< variable_value_type > property_type
variable property type
Variable< coefficient_value_type > variable_type
variable type
T coefficient_value_type
T coefficient.
LinearConstraint< coefficient_value_type > constraint_type
constraint type
LinearExpression< coefficient_value_type > expression_type
expression type
LinearTerm< coefficient_value_type > term_type
term type
coefficient_value_type coefficient() const
value_type m_scalingFactor
constant scaling factor
base_type::expression_type expression_type
expression type
base_type::model_type model_type
model type
ProblemScaler< T, V > base_type
base type
base_type::constraint_type constraint_type
constraint type
base_type::value_type value_type
value type
value_type operator()(constraint_type const &constr) const
API to compute scaling factor for constraints using L2 norm.
value_type operator()(expression_type const &expr) const
API to compute scaling factor for expression using L2 norm.
~MinCoefficientScaler()
destructor
base_type::term_type term_type
term type
MinCoefficientScaler(value_type factor=1)
constructor
Solve multiple knapsack problem with lagrangian relaxation.
coefficient_value_type * m_vNewLagMultiplier
array of new lagrangian multipliers, temporary storage
unsigned int numNegativeSlackConstraints(bool evaluateFlag)
get number of constraints with negative slackness in current iteration
void scale(scaler_type *scaler)
scale problem for better numerical instability
void destroy()
destroy model
unsigned int maxIterations() const
std::vector< variable_value_type > m_vBestVariableSol
best feasible solution found so far
coefficient_value_type evaluateLagObjective() const
evaluate objective of the lagrangian subproblem
~MultiKnapsackLagRelax()
destructor
bool printVariableGroup(std::string const &filename) const
print variable groups to file
std::ostream & printConstraint(std::ostream &os, std::string const &name) const
print constraint
bool m_useInitialSol
whether use initial solutions or not
std::vector< unsigned int > m_vConstraintPartition
indices of constraints, the first partition is capacity constraints
SolverProperty solveSubproblems(updater_type *updater, unsigned int beginIter, unsigned int endIter)
kernel lagrangian iterations
coefficient_value_type * m_vObjCoef
coefficients variables in objective
MultiKnapsackLagRelax(model_type *model)
constructor
void updateLagMultipliers(updater_type *updater)
update lagrangian multipliers
void solveLag()
solve lagrangian subproblem
void computeSlackness()
compute slackness in an iteration
coefficient_value_type * m_vLagMultiplier
array of lagrangian multipliers
coefficient_value_type * m_vConstrRhs
constraint right hand side
void printArray(unsigned int n, TT const *array, bool nonzeroFlag) const
print array
void copy(MultiKnapsackLagRelax const &rhs)
copy object
void setLagObjFlag(bool f)
set evaluating objective of lagrangian subproblem in each iteration
SolverProperty solve(updater_type *updater, scaler_type *scaler, searcher_type *searcher)
kernel function to solve the problem
coefficient_value_type m_lagObj
current objective of the lagrangian subproblem
unsigned int m_numGroups
number of groups
variable_type * m_vGroupedVariable
array of grouped variables according to item
unsigned int * m_vVariableGroupBeginIndex
begin index of grouped variable
coefficient_value_type m_bestObj
best objective found so far
unsigned int m_maxIters
maximum number of iterations
model_type * m_model
model for the problem
LinearModel< T, V > model_type
linear model type for the problem
bool useInitialSolutions() const
coefficient_value_type * m_vSlackness
array of slackness values in each iteration,
void bMinusAx(matrix_type const &A, VV const *x, TT const *b, TT *y) const
function to compute
void setMaxIterations(unsigned int maxIter)
set maximum iterations
matrix_type m_constrMatrix
constraint matrix
bool m_lagObjFlag
whether evaluate objective of the lagrangian subproblem in each iteration
void setUseInitialSolutions(bool f)
set whether use initial solutions
unsigned int m_iter
current iteration
MultiKnapsackLagRelax & operator=(MultiKnapsackLagRelax const &rhs)
assignment
SolverProperty converge()
check convergence of current solution
bool printLagMultiplier(std::string const &filename) const
print lagrangian multipliers to file
SolverProperty operator()(updater_type *updater=NULL, scaler_type *scaler=NULL, searcher_type *searcher=NULL)
API to run the algorithm.
coefficient_value_type m_objConstant
constant value in objective from lagrangian relaxation
SolverProperty postProcess(updater_type *updater, searcher_type *searcher, SolverProperty status)
post process solution if failed to converge to OPTIMAL after maximum iteration. It choose the best fe...
bool printObjCoef(std::string const &filename) const
print coefficients of variables in objective to file
void prepare()
prepare weights of variables in objective and classify constraints by marking capacity constraints an...
void unscale()
recover problem from scaling
MultiKnapsackLagRelax(MultiKnapsackLagRelax const &rhs)
copy constructor
std::vector< coefficient_value_type > m_vScalingFactor
scaling factor for constraints and objective, last entry is for objective
Base class for scaling scheme with default no scaling.
model_type::constraint_type constraint_type
model_type::coefficient_value_type value_type
LinearModel< coefficient_value_type, variable_value_type > model_type
model_type::term_type term_type
ProblemScaler()
constructor
model_type::expression_type expression_type
virtual ~ProblemScaler()
destructor
virtual value_type operator()(constraint_type const &constr) const
API to compute scaling factor for constraints using L2 norm.
virtual value_type operator()(expression_type const &) const
API to compute scaling factor for expression using L2 norm.
Heuristic to search for feasible solutions by adjusting coefficients so that some items will not be a...
coefficient_value_type m_convergeRatio
ratio for convergence criteria, how much percent the number of negative slacks reduced
void computeMoveCost(constraint_type const &constr, std::vector< bool > const &vVariableProcess, std::vector< VariableMoveCost > &vVariableMoveCost) const
compute move cost for an item to move out from current bin
void mapVariable2Group()
construct mapping from variables to groups
FeasibleSearcher< T, V > base_type
base type
model_type::variable_value_type variable_value_type
variable value type
virtual SolverProperty operator()(updater_type *updater)
API to search for feasible solutions.
model_type::constraint_type constraint_type
constraint type
solver_type::matrix_type matrix_type
matrix type
model_type::coefficient_value_type coefficient_value_type
coefficient value type
model_type::variable_type variable_type
variable type
model_type::term_type term_type
term type
solver_type::updater_type updater_type
updater type for lagrangian multipliers
base_type::model_type model_type
model type
base_type::solver_type solver_type
solver type
~SearchByAdjustCoefficient()
destructor
model_type::expression_type expression_type
expression type
std::vector< unsigned int > m_vVariable2Group
map variables to groups
SearchByAdjustCoefficient(solver_type *solver, coefficient_value_type convergeRatio=0.1)
constructor
Heuristic to search for feasible solutions by smoothing dense bins.
base_type::model_type model_type
model type
virtual SolverProperty operator()(updater_type *)
API to search for feasible solutions.
~SearchByBinSmoothing()
destructor
SearchByAdjustCoefficient< T, V > base_type
base type
solver_type::updater_type updater_type
updater type for lagrangian multipliers
SearchByBinSmoothing(solver_type *solver)
constructor
model_type::term_type term_type
term type
void mapVariable2Constraint()
construct mapping from variables to constraints
model_type::variable_type variable_type
variable type
model_type::constraint_type constraint_type
constraint type
std::vector< coefficient_value_type > m_vObjCoefOrig
original coefficient of variable in objective
model_type::coefficient_value_type coefficient_value_type
coefficient value type
model_type::expression_type expression_type
expression type
solver_type::matrix_type matrix_type
matrix type
void computeMoveCost(constraint_type const &constr, std::vector< VariableMoveCost > &vVariableMoveCost) const
compute move cost for an item to move out from current bin
std::vector< std::vector< std::pair< unsigned int, unsigned int > > > m_mVariable2Constr
map variables to constraints by pair of (constraint index, term index), a variable may have multiple ...
base_type::solver_type solver_type
solver type
base_type::model_type model_type
model type
base_type::solver_type solver_type
solver type
SearchByBinSmoothing< coefficient_value_type, variable_value_type > m_searcherSmoothing
search by smoothing dense bins
model_type::expression_type expression_type
expression type
~SearchByCombinedStrategy()
destructor
model_type::variable_value_type variable_value_type
variable value type
FeasibleSearcher< T, V > base_type
base type
SearchByAdjustCoefficient< coefficient_value_type, variable_value_type > m_searcherCoeff
search by adjusting coefficient
model_type::term_type term_type
term type
SearchByCombinedStrategy(solver_type *solver, coefficient_value_type convergeRatio=0.1)
constructor
solver_type::updater_type updater_type
updater type for lagrangian multipliers
model_type::constraint_type constraint_type
constraint type
virtual SolverProperty operator()(updater_type *updater)
API to search for feasible solutions.
model_type::coefficient_value_type coefficient_value_type
coefficient value type
model_type::variable_type variable_type
variable type
Update lagrangian multiplier with subgradient descent.
value_type operator()(unsigned int iter, value_type multiplier, value_type slackness)
API to update lagrangian multiplier using subgradient descent.
base_type::value_type value_type
value type
value_type m_scalingFactor
scaling factor
void copy(SubGradientDescent const &rhs)
copy object
SubGradientDescent(value_type alpha=1, value_type beta=1)
constructor
SubGradientDescent & operator=(SubGradientDescent const &rhs)
assignment
~SubGradientDescent()
destructor
void computeScalingFactor(unsigned int iter)
compute scaling factor
value_type m_beta
constant
unsigned int m_iter
current iteration
void operator()(unsigned int iter, unsigned int n, value_type const *vSlackness, value_type const *vLagMultiplier, value_type *vNewLagMultiplier)
API to update lagrangian multiplier using subgradient descent.
LagMultiplierUpdater< T > base_type
base type
SubGradientDescent(SubGradientDescent const &rhs)
copy constructor
namespace for Limbo.Solvers
void vcopy(unsigned int n, T const *x, T *y)
copy vector
SolverProperty
Some enums used in solver.
@ OPTIMAL
optimally solved
@ SUBOPTIMAL
the model is suboptimal
@ INFEASIBLE
the model is infeasible
void axpy(unsigned int n, T a, V const *x, T *y)
void AxPlusy(T a, MatrixType const &A, V const *x, T *y)
T dot(unsigned int n, T const *x, T const *y)
compute dot product
void ATxPlusy(T a, MatrixType const &A, V const *x, T *y)
std::iterator_traits< Iterator >::value_type max(Iterator first, Iterator last)
get max of an array
int limboPrint(MessageType m, const char *format,...)
formatted print with prefix
int limboSPrint(MessageType m, char *buf, const char *format,...)
formatted print with prefix to buffer
Compressed sparse row (CSR) matrix.
static index_type s_startingIndex
index_type numRows
number of rows, not in the CSR format
Predicate whether a constraint is a capacity constraint.
std::vector< constraint_type > const & vConstraint
constraints
CapacityConstraintPred(std::vector< constraint_type > const &v)
constructor
bool operator()(unsigned int id) const
bool operator()(constraint_type const &constr) const
Predicate to sort variables according to their coefficient from small to large.
bool operator()(variable_type const &v1, variable_type const &v2) const
CompareVariableByCoefficient(coefficient_value_type const *v)
constructor
coefficient_value_type const * vObjCoef
coefficients in objective for comparison
Compare variables by its move cost.
bool operator()(VariableMoveCost const &c1, VariableMoveCost const &c2) const
Wrapper for the move cost of an item.
coefficient_value_type capacity
capacity of the item
coefficient_value_type moveCost
move cost
VariableMoveCost(variable_type var, coefficient_value_type mc, coefficient_value_type cap)
constructor
variable_type variable
variable of the item
Compare constraints by their slackness.
CompareConstraintSlack(coefficient_value_type const *v)
constructor
coefficient_value_type const * vSlackness
array of slackness
bool operator()(unsigned int i, unsigned int j) const
Compare variables by its move cost.
bool operator()(VariableMoveCost const &c1, VariableMoveCost const &c2) const
Wrapper for the move cost of an item.
variable_type variable
variable of the item for the original bin
coefficient_value_type moveCost
move cost
VariableMoveCost(variable_type var, variable_type targetVar, coefficient_value_type mc)
constructor
variable_type targetVariable
variable of the item for the target bin