Skip to content

Commit 54378a4

Browse files
committed
Refactor variable and constraint name setting to use _set_value for improved consistency
1 parent 60f18f7 commit 54378a4

2 files changed

Lines changed: 3 additions & 10 deletions

File tree

include/pyoptinterface/knitro_model.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -734,13 +734,6 @@ class KNITROModel : public OnesideLinearConstraintMixin<KNITROModel>,
734734
}
735735
}
736736

737-
template <typename F>
738-
void _set_name(F set, KNINT index, const std::string &name)
739-
{
740-
int error = set(m_kc.get(), index, name.c_str());
741-
_check_error(error);
742-
}
743-
744737
template <typename I>
745738
KNINT _get_index(const I &index) const
746739
{

lib/knitro_model.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ VariableIndex KNITROModel::add_variable(VariableDomain domain, double lb, double
200200

201201
if (!is_name_empty(name))
202202
{
203-
_set_name(knitro::KN_set_var_name, indexVar, name);
203+
_set_value<KNINT, const char *>(knitro::KN_set_var_name, indexVar, name);
204204
}
205205

206206
m_n_vars++;
@@ -261,7 +261,7 @@ std::string KNITROModel::get_variable_name(const VariableIndex &variable) const
261261
void KNITROModel::set_variable_name(const VariableIndex &variable, const std::string &name)
262262
{
263263
KNINT indexVar = _variable_index(variable);
264-
_set_name(knitro::KN_set_var_name, indexVar, name);
264+
_set_value<KNINT, const char *>(knitro::KN_set_var_name, indexVar, name.c_str());
265265
}
266266

267267
void KNITROModel::set_variable_domain(const VariableIndex &variable, VariableDomain domain)
@@ -551,7 +551,7 @@ void KNITROModel::delete_constraint(const ConstraintIndex &constraint)
551551
void KNITROModel::set_constraint_name(const ConstraintIndex &constraint, const std::string &name)
552552
{
553553
KNINT indexCon = _constraint_index(constraint);
554-
_set_name(knitro::KN_set_con_name, indexCon, name);
554+
_set_value<KNINT, const char *>(knitro::KN_set_con_name, indexCon, name.c_str());
555555
}
556556

557557
std::string KNITROModel::get_constraint_name(const ConstraintIndex &constraint) const

0 commit comments

Comments
 (0)