40 #ifndef H_EXPLORAGRAM_OPTIMAL_TRANSPORT_OPTIMAL_TRANSPORT_H
41 #define H_EXPLORAGRAM_OPTIMAL_TRANSPORT_OPTIMAL_TRANSPORT_H
54 OT_PRECG, OT_SUPERLU, OT_CHOLMOD
65 #include <geogram/third_party/HLBFGS/HLBFGS.h>
73 class CentroidalVoronoiTesselation;
102 const std::string& delaunay =
"default",
165 index_t nb_air_particles,
const double* air_particles,
index_t stride,
168 nb_air_particles_ = nb_air_particles;
169 air_particles_ = air_particles;
170 air_particles_stride_ = (stride == 0) ? dimension_ : stride;
171 air_fraction_ = air_fraction;
174 clip_by_balls_ = (nb_air_particles == 0) && (air_fraction != 0.0);
182 return air_fraction_;
190 return nb_air_particles_;
210 Laguerre_centroids_ = x;
229 linsolve_epsilon_ = eps;
238 linsolve_maxiter_ = maxiter;
247 linesearch_maxiter_ = maxiter;
259 linesearch_init_iter_ = init_iter;
270 epsilon_regularization_ = eps_reg;
282 linear_solver_ = solver;
346 return weights_.size();
357 return &(points_dimp1_[dimp1_ * i]);
384 return points_dimp1_[dimp1_*i + dimension_];
396 index_t n,
double* x,
double& f,
double* g
408 index_t n,
const double* x,
double f,
const double* g,
double gnorm
433 bool show_RVD_seed =
false,
434 bool last_iter_only =
false
437 save_RVD_iter_ =
false;
438 save_RVD_last_iter_ =
true;
442 show_RVD_seed_ = show_RVD_seed;
481 if(user_H_ !=
nullptr) {
536 const double* weights,
NLMatrix Laplacian,
double* measures
546 return nu_.size() == 0 ? constant_nu_ : nu_[p];
603 return ::sqrt(
double(n) *
geo_sqr(epsilon_ * constant_nu_));
653 return (mg_ !=
nullptr);
684 Newton_step_ = Newton;
702 funcval_.assign(nb, 0.0);
732 FOR(i,funcval_.size()) {
733 result += funcval_[i];
755 Delaunay_var delaunay_;
768 std::string last_stats_;
773 bool save_RVD_last_iter_;
Class and functions to compute restricted Voronoi diagrams and extract information from them.
#define geo_debug_assert(x)
Verifies that a condition is met.
bool is_defined(const std::string &name) const
Tests whether an attribute is defined.
AttributesManager & attributes() const
Gets the attributes manager.
Base class for the callbacks executed for each intersection between a Laguerre cell and a simplex of ...
void set_nb_threads(index_t nb)
Specifies the number of threads.
bool has_Laguerre_centroids() const
Tests whether Laguerre centroids should be computed.
bool is_Newton_step() const
Tests whether the current step is a Newton step.
void set_g(double *g)
Specifies where the gradient should be stored.
void set_Newton_step(bool Newton)
Specifies whether current step is a Newton step.
Callback(OptimalTransportMap *OTM)
Callback constructor.
double * Laguerre_centroids()
Gets a pointer to the Laguerre centroids.
void set_eval_F(bool x)
Specifies whether the objective function should be evaluated.
virtual ~Callback()
Callback destructor.
void set_w(const double *w, index_t n)
Sets the weight vector.
double funcval() const
Gets the computed value of the objective function.
void set_Laguerre_centroids(double *mg)
Sets where centroids should be output.
Computes semi-discrete optimal transport maps.
double gradient_threshold(index_t n) const
Computes the stopping criterion of the solver.
OTLinearSolver linear_solver_
one of OT_PRECG, OT_SUPERLU, OT_CHOLMOD.
double nu(index_t p) const
Gets the mass of the Dirac associated with point p.
NLMatrix user_H_
User-defined Hessian matrix.
double air_fraction_
The fraction of the total mass occupied by air.
void set_save_RVD_iter(bool x, bool show_RVD_seed=false, bool last_iter_only=false)
Sets whether the restricted Voronoi diagram at each iteration should be saved.
double measure_of_smallest_cell_
Measure of the smallest Laguerre cell.
void optimize_levels(const vector< index_t > &levels, index_t max_iterations)
Multi-level optimization.
void save_RVD(index_t id)
Saves the RVD at each iteration if specified on command line (just for debugging/ explaining the algo...
bool w_did_not_change_
True if w did not change, thus there is no need to recompute the power diagram.
void set_linsolve_epsilon(double eps)
Sets the tolerance for linear solve.
static void funcgrad_CB(index_t n, double *x, double &f, double *g)
Callback for the numerical solver.
double * Laguerre_centroids_
If user-specified, then Laguerre centroids are output here.
void set_linear_solver(OTLinearSolver solver)
Specifies whether a direct solver should be used.
void set_epsilon(double eps)
Sets the maximum error.
void set_nu(index_t i, double nu)
Sets the desired mass at one of the Diracs.
index_t linsolve_maxiter_
maximum number of iterations for linear solve
double epsilon_regularization_
Add a regularization term to remove translational degree of freedom for the weights.
bool user_H_g_
True if class is just used by user to compute Hessian and gradient instead of doing full computation.
index_t nb_points() const
Gets the number of points.
void set_regularization(double eps_reg)
Sets the weight of the regularization term.
double epsilon_
Acceptable relative deviation for the measure of a cell.
index_t nb_air_particles() const
Gets the number of air particles.
virtual ~OptimalTransportMap()
OptimalTransportMap destructor.
index_t air_particles_stride_
Number of doubles between two consecutive air particles in air_particles_.
OptimalTransportMap(index_t dimension, Mesh *mesh, const std::string &delaunay="default", bool BRIO=false)
OptimalTransportMap constructor.
virtual void get_RVD(Mesh &M)=0
Computes a mesh with the restricted Voronoi diagram.
bool clip_by_balls_
Enabled if air fraction is specified without any air particles.
void set_linesearch_init_iter(index_t init_iter)
Sets the number of steplength reductions to be done at the first iteration.
void solve_linear_system()
Solves a linear system.
const double * air_particles_
if set, pointer to the air particles.
void set_initial_weight(index_t i, double w)
Sets the initial value of the weight associated with one of the points.
double constant_nu_
Value of one of the Diracs if cte.
void new_linear_system(index_t n, double *x)
Starts a new linear system.
double weight(index_t i) const
Gets weight of a point.
void set_air_particles(index_t nb_air_particles, const double *air_particles, index_t stride, double air_fraction)
Sets the air particles that define the volume occupied by the free space.
void compute_P1_Laplacian(const double *weights, NLMatrix Laplacian, double *measures)
Computes the P1 Laplacian of the Laguerre cells.
double potential(index_t i) const
Gets the d+1-th coordinate of the embedding for a point.
void set_linsolve_maxiter(index_t maxiter)
Sets the maximum number of iterations for linear solve.
void set_weight(index_t i, double val)
Sets a weight of a point.
vector< double > nu_
Value of all the Diracs.
index_t nb_air_particles_
if non-zero, number of air particles.
void set_verbose(bool x)
Enable/disable messages during optimization.
static void newiteration_CB(index_t n, const double *x, double f, const double *g, double gnorm)
Callback for the numerical solver.
index_t linesearch_maxiter_
maximum number of steplength divisions
void eval_func_grad_Hessian(index_t n, const double *w, double &f, double *g)
Computes the objective function, its gradient and its Hessian.
RestrictedVoronoiDiagram * RVD()
Gets the restricted Voronoi diagram.
double g_norm_
Norm of the gradient in last iteration.
virtual void call_callback_on_RVD()=0
Calls the callback for each intersection between a Laguerre cell and a simplex of the background mesh...
double air_fraction() const
Gets the air fraction.
virtual void newiteration()
Callback for the numerical solver.
void add_i_right_hand_side(index_t i, double a)
Adds a coefficient to the right hand side.
void optimize(index_t max_iterations)
Computes the weights that realize the optimal transport map between the source mesh and the target po...
double total_mass() const
Gets the total mass of the domain.
virtual void compute_Laguerre_centroids(double *centroids)=0
Computes the centroids of the Laguerre cells.
void set_Laguerre_centroids(double *x)
Specifies a user vector where the centroids of the Laguerre cells will be stored after computing tran...
void optimize_level(index_t b, index_t e, index_t max_iterations)
Optimizes one level of the multilevel algorithm.
void set_linesearch_maxiter(index_t maxiter)
Sets the maximum number of line search iterations.
void update_sparsity_pattern()
Updates the sparsity pattern of the Hessian right after a new Laguerre diagram was computed.
const double * point_ptr(index_t i) const
Gets a point.
Mesh & mesh()
Gets the mesh.
void set_points(index_t nb_points, const double *points, index_t stride=0)
Sets the points that define the target distribution.
void set_Newton(bool x)
Sets whether Newton algorithm should be used.
index_t nbZ_
Number of empty cells in last iteration.
void funcgrad(index_t n, double *w, double &f, double *g)
Computes the objective function and its gradient.
double linsolve_epsilon_
maximum value of
index_t dimension() const
Gets the dimension.
index_t linesearch_init_iter_
starting number of steplength divisions
void add_ij_coefficient(index_t i, index_t j, double a)
Adds a coefficient to the matrix of the system.
index_t dimp1_
dimension_ + 1
void optimize_full_Newton(index_t max_iterations, index_t n=0)
Computes the weights that realize the optimal transport map between the source mesh and the target po...
Computes a Restricted Voronoi Diagram (RVD).
Abstract interface for Delaunay.
#define EXPLORAGRAM_API
Linkage declaration for exploragram symbols.
Included by all headers in exploragram.
The class that represents a mesh.
Global Vorpaline namespace.
T geo_sqr(T x)
Gets the square value of a value.
OTLinearSolver
Specifies the linear solver to be used with OptimalTransport.
geo_index_t index_t
The type for storing and manipulating indices.
The public API of the OpenNL linear solver library. Click the "More..." link below for simple example...
NLAPI NLulong NLAPIENTRY nlAddIJCoefficient(NLuint i, NLuint j, NLdouble value)
Adds a coefficient to the current matrix.
struct NLMatrixStruct * NLMatrix
Opaque handle to a matrix.
NLAPI void NLAPIENTRY nlAddIRightHandSide(NLuint i, NLdouble value)
Adds a coefficient to a component of the right hand side of the equation.
Internal OpenNL functions to manipulate sparse matrices.
The base class for abstract matrices.