ConicBundle
MinorantPointer.hxx
Go to the documentation of this file.
1 
2 
3 #ifndef CONICBUNDLE_MINORANTPOINTER_HXX
4 #define CONICBUNDLE_MINORANTPOINTER_HXX
5 
6 
14 #include "MinorantUseData.hxx"
15 #include "sparsmat.hxx"
16 
17 namespace ConicBundle {
18 
19  class GroundsetModification;
20 
25 
27  typedef std::vector<MinorantPointer> MinorantBundle;
28 
34 class MinorantPointer: public CBout
35 {
36 private:
40 
42  void delete_data();
43 
45  void new_data(MinorantUseData* in_md);
46 
48  int prepare_for_changes(CH_Matrix_Classes::Real factor=1.,bool with_primal=false);
49 
50 public:
53 
55  void init(const MinorantPointer& mp,CH_Matrix_Classes::Real factor=1.,bool enforce_copy=false);
56 
58  void init(Minorant* mp,CH_Matrix_Classes::Integer modification_id=-1,CH_Matrix_Classes::Real factor=1.);
59 
62  {}
63 
66  {new_data(in_md);}
67 
69  MinorantPointer(const MinorantPointer& mp):CBout(mp),md(0)
70  {new_data(mp.md);}
71 
74  CBout(mp),md(0)
75  {init(mp,factor);}
76 
79  CBout(),md(0)
80  {init(mnrt,modification_id,factor);}
81 
84 
86  void clear() { delete_data();}
87 
89  int synchronize_ids(CH_Matrix_Classes::Integer new_modification_id,
90  CH_Matrix_Classes::Integer new_center_id,
91  CH_Matrix_Classes::Integer old_center_id,
92  CH_Matrix_Classes::Integer new_cand_id,
93  CH_Matrix_Classes::Integer old_cand_id,
94  CH_Matrix_Classes::Integer new_prex_id=0);
95 
97  bool empty() const {return (md==0);}
98 
100  bool valid() const {return (md!=0)&&(md->valid());}
101 
103  bool zero() const;
104 
114  bool aggregate() const;
115 
117  bool one_user() const;
118 
120  const Minorant* get_minorant() const
121  {if (empty()) return 0; return md->get_minorant();}
122 
125  {if (empty()) { m=0;sv=0.;return 0;} return md->get_scaleval_and_minorant(sv,m);}
126 
128  const PrimalData* get_primal();
129 
132 
135 
138  {if (empty()) return 0; return md->get_minorant()->nonzeros();}
139 
142 
145 
147  int apply_modification(const GroundsetModification& gsmdf,
149  MinorantExtender* mex,
150  bool apply_gsmdf_costs=false);
151 
154  const CH_Matrix_Classes::Matrix& y,bool with_constant=true) const;
155 
158 
172  CH_Matrix_Classes::Real alpha=1.,
173  bool add=false,
174  const CH_Matrix_Classes::Indexmatrix* skip_fixed=0,
175  const CH_Matrix_Classes::Matrix* fixed_vals=0) const;
176 
177 
185  CH_Matrix_Classes::Real alpha=1.) const;
186 
202  const CH_Matrix_Classes::Indexmatrix* provided_row_indices=0,
203  const CH_Matrix_Classes::Indexmatrix* needed_col_indices=0,
204  bool enforce_copy=false) const;
205 
211  int aggregate(const MinorantBundle& minorants,const CH_Matrix_Classes::Matrix& coeff,CH_Matrix_Classes::Real factor=1.);
212 
215  int aggregate(const MinorantPointer& minorant,double itsfactor=1.);
216 
219  CH_Matrix_Classes::Real ip(const MinorantPointer& mp,const CH_Matrix_Classes::Indexmatrix* skip_fixed=0,const CH_Matrix_Classes::Matrix* ipdiag=0) const;
220 
223 
225  bool operator<(const MinorantPointer& mp) const
226  {return (md<mp.md);}
227 
229  bool operator==(const MinorantPointer& mp) const
230  {return (md==mp.md);}
231 
233  bool operator>(const MinorantPointer& mp) const
234  {return (md>mp.md);}
235 
237  bool equals(const MinorantPointer& mp,CH_Matrix_Classes::Real tol=1e-10) const;
238 
241 
244 
248  CH_Matrix_Classes::Real alpha=1.,
249  CH_Matrix_Classes::Real beta=0.,
250  int thistrans=0,
251  int btrans=0,
252  CH_Matrix_Classes::Integer thisindex=0) const;
253 
257  CH_Matrix_Classes::Real alpha=1.,
258  CH_Matrix_Classes::Real beta=0.,
259  int atrans=0,
260  int thistrans=0,
261  CH_Matrix_Classes::Integer thisindex=0) const;
262 
264  std::ostream& display(std::ostream& out,int precision=8) const;
265 };
266 
268  CH_Matrix_Classes::Matrix& genmult(const MinorantBundle& A,
269  const CH_Matrix_Classes::Matrix& B,
271  CH_Matrix_Classes::Real alpha=1.,
272  CH_Matrix_Classes::Real beta=0.,
273  int Atrans=0,
274  int Btrans=0,
275  CH_Matrix_Classes::Matrix* Coffset=0);
276 
279  const MinorantBundle& B,
281  CH_Matrix_Classes::Real alpha=1.,
282  CH_Matrix_Classes::Real beta=0.,
283  int Atrans=0,
284  int Btrans=0,
285  CH_Matrix_Classes::Matrix* Coffset=0);
286 
287 
289 
290 
291 }
292 
293 
294 #endif
295 
int Integer
all integer numbers in calculations and indexing are of this type
Definition: matop.hxx:40
MinorantPointer(MinorantUseData *in_md)
initialize this to point to in_md
Definition: MinorantPointer.hxx:65
void init(const MinorantPointer &mp, CH_Matrix_Classes::Real factor=1., bool enforce_copy=false)
if factor!=1 it generates another MinorantUseData referring to the one of mp, otherwise it simply use...
bool operator<(const MinorantPointer &mp) const
they are equal if they point to the same object, compares the addresses of this objects ...
Definition: MinorantPointer.hxx:225
bool zero() const
returns true if the pointer is not empty but all entrys (also the offset) are zero ...
double Real
all real numbers in calculations are of this type
Definition: matop.hxx:50
CH_Matrix_Classes::Matrix & genmult(const MinorantBundle &A, const CH_Matrix_Classes::Matrix &B, CH_Matrix_Classes::Matrix &C, CH_Matrix_Classes::Real alpha=1., CH_Matrix_Classes::Real beta=0., int Atrans=0, int Btrans=0, CH_Matrix_Classes::Matrix *Coffset=0)
computes and returns C=alpha*A*B+beta*C where A and B may be transposed and A is considered to have t...
CH_Matrix_Classes::Real norm_squared(const CH_Matrix_Classes::Matrix *D=0) const
Compute the norm squared of this for the given diagonal matrix D (identity if not given)...
Minorant * get_minorant() const
return the final minorant (by a recursive call) or 0 if there is none
bool valid() const
check validity recursively
bool equals(const MinorantPointer &mp, CH_Matrix_Classes::Real tol=1e-10) const
they are equal if they point to the same object or are both 0. If not, they differ if their matrix re...
std::ostream & display(std::ostream &out, int precision=8) const
output the Minorant in a nice format
Interface for extending a Minorant, e.g., in Lagrangian Relaxation of cutting plane approaches...
Definition: CBSolver.hxx:490
int get_scaleval_and_minorant(CH_Matrix_Classes::Real &sv, Minorant *&m)
returns the Minorant *this points to with its scaling value or 0 if empty
Definition: MinorantPointer.hxx:124
MinorantPointer(const MinorantPointer &mp)
calls new_data
Definition: MinorantPointer.hxx:69
bool valid() const
returns true if the pointer is not empty and the data is valid
Definition: MinorantPointer.hxx:100
Matrix class for integral values of type Integer
Definition: indexmat.hxx:195
CH_Matrix_Classes::Real offset() const
returns the offset of the minorant (including the internal scalings) or CB_minus_infinity if empty ...
MinorantPointer(Minorant *mnrt, CH_Matrix_Classes::Integer modification_id, CH_Matrix_Classes::Real factor=1.)
calls init(Minorant*,CH_Matrix_Classes::Integer,CH_Matrix_Classes::Real)
Definition: MinorantPointer.hxx:78
bool operator>(const MinorantPointer &mp) const
they are equal if they point to the same object, compares the addresses of this objects ...
Definition: MinorantPointer.hxx:233
int synchronize_ids(CH_Matrix_Classes::Integer new_modification_id, CH_Matrix_Classes::Integer new_center_id, CH_Matrix_Classes::Integer old_center_id, CH_Matrix_Classes::Integer new_cand_id, CH_Matrix_Classes::Integer old_cand_id, CH_Matrix_Classes::Integer new_prex_id=0)
if not empty it sets the modification_id to its new id and reinitializes the evaluation map ...
stores use information for the model that the minorant is generated for or to the data the model refe...
Definition: MinorantUseData.hxx:34
bool empty() const
returns true if the pointer is empty
Definition: MinorantPointer.hxx:97
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
CH_Matrix_Classes::Real evaluate(CH_Matrix_Classes::Integer yid, const CH_Matrix_Classes::Matrix &y, bool with_constant=true) const
negative ids are allowed and indicate there is no need to memorize this result, returns CB_minus_infi...
const PrimalData * get_primal()
returns the primal of the Minorant *this points to or 0 if empty (first carrying out any pending scal...
base class for uniform use of WARNINGS and ERRORS (at some point in time)
Definition: CBout.hxx:30
MinorantUseData * md
if null, it is regarded as not initialized or empty
Definition: MinorantPointer.hxx:38
int add_offset(CH_Matrix_Classes::Real offset)
add the offset; if empty, initialize to offset with zero linear part, if not the only user (use_cnt>1...
bool operator==(const MinorantPointer &mp) const
they are equal if they point to the same object, compares the addresses of this objects ...
Definition: MinorantPointer.hxx:229
CH_Matrix_Classes::Integer nonzeros() const
returns the number of nonzero coefficients
Definition: MinorantPointer.hxx:137
int apply_modification(const GroundsetModification &gsmdf, CH_Matrix_Classes::Integer mod_id, MinorantExtender *mex, bool apply_gsmdf_costs=false)
if valid and the local modification_id is smaller than mod_id, it modifies the coefficients as descri...
int get_scaleval_and_minorant(CH_Matrix_Classes::Real &sv, Minorant *&m)
by a recursive call return the collected scaling value and the final minorant
Matrix class for real values of type Real
Definition: matrix.hxx:74
std::ostream * out
not output at all if out==0, otherwise use this output stream
Definition: CBout.hxx:33
MinorantPointer & operator=(const MinorantPointer &mp)
calls new_data with the data of mp and copies the modification_id
Matrix class of sparse matrices with real values of type Real
Definition: sparsmat.hxx:74
std::vector< MinorantPointer > MinorantBundle
a bundle is a vector with MinorantPointer entries
Definition: MinorantPointer.hxx:24
int call_primal_extender(PrimalExtender &prex, CH_Matrix_Classes::Integer prex_id)
executes prex on the primal if its id is smaller then prex_id; returns != if this fails or not primal...
void delete_data()
if -1 it is invalid or empty, otherwise it gives the modification id of the function that it was crea...
virtual ~MinorantPointer()
calls delete_data
Definition: MinorantPointer.hxx:83
const Minorant * get_minorant() const
returns the Minorant *this points to or 0 if empty
Definition: MinorantPointer.hxx:120
CH_Matrix_Classes::Real dual_norm_squared(const CH_Matrix_Classes::Matrix *D=0) const
Compute the dual norm squared of this for the given diagonal matrix D (identity if not given)...
int prepare_for_changes(CH_Matrix_Classes::Real factor=1., bool with_primal=false)
check whether the minorant is owend by this pointer (use_cnt==1) and if not, clone it first ...
MinorantPointer()
declares the pointer empty
Definition: MinorantPointer.hxx:61
bool aggregate() const
returns ture if it points to a combination of minorants from the same function;
In Lagrangean relaxation an approximate primal solution can be generated by supplying primal informat...
Definition: CBSolver.hxx:151
CH_Matrix_Classes::Matrix & right_genmult(const CH_Matrix_Classes::Matrix &A, CH_Matrix_Classes::Matrix &C, CH_Matrix_Classes::Real alpha=1., CH_Matrix_Classes::Real beta=0., int atrans=0, int thistrans=0, CH_Matrix_Classes::Integer thisindex=0) const
computes and returns C=alpha*A*(*this)+beta*C where A and *this may be transposed and *this is consid...
void new_data(MinorantUseData *in_md)
first deletes the old data and then fills the information with the new
Collects modifications for the unconstrained Groundset for appending, deleting or reassigning variabl...
Definition: GroundsetModification.hxx:32
int scale(CH_Matrix_Classes::Real val)
multiply the MinorantPointer by val (this is an external factor for the minorant and possibly its pri...
Header declaring the class ConicBundle::MinorantUseData.
Interface for extending PrimalData, e.g., in Lagrangian relaxation of column generation approaches...
Definition: CBSolver.hxx:180
virtual int nonzeros()
returns the number of nonzero coefficients
CH_Matrix_Classes::Real coeff(CH_Matrix_Classes::Integer i) const
returns coefficient i of the minorant (including the internal scalings) or 0. if empty ...
MinorantPointer(const MinorantPointer &mp, CH_Matrix_Classes::Real factor)
calls init(const MinorantPointer&,CH_Matrix_Classes::Real)
Definition: MinorantPointer.hxx:73
CH_Matrix_Classes::Real ip(const MinorantPointer &mp, const CH_Matrix_Classes::Indexmatrix *skip_fixed=0, const CH_Matrix_Classes::Matrix *ipdiag=0) const
computes the inner product of the two minorants; if skip_fixed!=NULL the corrsponding indices are not...
CH_Matrix_Classes::Matrix & left_genmult(const CH_Matrix_Classes::Matrix &B, CH_Matrix_Classes::Matrix &C, CH_Matrix_Classes::Real alpha=1., CH_Matrix_Classes::Real beta=0., int thistrans=0, int btrans=0, CH_Matrix_Classes::Integer thisindex=0) const
computes and returns C=alpha*(*this)*B+beta*C where B and *this may be transposed and *this is consid...
bool one_user() const
returns true if not valid or this is the only active pointer to the minorant
points to MinorantUseData that may be shared by many and allows computations with Minorants ...
Definition: MinorantPointer.hxx:34
Header declaring the class CH_Matrix_Classes::Sparsemat for sparse matrices with Real elements...
void clear()
afterwards the pointer is empty (calls delete_data())
Definition: MinorantPointer.hxx:86