enumerate_ext.h
Go to the documentation of this file.
1/*
2 (C) 2016 Marc Stevens.
3
4 This file is part of fplll. fplll is free software: you
5 can redistribute it and/or modify it under the terms of the GNU Lesser
6 General Public License as published by the Free Software Foundation,
7 either version 2.1 of the License, or (at your option) any later version.
8
9 fplll is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public License
15 along with fplll. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifndef FPLLL_ENUMERATE_EXT_H
18#define FPLLL_ENUMERATE_EXT_H
19
20#include "enumerate_ext_api.h"
21
24#include <fplll/gso_interface.h>
25
27
28/* function callback API for external enumeration library (extenum) */
29
52// typedef void(extenum_cb_set_config)(enumf *mu, size_t mudim, bool mutranspose, enumf *rdiag,
53// enumf *pruning);
55
63// typedef enumf(extenum_cb_process_sol)(enumf dist, enumf *sol);
65
71// typedef void(extenum_cb_process_subsol)(enumf dist, enumf *subsol, int offset);
73
89// typedef array<uint64_t, FPLLL_EXTENUM_MAX_EXTENUM_DIM>(extenum_fc_enumerate)(
90// const int dim, enumf maxdist, std::function<extenum_cb_set_config> cbfunc,
91// std::function<extenum_cb_process_sol> cbsol, std::function<extenum_cb_process_subsol>
92// cbsubsol, bool dual /*=false*/, bool findsubsols /*=false*/
93//);
94using ::extenum_fc_enumerate;
95
96/* set & get external enumerator. If extenum = nullptr then this interface is disabled,
97 and fplll will use the internal enumerator.
98 Otherwise, fplll will use the enumeration function pointed to
99 by extenum.
100*/
101void set_external_enumerator(std::function<extenum_fc_enumerate> extenum = nullptr);
102std::function<extenum_fc_enumerate> get_external_enumerator();
103
104template <typename ZT, typename FT> class ExternalEnumeration
105{
106public:
108 : _gso(gso), _evaluator(evaluator)
109 {
110 }
111
112 bool enumerate(int first, int last, FT &fmaxdist, long fmaxdistexpo,
113 const vector<enumf> &pruning = vector<enumf>(), bool dual = false);
114
115 // get_nodes. This returns the number of nodes visited by the external enumeration process.
116 // If this returns 0, then fplll will fall back to the internal enumerator.
117 inline uint64_t get_nodes(const int level = -1) const
118 {
119 if (level == -1)
120 {
121 return std::accumulate(_nodes.begin(), _nodes.end(), 0);
122 }
123 return _nodes[level];
124 }
125
126 inline std::array<uint64_t, FPLLL_EXTENUM_MAX_EXTENUM_DIM> get_nodes_array() const
127 {
128 return _nodes;
129 }
130
131private:
132 void callback_set_config(enumf *mu, size_t mudim, bool mutranspose, enumf *rdiag, enumf *pruning);
133
134 enumf callback_process_sol(enumf dist, enumf *sol);
135
136 void callback_process_subsol(enumf dist, enumf *subsol, int offset);
137
139 Evaluator<FT> &_evaluator;
140 vector<enumf> _pruning;
141 long _normexp;
142
143 array<uint64_t, FPLLL_EXTENUM_MAX_EXTENUM_DIM> _nodes;
144 bool _dual;
145 int _d, _first;
146 enumf _maxdist;
147 vector<FT> _fx;
148};
149
151
152#endif
Definition: evaluator.h:66
Definition: enumerate_ext.h:105
uint64_t get_nodes(const int level=-1) const
Definition: enumerate_ext.h:117
ExternalEnumeration(MatGSOInterface< ZT, FT > &gso, Evaluator< FT > &evaluator)
Definition: enumerate_ext.h:107
std::array< uint64_t, FPLLL_EXTENUM_MAX_EXTENUM_DIM > get_nodes_array() const
Definition: enumerate_ext.h:126
bool enumerate(int first, int last, FT &fmaxdist, long fmaxdistexpo, const vector< enumf > &pruning=vector< enumf >(), bool dual=false)
Definition: enumerate_ext.cpp:49
Definition: gso_interface.h:60
#define FPLLL_END_NAMESPACE
Definition: defs.h:117
#define FPLLL_BEGIN_NAMESPACE
Definition: defs.h:114
void set_external_enumerator(std::function< extenum_fc_enumerate > extenum=nullptr)
Definition: enumerate_ext.cpp:41
std::function< extenum_fc_enumerate > get_external_enumerator()
Definition: enumerate_ext.cpp:46
void() extenum_cb_process_subsol(fplll_extenum_enumf dist, fplll_extenum_enumf *subsol, int offset)
Definition: enumerate_ext_api.h:70
fplll_extenum_enumf() extenum_cb_process_sol(fplll_extenum_enumf dist, fplll_extenum_enumf *sol)
Definition: enumerate_ext_api.h:62
fplll_extenum_enumf std::function< extenum_cb_set_config > std::function< extenum_cb_process_sol > std::function< extenum_cb_process_subsol > bool dual
Definition: enumerate_ext_api.h:91
void() extenum_cb_set_config(fplll_extenum_enumf *mu, std::size_t mudim, bool mutranspose, fplll_extenum_enumf *rdiag, fplll_extenum_enumf *pruning)
Definition: enumerate_ext_api.h:52
FPLLL_BEGIN_NAMESPACE typedef double enumf
Definition: nr.h:42