/* Point_brute.cpp - Find a brain-dead brute-force solution James S. Plank CS494/594 Lecture notes. Fri May 15 16:38:07 EDT 2020 */ #include "points.hpp" #include #include #include #include #include #include #include using namespace std; typedef std::runtime_error SRE; int main(int argc, char **argv) { Points points; vector x, best; double d; double granularity; double max; size_t i; bool done; if (argc != 2) { fprintf(stderr, "usage: points_brute granularity - points on stdin\n"); exit(1); } if (sscanf(argv[1], "%lf", &granularity) != 1) { fprintf(stderr, "Bad granularity\n"); exit(0); } /* Read the points from stdin. */ try { points.Read(cin); } catch (const SRE &e) { fprintf(stderr, "Error reading points on stdin:\n%s\n", e.what()); exit(1); } /* Run through all of the points that you're going to graph, and find the one that optimizes the equation. */ max = 0; x.resize(points.p[0].size(), 1); done = false; while (!done) { d = points.Min_Distance(x); if (d > max) { max = d; best = x; } for (i = 0; i < x.size(); i++) { x[i] += granularity; if (x[i] <= 9) break; x[i] = 1; } done = (i == x.size()); } printf("Best x:"); for (i = 0; i < best.size(); i++) printf(" %lg", best[i]); printf("\n"); printf("Max: %lg\n", max); return 0; }