Minotaur 0.4.1
Docs for developers
Public Member Functions | Protected Member Functions | Friends | List of all members
Minotaur::Constraint Class Reference

The Constraint class is used to manage a constraint. More...

#include <Constraint.h>

Public Member Functions

 Constraint ()
 Default constructor.
 
 Constraint (UInt id, UInt index, FunctionPtr f, double lb, double ub, std::string name)
 This is the only real constructor. All others should call this constructor. More...
 
virtual ~Constraint ()
 Destroy.
 
double getActivity (const double *x, int *error) const
 Get the value or activity at a given point.
 
bool getBFlag () const
 Get the value of the bool flag.
 
int getITemp () const
 
void setITemp (int i)
 
FunctionPtr getFunction () const
 Return a pointer to the function.
 
FunctionType getFunctionType () const
 Get the function type.
 
UInt getId () const
 Return the unique id of the constraint.
 
UInt getIndex () const
 Return the index of the constraint.
 
double getLb () const
 Get the 'l' value. or the lower bound constraint on 'f'.
 
LinearFunctionPtr getLinearFunction () const
 Get the linear part of the constraint function 'f'.
 
const std::string getName () const
 
NonlinearFunctionPtr getNonlinearFunction () const
 Get the nonlinear part of the constraint function 'f'.
 
QuadraticFunctionPtr getQuadraticFunction () const
 Get the quadratic part of the constraint function 'f'.
 
ConsState getState () const
 Get the current state of the constraint: freed, fixed etc.
 
ConsSrcType getSrcType () const
 Get the src type of the constraint.
 
ConsType getType () const
 
double getUb () const
 Get the 'u' value. or the upper bound constraint on 'f'.
 
void setpId (UInt n)
 
int getpId ()
 
void setUB (double newub)
 
Convexity getConvexity ()
 
void setConvexity (Convexity convex)
 
void incrAct ()
 
void setBFlag (bool b)
 Set the value of the bool flag.
 
void setSrcType (ConsSrcType src)
 Set src type.
 
void setType (ConsType type)
 
void write (std::ostream &out) const
 display the constraint
 

Protected Member Functions

void add_ (double cb)
 Add a constant to the constraint function. lb - c <= f <= ub - c.
 
void changeLf_ (LinearFunctionPtr lf)
 Change the linear part of constraint.
 
void changeNlf_ (NonlinearFunctionPtr nlf)
 Change the nonlinear part of constraint.
 
void delFixedVar_ (VariablePtr v, double val)
 Delete variables fixed at value val.
 
void reverseSense_ ()
 Negate the constraint. More...
 
void setId_ (UInt n)
 Set the id.
 
void setIndex_ (UInt n)
 Set the index.
 
void setLb_ (double newlb)
 Set a new lower bound. More...
 
void setName_ (std::string name)
 Set name of the constraint.
 
void setState_ (ConsState state)
 Set state of the constraint.
 
void setUb_ (double newub)
 Set a new upper bound. More...
 
void subst_ (VariablePtr out, VariablePtr in, double rat, bool *instay)
 Substitute a variable $x_1$ by $rx_2$.
 

Friends

class Problem
 
class PerspCon
 
class TransSep
 
class QGHandler
 

Detailed Description

The Constraint class is used to manage a constraint.

The general form of a constraint is:

\[
l \leq f(x) \leq u,
\]

where $f(x)$ is a function of the variables and $l, u$ are constraints placed on $f$. $l$ can be $-\infty$ and/or $u$ can be $\infty$.

A constraint should only be constructed through a Problem object. Doing this ensures that constraints have ID's unique for that problem. A constraint can thus be part of only one problem. A function $f$ that is part of a constraint should also not be shared at several places in the same problem or amongst different problems. Similarly, constraints should be deleted only through a problem. Changes in a constraint (e.g. changing name, bounds etc) may be done directly.

The state of a constraint describes whether the constraint is free or deleted etc. It is Fixed if each variable in the constraints has been fixed.

A Constraint also stores a map of variables that occur in that constraint. The map tells whether the variable is in a non-linear, or quadratic etc part of the constraint. A variable that occurs once in linear and thrice in quadratic parts will have four entries in the map, once for each occurrence.

The name of a constraint can be set by the user. There are no checks for duplicate names. The ID of the constraint however is unique in the problem.

Constructor & Destructor Documentation

◆ Constraint()

Constraint::Constraint ( UInt  id,
UInt  index,
FunctionPtr  f,
double  lb,
double  ub,
std::string  name 
)

This is the only real constructor. All others should call this constructor.

Create a constraint with

Parameters
[in]idthe unique id of the constraint (determined by Problem object),
[in]indexthe index of the constraint in the problem,
[in]fthe function in the body of the constraint,
[in]lbthe lower bound, can be -INFINITY,
[in]ubthe upper bound, can be INFINITY,
[in]nameThe string name of the constraint.
[in]srcThe source type of the constraint.

Member Function Documentation

◆ reverseSense_()

void Constraint::reverseSense_ ( )
protected

Negate the constraint.

Convert the constraint to

\[
-u \leq -f(x) \leq -l
 \]

◆ setLb_()

void Minotaur::Constraint::setLb_ ( double  newlb)
inlineprotected

Set a new lower bound.

The new lower bound can be -INFINITY. It can change the state of the constraint.

◆ setUb_()

void Minotaur::Constraint::setUb_ ( double  newub)
inlineprotected

Set a new upper bound.

The new bound can be INFINITY. It can affect the state of the constraint.

Friends And Related Function Documentation

◆ Problem

friend class Problem
friend

Only Problem class can modify a Constraint. All modification methods are private.


The documentation for this class was generated from the following files:

Minotaur source code documented by Doxygen 1.9.4 on Sat May 17 2025