root/applications/robust/robustlib.cpp @ 1256

Revision 1254, 2.3 kB (checked in by sindj, 14 years ago)

Rozdelane pocitani integralu. JS

Line 
1#include "robustlib.h"
2
3void polyhedron::triangulate(bool should_integrate)
4        {               
5                for(list<polyhedron*>::iterator child_ref = children.begin();child_ref!=children.end();child_ref++)
6                {
7                        set<double> simplex_integrals;
8                       
9                        for(list<set<vertex*>>::iterator t_ref = (*child_ref)->triangulation.begin();t_ref!=(*child_ref)->triangulation.end();t_ref++)
10                        {
11                                set<vertex*> new_simplex;
12                                new_simplex.insert((*t_ref).begin(),(*t_ref).end());                           
13
14                                pair<set<vertex*>::iterator,bool> ret_val = new_simplex.insert(*vertices.begin());
15
16                                if(ret_val.second == true)
17                                {
18                                        triangulation.push_back(new_simplex);
19
20                                        if(should_integrate)
21                                        {
22                                                toprow* as_toprow = (toprow*)this;
23
24                                                vec cur_condition = as_toprow->condition.get(1,as_toprow->condition.size()-1);
25
26                                                vertex* base_vertex = (*new_simplex.begin());
27
28                                                int dimension = new_simplex.size()-1;
29
30                                                mat jacobian(dimension,dimension);
31
32                                                double a_0 = base_vertex->get_coordinates()*cur_condition+as_toprow->condition[0];
33                                                vec as;
34
35                                                int row_count = 0;
36
37                                                for(set<vertex*>::iterator vert_ref = (++new_simplex.begin()); vert_ref!=new_simplex.end();vert_ref++)
38                                                {
39                                                        vec relative_coords = (*vert_ref)->get_coordinates()-base_vertex->get_coordinates();
40                                                        jacobian.set_row(row_count,relative_coords);
41
42                                                        double new_a = relative_coords*cur_condition;                                                   
43                                                                                                               
44                                                        as.ins(as.size(),new_a);                                                       
45                                                       
46                                                        row_count++;
47                                                }
48
49                                                double int_value = 0;
50                                                for(int a_count = 0;a_count<as.size();a_count++)
51                                                {
52                                                        vec reduced_as = (as.get(a_count)-as);
53
54                                                        reduced_as.del(a_count);
55
56                                                        int fac_order = ((toprow*)this)->condition_order-reduced_as.size()-1;
57
58                                                        double fac_value = ((double)tgamma(fac_order)*det(jacobian))/as[a_count]/pow(as[a_count]-a_0,fac_order); 
59
60                                                        for(int b_count = 0;b_count<reduced_as.size();b_count++)
61                                                        {
62                                                                fac_value /= reduced_as[b_count];                                                               
63                                                        }
64
65                                                        int_value += fac_value;                                                 
66                                                }
67
68                                                simplex_integrals.insert(int_value);
69                                        }
70                                } 
71                        }
72
73                        if(should_integrate)
74                        {
75                                ((toprow*)this)->probability = 0.0;
76
77                                for(set<double>::iterator integ_ref = simplex_integrals.begin();integ_ref!=simplex_integrals.end();integ_ref++)
78                                {
79                                        ((toprow*)this)->probability += (*integ_ref);
80                                }
81                        }
82                }               
83        }
Note: See TracBrowser for help on using the browser.