Minotaur 0.4.1
Docs for developers
Objective.h
Go to the documentation of this file.
1//
2// Minotaur -- It's only 1/2 bull
3//
4// (C)opyright 2009 - 2025 The Minotaur Team.
5//
6
14#ifndef OBJECTIVE_H
15#define OBJECTIVE_H
16
17#include <string>
18
19#include "Types.h"
20
21namespace Minotaur {
22
23 typedef std::set<std::pair<VariablePtr, FunctionType> >::const_iterator
24 VariableFunIterator;
39 {
40 public:
43 friend class Problem;
44
46 Objective();
47
52 Objective(double cb = 0.0, ObjectiveType otyp = Minimize);
53
54 /*
55 * Create an objective with a specific function, id, constant term and
56 * sense. A default name is created.
57 */
58 Objective(FunctionPtr fPtr, double cb = 0.0,
59 ObjectiveType otyp = Minimize);
60
65 Objective(FunctionPtr fPtr, double cb, ObjectiveType otyp,
66 std::string name);
67
69 virtual ~Objective();
70
71
72 // Functions that query or get information.
73
75 double getConstant() const { return cb_; }
76
79
82
84 ObjState getState() const { return state_; }
85
86 /*
87 * Return the name of this objective. If the user did not create a name
88 * for the objective, it is generated automatically
89 */
90 virtual const std::string getName() const;
91
94 return f_;
95 }
96
102
108
114
116 void write(std::ostream &out) const;
117
122 double eval(const double *x, int *err) const;
123
129 void evalGradient(const double *x, double *grad_f, int *error);
130
137 void evalGradient(VariableGroup &point, double *grad_f);
138
139 // Functions that modify or change the objective.
140
141 private:
146 double cb_;
147
149 ObjectiveType otyp_;
150
152 ObjState state_;
153
155 FunctionPtr f_;
156
161 std::string name_;
162
163 void delFixedVar_(VariablePtr v, double val);
164
166 void setState_(ObjState state) { state_ = state; return; }
167
174 void add_(ConstLinearFunctionPtr lPtr);
175
177 void add_(double cb);
178
180 QuadraticFunctionPtr removeQuadratic_();
181
182 NonlinearFunctionPtr removeNonlinear_();
183
184 void subst_(VariablePtr out, VariablePtr in, double rat=1.0);
185
190 void negate_();
191 };
192}
193#endif
194
Declare important 'types' used in Minotaur.
Definition: Function.h:37
The base class linear function is of the form c'x.
Definition: LinearFunction.h:31
Base class for nonlinear functions.
Definition: NonlinearFunction.h:31
Definition: Objective.h:39
LinearFunctionPtr getLinearFunction() const
Definition: Objective.cpp:71
FunctionType getFunctionType() const
Return the type of the function in objective.
Definition: Objective.cpp:196
ObjState getState() const
Return the state of the objective. Fixed, removed, freed etc.
Definition: Objective.h:84
QuadraticFunctionPtr getQuadraticFunction() const
Definition: Objective.cpp:81
void evalGradient(const double *x, double *grad_f, int *error)
Definition: Objective.cpp:111
FunctionPtr getFunction() const
Return the function in the objective.
Definition: Objective.h:93
void write(std::ostream &out) const
Print the objective function to the output stream.
Definition: Objective.cpp:212
ObjectiveType getObjectiveType() const
Return the type (Maximize or Minimize) of this objective.
Definition: Objective.cpp:190
virtual ~Objective()
Destroy.
Definition: Objective.cpp:63
Objective()
Default constructor.
Definition: Objective.cpp:26
NonlinearFunctionPtr getNonlinearFunction() const
Definition: Objective.cpp:91
double eval(const double *x, int *err) const
Definition: Objective.cpp:101
void evalGradient(VariableGroup &point, double *grad_f)
double getConstant() const
Return the constant term in this objective.
Definition: Objective.h:75
Definition: Problem.h:74
Definition: QuadraticFunction.h:38
Definition: Variable.h:31
Definition: ActiveNodeStore.h:20
ObjState
Different states an objective can be in.
Definition: Types.h:152
std::map< ConstVariablePtr, double, CompareVariablePtr > VariableGroup
Variables should always be constant within a group.
Definition: Types.h:511
ObjectiveType
Definition: Types.h:62
FunctionType
Different types of functions in Minotaur.
Definition: Types.h:65

Minotaur source code documented by Doxygen 1.9.4 on Thu Apr 24 2025