-
Notifications
You must be signed in to change notification settings - Fork 0
/
discrepancy.h
86 lines (80 loc) · 2.65 KB
/
discrepancy.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/******************************************************/
/* */
/* discrepancy.h - compute discrepancy */
/* */
/******************************************************/
/* Copyright 2020,2021 Pierre Abbat.
* This file is part of the Quadlods program.
*
* The Quadlods program is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* Quadlods is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License and Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* and Lesser General Public License along with Quadlods. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <vector>
#include <array>
#include "threads.h"
/* This computes the discrepancy using a genetic algorithm like that invented
* by Manan Shah. Each individual is a box; its fitness is its discrepancy.
* In each generation, the least fit boxes die, and the remaining boxes have
* children, with occasional mutations.
*/
#define sizeMismatch 1
double areaInCircle(double minx,double miny,double maxx,double maxy);
void setFlowerDisc(bool fd);
class Box
{
public:
Box();
Box(std::vector<double> pnt0,std::vector<double> pnt1);
Box(Box &mother,Box &father);
int in(const std::vector<double> &point);
void countPoints(const std::vector<std::vector<double> > &points);
double discrepancy();
int getPointsTotal()
{
return pointsTotal;
}
void mutate(const std::vector<std::vector<double> > &points,int pntnum=-1,int coord=-1);
void dump();
friend bool operator==(const Box &l,const Box &r);
private:
std::vector<std::array<double,2> > bounds;
double volume;
int pointsIn,pointsBound,pointsTotal;
};
struct BoxCountItem
{
Box *box;
const std::vector<std::vector<double> > &points;
};
class BoxCountBlock
{
public:
BoxCountBlock();
void load(std::vector<Box> &population,int begin,int end,const std::vector<std::vector<double> > &points);
BoxCountItem getItem();
void countFinished();
bool done();
int getLeft()
{
return left;
}
private:
std::vector<Box> *pop;
int b,e,left;
const std::vector<std::vector<double> > *pts;
std::mutex mtx;
};
double discrepancy(const std::vector<std::vector<double> > &points,bool keepPop=false);
bool countAnyBlock();