ConicBundle
CBSolver.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CONICBUNDLE_CBSOLVER_HXX
4 #define CONICBUNDLE_CBSOLVER_HXX
5 
13 #include <assert.h>
14 #include <iostream>
15 #include <vector>
16 
17 //------------------------------------------------------------
18 
22 namespace ConicBundle {
23 
105 
109  extern const double CB_plus_infinity;
113  extern const double CB_minus_infinity;
114 
115  //------------------------------------------------------------
116 
117 
121  typedef std::vector<double> DVector;
122 
126  typedef std::vector<int> IVector;
127 
152  {
153 
154  public:
155 
157  virtual ~PrimalData();
158 
160  virtual PrimalData* clone_primal_data() const=0;
161 
163  virtual int aggregate_primal_data(const PrimalData& it,double factor=1.)=0;
164 
166  virtual int scale_primal_data(double myfactor)=0;
167 
168  };
169 
181  {
182  public:
184  virtual ~PrimalExtender();
185 
187  virtual int extend(PrimalData&)=0;
188  };
189 
190 
191 
194  extern const double CB_minorant_zero_tolerance;
195 
199  extern const double CB_minorant_sparsity_ratio;
200 
201 
222  ObjectiveFunction=0,
223  ConstantPenaltyFunction=1,
224  AdaptivePenaltyFunction=2
225  };
226 
227 
237  {
238  public:
240  virtual ~FunctionObject();
241  };
242 
274  class Minorant
275  {
276  public:
277 
278 
297  Minorant(double offset,const DVector& subg,PrimalData* primal=0,bool offset_at_origin=false);
298 
317  Minorant(double offset,const DVector& subg_val,const IVector& subg_ind,PrimalData* primal=0,bool offset_at_origin=false);
318 
354  Minorant(bool offset_at_origin=true,
355  double offset=0.,
356  int n_elementes=0,
357  const double* coeffs=0,
358  const int* indices=0,
359  double scale_val=1.,
360  PrimalData* primal=0
361  );
362 
364  Minorant(const Minorant* mnrt,double factor=1.,bool with_primal=false);
365 
367  virtual ~Minorant();
368 
370  virtual double offset() const;
372  virtual int add_offset(double value);
373 
375  virtual bool& offset_gives_value_at_origin();
377  virtual bool offset_gives_value_at_origin() const;
378 
380  virtual double coeff(int i);
381 
383  virtual int add_coeff(int i,double value);
384 
386  virtual int add_coeffs(int n_elements,const double* values,double factor=1.,int start_pos=0);
387 
389  virtual int add_coeffs(int n_elements,const double* values,const int* indices,double factor=1.);
390 
392  virtual int sparsify(double tol=CB_minorant_zero_tolerance,double sparsity_ratio=CB_minorant_sparsity_ratio);
393 
395  virtual int nonzeros();
396 
403  virtual int get_coeffs(int& n_elements,const double*& coeffs,const int*& indices) const;
404 
418  virtual double* get_dense_coeff_store(int n_elements);
419 
421  virtual int reassign_coeffs(int n_elements,const int* map_to_old_coeffs);
422 
424  virtual void set_primal(PrimalData*);
425 
427  virtual PrimalData* get_primal();
428 
430  virtual const PrimalData* get_primal() const;
431 
433  virtual Minorant* clone_minorant(double factor=1.,bool with_primal=true) const;
434 
436  virtual int aggregate(const Minorant& minorant,double factor=1.);
437 
439  virtual int number_aggregated() const;
440 
442  virtual int scale_minorant(double scale_val);
443 
445  virtual double norm_squared() const;
446 
447  protected:
449  class MinorantData;
451  mutable MinorantData* data;
452 
453  Minorant(const Minorant&){}
454  Minorant& operator=(const Minorant&);
455  };
456 
491  {
492  public:
494  virtual ~MinorantExtender();
495 
517  virtual int extend(Minorant& minorant,int n_coords,const int* indices)=0;
518  };
519 
545  {
546  public:
548  virtual ~OracleModification();
549 
551  virtual int get_old_vardim() const =0;
553  virtual int get_new_vardim() const =0;
555  virtual int get_appended_vardim() const =0;
557  virtual const int* get_map_to_old_variables() const =0;
558 
580  virtual int incorporate(const OracleModification& next_modification)=0;
581 
583  virtual OracleModification* new_initial_oraclemodification(int old_var_dim) const =0;
584 
586  virtual int add_append_variables(int append_dim)=0;
587 
589  virtual int add_reassign_variables(int new_dim,const int* map_to_old_indices)=0;
590 
592  virtual bool no_modification() const=0;
593 
595  virtual int set_append_to_old(bool ) =0;
596 
598  virtual bool append_to_old() const=0;
599 
600  };
601 
602 
624  class PrimalDVector: public PrimalData, public DVector
625  {
626 
627  public:
629  PrimalDVector(){}
631  PrimalDVector(int n) :DVector((unsigned long)(n)) {}
633  PrimalDVector(int n ,double d) :DVector((unsigned long)(n),d) {}
635  PrimalDVector(const PrimalDVector& pd) :PrimalData(),DVector(pd) {}
637  PrimalDVector(const DVector& pd) :DVector(pd) {}
639  PrimalDVector& operator=(const DVector& pd) { DVector::operator= (pd); return *this; }
640 
642  PrimalData* clone_primal_data() const{return new PrimalDVector(*this);}
643 
645  int assign_primal_data(const PrimalData& it,double factor=1.)
646  {
647  const PrimalDVector* pd=dynamic_cast<const PrimalDVector*>(&it);
648  assert(pd!=0);
649  DVector::operator=(*pd);
650  if (factor!=1)
651  for(unsigned int i=0;i<size();i++){
652  (*this)[i]*=factor;
653  }
654  return 0;
655  }
656 
658  int aggregate_primal_data(const PrimalData& it,double factor=1.)
659  {
660  const PrimalDVector* pd=dynamic_cast<const PrimalDVector*>(&it);
661  assert(pd!=0);
662  if (size()!=pd->size()) return 1;
663  for(unsigned int i=0;i<size();i++){
664  (*this)[i]+=(*pd)[i]*factor;
665  }
666  return 0;
667  }
668 
670  virtual int scale_primal_data(double myfactor)
671  {
672  if (myfactor!=1.){
673  for(unsigned int i=0;i<size();i++){
674  (*this)[i]*=myfactor;
675  }
676  }
677  return 0;
678 
679  }
680 
681  };
682 
683 
716  {
717  public:
718 
811  virtual
812  int
813  evaluate
814  (
815  const double* current_point,
816  double relprec,
817  double& objective_value,
818  std::vector<Minorant*>& minorants,
819  PrimalExtender*& primal_extender
820  )= 0;
821 
822 
862  virtual
863  int
864  apply_modification
865  (
866  const OracleModification& oracle_modification ,
867  const double* new_center,
868  const double* old_center,
869  bool& discard_objective_in_center,
870  bool& discard_model,
871  bool& discard_aggregates,
872  MinorantExtender*& minorant_extender
873  );
874  /*{return 1;}*/
875 
876 
878  virtual
879  bool
881  {return true;}
882 
883 
884  };
885 
886 
892  {
893  protected:
897 
898  public:
900  virtual int init(const BundleParameters& bp)
901  {
902  max_model_size=bp.max_model_size;
903  max_bundle_size=bp.max_bundle_size;
904  update_rule=bp.update_rule;
905  return 0;
906  }
907 
909  virtual int get_max_model_size() const
910  { return max_model_size; }
912  virtual int get_max_bundle_size() const
913  { return max_bundle_size; }
915  virtual int get_update_rule() const
916  { return update_rule; }
917 
919  virtual int set_max_model_size(int mms)
920  { max_model_size=mms; return 0; }
922  virtual int set_max_bundle_size(int mbs)
923  { max_bundle_size=mbs; return 0; }
925  virtual int set_update_rule(int ur)
926  { update_rule=ur; return 0; }
927 
931 
933  BundleParameters(int modelsize=-1,int bundlesize=-1,int updaterule=-1)
934  {
935  max_model_size=modelsize;
936  max_bundle_size=bundlesize;
937  update_rule=updaterule;
938  }
939 
941  virtual ~BundleParameters();
942 
945  { return new BundleParameters(*this); }
946 
947  };
948 
949 
950  class MatrixCBSolver;
951 
969  class CBSolver
970  {
971  private:
973 
974  CBSolver ( const CBSolver& );
975  CBSolver& operator= ( const CBSolver& );
976  public:
977 
979  CBSolver(std::ostream* out=0,int print_level=0);
981  virtual ~CBSolver();
982 
983  //------------------------------------------------------------
986 
990  void clear();
991 
994  void set_defaults();
995 
1031  int init_problem(int dim,
1032  const DVector* lbounds=0,
1033  const DVector* ubounds=0);
1034 
1048  int
1049  add_function
1050  ( FunctionObject& function );
1051 
1063  int set_lower_bound(int i, double lb);
1064 
1076  int set_upper_bound(int i, double ub);
1077 
1078 
1116  int append_variables(int n_append,
1117  const DVector* lbounds=0,
1118  const DVector* ubounds=0);
1119 
1151  int delete_variables(const IVector& delete_indices,IVector& map_to_old);
1152 
1180  int reassign_variables(const IVector& assign_new_from_old);
1181 
1183 
1184  //------------------------------------------------------------
1187 
1242  int
1243  solve(int maxsteps=0,bool stop_at_descent_steps=false);
1244 
1278  int
1279  termination_code()
1280  const;
1281 
1289  std::ostream&
1290  print_termination_code(std::ostream& out);
1291 
1297  double
1298  get_objval()
1299  const;
1300 
1311  int
1312  get_center
1313  ( DVector& center )
1314  const;
1315 
1316 
1319  double
1320  get_sgnorm()
1321  const;
1322 
1330  int
1331  get_subgradient
1332  ( DVector& subgradient )
1333  const;
1334 
1343  virtual double
1344  get_candidate_value()
1345  const;
1346 
1357  virtual int
1358  get_candidate
1359  ( DVector& candidate )
1360  const;
1361 
1362 
1364 
1365  //------------------------------------------------------------
1368 
1382  int
1383  set_term_relprec
1384  ( const double term_relprec );
1385 
1394  int
1395  set_new_center_point
1396  ( const DVector& center_point );
1397 
1398 
1402  int
1403  get_function_status
1404  ( const FunctionObject& function )
1405  const;
1406 
1414  int
1415  get_approximate_slacks
1416  ( DVector& center )
1417  const;
1418 
1433  const PrimalData*
1434  get_approximate_primal
1435  ( const FunctionObject& function)
1436  const;
1437 
1448  const PrimalData*
1449  get_center_primal
1450  ( const FunctionObject& function)
1451  const;
1452 
1453 
1464  const PrimalData*
1465  get_candidate_primal
1466  (const FunctionObject& function)
1467  const;
1468 
1469 
1495  int
1496  set_max_modelsize
1497  ( const FunctionObject& function, int max_modelsize );
1498 
1517  int
1518  set_max_bundlesize
1519  ( const FunctionObject& function, int max_bundlesize );
1520 
1537  int
1538  set_bundle_parameters
1539  ( const FunctionObject& function,
1540  const BundleParameters& params );
1541 
1556  const BundleParameters*
1557  get_bundle_parameters
1558  ( const FunctionObject& function )
1559  const;
1560 
1561 
1577  int reinit_function_model
1578  ( const FunctionObject& function );
1579 
1600  int call_primal_extender
1601  (const FunctionObject& function,
1602  PrimalExtender& primal_extender);
1603 
1607  double
1608  get_last_weight() const;
1609 
1630  int
1631  set_next_weight
1632  ( const double weight );
1633 
1648  int
1649  set_min_weight
1650  ( const double min_weight );
1651 
1665  int
1666  set_max_weight
1667  ( const double max_weight );
1668 
1669 
1683  virtual int
1684  set_variable_metric
1685  ( int do_scaling );
1686 
1708  virtual void
1709  set_active_bounds_fixing
1710  ( bool allow_fixing );
1711 
1716  virtual void
1717  clear_fail_counts
1718  (void);
1719 
1729  virtual void
1730  set_eval_limit
1731  (int eval_limit);
1732 
1743  virtual void
1744  set_inner_update_limit
1745  (int update_limit);
1746 
1748 
1749  //------------------------------------------------------------
1752 
1756  int get_dim();
1757 
1760  int get_n_functions();
1761 
1771  int get_fixed_active_bounds(IVector& fixed_active_bounds) const;
1772 
1774 
1775  //------------------------------------------------------------
1778 
1836  void
1837  set_out
1838  (std::ostream* out=0,int print_level=1);
1839 
1841 
1842  };
1843 
1845 }
1846 
1847 
1848 
1849 #endif
1850 
1851 
1852 
Base class for informing oracles (or the solver) about dynamic changes in the number and sorting of t...
Definition: CBSolver.hxx:544
virtual int get_max_model_size() const
returns the value of the variable
Definition: CBSolver.hxx:909
oracle interface (abstract class). For each of your functions, provide a derived class.
Definition: CBSolver.hxx:715
virtual int set_max_model_size(int mms)
sets the value of the variable
Definition: CBSolver.hxx:919
virtual int set_max_bundle_size(int mbs)
sets the value of the variable
Definition: CBSolver.hxx:922
BundleParameters(int modelsize=-1, int bundlesize=-1, int updaterule=-1)
often works well for fast initial progress: small model of size 2 and some history in bundle size for...
Definition: CBSolver.hxx:933
Bundle method solver.
Definition: CBSolver.hxx:969
PrimalDVector & operator=(const DVector &pd)
assignment of a DVector
Definition: CBSolver.hxx:639
The Full Conic Bundle method solver invoked by ConicBundle::MatrixCBSolver(), it uses a separate cutt...
Definition: MatrixCBSolver.hxx:540
Minorant(const Minorant &)
forbidden, blocked deliberately
Definition: CBSolver.hxx:453
PrimalDVector(int n, double d)
construct a primal double vector with n elements initialized to d
Definition: CBSolver.hxx:633
Interface for extending a Minorant, e.g., in Lagrangian Relaxation of cutting plane approaches...
Definition: CBSolver.hxx:490
std::vector< double > DVector
A dense vector of double, arguments and subgradients are specified like this.
Definition: CBSolver.hxx:121
If in Lagrangean relaxation primal solutions are in the form of a ConicBundle::DVector, then an approximate primal solution can be generated by supplying primal information of this form for each epsilon subgradient within ConicBundle::FunctionOracle::evaluate().
Definition: CBSolver.hxx:624
std::vector< int > IVector
A dense vector of int, index vectors for deleting/reorganizing variables are specified like this...
Definition: CBSolver.hxx:126
this is used to describe affine minorants of convex functions that will be used for generating cuttin...
Definition: CBSolver.hxx:274
conic bundle method solver for sum of convex functions. See the ConicBundle_Manual for a quick introd...
Definition: CBSolver.hxx:22
MinorantData * data
implementation details are hidden on purpose
Definition: CBSolver.hxx:449
const double CB_minorant_zero_tolerance
serves as the default tolerance for considering minorant entries as zero
int assign_primal_data(const PrimalData &it, double factor=1.)
copy its information to *this
Definition: CBSolver.hxx:645
BundleParameters(const BundleParameters &bp)
often works well: small model of size 2 and some history in bundle size for use in scaling ...
Definition: CBSolver.hxx:929
virtual int init(const BundleParameters &bp)
initialize to given values
Definition: CBSolver.hxx:900
Serves for specifying parameters regarding the construction of cutting models.
Definition: CBSolver.hxx:891
virtual BundleParameters * clone_BundleParameters() const
return a new clone object of this on the heap (caller needs to delete the result) ...
Definition: CBSolver.hxx:944
virtual PrimalData * clone_primal_data() const =0
Returns a newly generated identical Object.
PrimalData * clone_primal_data() const
produces a new PrimalDVector that is a copy of itself
Definition: CBSolver.hxx:642
int update_rule
in case several update rules are available
Definition: CBSolver.hxx:896
const double CB_minus_infinity
serves as the value "plus infinity", i.e., all bounds >= this value are set to this value and are reg...
int max_bundle_size
suggested maximum number of latest minorants stored for use in a model, for constructing variable met...
Definition: CBSolver.hxx:895
int aggregate_primal_data(const PrimalData &it, double factor=1.)
if it is a PrimalDVector of the same dimension, add factor*it to *this
Definition: CBSolver.hxx:658
FunctionTask
Each function represented by a FunctionModel is equipped with a function_factor (it defaults to 1...
Definition: CBSolver.hxx:221
PrimalDVector(const PrimalDVector &pd)
copy constructor
Definition: CBSolver.hxx:635
const double CB_plus_infinity
serves as the value "minus infinity", i.e., all bounds <= this value are set to this value and are re...
virtual int set_update_rule(int ur)
sets the value of the variable
Definition: CBSolver.hxx:925
virtual int scale_primal_data(double myfactor)
multiply/scale *this with a nonnegative myfactor
Definition: CBSolver.hxx:670
const double CB_minorant_sparsity_ratio
serves as the default ratio of nonzeros to dimension for using a sparse representatio of a minorant ...
virtual int scale_primal_data(double myfactor)=0
multiply/scale *this with a nonnegative myfactor
basic function object (abstract class). It serves for using the same interface on distinct oracle typ...
Definition: CBSolver.hxx:236
int max_model_size
maximum number of minorants to be selected for the cutting model (numbers<=1 for no limit...
Definition: CBSolver.hxx:894
In Lagrangean relaxation an approximate primal solution can be generated by supplying primal informat...
Definition: CBSolver.hxx:151
virtual int get_update_rule() const
returns the value of the variable
Definition: CBSolver.hxx:915
Interface for extending PrimalData, e.g., in Lagrangian relaxation of column generation approaches...
Definition: CBSolver.hxx:180
virtual bool check_correctness() const
switch on/off some correctness checks on the oracle
Definition: CBSolver.hxx:880
PrimalDVector(int n)
construct a primal double vector with n elements
Definition: CBSolver.hxx:631
PrimalDVector(const DVector &pd)
conversion from a DVector
Definition: CBSolver.hxx:637
virtual int aggregate_primal_data(const PrimalData &it, double factor=1.)=0
add factor*it to this (types will need to be compatible to this)
MatrixCBSolver * solver
pointer to internal solver
Definition: CBSolver.hxx:972
virtual int get_max_bundle_size() const
returns the value of the variable
Definition: CBSolver.hxx:912