Scippy

SoPlex

Sequential object-oriented simPlex

spxid.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-2024 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 spxid.h
26 * @brief Row and columns Id's \ref soplex::SPxLP "SPxLP".
27 */
28#ifndef _SPXID_H_
29#define _SPXID_H_
30
31#include <iostream>
32
33#include "soplex/datakey.h"
34
35namespace soplex
36{
37class SPxId;
38
39/**@brief Ids for LP columns.
40 * @ingroup Algo
41 *
42 * Class SPxColId provides #DataKey%s for the
43 * column indices of an SPxLP.
44 */
45class SPxColId : public DataKey
46{
47public:
48 /// default constructor.
50 {}
51 /// copy constructor from DataKey.
52 explicit SPxColId(const DataKey& p_key);
53 /// copy constructor from SPxId.
54 explicit SPxColId(const SPxId& p_key);
55};
56
57
58/**@brief Ids for LP rows.
59 * @ingroup Algo
60 *
61 * Class SPxRowId provides #DataKey%s for the row
62 * indices of an SPxLP.
63 */
64class SPxRowId : public DataKey
65{
66public:
67 /// default constructor.
69 {}
70 /// copy constructor from DataKey.
71 explicit SPxRowId(const DataKey& p_key);
72 /// copy constructor from SPxId.
73 explicit SPxRowId(const SPxId& p_key);
74};
75
76/**@brief Generic Ids for LP rows or columns.
77 * @ingroup Algo
78 *
79 * Both \ref soplex::SPxColId "SPxColIds" and \ref soplex::SPxRowId
80 * "SPxRowIds" may be treated uniformly as #SPxId%s:
81 *
82 * Rows and columns are numbered from 0 to num()-1 and 0 to dim()-1
83 * respectively. These numbers may be used to select individual rows or
84 * columns. However, these numbers may change if other rows or columns are
85 * added or removed.
86 *
87 * Further, each row or column of the problem matrix is assigned a \ref
88 * soplex::SPxRowId "SPxRowId" or \ref soplex::SPxColId "SPxColId",
89 * respectively. They are be used to select individual rows or columns just
90 * like numbers. In contrast to row and column numbers, ids remain unchanged
91 * for the time a row or column belongs to a SPxLP, no matter what other
92 * rows or columns are added to it or removed from it.
93 */
94class SPxId : public DataKey
95{
96 friend std::ostream& operator<<(std::ostream& os, const SPxId& id);
97
98public:
99
100 //--------------------------------
101 /**@name Types */
102 ///@{
103 /// type of the id.
104 enum Type
105 {
106 ROW_ID = -1, ///< row identifier.
107 INVALID = 0, ///< invalid id.
108 COL_ID = 1 ///< column identifier.
109 };
110 ///@}
111
112 //------------------------------------
113 /**@name Construction / destruction */
114 ///@{
115 /// default constructor. Constructs an invalid id.
117 : DataKey(INVALID, -1)
118 {}
119 /// constructs an id out of a column identifier \p cid.
120 explicit SPxId(const SPxColId& cid)
121 : DataKey(COL_ID, cid.idx)
122 {}
123 /// constructs an id out of a row identifier \p rid.
124 explicit SPxId(const SPxRowId& rid)
125 : DataKey(ROW_ID, rid.idx)
126 {}
127
128 /// assignment operator
130 {
131 DataKey::operator= (cid);
132 info = COL_ID;
133 return *this;
134 }
135 /// assignment operator
137 {
138 DataKey::operator= (rid);
139 info = ROW_ID;
140 return *this;
141 }
142 ///@}
143
144 //--------------------------------
145 /**@name Access / modification */
146 ///@{
147 /// returns the type of the id.
148 inline Type type() const
149 {
150 return info ? (info < 0 ? ROW_ID : COL_ID) : INVALID;
151 }
152 /// returns TRUE iff the id is a valid column or row identifier.
153 inline bool isValid() const
154 {
155 return info != 0;
156 }
157 /// makes the id invalid.
158 inline void inValidate()
159 {
160 info = 0;
161 }
162 /// is id a row id?
163 inline bool isSPxRowId() const
164 {
165 return info < 0;
166 }
167 /// is id a column id?
168 inline bool isSPxColId() const
169 {
170 return info > 0;
171 }
172 ///@}
173
174 //------------------------------------
175 /**@name Comparison of Ids */
176 ///@{
177 /// equality operator.
178 int operator==(const SPxId& id) const
179 {
180 return (this == &id);
181 }
182 /// inequality operator.
183 int operator!=(const SPxId& id) const
184 {
185 return (this != &id);
186 }
187 /// less then operator
188 bool operator<(const SPxId& id) const
189 {
190 return getIdx() < id.getIdx();
191 }
192 ///@}
193};
194
195
196} // namespace soplex
197#endif // _SPXID_H_
Entry identifier class for items of a DataSet.
Definition: datakey.h:56
int getIdx() const
gets the index number (idx) of the DataKey.
Definition: datakey.h:91
int info
user information to store values -1, 0, +1
Definition: datakey.h:64
int idx
(locally) unique key index
Definition: datakey.h:65
Ids for LP columns.
Definition: spxid.h:46
SPxColId()
default constructor.
Definition: spxid.h:49
Generic Ids for LP rows or columns.
Definition: spxid.h:95
SPxId()
default constructor. Constructs an invalid id.
Definition: spxid.h:116
bool operator<(const SPxId &id) const
less then operator
Definition: spxid.h:188
bool isSPxColId() const
is id a column id?
Definition: spxid.h:168
Type
type of the id.
Definition: spxid.h:105
@ ROW_ID
row identifier.
Definition: spxid.h:106
@ COL_ID
column identifier.
Definition: spxid.h:108
@ INVALID
invalid id.
Definition: spxid.h:107
int operator!=(const SPxId &id) const
inequality operator.
Definition: spxid.h:183
bool isValid() const
returns TRUE iff the id is a valid column or row identifier.
Definition: spxid.h:153
SPxId & operator=(const SPxRowId &rid)
assignment operator
Definition: spxid.h:136
SPxId(const SPxRowId &rid)
constructs an id out of a row identifier rid.
Definition: spxid.h:124
void inValidate()
makes the id invalid.
Definition: spxid.h:158
SPxId & operator=(const SPxColId &cid)
assignment operator
Definition: spxid.h:129
bool isSPxRowId() const
is id a row id?
Definition: spxid.h:163
SPxId(const SPxColId &cid)
constructs an id out of a column identifier cid.
Definition: spxid.h:120
Type type() const
returns the type of the id.
Definition: spxid.h:148
friend std::ostream & operator<<(std::ostream &os, const SPxId &id)
Definition: spxid.cpp:61
int operator==(const SPxId &id) const
equality operator.
Definition: spxid.h:178
Ids for LP rows.
Definition: spxid.h:65
SPxRowId()
default constructor.
Definition: spxid.h:68
Entry identifier class for items of a DataSet.
Everything should be within this namespace.