Ignore:
Timestamp:
Aug 20, 2014, 1:06:16 PM (11 years ago)
Author:
Frederik Heber <heber@…>
Children:
ff72fb
Parents:
0b517b
git-author:
Frederik Heber <heber@…> (07/12/14 19:07:44)
git-committer:
Frederik Heber <heber@…> (08/20/14 13:06:16)
Message:

recurseMatching() now takes connections into account.

  • matchSphericalPointDistribution() replaced by getRemainingPoints() as that describes what it does. match...() sounds symmetrical which the function is no longer as connection is associated with former _newpolygon.
  • SphericalPointDistribution now has internal points and adjacency, initialized by initSelf().
  • findBestMatching() and getRemainingPoints() are no longer static functions.
  • all unit tests are working again, including the .._multiple() that tests for joint points due to bond degree greater than 1.
  • the huge case switch in SaturatedFragment::saturateAtom() now resides in initSelf().
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/Fragmentation/Exporters/SphericalPointDistribution.cpp

    r0b517b re6ca85  
    479479      for (IndexList_t::iterator iter = _indices.begin();
    480480          (iter != _indices.end()) && (!_MCS.foundflag);) {
     481
    481482        // check whether we can stay in the current bin or have to move on to next one
    482483        if (*_remainiter == 0) {
     
    489490          }
    490491        }
    491         // advance in matching to same position
     492
     493        // advance in matching to current bin to fill in
    492494        const size_t OldIndex = std::distance(_remainingweights.begin(), _remainiter);
    493495        while (_matching.size() <= OldIndex) { // add empty lists of new bin is opened
     
    497499        IndexTupleList_t::iterator filliniter = _matching.begin();
    498500        std::advance(filliniter, OldIndex);
     501
     502        // check whether connection between bins' indices and candidate is satisfied
     503        {
     504          adjacency_t::const_iterator finder = _MCS.adjacency.find(*iter);
     505          ASSERT( finder != _MCS.adjacency.end(),
     506              "recurseMatchings() - "+toString(*iter)+" is not in adjacency list.");
     507          if ((!filliniter->empty())
     508              && (finder->second.find(*filliniter->begin()) == finder->second.end())) {
     509            LOG(5, "DEBUG; Skipping index " << *iter
     510                << " as is not connected to current set." << *filliniter << ".");
     511            ++iter; // note that for loop does not contain incrementor
     512            continue;
     513          }
     514        }
     515
    499516        // add index to matching
    500517        filliniter->push_back(*iter);
     
    531548}
    532549
     550SphericalPointDistribution::MatchingControlStructure::MatchingControlStructure(
     551    const adjacency_t &_adjacency,
     552    const VectorArray_t &_oldpoints,
     553    const VectorArray_t &_newpoints,
     554    const WeightsArray_t &_weights
     555    ) :
     556  foundflag(false),
     557  bestL2(std::numeric_limits<double>::max()),
     558  adjacency(_adjacency),
     559  oldpoints(_oldpoints),
     560  newpoints(_newpoints),
     561  weights(_weights)
     562{}
     563
    533564/** Finds combinatorially the best matching between points in \a _polygon
    534565 * and \a _newpolygon.
     
    550581 */
    551582SphericalPointDistribution::IndexList_t SphericalPointDistribution::findBestMatching(
    552     const WeightedPolygon_t &_polygon,
    553     Polygon_t &_newpolygon
     583    const WeightedPolygon_t &_polygon
    554584    )
    555585{
    556   MatchingControlStructure MCS;
    557   MCS.foundflag = false;
    558   MCS.bestL2 = std::numeric_limits<double>::max();
    559586  // transform lists into arrays
     587  VectorArray_t oldpoints;
     588  VectorArray_t newpoints;
     589  WeightsArray_t weights;
    560590  for (WeightedPolygon_t::const_iterator iter = _polygon.begin();
    561591      iter != _polygon.end(); ++iter) {
    562     MCS.oldpoints.push_back(iter->first);
    563     MCS.weights.push_back(iter->second);
    564   }
    565   MCS.newpoints.insert(MCS.newpoints.begin(), _newpolygon.begin(),_newpolygon.end() );
     592    oldpoints.push_back(iter->first);
     593    weights.push_back(iter->second);
     594  }
     595  newpoints.insert(newpoints.begin(), points.begin(), points.end() );
     596  MatchingControlStructure MCS(adjacency, oldpoints, newpoints, weights);
    566597
    567598  // search for bestmatching combinatorially
    568599  {
    569600    // translate polygon into vector to enable index addressing
    570     IndexList_t indices(_newpolygon.size());
     601    IndexList_t indices(points.size());
    571602    std::generate(indices.begin(), indices.end(), UniqueNumber);
    572603    IndexTupleList_t matching;
     
    593624  // combine multiple points and create simple IndexList from IndexTupleList
    594625  const SphericalPointDistribution::IndexList_t IndexList =
    595       joinPoints(_newpolygon, MCS.newpoints, MCS.bestmatching);
     626      joinPoints(points, MCS.newpoints, MCS.bestmatching);
    596627
    597628  return IndexList;
     
    774805}
    775806
     807void SphericalPointDistribution::initSelf(const int _NumberOfPoints)
     808{
     809  switch (_NumberOfPoints)
     810  {
     811    case 0:
     812      points = get<0>();
     813      adjacency = getConnections<0>();
     814      break;
     815    case 1:
     816      points = get<1>();
     817      adjacency = getConnections<1>();
     818      break;
     819    case 2:
     820      points = get<2>();
     821      adjacency = getConnections<2>();
     822      break;
     823    case 3:
     824      points = get<3>();
     825      adjacency = getConnections<3>();
     826      break;
     827    case 4:
     828      points = get<4>();
     829      adjacency = getConnections<4>();
     830      break;
     831    case 5:
     832      points = get<5>();
     833      adjacency = getConnections<5>();
     834      break;
     835    case 6:
     836      points = get<6>();
     837      adjacency = getConnections<6>();
     838      break;
     839    case 7:
     840      points = get<7>();
     841      adjacency = getConnections<7>();
     842      break;
     843    case 8:
     844      points = get<8>();
     845      adjacency = getConnections<8>();
     846      break;
     847    case 9:
     848      points = get<9>();
     849      adjacency = getConnections<9>();
     850      break;
     851    case 10:
     852      points = get<10>();
     853      adjacency = getConnections<10>();
     854      break;
     855    case 11:
     856      points = get<11>();
     857      adjacency = getConnections<11>();
     858      break;
     859    case 12:
     860      points = get<12>();
     861      adjacency = getConnections<12>();
     862      break;
     863    case 14:
     864      points = get<14>();
     865      adjacency = getConnections<14>();
     866      break;
     867    default:
     868      ASSERT(0, "SphericalPointDistribution::initSelf() - cannot deal with the case "
     869          +toString(_NumberOfPoints)+".");
     870  }
     871  LOG(3, "DEBUG: Ideal polygon is " << points);
     872}
    776873
    777874SphericalPointDistribution::Polygon_t
    778 SphericalPointDistribution::matchSphericalPointDistributions(
    779     const SphericalPointDistribution::WeightedPolygon_t &_polygon,
    780     SphericalPointDistribution::Polygon_t &_newpolygon
    781     )
     875SphericalPointDistribution::getRemainingPoints(
     876    const WeightedPolygon_t &_polygon,
     877    const int _N)
    782878{
    783879  SphericalPointDistribution::Polygon_t remainingpoints;
    784880
     881  // initialze to given number of points
     882  initSelf(_N);
    785883  LOG(2, "INFO: Matching old polygon " << _polygon
    786       << " with new polygon " << _newpolygon);
    787 
    788   if (_polygon.size() == _newpolygon.size()) {
    789     // same number of points desired as are present? Do nothing
    790     LOG(2, "INFO: There are no vacant points to return.");
     884      << " with new polygon " << points);
     885
     886  // check whether any points will remain vacant
     887  int RemainingPoints = _N;
     888  for (WeightedPolygon_t::const_iterator iter = _polygon.begin();
     889      iter != _polygon.end(); ++iter)
     890    RemainingPoints -= iter->second;
     891  if (RemainingPoints == 0)
    791892    return remainingpoints;
    792   }
    793 
    794   if (_polygon.size() > 0) {
    795     IndexList_t bestmatching = findBestMatching(_polygon, _newpolygon);
     893
     894  if (_N > 0) {
     895    IndexList_t bestmatching = findBestMatching(_polygon);
    796896    LOG(2, "INFO: Best matching is " << bestmatching);
    797897
     
    812912    newSet.indices.resize(NumberIds, -1);
    813913    std::copy(beginiter, enditer, newSet.indices.begin());
    814     std::copy(_newpolygon.begin(),_newpolygon.end(), std::back_inserter(newSet.polygon));
     914    std::copy(points.begin(),points.end(), std::back_inserter(newSet.polygon));
    815915
    816916    // determine rotation angles to align the two point distributions with
     
    9201020    return remainingpoints;
    9211021  } else
    922     return _newpolygon;
    923 }
    924 
    925 
     1022    return points;
     1023}
     1024
     1025
Note: See TracChangeset for help on using the changeset viewer.