Couenne 0.5.8
CouenneMatrix.hpp
Go to the documentation of this file.
1/* $Id: CouenneMatrix.hpp 1094 2015-01-10 16:59:20Z pbelotti $
2 *
3 * Name: CouenneMatrix.hpp
4 * Author: Pietro Belotti
5 * Purpose: define the class of expression matrices
6 *
7 * This file is licensed under the Eclipse Public License (EPL)
8 */
9
10#ifndef CouenneMatrix_hpp
11#define CouenneMatrix_hpp
12
13#include <set>
14#include <vector>
15
16#include "CouenneExprClone.hpp"
17
18namespace Couenne {
19
20 class expression;
21 class CouenneExprMatrix;
22
23 // Base class for elements of our sparse structures ////////////////////////////
24
26
27 protected:
28
29 int index_;
31
32 public:
33
34 CouenneScalar (int index, expression *elem):
35 index_ (index),
36 elem_ (elem -> code () == COU_EXPRCONST ? elem : new exprClone (elem)) {}
37
39
41 index_ (rhs.index_),
42 elem_ (new exprClone (rhs.elem_)) {}
43
45 index_ = rhs.index_;
46 elem_ = new exprClone (rhs.elem_);
47 return *this;
48 }
49
50 inline CouenneScalar *clone () {return new CouenneScalar (*this);}
51
52 inline int getIndex () const {return index_;}
53 inline expression *getElem () const {return elem_;}
54
55 inline bool operator< (const CouenneScalar &rhs) const {return (index_ < rhs.index_);}
56
57 friend bool operator< (const CouenneScalar &first, const CouenneScalar &second);
58
59 void print () const;
60 };
61
62 inline bool operator< (const CouenneScalar &first, const CouenneScalar &second) {return (first.index_ < second.index_);}
63
64 // Sparse vector of expressions /////////////////////////////////////////////////
65
67
68 public:
69
71 inline bool operator() (register CouenneScalar * const &a,
72 register CouenneScalar * const &b) const
73 {return a -> getIndex () < b -> getIndex ();}
74 };
75
76 protected:
77
78 std::set <CouenneScalar *, compare_scalars> elem_;
79
80 public:
81
84
88
89 void add_element (int index, expression *elem);
90
91 void print () const;
92
93 const std::set <CouenneScalar *, compare_scalars> &getElements () {return elem_;}
94
95 double operator * (const CouenneSparseVector &factor) const;
97
98 double multiply_thres (const CouenneSparseVector &v2, double thres) const;
99 };
100
101
102 // Sparse matrix of expressions ///////////////////////////////////////////////////
103
105
106 public:
107
109 inline bool operator() (register const std::pair <int, CouenneSparseVector *> &a,
110 register const std::pair <int, CouenneSparseVector *> &b) const
111 {return a. first < b. first;}
112 };
113
114 protected:
115
116 std::set <std::pair <int, CouenneSparseVector *>, compare_pair_ind> row_;
117 std::set <std::pair <int, CouenneSparseVector *>, compare_pair_ind> col_;
118
119 std::vector <expression *> varIndices_;
120
121 public:
122
125
128
129 CouenneExprMatrix *clone () {return new CouenneExprMatrix (*this);}
130
131 const std::set <std::pair <int, CouenneSparseVector *>, compare_pair_ind> &getRows () const {return row_;}
132 const std::set <std::pair <int, CouenneSparseVector *>, compare_pair_ind> &getCols () const {return col_;}
133
134 std::vector <expression *> &varIndices () {return varIndices_;}
135
136 void add_element (int row, int column, expression *elem);
137 void print () const;
138 long unsigned int size ();
139
142 };
143}
144
145#endif
std::vector< expression * > varIndices_
if used in sdp cuts, contains indices of x_i used in X_ij = x_i * x_j
CouenneExprMatrix & operator=(const CouenneExprMatrix &rhs)
void add_element(int row, int column, expression *elem)
CouenneSparseVector & operator*(const CouenneSparseVector &factor) const
matrix * vector
long unsigned int size()
std::set< std::pair< int, CouenneSparseVector * >, compare_pair_ind > col_
col major
CouenneExprMatrix(const CouenneExprMatrix &rhs)
const std::set< std::pair< int, CouenneSparseVector * >, compare_pair_ind > & getCols() const
std::set< std::pair< int, CouenneSparseVector * >, compare_pair_ind > row_
row major
std::vector< expression * > & varIndices()
const std::set< std::pair< int, CouenneSparseVector * >, compare_pair_ind > & getRows() const
CouenneExprMatrix * clone()
CouenneScalar(const CouenneScalar &rhs)
CouenneScalar(int index, expression *elem)
bool operator<(const CouenneScalar &rhs) const
expression * getElem() const
int index_
index of element in vector
CouenneScalar & operator=(const CouenneScalar &rhs)
CouenneScalar * clone()
expression * elem_
element
const std::set< CouenneScalar *, compare_scalars > & getElements()
returns elements of vector as (ordered) set
CouenneSparseVector(const CouenneSparseVector &rhs)
void add_element(int index, expression *elem)
CouenneSparseVector * clone()
double multiply_thres(const CouenneSparseVector &v2, double thres) const
stops multiplication if above threshold
double operator*(const CouenneSparseVector &factor) const
vector * vector (dot product)
CouenneSparseVector & operator=(const CouenneSparseVector &rhs)
std::set< CouenneScalar *, compare_scalars > elem_
expression clone (points to another expression)
Expression base class.
general include file for different compilers
bool operator<(const CouenneScalar &first, const CouenneScalar &second)
bool operator()(register const std::pair< int, CouenneSparseVector * > &a, register const std::pair< int, CouenneSparseVector * > &b) const
bool operator()(register CouenneScalar *const &a, register CouenneScalar *const &b) const