Skip to content

Commit 560c53a

Browse files
committed
Add possibility to make variable constant during optimization
1 parent 0e7af5e commit 560c53a

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

fuse_core/include/fuse_core/variable.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,9 @@ class Variable
213213
* the generator to create the UUID for a specific variable instance.
214214
*
215215
* @param[in] uuid The unique ID number for this variable
216+
* @param[in] hold_constant Whether or not to mark variable as constant during optimization
216217
*/
217-
explicit Variable(const UUID& uuid);
218+
explicit Variable(const UUID& uuid, const bool hold_constant = false);
218219

219220
/**
220221
* @brief Destructor
@@ -383,11 +384,20 @@ class Variable
383384
}
384385

385386
/**
386-
* @brief Specifies if the value of the variable should not be changed during optimization
387+
* @brief Retrieve whether or not the variable should be held constant during optimization
387388
*/
388389
virtual bool holdConstant() const
389390
{
390-
return false;
391+
return hold_constant_;
392+
}
393+
/**
394+
* @brief Set whether or not to consider variable as constant during optimization
395+
*
396+
* @param[in] hold_constant If true, variable will not change during optimization, false otherwise
397+
*/
398+
virtual void setHoldConstant(const bool hold_constant)
399+
{
400+
hold_constant_ = hold_constant;
391401
}
392402

393403
/**
@@ -440,7 +450,7 @@ class Variable
440450

441451
private:
442452
fuse_core::UUID uuid_; //!< The unique ID number for this variable
443-
453+
bool hold_constant_ { false }; //!< Flag whether a variable should not be changed during optimization
444454
// Allow Boost Serialization access to private methods
445455
friend class boost::serialization::access;
446456

fuse_core/src/variable.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@
3939
namespace fuse_core
4040
{
4141

42-
Variable::Variable(const UUID& uuid) :
43-
uuid_(uuid)
42+
Variable::Variable(const UUID& uuid, const bool hold_constant) :
43+
uuid_(uuid),
44+
hold_constant_(hold_constant)
4445
{
4546
}
4647

0 commit comments

Comments
 (0)