24 #include <basic/Tracer.hh>
27 #include <utility/excn/Exceptions.hh>
31 #include <utility/vector1.hh>
32 #include <ObjexxFCL/FArray1A.hh>
39 namespace interaction_graph {
41 static basic::Tracer
T(
"core.pack.interaction_graph.symmlinmem_ig", basic::t_error );
44 bool const debug = {
false };
55 curr_state_one_body_energy_( 0.0f ),
56 curr_state_total_energy_( 0.0f ),
57 alternate_state_( 0 ),
58 alternate_state_one_body_energy_( 0 ),
59 alternate_state_total_energy_( 0 ),
60 alternate_state_is_being_considered_( false ),
61 already_prepped_for_simA_( false ),
62 accepted_rejected_substitution_history_( ACCEPTANCE_REJECTION_HISTORY_LENGTH, 0 ),
63 accepted_history_head_( 1 ),
64 num_recently_accepted_( 0 ),
65 filled_substitution_history_( false )
67 rhq_.num_elements( num_states );
87 rhq_.pos_in_history_queue( ii )
109 T <<
"Curr Two Body Energies:";
118 T <<
"Alt Two Body Energies:";
123 T << std::endl <<
"-----------------" << std::endl;
139 total_memory +=
rhq_.dynamic_memory_usage();
181 if (new_state == 0) {
196 bumped_recent_history_index,
197 rhq_.head_of_queue(),
230 bumped_recent_history_index,
246 get_energy_following_partial_state_assignment();
259 alternate_state_is_being_considered_ =
true;
260 alternate_state_ = alternate_state;
261 int alternate_state_recent_history_index = rhq_.pos_in_history_queue( alternate_state_ );
263 bool store_rpes = num_recently_accepted_ < THRESHOLD_ACCEPTANCE_RATE_FOR_RPE_STORAGE;
265 alternate_state_one_body_energy_ = get_one_body_energy( alternate_state );
266 alternate_state_total_energy_ = alternate_state_one_body_energy_;
267 prev_node_energy = curr_state_total_energy_;
269 for (
int ii = 1; ii <= get_num_incident_edges(); ++ii )
272 if ( neighbors_curr_state_[ ii ] != 0 ) {
274 alternate_state_two_body_energies_[ ii ] =
275 get_incident_symmlinmem_edge( ii )->get_energy_for_alt_state(
279 alternate_state_recent_history_index,
280 neighbors_curr_state_[ ii ],
281 neighbors_state_recent_history_index_[ ii ]
285 alternate_state_two_body_energies_[ ii ] = 0;
288 alternate_state_total_energy_ += alternate_state_two_body_energies_[ ii ];
291 if (
debug && ! get_owner()->any_vertex_state_unassigned() ) {
547 return alternate_state_total_energy_ - curr_state_total_energy_;
577 bumped_recent_history_index,
578 rhq_.head_of_queue(),
622 int edge_making_energy_request
626 edge_making_energy_request,
633 int edge_making_energy_request
637 edge_making_energy_request,
645 int edge_to_altered_neighbor,
646 int other_node_new_state,
647 int other_state_recent_history_index
654 other_state_recent_history_index;
660 int num_states_to_maintain_in_recent_history
663 rhq_.history_size( num_states_to_maintain_in_recent_history );
669 return rhq_.history_size();
677 T <<
"curr_state_one_body_energy_ ";
721 return rhq_.push_to_front_of_history_queue( state );
735 curr_state_energy_( 0.0f ),
736 partial_state_assignment_( false ),
737 preped_for_sim_annealing_( false )
747 throw utility::excn::EXCN_Msg_Exception(
"Method unimplemented: SymmLinearMemEdge::get_two_body_energy" );
758 for (
int ii = 0; ii < 2; ++ii ) {
765 for (
int ii = 0; ii < 2; ++ii) {
766 int const other = ! ii;
797 for (
int ii = 0; ii < 2; ++ii) {
819 int bumped_recent_history_index,
820 int new_state_recent_history_index,
825 int node_not_substituted = ! node_substituted;
829 node_not_substituted,
830 bumped_recent_history_index );
833 compute_pair_energy_for_current_state(
841 acknowledge_neighbors_state_substitution
846 new_state_recent_history_index
857 int node_not_substituted = ! node_substituted;
861 acknowledge_neighbors_state_substitution(
871 int bumped_recent_history_index,
872 int new_state_recent_history_index
876 int node_not_substituted = ! node_substituted;
880 node_not_substituted,
881 bumped_recent_history_index );
886 acknowledge_neighbors_partial_state_substitution
890 new_state_recent_history_index
905 compute_pair_energy_for_current_state(
917 int recent_history_id
920 int node_with_reset_state = node_index ==
get_node_index( 0 ) ? 0 : 1;
921 int other = ! node_with_reset_state;
923 if ( recent_history_id != 0 ) {
924 ObjexxFCL::FArray1A< core::PackerEnergy > row_to_wipe(
925 stored_rpes_[ node_with_reset_state ]( 1, recent_history_id ),
930 for (
unsigned int ii = 1; ii <=
stored_rpes_[ other ].size2(); ++ii) {
940 int changing_node_index,
942 int alternate_state_recent_history_index,
943 int other_node_curr_state,
944 int other_node_state_recent_history_index
947 assert( other_node_curr_state != 0 );
953 bool assignment_of_interest =
debug &&
false;
956 if ( assignment_of_interest ){
957 T <<
"get_energy_for_alt_state: " << get_node_index( 0 ) <<
" " << get_node_index( 1 ) <<
" srpe: " << store_rpes;
958 T <<
" chID " << changing_node_index <<
" alt: " << alternate_state <<
" altHI: " << alternate_state_recent_history_index;
959 T <<
" oncurr: " << other_node_curr_state <<
" oncurrHI: " << other_node_state_recent_history_index << std::endl;
960 T <<
"store_rpes_[ 0 ] " << store_rpes_[ 0 ] <<
"store_rpes_[ 1 ] " << store_rpes_[ 1 ] << std::endl;
963 int const node_changing = changing_node_index == get_node_index( 0 ) ? 0 : 1;
964 int const node_not_changing = ! node_changing;
966 if ( store_rpes && ! store_rpes_[ node_changing ] ) {
967 wipe( node_changing );
969 store_rpes_[ node_changing ] = store_rpes;
971 if ( store_rpes_[ node_changing ] && alternate_state_recent_history_index != 0 ) {
972 alt_state_energy_ = stored_rpes_[ node_changing ]( other_node_curr_state, alternate_state_recent_history_index );
973 if (alt_state_energy_ != NOT_YET_COMPUTED_ENERGY ) {
975 if ( assignment_of_interest ) {
976 T <<
"retrieving from stored_rpes_[ " << node_changing <<
" ] " << alt_state_energy_ << std::endl;
977 T <<
"stored at location: " << & ( stored_rpes_[ node_changing ]( other_node_curr_state, alternate_state_recent_history_index ) ) << std::endl;
980 return alt_state_energy_;
984 if ( store_rpes_[ node_not_changing ] ) {
985 alt_state_energy_ = stored_rpes_[ node_not_changing ]( alternate_state, other_node_state_recent_history_index );
986 if ( alt_state_energy_ != NOT_YET_COMPUTED_ENERGY ) {
988 if ( assignment_of_interest ) {
989 T <<
"retrieving from stored_rpes_[ " << node_not_changing <<
" ] " << alt_state_energy_ << std::endl;
990 T <<
"stored at location: " << & ( stored_rpes_[ node_not_changing ]( alternate_state, other_node_state_recent_history_index ) ) << std::endl;
992 return alt_state_energy_;
996 alt_state_energy_ = get_symmlinmem_node( node_changing )->
997 compute_pair_energy_for_alternate_state(
998 get_edges_position_in_nodes_edge_vector( node_changing ));
1001 if ( assignment_of_interest ) {
1002 T <<
"get_energy_for_alt_state: computing energy: " << alt_state_energy_ << std::endl;
1005 if ( store_rpes_[ node_changing ] && alternate_state_recent_history_index != 0 ) {
1006 stored_rpes_[ node_changing ]( other_node_curr_state, alternate_state_recent_history_index ) = alt_state_energy_;
1008 if ( store_rpes_[ node_not_changing ] ) {
1009 assert( other_node_state_recent_history_index );
1010 if ( assignment_of_interest ) {
1011 T <<
"about to write alt_state_energy_ to location: " << & ( stored_rpes_[ node_not_changing ]( alternate_state, other_node_state_recent_history_index ) ) << std::endl;
1014 stored_rpes_[ node_not_changing ]( alternate_state, other_node_state_recent_history_index ) = alt_state_energy_;
1017 return alt_state_energy_;
1036 int node_substituted,
1037 int node_not_substituted,
1038 int bumped_recent_history_index
1041 if ( ! store_rpes_[ node_substituted ] || bumped_recent_history_index == 0 )
return;
1043 ObjexxFCL::FArray1A< core::PackerEnergy > row_to_reset(
1044 stored_rpes_[ node_substituted ](1, bumped_recent_history_index ),
1045 get_num_states_for_node( node_not_substituted ) );
1046 row_to_reset = NOT_YET_COMPUTED_ENERGY;
1052 int curr_states[ 2 ];
1053 int recent_history_ids[ 2 ];
1054 for (
int ii = 0; ii < 2; ++ii) {
1057 if ( curr_states[ ii ] == 0 )
return;
1060 for (
int ii = 0; ii < 2; ++ii ) {
1061 int const other = ! ii;
1080 first_time_prepping_for_simA_( true ),
1081 num_commits_since_last_update_( 0 ),
1082 total_energy_current_state_assignment_( 0.0 ),
1083 total_energy_alternate_state_assignment_( 0.0 ),
1084 node_considering_alt_state_( 0 ),
1085 have_not_committed_last_substitution_( false )
1116 ObjexxFCL::FArray1_int & node_states
1143 acknowledge_last_substititon_not_committed();
1149 project_deltaE_for_substitution( new_state, prev_energy_for_node );
1204 T <<
"State Assignment: " << std::endl;
1234 int first_node_ind = (*edge_iter)->get_first_node_ind();
1235 int second_node_ind = (*edge_iter)->get_second_node_ind();
1267 return total_memory;
1291 get_one_body_energy_current_state();
1307 static int const symmlinmemIG_history_size( 10 );