Changeset 80bf6e


Ignore:
Timestamp:
Nov 1, 2022, 10:35:20 PM (3 years ago)
Author:
Frederik Heber <frederik.heber@…>
Branches:
Candidate_v1.7.0, stable
Children:
fb08cc
Parents:
78e5cf
Message:

FIX: GeneratePotentialsAction generates all combination. Merge with 55c494f698

  • we now generate all possible permutations of fragment charges and pick the first N up to the number of particles needed for the potential.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Actions/PotentialAction/GeneratePotentialsAction.cpp

    r78e5cf r80bf6e  
    4444
    4545#include <boost/foreach.hpp>
     46#include <boost/iterator/counting_iterator.hpp>
    4647
    4748#include "Actions/PotentialAction/GeneratePotentialsAction.hpp"
     
    6162#include "Action_impl_pre.hpp"
    6263/** =========== define the function ====================== */
    63 
    6464ActionState::ptr PotentialGeneratePotentialsAction::performCall()
    6565{
     
    124124
    125125    /**
    126      * We have num_particles places and fragmentnumbers.size() elements to place.
    127      * We use a "selection" array and pick every possible selection from the
    128      * fragmentnumbers array, kudos to https://stackoverflow.com/a/9430993
     126     * 2. create all unique combinations for the given elements and the number of particles
     127     *
     128     * Use the {1,...,fragmentnumbers.size()}, create every permutation and pick the first num_particle
     129     * from the given charges. Finally, put all those into a set to retain only unique combinations.
    129130     */
    130 
    131     /// 2. create all combinations for the given elements and the number of particles
    132     std::vector<bool> selection(fragmentnumbers.size());
    133     std::fill(selection.begin(), selection.begin() + num_particles, true);
     131    std::set<SerializablePotential::ParticleTypes_t> charges_for_potentials;
     132    std::vector<size_t> selection(boost::counting_iterator<int>(0), boost::counting_iterator<int>(fragmentnumbers.size()));
    134133    do {
    135134      charges.clear();
    136         for (unsigned int i = 0; i < fragmentnumbers.size(); ++i) {
    137             if (selection[i]) {
    138               charges.push_back(fragmentnumbers[i]);
    139             }
    140         }
     135      for (unsigned int i = 0; i < num_particles; ++i) {
     136          charges.push_back(fragmentnumbers[selection[i]]);
     137      }
     138      // LOG(3, "DEBUG: Inserting charges " << charges);
     139      charges_for_potentials.insert(charges);
     140    } while (std::next_permutation(selection.begin(), selection.end()));
     141
     142
     143    for (std::set<SerializablePotential::ParticleTypes_t>::const_iterator iter = charges_for_potentials.begin();
     144        iter != charges_for_potentials.end(); ++iter) {
    141145      /// 3. create the potential
    142       EmpiricalPotential* potential = factory.createInstance(potential_name, charges);
     146      EmpiricalPotential* potential = factory.createInstance(potential_name, *iter);
    143147
    144148      /// 4. Gather all created potential's binding model in a set
     
    157161      LOG(2, "DEBUG: Discarding potential " << *potential);
    158162      delete(potential);
    159     } while (std::prev_permutation(selection.begin(), selection.end()));
     163    }
    160164  }
    161165
Note: See TracChangeset for help on using the changeset viewer.