SoPlex
Toggle main menu visibility
Loading...
Searching...
No Matches
src
soplex
idxset.cpp
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
#include "
soplex/idxset.h
"
26
27
namespace
soplex
28
{
29
30
int
IdxSet::dim
()
const
31
{
32
int
ddim = -1;
33
34
for
(
int
i = 0; i <
size
(); i++)
35
if
(ddim <
idx
[i])
36
ddim =
idx
[i];
37
38
return
ddim;
39
}
40
41
int
IdxSet::pos
(
int
i)
const
42
{
43
for
(
int
n = 0; n <
size
(); n++)
44
if
(
idx
[n] == i)
45
return
n;
46
47
return
-1;
48
}
49
50
void
IdxSet::add
(
int
n,
const
int
i[])
51
{
52
assert(n >= 0 &&
size
() + n <=
max
());
53
54
for
(
int
j = 0; j < n; j++)
55
idx
[
size
() + j] = i[j];
56
57
add
(n);
58
}
59
60
void
IdxSet::remove
(
int
n,
int
m)
61
{
62
assert(n <= m && m <
size
() && n >= 0);
63
++m;
64
65
int
cpy = m - n;
66
int
newnum =
num
- cpy;
67
cpy = (
size
() - m >= cpy) ? cpy :
size
() - m;
68
69
do
70
{
71
--
num
;
72
--cpy;
73
idx
[n + cpy] =
idx
[
num
];
74
}
75
while
(cpy > 0);
76
77
num
= newnum;
78
}
79
80
IdxSet
&
IdxSet::operator=
(
const
IdxSet
& rhs)
81
{
82
if
(
this
!= &rhs)
83
{
84
if
(
idx
!=
nullptr
&&
max
() < rhs.
size
())
85
{
86
if
(
freeArray
)
87
spx_free
(
idx
);
88
89
idx
=
nullptr
;
90
}
91
92
if
(
idx
==
nullptr
)
93
{
94
len
= rhs.
size
();
95
spx_alloc
(
idx
,
len
);
96
freeArray
=
true
;
97
}
98
99
for
(
num
= 0;
num
< rhs.
size
(); ++
num
)
100
idx
[
num
] = rhs.
idx
[
num
];
101
}
102
103
assert(
size
() == rhs.
size
());
104
assert(
size
() <=
max
());
105
assert(
isConsistent
());
106
107
return
*
this
;
108
}
109
110
IdxSet::IdxSet
(
const
IdxSet
& old)
111
:
len
(old.
len
)
112
,
idx
(nullptr)
113
{
114
spx_alloc
(
idx
,
len
);
115
116
for
(
num
= 0;
num
< old.
num
;
num
++)
117
idx
[
num
] = old.
idx
[
num
];
118
119
freeArray
=
true
;
120
121
assert(
size
() == old.
size
());
122
assert(
size
() <=
max
());
123
assert(
isConsistent
());
124
}
125
126
bool
IdxSet::isConsistent
()
const
127
{
128
#ifdef ENABLE_CONSISTENCY_CHECKS
129
int
i, j;
130
131
if
(
len
> 0 &&
idx
==
nullptr
)
132
return
SPX_MSG_INCONSISTENT
(
"IdxSet"
);
133
134
for
(i = 0; i <
size
(); ++i)
135
{
136
if
(
index
(i) < 0)
137
return
SPX_MSG_INCONSISTENT
(
"IdxSet"
);
138
139
for
(j = 0; j < i; j++)
140
if
(
index
(i) ==
index
(j))
141
return
SPX_MSG_INCONSISTENT
(
"IdxSet"
);
142
}
143
144
#endif
145
146
return
true
;
147
}
148
}
// namespace soplex
soplex::IdxSet::freeArray
bool freeArray
true iff idx should be freed inside of this object
Definition
idxset.h:75
soplex::IdxSet::isConsistent
bool isConsistent() const
consistency check.
Definition
idxset.cpp:126
soplex::IdxSet::pos
int pos(int i) const
returns the position of index i.
Definition
idxset.cpp:41
soplex::IdxSet::remove
void remove(int n, int m)
removes indices at position numbers n through m.
Definition
idxset.cpp:60
soplex::IdxSet::max
int max() const
returns the maximal number of indices which can be stored in IdxSet.
Definition
idxset.h:138
soplex::IdxSet::num
int num
number of used indices
Definition
idxset.h:72
soplex::IdxSet::IdxSet
IdxSet()
default constructor.
Definition
idxset.h:100
soplex::IdxSet::IdxSet
IdxSet(int n, int imem[], int l=0)
constructor.
Definition
idxset.h:89
soplex::IdxSet::index
int index(int n) const
access n 'th index.
Definition
idxset.h:127
soplex::IdxSet::dim
int dim() const
returns the maximal index.
Definition
idxset.cpp:30
soplex::IdxSet::idx
int * idx
array of indices
Definition
idxset.h:74
soplex::IdxSet::add
void add(int n)
appends n uninitialized indices.
Definition
idxset.h:158
soplex::IdxSet::size
int size() const
returns the number of used indices.
Definition
idxset.h:133
soplex::IdxSet::operator=
IdxSet & operator=(const IdxSet &set)
assignment operator.
Definition
idxset.cpp:80
soplex::IdxSet::len
int len
length of array idx
Definition
idxset.h:73
idxset.h
Set of indices.
soplex
Everything should be within this namespace.
soplex::spx_alloc
void spx_alloc(T &p, size_t n=1)
Allocate memory.
Definition
spxalloc.h:58
soplex::spx_free
void spx_free(T &p)
Release memory.
Definition
spxalloc.h:118
SPX_MSG_INCONSISTENT
#define SPX_MSG_INCONSISTENT(name)
Definition
spxdefines.h:175
Generated by
1.17.0