SoPlex
Toggle main menu visibility
Loading...
Searching...
No Matches
src
soplex
unitvectorbase.h
Go to the documentation of this file.
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2
/* */
3
/* This file is part of the class library */
4
/* SoPlex --- the Sequential object-oriented simPlex. */
5
/* */
6
/* Copyright (c) 1996-2026 Zuse Institute Berlin (ZIB) */
7
/* */
8
/* Licensed under the Apache License, Version 2.0 (the "License"); */
9
/* you may not use this file except in compliance with the License. */
10
/* You may obtain a copy of the License at */
11
/* */
12
/* http://www.apache.org/licenses/LICENSE-2.0 */
13
/* */
14
/* Unless required by applicable law or agreed to in writing, software */
15
/* distributed under the License is distributed on an "AS IS" BASIS, */
16
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
17
/* See the License for the specific language governing permissions and */
18
/* limitations under the License. */
19
/* */
20
/* You should have received a copy of the Apache-2.0 license */
21
/* along with SoPlex; see the file LICENSE. If not email to soplex@zib.de. */
22
/* */
23
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24
25
/**@file unitvector.h
26
* @brief Sparse vector \f$e_i\f$.
27
*/
28
29
#ifndef _UNITVECTORBASE_H_
30
#define _UNITVECTORBASE_H_
31
32
#include <assert.h>
33
#include "
soplex/spxdefines.h
"
34
#include "
soplex/svectorbase.h
"
35
36
namespace
soplex
37
{
38
39
40
/**@brief Sparse vector \f$e_i\f$.
41
@ingroup Algebra
42
43
A UnitVectorBase is an SVectorBase that can take only one nonzero value with
44
value 1 but arbitrary index.
45
46
\todo Several SVectorBase modification methods are still accessible for UnitVector.
47
They might be used to change the vector.
48
49
\todo UnitVectorBase memory management must be changed when SVectorBase is redesigned.
50
*/
51
52
template
<
class
R >
53
class
UnitVectorBase
:
public
SVectorBase
<R>
54
{
55
private
:
56
57
//------------------------------------
58
/**@name Data */
59
///@{
60
typename
SVectorBase<R>::Element
themem
;
///< memory for sparse vector entry
61
///@}
62
63
using
SVectorBase
<R>
::mem
;
64
65
using
SVectorBase
<R>
::size
;
66
67
using
SVectorBase
<R>
::max
;
68
69
public
:
70
71
//------------------------------------
72
/**@name Access */
73
///@{
74
/// returns value = 1
75
/**\pre \c n must be 0.
76
*/
77
/* ARGSUSED n */
78
R
value
(
int
n)
const
79
{
80
assert(n == 0);
81
return
1;
82
}
83
///@}
84
85
//------------------------------------
86
/**@name Constructors / destructors */
87
///@{
88
/// construct \c i 'th unit vector.
89
explicit
90
UnitVectorBase
(
int
i = 0)
91
:
SVectorBase
<R>(1, &
themem
)
92
{
93
// coverity[callee_ptr_arith]
94
SVectorBase<R>::add
(i, 1.0);
95
96
assert(
isConsistent
());
97
}
98
/// copy constructor
99
UnitVectorBase
(
const
UnitVectorBase<R>
& rhs)
100
:
SVectorBase
<R>(1, &
themem
)
101
{
102
themem
= rhs.
themem
;
103
this->
set_size
(1);
104
105
assert(
isConsistent
());
106
}
107
/// assignment
108
UnitVectorBase<R>
&
operator=
(
const
UnitVectorBase<R>
& rhs)
109
{
110
if
(
this
!= &rhs)
111
{
112
themem
= rhs.
themem
;
113
this->
set_size
(1);
114
115
assert(
isConsistent
());
116
}
117
118
return
*
this
;
119
}
120
/// move assignment
121
UnitVectorBase<R>
&
operator=
(
UnitVectorBase<R>
&& rhs)
122
{
123
if
(
this
!= &rhs)
124
{
125
themem
= std::move(rhs.themem);
126
this->
set_size
(1);
127
128
assert(
isConsistent
());
129
}
130
131
return
*
this
;
132
}
133
/// destructor
134
~UnitVectorBase
()
135
{}
136
///@}
137
138
//------------------------------------
139
/**@name Miscellaneous */
140
///@{
141
/// consistency check
142
bool
isConsistent
()
const
143
{
144
#ifdef ENABLE_CONSISTENCY_CHECKS
145
146
if
(
mem
() != &
themem
)
147
return
SPX_MSG_INCONSISTENT
(
"UnitVectorBase"
);
148
149
if
(
size
() != 1)
150
return
SPX_MSG_INCONSISTENT
(
"UnitVectorBase"
);
151
152
if
(
max
() != 1)
153
return
SPX_MSG_INCONSISTENT
(
"UnitVectorBase"
);
154
155
return
SVectorBase<R>::isConsistent
();
156
#else
157
return
true
;
158
#endif
159
}
160
///@}
161
};
162
163
164
}
// namespace soplex
165
#endif
// _UNITVECTORBASE_H_
soplex::SVectorBase::isConsistent
bool isConsistent() const
Consistency check.
Definition
svectorbase.h:830
soplex::SVectorBase::SVectorBase
friend class SVectorBase
Definition
svectorbase.h:141
soplex::SVectorBase::add
void add(int i, const R &v)
Append one nonzero (i,v).
Definition
svectorbase.h:282
soplex::SVectorBase< Real >::max
int max() const
Definition
svectorbase.h:171
soplex::SVectorBase::set_size
void set_size(int s)
Set size of the vector.
Definition
svectorbase.h:799
soplex::SVectorBase< Real >::mem
Nonzero< Real > * mem() const
Definition
svectorbase.h:793
soplex::SVectorBase::Element
Nonzero< R > Element
Definition
svectorbase.h:157
soplex::SVectorBase< Real >::size
int size() const
Definition
svectorbase.h:164
soplex::UnitVectorBase::operator=
UnitVectorBase< R > & operator=(const UnitVectorBase< R > &rhs)
assignment
Definition
unitvectorbase.h:108
soplex::UnitVectorBase< Real >::themem
SVectorBase< Real >::Element themem
Definition
unitvectorbase.h:60
soplex::UnitVectorBase::UnitVectorBase
UnitVectorBase(int i=0)
construct i 'th unit vector.
Definition
unitvectorbase.h:90
soplex::UnitVectorBase::isConsistent
bool isConsistent() const
consistency check
Definition
unitvectorbase.h:142
soplex::UnitVectorBase::value
R value(int n) const
returns value = 1
Definition
unitvectorbase.h:78
soplex::UnitVectorBase::UnitVectorBase
UnitVectorBase(const UnitVectorBase< R > &rhs)
copy constructor
Definition
unitvectorbase.h:99
soplex::UnitVectorBase::operator=
UnitVectorBase< R > & operator=(UnitVectorBase< R > &&rhs)
move assignment
Definition
unitvectorbase.h:121
soplex::UnitVectorBase::~UnitVectorBase
~UnitVectorBase()
destructor
Definition
unitvectorbase.h:134
soplex
Everything should be within this namespace.
spxdefines.h
Debugging, floating point type and parameter definitions.
SPX_MSG_INCONSISTENT
#define SPX_MSG_INCONSISTENT(name)
Definition
spxdefines.h:175
svectorbase.h
Sparse vectors.
Generated by
1.17.0