This example shows how to instantiate a weighted figure of merit and perform a CBC search for the best lattice.
#include "latbuilder/WeightedFigureOfMerit.h"
#include "latcommon/ProductWeights.h"
#include "latcommon/CoordinateSets.h"
#include "latbuilder/ProjDepMerit/Spectral.h"
#include "latcommon/NormaBestLat.h"
#include "latbuilder/Accumulator.h"
#include "latbuilder/Storage.h"
#include "latbuilder/Functor/binary.h"
#include "latbuilder/LatSeq/CBC.h"
#include "latbuilder/GenSeq/CoprimeIntegers.h"
#include "latbuilder/TextStream.h"
#include <iostream>
#include <limits>
using TextStream::operator<<;
template <typename T, typename... ARGS>
std::unique_ptr<T> unique(ARGS&&... args)
{ return std::unique_ptr<T>(new T(std::forward<ARGS>(args)...)); }
class Observer {
public:
Observer() { reset(); }
void reset() { m_bestMerit = std::numeric_limits<Real>::infinity(); }
const LatDef& bestLat() { return m_bestLat; }
const Real bestMerit() {
return m_bestMerit; }
void observe(
const LatDef& lat,
Real merit)
{
std::cout << lat << "\t:\t" << merit;
if (merit < m_bestMerit) {
std::cout << " <-- best";
m_bestMerit = merit;
m_bestLat = lat;
}
std::cout << std::endl;
}
private:
LatDef m_bestLat;
};
template <LatType L, Compress C>
{
auto weights = unique<LatCommon::ProductWeights>();
weights->setDefaultWeight(0.7);
std::cout << "figure of merit: " << figure << std::endl;
auto initialMerit = storage.createMeritValue(0.0);
auto eval = figure.evaluator(storage);
while (baseLat.dimension() < dimension) {
baseLat,
Coprime(baseDim == 0 ? 2 : storage.sizeParam().numPoints())
);
std::cout << "CBC search for dimension: " << (baseDim + 1) << std::endl;
std::cout << " base lattice: " << baseLat << std::endl;
std::cout << " base merit value: " << initialMerit << std::endl;
FromRanges baseProjections{
0, baseDim,
0, baseDim - 1
};
AddCoordinate<FromRanges> newProjections(
baseProjections,
baseDim
);
std::cout << " new projections: " << newProjections << std::endl;
Observer obs;
for (const auto& lat : latSeq) {
auto merit =
eval(lat, newProjections, initialMerit);
obs.observe(lat, merit);
}
std::cout << "BEST LATTICE: " << obs.bestLat() << " with merit value " << obs.bestMerit() << std::endl;
baseLat = obs.bestLat();
initialMerit = obs.bestMerit();
}
}
int main()
{
return 0;
}