Skip to content

Instantly share code, notes, and snippets.

@Hermann-SW
Created July 9, 2024 20:04
Show Gist options
  • Save Hermann-SW/b06abedde9798dce072bd262fe349c58 to your computer and use it in GitHub Desktop.
Save Hermann-SW/b06abedde9798dce072bd262fe349c58 to your computer and use it in GitHub Desktop.
Determination of convex set diameter with Miniball.hpp
#include <cstdlib>
#include <iostream>
#include <math.h>
#include "Miniball.hpp"
// from https://people.inf.ethz.ch/gaertner/subdir/software/miniball.html
/*
$ g++ miniball_int.cpp -O3 -o miniball_int
$
*/
int main (int argc, char* argv[])
{
typedef double mytype;
int d = 3;
int n = 48;
typedef mytype mytype3[d];
mytype A[n][3] = {{89,-21,-5},{152,-36,-9},{-16,4,1},{47,-11,-3},{261,-62,-15},{-75,18,5},{177,-42,-11},{-159,38,9},{265,-63,-15},{-71,17,5},{328,-78,-19},{-176,42,11},{244,-58,-15},{-260,62,15},{139,-33,-9},{-197,47,11},{101,-24,-5},{353,-84,-21},{-319,76,19},{-67,16,3},{168,-40,-9},{0,0,1},{357,-85,-21},{-315,75,19},{315,-75,-19},{-357,85,21},{0,0,-1},{-168,40,9},{67,-16,-3},{319,-76,-19},{-353,84,21},{-101,24,5},{197,-47,-11},{-139,33,9},{260,-62,-15},{-244,58,15},{176,-42,-11},{-328,78,19},{71,-17,-5},{-265,63,15},{159,-38,-9},{-177,42,11},{75,-18,-5},{-261,62,15},{-47,11,3},{16,-4,-1},{-152,36,9},{-89,21,5}};
mytype** ap = new mytype*[n];
for (int i=0; i<n; ++i) {
mytype* p = new mytype[d];
for (int j=0; j<d; ++j) {
p[j] = A[i][j];
}
ap[i]=p;
}
typedef mytype* const* PointIterator;
typedef const mytype* CoordIterator;
typedef Miniball::
Miniball <Miniball::CoordAccessor<PointIterator, CoordIterator> >
MB;
MB mb (d, ap, ap+n);
std::cout << "Center:\n ";
const mytype* center = mb.center();
for(int i=0; i<d; ++i, ++center)
std::cout << *center << " ";
std::cout << std::endl;
std::cout << "diameter:\n ";
std::cout << 2*sqrt(mb.squared_radius()) << std::endl;
std::cout << "Number of support points:\n ";
std::cout << mb.nr_support_points() << std::endl;
std::cout << "Relative error:\n ";
mytype suboptimality;
std::cout << mb.relative_error (suboptimality) << std::endl;
std::cout << "Suboptimality:\n ";
std::cout << suboptimality << std::endl;
std::cout << "Validity:\n ";
std::cout << (mb.is_valid() ? "ok" : "possibly invalid") << std::endl;
std::cout << "Computation time was "<< mb.get_time() << " seconds\n";
return 0;
}
@Hermann-SW
Copy link
Author

https://math.stackexchange.com/a/4943873/1084297

$ ./miniball_int 
Center:
  0 0 0 
diameter:
  735.16
Number of support points:
  2
Relative error:
  0
Suboptimality:
  0
Validity:
  ok
Computation time was 1.1e-05 seconds
$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment