Open
Graph Drawing
Framework

 v. 2023.09 (Elderberry)
 

constraint.h
Go to the documentation of this file.
1 
30 #pragma once
31 
32 #include <ogdf/lib/abacus/convar.h>
33 
35 #include <ogdf/lib/abacus/csense.h>
37 
38 
39 namespace abacus {
40 
41 class Row;
42 class Master;
43 class Variable;
44 class LpSub;
45 
46 template<class BaseType, class CoType> class Active;
47 
48 
50 
56 class OGDF_EXPORT Constraint : public ConVar {
57 
58  friend class LpSub;
59 
60 public:
61 
63 
79  Constraint (
80  Master *master,
81  const Sub *sub,
82  CSense::SENSE sense,
83  double rhs,
84  bool dynamic,
85  bool local,
86  bool liftable);
87 
88 
90 
97  Constraint (Master *master);
98 
99 
101 
104  Constraint(const Constraint &rhs)
105  : ConVar(rhs), sense_(rhs.sense_), rhs_(rhs.rhs_), conClass_(nullptr), liftable_(rhs.liftable_)
106  {
107  if (rhs.conClass_) conClass_ = new ConClass(*(rhs.conClass_));
108  }
109 
110 
111  virtual ~Constraint() { delete conClass_; }
112 
113 
115  CSense *sense() { return &sense_; }
116 
118  const CSense *sense() const { return &sense_; }
119 
120 
122 
127  virtual double coeff(const Variable *v) const = 0;
128 
130  virtual double rhs() const { return rhs_; }
131 
132 
134 
140  bool liftable() const { return liftable_; }
141 
142 
144 
153  virtual bool valid(Sub *sub) const;
154 
155 
157 
170  virtual int genRow(Active<Variable, Constraint> *var,
171  Row &row) const;
172 
174 
180  virtual double slack(Active<Variable, Constraint> *variables,
181  double *x) const;
182 
184 
192  virtual bool violated(
193  Active<Variable, Constraint> *variables, double *x, double *sl = nullptr) const;
194 
196 
204  virtual bool violated(double slack) const;
205 
207 
211  void printRow(std::ostream &out, Active<Variable, Constraint> *var) const;
212 
214 
227  virtual double distance(double *x, Active<Variable, Constraint> *actVar) const;
228 
229  //Constraint *duplicate() { return 0; }
230 
232 
239  ConClass *classification(Active<Variable, Constraint> *var = nullptr) const;
240 
241 protected:
242 
255  virtual InfeasCon::INFEAS voidLhsViolated(double newRhs) const;
256 
261  return nullptr;
262  }
263 
264 
266 
267  double rhs_;
268 
269  mutable ConClass *conClass_; //this is just s cached-value, and hence can be set in const classify-call (it's nullptr initially, and computed upon first call
270 
275  bool liftable_;
276 
277 private:
278  const Constraint &operator=(const Constraint &rhs);
279 };
280 
281 }
282 
283 #include <ogdf/lib/abacus/sub.h>
284 #include <ogdf/lib/abacus/master.h>
285 
286 namespace abacus {
287 
289  Master *master,
290  const Sub *sub,
291  CSense::SENSE sense,
292  double rhs,
293  bool dynamic,
294  bool local,
295  bool liftable)
296  : ConVar(master, sub, dynamic, local), sense_(sense), rhs_(rhs), conClass_(nullptr), liftable_(liftable)
297 {
298  if (local && sub == nullptr) {
299  Logger::ifout() << "Constraint::Constraint(): subtree of local item must not be 0\n";
301  }
302 }
303 
304 
306  : ConVar(master, nullptr, true, true), conClass_(nullptr) { }
307 
308 
309 inline bool Constraint::valid(Sub *sub) const {
310  OGDF_ASSERT(!local_ || sub != nullptr);
311 
312  return (!local_ || sub_->ancestor(sub));
313 }
314 
315 }
abacus::Constraint::classify
virtual ConClass * classify(Active< Variable, Constraint > *var) const
The default implementation returns a 0 pointer.
Definition: constraint.h:260
abacus::Active
Implements the sets of active constraints and variables which are associated with each subproblem.
Definition: active.h:43
abacus::ConVar::local
bool local() const
Returns true if the constraint/variable is only locally valid, false otherwise.
Definition: convar.h:113
sub.h
abacus::ConVar::sub
const Sub * sub() const
Returns a const pointer to the subproblem associated with the constraint/variable.
Definition: convar.h:199
OGDF_ASSERT
#define OGDF_ASSERT(expr)
Assert condition expr. See doc/build.md for more information.
Definition: basic.h:66
abacus::Constraint::rhs
virtual double rhs() const
Returns the right hand side of the constraint.
Definition: constraint.h:130
convar.h
constraints and variables.
abacus::Constraint::conClass_
ConClass * conClass_
Definition: constraint.h:269
abacus::Constraint::valid
virtual bool valid(Sub *sub) const
Checks if the constraint is valid for the subproblem sub.
Definition: constraint.h:309
abacus::Constraint::Constraint
Constraint(Master *master, const Sub *sub, CSense::SENSE sense, double rhs, bool dynamic, bool local, bool liftable)
Initializes a constraint.
Definition: constraint.h:288
abacus::Constraint::rhs_
double rhs_
The right hand side of the constraint.
Definition: constraint.h:267
abacus::Constraint::sense
const CSense * sense() const
Returns a const pointer to the sense of the constraint.
Definition: constraint.h:118
abacus
Definition: ILPClusterPlanarity.h:50
abacus::ConVar::sub_
const Sub * sub_
A pointer to the subproblem associated with the constraint/variable.
Definition: convar.h:289
abacus::Constraint::liftable
bool liftable() const
Checks if the constraint is liftable.
Definition: constraint.h:140
abacus::Constraint::~Constraint
virtual ~Constraint()
Definition: constraint.h:111
ogdf::AlgorithmFailureCode::LpSub
@ LpSub
ogdf::AlgorithmFailureException
Exception thrown when an algorithm realizes an internal bug that prevents it from continuing.
Definition: exceptions.h:247
ogdf::AlgorithmFailureCode::Constraint
@ Constraint
abacus::ConVar
Common base class for constraints (Constraint) and variables (Variable).
Definition: convar.h:65
abacus::Row
Representation of constraints in the row format.
Definition: row.h:51
csense.h
csense.
abacus::Variable
Forms the virtual base class for all possible variables given in pool format.
Definition: variable.h:59
ogdf::AlgorithmFailureCode::Active
@ Active
abacus::Constraint::sense
CSense * sense()
Returns a pointer to the sense of the constraint.
Definition: constraint.h:115
abacus::ConClass
Constraint classification.
Definition: conclass.h:44
OGDF_THROW_PARAM
#define OGDF_THROW_PARAM(CLASS, PARAM)
Replacement for throw.
Definition: exceptions.h:71
abacus::LpSub
The linear program of a subproblem.
Definition: lpsub.h:61
infeascon.h
infeasible constraints.
abacus::ConVar::local_
bool local_
true if the constraint/variable is only locally valid
Definition: convar.h:312
ogdf::Logger::ifout
static std::ostream & ifout()
stream for forced output (global; used by internal libraries, e.g. Abacus)
Definition: Logger.h:218
master.h
the master of the optimization.
abacus::Constraint::sense_
CSense sense_
The sense of the constraint.
Definition: constraint.h:265
ogdf::AlgorithmFailureCode::Variable
@ Variable
abacus::Constraint::Constraint
Constraint(const Constraint &rhs)
Copy constructor.
Definition: constraint.h:104
OGDF_EXPORT
#define OGDF_EXPORT
Specifies that a function or class is exported by the OGDF DLL.
Definition: config.h:101
abacus::Sub
The subproblem.
Definition: sub.h:68
abacus::Constraint
Forms the virtual base class for all possible constraints given in pool format.
Definition: constraint.h:56
Minisat::Internal::var
int var(Lit p)
Definition: SolverTypes.h:61
conclass.h
constraint classification.
abacus::Constraint::liftable_
bool liftable_
This member is true if also coefficients of variables which have been inactive at generation time can...
Definition: constraint.h:275
abacus::CSense
Sense of constraints.
Definition: csense.h:48
abacus::Sub::ancestor
bool ancestor(const Sub *sub) const
Returns true if this subproblem is an ancestor of the subproblem sub, false otherwise.
abacus::CSense::SENSE
SENSE
Definition: csense.h:51
abacus::InfeasCon::INFEAS
INFEAS
The different ways of infeasibility of a constraint.
Definition: infeascon.h:55
abacus::Master
The master of the optimization.
Definition: master.h:69