ConicBundle
MatrixCBSolver.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CONICBUNDLE_MATRIXCBSOLVER_HXX
4 #define CONICBUNDLE_MATRIXCBSOLVER_HXX
5 
14 #include "CBSolver.hxx"
15 #include "matrix.hxx"
16 #include "UQPSolver.hxx"
17 #include "BundleProxObject.hxx"
18 #include "BundleData.hxx"
19 #include "BundleWeight.hxx"
23 
24 //------------------------------------------------------------
25 
26 
27 namespace ConicBundle {
28 
188 
212  {
213 
214  public:
232  { Matrix::operator=(pd); return *this; }
233 
235  PrimalData* clone_primal_data() const{return new PrimalMatrix(*this);}
236 
238  int aggregate_primal_data(const PrimalData& it,double itsfactor)
239  {
240  const PrimalMatrix* pd=dynamic_cast<const PrimalMatrix*>(&it);
241  if (pd!=0) {
242  xpeya(*pd,itsfactor);
243  return 0;
244  }
245  return 1;
246  }
247 
249  int scale_primal_data(double myfactor){ *this *= myfactor; return 0;}
250 
251  };
252 
271  class MatrixMinorant: public Minorant
272  {
273  public:
274 
277  const CH_Matrix_Classes::Matrix& subg,
278  PrimalData* primal=0,
279  bool offset_at_origin=false):
280  Minorant(offset_at_origin,double(offset),int(subg.rowdim()),(const double*)subg.get_store(),0,1.,primal)
281  {assert(subg.coldim()==1);}
282 
285  const CH_Matrix_Classes::Sparsemat& subg,
286  PrimalData* primal=0,
287  bool offset_at_origin=false):
288  Minorant(offset_at_origin,double(offset),int(subg.nonzeros()),(const double*)(subg.get_colval().get_store()),(const int*)(subg.get_colindex().get_store()),1.,primal)
289  {assert(subg.coldim()==1);}
290 
293  CH_Matrix_Classes::Real factor=1.,
294  bool with_primal=true)
295  :Minorant(mnrt,double(factor),with_primal)
296  {}
297 
299  ~MatrixMinorant(){}
300 
302  Minorant* clone_minorant(double factor=1.,bool with_primal=true) const
303  { return new MatrixMinorant(this,CH_Matrix_Classes::Real(factor),with_primal); }
304 
305  };
306 
310  {
311  public:
313  virtual ~ModifiableOracleObject();
314 
350  virtual
351  int
352  apply_modification
353  (
354  const OracleModification& oracle_modification,
355  const CH_Matrix_Classes::Matrix* new_center,
356  const CH_Matrix_Classes::Matrix* old_center,
357  bool& discard_objective_in_center,
358  bool& discard_model,
359  bool& discard_aggregates,
360  MinorantExtender*& minorant_extender
361  );
362 
364  virtual
365  bool
367  {return false;}
368 
369  };
370 
371 
405  {
406  public:
407 
500  virtual
501  int
502  evaluate
503  (
504  const CH_Matrix_Classes::Matrix& current_point,
505  CH_Matrix_Classes::Real relprec,
506  CH_Matrix_Classes::Real& objective_value,
507  std::vector<Minorant*>& minorants,
508  PrimalExtender*& primal_extender
509  )
510  = 0;
511 
512 
514  virtual
515  bool
517  {return true;}
518  };
519 
520 
521  class MatrixCBSolverData;
522 
540  class MatrixCBSolver: public CBout
541  {
542  private:
543  MatrixCBSolverData* data_;
544  MatrixCBSolver ( const MatrixCBSolver& );
546  public:
547 
549  MatrixCBSolver(std::ostream* out=0,int print_level=0);
551  MatrixCBSolver(const CBout* cb,int incr=0);
553  ~MatrixCBSolver();
554 
555  //------------------------------------------------------------
558 
562  void clear();
563 
566  void set_defaults();
567 
621  int init_problem(int dim,
622  const CH_Matrix_Classes::Matrix* lbounds=0,
623  const CH_Matrix_Classes::Matrix* ubounds=0,
624  const CH_Matrix_Classes::Matrix* startval=0,
625  const CH_Matrix_Classes::Matrix* costs=0,
626  CH_Matrix_Classes::Real offset=0.);
627 
628 
629 
671  int
672  add_function
673  ( FunctionObject& function,
674  CH_Matrix_Classes::Real fun_factor=1.,
675  FunctionTask fun_task=ObjectiveFunction,
677  bool argument_list_may_change_dynamically=false);
678 
690  int set_lower_bound(int i, double lb);
691 
703  int set_upper_bound(int i, double ub);
704 
705 
765  int append_variables(int n_append,
766  const CH_Matrix_Classes::Matrix* lbounds=0,
767  const CH_Matrix_Classes::Matrix* ubounds=0,
768  const CH_Matrix_Classes::Sparsemat* constraint_columns=0,
769  const CH_Matrix_Classes::Matrix* startval=0,
770  const CH_Matrix_Classes::Matrix* costs=0,
771  const FunObjModMap* affected_functions_with_modifications=0);
772 
814  int delete_variables(const CH_Matrix_Classes::Indexmatrix& delete_indices,
815  CH_Matrix_Classes::Indexmatrix& map_to_old,
816  const FunObjModMap* affected_functions_with_modifications=0);
817 
855  int reassign_variables(const CH_Matrix_Classes::Indexmatrix& assign_new_from_old,
856  const FunObjModMap* affected_functions_with_modifications=0);
857 
886  int append_constraints(CH_Matrix_Classes::Integer append_n_rows,
887  const CH_Matrix_Classes::Sparsemat* append_rows=0,
888  const CH_Matrix_Classes::Matrix* append_rhslb=0,
889  const CH_Matrix_Classes::Matrix* append_rhsub=0);
890 
892 
893  //------------------------------------------------------------
896 
950  int
951  solve(int maxsteps=0,bool stop_at_descent_steps=false);
952 
953 
988  int
989  termination_code() const;
990 
998  std::ostream&
999  print_termination_code(std::ostream& out);
1000 
1006  double
1007  get_objval() const;
1008 
1019  int
1020  get_center
1021  ( CH_Matrix_Classes::Matrix& center ) const;
1022 
1023 
1026  double
1027  get_sgnorm() const;
1028 
1036  int
1037  get_subgradient
1038  ( CH_Matrix_Classes::Matrix& subgradient) const;
1039 
1043  double
1044  get_cutval() const;
1045 
1054  double
1055  get_candidate_value() const;
1056 
1067  int
1068  get_candidate
1069  ( CH_Matrix_Classes::Matrix& center ) const;
1070 
1071 
1073 
1074  //------------------------------------------------------------
1077 
1091  int
1092  set_term_relprec
1093  ( const double term_relprec );
1094 
1103  int
1104  set_new_center_point
1105  ( const CH_Matrix_Classes::Matrix& center_point );
1106 
1107 
1111  int
1112  get_function_status
1113  ( const FunctionObject& function ) const;
1114 
1122  int
1123  get_approximate_slacks(CH_Matrix_Classes::Matrix &) const;
1124 
1139  const PrimalData*
1140  get_approximate_primal
1141  ( const FunctionObject& function)
1142  const;
1143 
1154  const PrimalData*
1155  get_center_primal
1156  ( const FunctionObject& function)
1157  const;
1158 
1159 
1170  const PrimalData*
1171  get_candidate_primal
1172  (const FunctionObject& function)
1173  const;
1174 
1175 
1214  int
1215  set_sumbundle
1216  (bool use_sumbundle,
1217  int n_local_models=-1,
1218  const BundleParameters* bundle_parameters=0,
1219  int strategy=1);
1220 
1249  int
1250  set_max_modelsize
1251  (int max_modelsize, const FunctionObject* function=0);
1252 
1277  int
1278  set_max_bundlesize
1279  (int max_bundlesize, const FunctionObject* function=0);
1280 
1301  int
1302  set_bundle_parameters
1303  (const BundleParameters& params, const FunctionObject* function=0);
1304 
1332  const BundleParameters*
1333  get_bundle_parameters
1334  ( const FunctionObject* function=0) const;
1335 
1336 
1362  int
1363  set_sumbundle_parameters
1364  (const SumBundleParametersObject& params, const FunctionObject* function=0);
1365 
1383  const BundleData*
1384  get_bundle_data
1385  ( const FunctionObject* function=0) const;
1386 
1408  int reinit_function_model
1409  ( const FunctionObject* function=0);
1410 
1429  int clear_aggregates
1430  ( const FunctionObject* function=0);
1431 
1452  int call_primal_extender
1453  (const FunctionObject& function,
1454  PrimalExtender& primal_extender);
1455 
1459  double
1460  get_last_weight() const;
1461 
1465  double
1466  get_next_weight() const;
1467 
1488  int
1489  set_next_weight
1490  ( const double weight );
1491 
1506  int
1507  set_min_weight
1508  ( const double min_weight );
1509 
1523  int
1524  set_max_weight
1525  ( const double max_weight );
1526 
1539  int
1540  set_weight_update
1541  ( BundleWeight* bw );
1542 
1559  int
1560  adjust_multiplier
1561  ( void );
1562 
1563 
1580  int
1581  set_variable_metric
1582  ( int do_variable_metric );
1583 
1584 
1596  int
1597  set_prox
1598  (BundleProxObject* proxp);
1599 
1628  void
1629  set_active_bounds_fixing
1630  ( bool allow_fixing );
1631 
1639  void
1640  clear_fail_counts
1641  (void);
1642 
1656  void
1657  set_eval_limit
1658  (CH_Matrix_Classes::Integer eval_limit);
1659 
1673  void
1674  set_inner_update_limit
1675  (CH_Matrix_Classes::Integer update_limit);
1676 
1685  void
1686  set_time_limit
1687  (CH_Matrix_Classes::Integer time_limit);
1688 
1689  /* * @brief Set parameters for the internal QP solver, possibly after first exchanging the solver with a new one
1690 
1691  The objects passed need to be heap objects; their ownership is transferred
1692  to the bundle code and they will be deleted there. The pointers may be null,
1693  in which case nothing is done for this object
1694 
1695  @param[in] qpparams (QPSolverParametersObject*)
1696 
1697  @param[in] newqpsolver (QPSolverObject*)
1698 
1699  @return
1700  - 0 on success
1701  - != 0 otherwise
1702  */
1703 
1704  int set_qp_solver(QPSolverParametersObject* qpparams,
1705  QPSolverObject* newqpsolver=0);
1706 
1708 
1709  //------------------------------------------------------------
1715  int get_dim() const;
1716 
1719  int get_n_functions() const;
1720 
1723  int get_n_oracle_calls() const;
1724 
1727  int get_n_descent_steps() const;
1728 
1731  int get_n_inner_iterations() const;
1732 
1735  int get_n_inner_updates() const;
1736 
1743  bool get_descent_step() const;
1744 
1751  bool get_null_step() const;
1752 
1755  int get_costs(CH_Matrix_Classes::Matrix& costs) const;
1756 
1759  const CH_Matrix_Classes::Matrix* get_lbounds() const;
1760 
1763  const CH_Matrix_Classes::Matrix* get_ubounds() const;
1764 
1779  const CH_Matrix_Classes::Indexmatrix* get_fixed_active_bounds() const;
1780 
1783  BundleProxObject* get_prox() const;
1784 
1786  bool
1787  pending_oracle_modification(const FunctionObject& function,
1788  CH_Matrix_Classes::Integer& old_dim,
1789  CH_Matrix_Classes::Integer& new_dim,
1790  CH_Matrix_Classes::Integer& append_dim,
1791  const CH_Matrix_Classes::Indexmatrix*& map_to_old,
1792  const CH_Matrix_Classes::Indexmatrix*& deleted_indices,
1793  const CH_Matrix_Classes::Indexmatrix*& new_indices,
1794  const OracleModification*& oracle_modification
1795  ) const;
1796 
1798 
1799  //------------------------------------------------------------
1802 
1860  void
1861  set_out
1862  (std::ostream* out=0,int print_level=1);
1863 
1865  std::ostream& print_line_summary(std::ostream& out) const;
1866 
1868  std::ostream& print_statistics(std::ostream& out) const;
1869 
1871 
1872  };
1873 
1875 }
1876 
1877 #endif
1878 
1879 
1880 
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
Base class for informing oracles (or the solver) about dynamic changes in the number and sorting of t...
Definition: CBSolver.hxx:544
abstract interface for a QPSolver
Definition: QPSolverObject.hxx:105
Header declaring the classes CH_Matrix_Classes::Realrange and CH_Matrix_Classes::Matrix having Real e...
Matrix & xpeya(const Matrix &A, Real d=1.)
sets *this+=d*A and returns *this
abstract interface that allows to use different -norms with a positive definite matrix in the proxi...
Definition: BundleProxObject.hxx:88
If in Lagrangean relaxation primal solutions are in the form of a real vector or, more generally a ma...
Definition: MatrixCBSolver.hxx:211
MatrixMinorant(CH_Matrix_Classes::Real offset, const CH_Matrix_Classes::Matrix &subg, PrimalData *primal=0, bool offset_at_origin=false)
initializaton by a Matrix column vector; if offset_at_origin==true, the offset gives the value at the...
Definition: MatrixCBSolver.hxx:276
Integer rowdim() const
returns the row dimension
Definition: matrix.hxx:215
The Full Conic Bundle method solver invoked by ConicBundle::MatrixCBSolver(), it uses a separate cutt...
Definition: MatrixCBSolver.hxx:540
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
virtual bool check_correctness() const
switch on/off some correctnes checks on the oracle
Definition: MatrixCBSolver.hxx:516
MatrixCBSolverData * data_
pointer to internal solver data
Definition: MatrixCBSolver.hxx:543
int scale_primal_data(double myfactor)
multiply/scale *this with a nonnegative myfactor
Definition: MatrixCBSolver.hxx:249
Interface for extending a Minorant, e.g., in Lagrangian Relaxation of cutting plane approaches...
Definition: CBSolver.hxx:490
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
Oracle interface (abstract class). For each of your functions, provide an instance of a derived class...
Definition: MatrixCBSolver.hxx:404
Header declaring the class ConicBundle::SumBundleParametersObject.
Header declaring the class ConicBundle::BundleProxObject.
Real * get_store()
returns the current address of the internal value array; use cautiously, do not use delete! ...
Definition: matrix.hxx:326
Minorant * clone_minorant(double factor=1., bool with_primal=true) const
produces a clone of itself
Definition: MatrixCBSolver.hxx:302
abstract interface for SumBundleHandler for the model selection and variable metric seletcion routine...
Definition: SumBundleParametersObject.hxx:50
this is used to describe affine minorants of convex functions that will be used for generating cuttin...
Definition: CBSolver.hxx:274
in order to pass parameters to a customized QPSolverObject, derive the parameters from this object; n...
Definition: QPSolverObject.hxx:46
conic bundle method solver for sum of convex functions. See the ConicBundle_Manual for a quick introd...
Definition: CBSolver.hxx:22
MatrixMinorant(CH_Matrix_Classes::Real offset, const CH_Matrix_Classes::Sparsemat &subg, PrimalData *primal=0, bool offset_at_origin=false)
initializaton by a Sparsemat column vector; if offset_at_origin==true, the offset gives the value at ...
Definition: MatrixCBSolver.hxx:284
base class for uniform use of WARNINGS and ERRORS (at some point in time)
Definition: CBout.hxx:30
PrimalMatrix & operator=(const CH_Matrix_Classes::Matrix &pd)
copy operator, *this=pm
Definition: MatrixCBSolver.hxx:231
Header declaring the class ConicBundle::UQPSolver.
Header declaring the classes ConicBundle::FunctionObjectModification and ConicBundle::FunObjModMap.
Header declaring the classes ConicBundle::CBSolver, ConicBundle::FunctionOracle and ConicBundle::Prim...
Serves for specifying parameters regarding the construction of cutting models.
Definition: CBSolver.hxx:891
int aggregate_primal_data(const PrimalData &it, double itsfactor)
multiply *this Matrix with myfactor and add itsfactor*it (it must dynamic_cast to a PrimalMatrix) ...
Definition: MatrixCBSolver.hxx:238
Integer dim() const
returns the dimension rows * columns when the matrix is regarded as a vector
Definition: matrix.hxx:212
PrimalMatrix(const CH_Matrix_Classes::Matrix &pm)
copy constructor, *this=pm
Definition: MatrixCBSolver.hxx:229
Header declaring the class ConicBundle::BundleData (see ConicBundle::SumBlockModel) ...
Integer coldim() const
returns the column dimension
Definition: matrix.hxx:218
Header declaring the class ConicBundle::BundleWeight.
ModifiableOracle provides all oracles with a uniform interface for a modification routine and an on/o...
Definition: MatrixCBSolver.hxx:309
Matrix class for real values of type Real
Definition: matrix.hxx:74
virtual bool check_correctness() const
switch on/off some correctnes checks on the oracle
Definition: MatrixCBSolver.hxx:366
std::map< const FunctionObject *, FunctionObjectModification > FunObjModMap
In order to pass on problem modifications, FunObjModMap allows to specify a FunctionObjectModificatio...
Definition: FunctionObjectModification.hxx:104
FunctionTask
Each function represented by a FunctionModel is equipped with a function_factor (it defaults to 1...
Definition: CBSolver.hxx:221
Matrix class of sparse matrices with real values of type Real
Definition: sparsmat.hxx:74
Abstract interface for BundleSolver providing routines that determine the weight of the quadratic ter...
Definition: BundleWeight.hxx:35
Minorant interface supporting Matrix classes; simple constructros for subgradients given by column ve...
Definition: MatrixCBSolver.hxx:271
Integer nc
number of columns
Definition: matrix.hxx:85
PrimalMatrix()
empty matrix
Definition: MatrixCBSolver.hxx:216
MatrixMinorant(const Minorant *mnrt, CH_Matrix_Classes::Real factor=1., bool with_primal=true)
generates a MatrixMinorat copy of a Minorant scaled by factor (deault =1.) and optionally without clo...
Definition: MatrixCBSolver.hxx:292
PrimalData * clone_primal_data() const
produces a new PrimalMatrix that is a copy of itself; the caller has to delete the returned object at...
Definition: MatrixCBSolver.hxx:235
basic function object (abstract class). It serves for using the same interface on distinct oracle typ...
Definition: CBSolver.hxx:236
Integer nr
number of rows
Definition: matrix.hxx:85
In Lagrangean relaxation an approximate primal solution can be generated by supplying primal informat...
Definition: CBSolver.hxx:151
Interface for extending PrimalData, e.g., in Lagrangian relaxation of column generation approaches...
Definition: CBSolver.hxx:180
transform a function f(z) to fun_coeff*f(arg_offset+arg_trafo*y)+linear_cost*y+fun_offset (scales the...
Definition: AffineFunctionTransformation.hxx:68
PrimalMatrix(CH_Matrix_Classes::Integer r, CH_Matrix_Classes::Integer c, CH_Matrix_Classes::Real d)
generate a matrix of size nr x nc initializing all elements to the value d
Definition: MatrixCBSolver.hxx:225
base class for use with SumBlockModel for storing and managing essential data of evaluations and the ...
Definition: BundleData.hxx:77
PrimalMatrix(const PrimalMatrix &pm)
copy constructor, *this=pm
Definition: MatrixCBSolver.hxx:227
Integer coldim() const
returns the column dimension
Definition: sparsmat.hxx:202
Matrix()
empty matrix
Definition: matrix.hxx:1082
PrimalMatrix(CH_Matrix_Classes::Integer nr, CH_Matrix_Classes::Integer nc)
generate a matrix of size nr x nc but WITHOUT initializing the memory
Definition: MatrixCBSolver.hxx:223
Header declaring the classes ConicBundle::AffineFunctionTransformation.