Skip to content

Commit

Permalink
Performance: Improve the computational efficiency to update applicabl…
Browse files Browse the repository at this point in the history
…e chain moves.
  • Loading branch information
snowberryfield committed Jan 6, 2025
1 parent 322fce4 commit bd81eb1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 2 additions & 0 deletions printemps/model/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,8 @@ class Model {
m_neighborhood.selection().setup(
this->variable_type_reference().selection_variable_ptrs);
this->setup_positive_and_negative_coefficient_mutable_variable_ptrs();

m_neighborhood.chain().remove_moves_on_fixed_variables();
}
}

Expand Down
14 changes: 10 additions & 4 deletions printemps/neighborhood/chain_move_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ class ChainMoveGenerator
(*a_flags)[i] = 0;
continue;
}
if ((*a_moves_ptr)[i].has_fixed_variable()) {
(*a_flags)[i] = 0;
continue;
}
for (const auto &alteration :
(*a_moves_ptr)[i].alterations) {
if (alteration.first->value() == alteration.second) {
Expand Down Expand Up @@ -203,6 +199,16 @@ class ChainMoveGenerator
this->m_moves.resize(a_NUMBER_OF_MOVES);
this->m_flags.resize(a_NUMBER_OF_MOVES);
}

/*************************************************************************/
inline void remove_moves_on_fixed_variables(void) {
this->m_moves.erase(
std::remove_if(
this->m_moves.begin(), this->m_moves.end(),
[](const auto &a_MOVE) { return a_MOVE.has_fixed_variable(); }),
this->m_moves.end());
this->m_flags.resize(this->m_moves.size());
}
};
} // namespace printemps::neighborhood
#endif
Expand Down

0 comments on commit bd81eb1

Please sign in to comment.