Ignore:
Timestamp:
May 25, 2016, 7:13:59 AM (9 years ago)
Author:
Frederik Heber <heber@…>
Children:
ec9bd2
Parents:
a52369
git-author:
Frederik Heber <heber@…> (07/12/14 19:07:44)
git-committer:
Frederik Heber <heber@…> (05/25/16 07:13:59)
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

    ra52369 r9cf90e  
    480480      for (IndexList_t::iterator iter = _indices.begin();
    481481          (iter != _indices.end()) && (!_MCS.foundflag);) {
     482
    482483        // check whether we can stay in the current bin or have to move on to next one
    483484        if (*_remainiter == 0) {
     
    490491          }
    491492        }
    492         // advance in matching to same position
     493
     494        // advance in matching to current bin to fill in
    493495        const size_t OldIndex = std::distance(_remainingweights.begin(), _remainiter);
    494496        while (_matching.size() <= OldIndex) { // add empty lists of new bin is opened
     
    498500        IndexTupleList_t::iterator filliniter = _matching.begin();
    499501        std::advance(filliniter, OldIndex);
     502
     503        // check whether connection between bins' indices and candidate is satisfied
     504        {
     505          adjacency_t::const_iterator finder = _MCS.adjacency.find(*iter);
     506          ASSERT( finder != _MCS.adjacency.end(),
     507              "recurseMatchings() - "+toString(*iter)+" is not in adjacency list.");
     508          if ((!filliniter->empty())
     509              && (finder->second.find(*filliniter->begin()) == finder->second.end())) {
     510            LOG(5, "DEBUG; Skipping index " << *iter
     511                << " as is not connected to current set." << *filliniter << ".");
     512            ++iter; // note that for loop does not contain incrementor
     513            continue;
     514          }
     515        }
     516
    500517        // add index to matching
    501518        filliniter->push_back(*iter);
     
    532549}
    533550
     551SphericalPointDistribution::MatchingControlStructure::MatchingControlStructure(
     552    const adjacency_t &_adjacency,
     553    const VectorArray_t &_oldpoints,
     554    const VectorArray_t &_newpoints,
     555    const WeightsArray_t &_weights
     556    ) :
     557  foundflag(false),
     558  bestL2(std::numeric_limits<double>::max()),
     559  adjacency(_adjacency),
     560  oldpoints(_oldpoints),
     561  newpoints(_newpoints),
     562  weights(_weights)
     563{}
     564
    534565/** Finds combinatorially the best matching between points in \a _polygon
    535566 * and \a _newpolygon.
     
    551582 */
    552583SphericalPointDistribution::IndexList_t SphericalPointDistribution::findBestMatching(
    553     const WeightedPolygon_t &_polygon,
    554     Polygon_t &_newpolygon
     584    const WeightedPolygon_t &_polygon
    555585    )
    556586{
    557   MatchingControlStructure MCS;
    558   MCS.foundflag = false;
    559   MCS.bestL2 = std::numeric_limits<double>::max();
    560587  // transform lists into arrays
     588  VectorArray_t oldpoints;
     589  VectorArray_t newpoints;
     590  WeightsArray_t weights;
    561591  for (WeightedPolygon_t::const_iterator iter = _polygon.begin();
    562592      iter != _polygon.end(); ++iter) {
    563     MCS.oldpoints.push_back(iter->first);
    564     MCS.weights.push_back(iter->second);
    565   }
    566   MCS.newpoints.insert(MCS.newpoints.begin(), _newpolygon.begin(),_newpolygon.end() );
     593    oldpoints.push_back(iter->first);
     594    weights.push_back(iter->second);
     595  }
     596  newpoints.insert(newpoints.begin(), points.begin(), points.end() );
     597  MatchingControlStructure MCS(adjacency, oldpoints, newpoints, weights);
    567598
    568599  // search for bestmatching combinatorially
    569600  {
    570601    // translate polygon into vector to enable index addressing
    571     IndexList_t indices(_newpolygon.size());
     602    IndexList_t indices(points.size());
    572603    std::generate(indices.begin(), indices.end(), UniqueNumber);
    573604    IndexTupleList_t matching;
     
    594625  // combine multiple points and create simple IndexList from IndexTupleList
    595626  const SphericalPointDistribution::IndexList_t IndexList =
    596       joinPoints(_newpolygon, MCS.newpoints, MCS.bestmatching);
     627      joinPoints(points, MCS.newpoints, MCS.bestmatching);
    597628
    598629  return IndexList;
     
    779810}
    780811
     812void SphericalPointDistribution::initSelf(const int _NumberOfPoints)
     813{
     814  switch (_NumberOfPoints)
     815  {
     816    case 0:
     817      points = get<0>();
     818      adjacency = getConnections<0>();
     819      break;
     820    case 1:
     821      points = get<1>();
     822      adjacency = getConnections<1>();
     823      break;
     824    case 2:
     825      points = get<2>();
     826      adjacency = getConnections<2>();
     827      break;
     828    case 3:
     829      points = get<3>();
     830      adjacency = getConnections<3>();
     831      break;
     832    case 4:
     833      points = get<4>();
     834      adjacency = getConnections<4>();
     835      break;
     836    case 5:
     837      points = get<5>();
     838      adjacency = getConnections<5>();
     839      break;
     840    case 6:
     841      points = get<6>();
     842      adjacency = getConnections<6>();
     843      break;
     844    case 7:
     845      points = get<7>();
     846      adjacency = getConnections<7>();
     847      break;
     848    case 8:
     849      points = get<8>();
     850      adjacency = getConnections<8>();
     851      break;
     852    case 9:
     853      points = get<9>();
     854      adjacency = getConnections<9>();
     855      break;
     856    case 10:
     857      points = get<10>();
     858      adjacency = getConnections<10>();
     859      break;
     860    case 11:
     861      points = get<11>();
     862      adjacency = getConnections<11>();
     863      break;
     864    case 12:
     865      points = get<12>();
     866      adjacency = getConnections<12>();
     867      break;
     868    case 14:
     869      points = get<14>();
     870      adjacency = getConnections<14>();
     871      break;
     872    default:
     873      ASSERT(0, "SphericalPointDistribution::initSelf() - cannot deal with the case "
     874          +toString(_NumberOfPoints)+".");
     875  }
     876  LOG(3, "DEBUG: Ideal polygon is " << points);
     877}
    781878
    782879SphericalPointDistribution::Polygon_t
    783 SphericalPointDistribution::matchSphericalPointDistributions(
    784     const SphericalPointDistribution::WeightedPolygon_t &_polygon,
    785     SphericalPointDistribution::Polygon_t &_newpolygon
    786     )
     880SphericalPointDistribution::getRemainingPoints(
     881    const WeightedPolygon_t &_polygon,
     882    const int _N)
    787883{
    788884  SphericalPointDistribution::Polygon_t remainingpoints;
    789885
     886  // initialze to given number of points
     887  initSelf(_N);
    790888  LOG(2, "INFO: Matching old polygon " << _polygon
    791       << " with new polygon " << _newpolygon);
    792 
    793   if (_polygon.size() == _newpolygon.size()) {
    794     // same number of points desired as are present? Do nothing
    795     LOG(2, "INFO: There are no vacant points to return.");
     889      << " with new polygon " << points);
     890
     891  // check whether any points will remain vacant
     892  int RemainingPoints = _N;
     893  for (WeightedPolygon_t::const_iterator iter = _polygon.begin();
     894      iter != _polygon.end(); ++iter)
     895    RemainingPoints -= iter->second;
     896  if (RemainingPoints == 0)
    796897    return remainingpoints;
    797   }
    798 
    799   if (_polygon.size() > 0) {
    800     IndexList_t bestmatching = findBestMatching(_polygon, _newpolygon);
     898
     899  if (_N > 0) {
     900    IndexList_t bestmatching = findBestMatching(_polygon);
    801901    LOG(2, "INFO: Best matching is " << bestmatching);
    802902
     
    817917    newSet.indices.resize(NumberIds, -1);
    818918    std::copy(beginiter, enditer, newSet.indices.begin());
    819     std::copy(_newpolygon.begin(),_newpolygon.end(), std::back_inserter(newSet.polygon));
     919    std::copy(points.begin(),points.end(), std::back_inserter(newSet.polygon));
    820920
    821921    // determine rotation angles to align the two point distributions with
     
    9251025    return remainingpoints;
    9261026  } else
    927     return _newpolygon;
    928 }
     1027    return points;
     1028}
Note: See TracChangeset for help on using the changeset viewer.