root/applications/robust/robustlib.cpp @ 1266

Revision 1262, 2.9 kB (checked in by sindj, 13 years ago)

Dodelavani korekcnich faktoru pri stjene hodnote funkce ve dvou bodech polyhedronu. Rozdelano. 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                                                map<double,int> 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                                                        pair<map<double,int>::iterator,bool> returned = as.insert(pair<double,int>(new_a,1));
45                                                        if(returned.second == false)
46                                                        {
47                                                                (*returned.first).second++;
48                                                        }
49                                                        //as.ins(as.size(),new_a);                                                     
50                                                       
51                                                        row_count++;
52                                                }
53
54                                                double int_value = 0;
55                                                for(map<double,int>::iterator as_ref = as.begin();as_ref!=as.end();as_ref++)
56                                                {
57                                                        int fac_order = ((toprow*)this)->condition_order-as.size()-1;
58
59                                                        double fac_value = 1;
60                                                        if(a_0!=(*as_ref).first)
61                                                        {
62                                                                //fac_value = ((double)tgamma(fac_order)*det(jacobian))/(*as_ref).first/pow((*as_ref).first-a_0,fac_order);
63                                                               
64                                                                fac_value /= (*as_ref).first;
65
66                                                                for(map<double,int>::iterator as2_ref = as.begin();as2_ref!=as.end();as2_ref++)
67                                                                {
68                                                                        if(as2_ref!=as_ref)
69                                                                        {
70                                                                                double current_factor = (*as_ref).first-(*as2_ref).first;
71
72                                                                                fac_value /= current_factor;
73
74                                                                                                                                                               
75                                                                        }
76                                                                }
77                                                        }
78                                                        else
79                                                        {
80                                                                throw new exception("Should this happen? a_i=a_0 in the formula for integrating over a simplex! I think it can happen with 0 probability(when phi*2*v_0=phi*v_i)");
81                                                        }
82
83                                                       
84                                                        int_value += fac_value;                                                 
85                                                }
86
87                                                simplex_integrals.insert(int_value);
88                                        }
89                                } 
90                        }
91
92                        if(should_integrate)
93                        {
94                                ((toprow*)this)->probability = 0.0;
95
96                                for(set<double>::iterator integ_ref = simplex_integrals.begin();integ_ref!=simplex_integrals.end();integ_ref++)
97                                {
98                                        ((toprow*)this)->probability += (*integ_ref);
99                                }
100                        }
101                }               
102        }
Note: See TracBrowser for help on using the browser.