CBSolver.hxx
Go to the documentation of this file.00001
00002
00003 #ifndef CONICBUNDLE_CBSOLVER_HXX
00004 #define CONICBUNDLE_CBSOLVER_HXX
00005
00013 #include <assert.h>
00014 #include <iostream>
00015 #include <vector>
00016
00017
00018
00022 namespace ConicBundle {
00023
00101
00105 extern const double CB_plus_infinity;
00109 extern const double CB_minus_infinity;
00110
00111 class MatrixBSolver;
00112
00113
00114
00115
00119 typedef std::vector<double> DVector;
00120
00124 typedef std::vector<int> IVector;
00125
00149 class PrimalData
00150 {
00151
00152 public:
00153
00155 virtual ~PrimalData(){}
00156
00158 virtual PrimalData* clone_primal_data()=0;
00159
00161 virtual int assign_primal_data(const PrimalData& pd)=0;
00162
00164 virtual int aggregate_primal_data(double myfactor,double itsfactor,const PrimalData& it)=0;
00165
00166 };
00167
00177 class PrimalExtender
00178 {
00179 public:
00180 virtual ~PrimalExtender(){}
00181
00183 virtual int extend(PrimalData&)=0;
00184 };
00185
00186
00208 class PrimalDVector: public PrimalData, public DVector
00209 {
00210
00211 public:
00213 PrimalDVector(){}
00215 PrimalDVector(int n) :DVector(n) {}
00217 PrimalDVector(int n ,double d) :DVector(n,d) {}
00219 PrimalDVector(const PrimalDVector& pd) :PrimalData(),DVector(pd) {}
00221 PrimalDVector(const DVector& pd) :DVector(pd) {}
00223 PrimalDVector& operator=(const DVector& pd) { DVector::operator= (pd); return *this; }
00224
00226 PrimalData* clone_primal_data(){return new PrimalDVector(*this);}
00227
00229 int assign_primal_data(const PrimalData& it)
00230 {
00231 const PrimalDVector* pd=dynamic_cast<const PrimalDVector*>(&it);
00232 assert(pd!=0);
00233 *this = *pd;
00234 return 0;
00235 }
00236
00238 int aggregate_primal_data(double myfactor,double itsfactor,const PrimalData& it)
00239 {
00240 const PrimalDVector* pd=dynamic_cast<const PrimalDVector*>(&it);
00241 assert(pd!=0);
00242 if (size()!=pd->size()) return 1;
00243 if (myfactor!=1.){
00244 for(int i=0;i<int(size());i++){
00245 (*this)[i]=(*this)[i]*myfactor+(*pd)[i]*itsfactor;
00246 }
00247 return 0;
00248 }
00249 for(int i=0;i<int(size());i++){
00250 (*this)[i]+=(*pd)[i]*itsfactor;
00251 }
00252 return 0;
00253 }
00254 };
00255
00256
00257
00266 class FunctionObject{
00267 public:
00268 virtual ~FunctionObject(){}
00269 };
00270
00301 class FunctionOracle: public FunctionObject
00302 {
00303 public:
00304
00405 virtual
00406 int
00407 evaluate
00408 (
00409 const DVector& current_point,
00410 double relprec,
00411 double& objective_value,
00412 DVector& cut_values,
00413 std::vector<DVector>& eps_subgradients,
00414 std::vector<PrimalData*>& primal_data,
00415 PrimalExtender*& primal_extender
00416 )= 0;
00417
00459 virtual
00460 int
00461 subgradient_extension
00462 (
00463 const PrimalData* ,
00464 const IVector& ,
00465 DVector& )
00466 {return 1;}
00467
00468
00469 };
00470
00471
00476 class BundleParameters
00477 {
00478 public:
00479 int n_new_subgradients;
00480 int n_bundle_size;
00481
00482 virtual ~BundleParameters(){}
00483 };
00484
00485
00503 class CBSolver
00504 {
00505 private:
00506 MatrixBSolver* solver;
00507
00508 CBSolver ( const CBSolver& );
00509 CBSolver& operator= ( const CBSolver& );
00510 public:
00511
00516 CBSolver(bool no_bundle=false);
00518 virtual ~CBSolver();
00519
00520
00523
00527 void clear();
00528
00531 void set_defaults();
00532
00568 int init_problem(int dim,
00569 const DVector* lbounds=0,
00570 const DVector* ubounds=0);
00571
00585 int
00586 add_function
00587 ( FunctionObject& function );
00588
00600 int set_lower_bound(int i, double lb);
00601
00613 int set_upper_bound(int i, double ub);
00614
00615
00653 int append_variables(int n_append,
00654 const DVector* lbounds=0,
00655 const DVector* ubounds=0);
00656
00688 int delete_variables(const IVector& delete_indices,IVector& map_to_old);
00689
00717 int reassign_variables(const IVector& assign_new_from_old);
00718
00720
00721
00724
00775 int
00776 do_descent_step(int maxsteps=0);
00777
00811 int
00812 termination_code()
00813 const;
00814
00822 std::ostream&
00823 print_termination_code(std::ostream& out);
00824
00830 double
00831 get_objval()
00832 const;
00833
00844 int
00845 get_center
00846 ( DVector& center )
00847 const;
00848
00849
00852 double
00853 get_sgnorm()
00854 const;
00855
00863 int
00864 get_subgradient
00865 ( DVector& subgradient )
00866 const;
00867
00876 virtual double
00877 get_candidate_value()
00878 const;
00879
00890 virtual int
00891 get_candidate
00892 ( DVector& candidate )
00893 const;
00894
00895
00897
00898
00901
00915 int
00916 set_term_relprec
00917 ( const double term_relprec );
00918
00927 int
00928 set_new_center_point
00929 ( const DVector& center_point );
00930
00931
00935 int
00936 get_function_status
00937 ( const FunctionObject& function )
00938 const;
00939
00947 int
00948 get_approximate_slacks
00949 ( DVector& center )
00950 const;
00951
00965 int
00966 get_approximate_primal
00967 ( const FunctionObject& function,
00968 PrimalData& primal )
00969 const;
00970
00984 int
00985 get_center_primal
00986 ( const FunctionObject& function,
00987 PrimalData& primal )
00988 const;
00989
00990
01001 virtual int
01002 get_candidate_primal
01003 ( const FunctionObject& function,
01004 PrimalData& primal )
01005 const;
01006
01007
01033 int
01034 set_max_bundlesize
01035 ( const FunctionObject& function, int max_bundlesize );
01036
01054 int
01055 set_max_new_subgradients
01056 ( const FunctionObject& function, int max_new_subgradients );
01057
01074 int
01075 set_bundle_parameters
01076 ( const FunctionObject& function,
01077 const BundleParameters& params );
01078
01095 int
01096 get_bundle_parameters
01097 ( const FunctionObject& function, BundleParameters& params )
01098 const;
01099
01117 int
01118 get_bundle_values
01119 ( const FunctionObject& function, BundleParameters& params )
01120 const;
01121
01137 int reinit_function_model
01138 ( const FunctionObject& function );
01139
01160 int call_primal_extender
01161 (const FunctionObject& function,
01162 PrimalExtender& primal_extender);
01163
01167 double
01168 get_last_weight()
01169 const;
01170
01191 int
01192 set_next_weight
01193 ( const double weight );
01194
01209 int
01210 set_min_weight
01211 ( const double min_weight );
01212
01226 int
01227 set_max_weight
01228 ( const double max_weight );
01229
01230
01237 virtual int
01238 set_scaling
01239 ( bool do_scaling );
01240
01263 virtual void
01264 set_active_bounds_fixing
01265 ( bool allow_fixing );
01266
01271 virtual void
01272 clear_fail_counts
01273 (void);
01274
01284 virtual void
01285 set_eval_limit
01286 (int eval_limit);
01287
01298 virtual void
01299 set_inner_update_limit
01300 (int update_limit);
01301
01303
01304
01307
01311 int get_dim();
01312
01315 int get_n_functions();
01316
01325 int get_active_bounds_indicator(IVector& active_bounds_indicator) const;
01326
01328
01329
01332
01390 void
01391 set_out
01392 (std::ostream* out=0,int print_level=1);
01393
01395
01396 };
01397
01399 }
01400
01401
01402
01403 #endif
01404
01405
01406