Changeset 1299 for applications/robust

Show
Ignore:
Timestamp:
03/16/11 17:20:48 (13 years ago)
Author:
sindj
Message:

Skoro dodelano slucovani polyhedronu v pripade odstraneni podminky (bylo nutne udelat znovu, kvuli predchozi ztrate prace zpusebene budto SVN nebo mnou). JS

Location:
applications/robust
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • applications/robust/main.cpp

    r1284 r1299  
    1919 
    2020int main ( int argc, char* argv[] ) { 
    21          
    22          
    2321         
    2422         
     
    8583                                        emliga->add_condition(conditions[k-3]); 
    8684 
    87                                         /* 
    88                                         if(k>5) 
    89                                         { 
    90                                                 cout << "MaxLik coords:" << emliga->minimal_vertex->get_coordinates() << endl; 
    91                                         } 
    92                                         */ 
    93                                 } 
     85                                         
     86                                        //if(k>5) 
     87                                        //{ 
     88                                        //      cout << "MaxLik coords:" << emliga->minimal_vertex->get_coordinates() << endl; 
     89                                        //} 
     90                                         
     91                                }                                
     92                                 
    9493                        } 
    9594 
     
    119118                myfile.close(); 
    120119        } 
    121  
    122          
    123  
    124         //emlig* emlig1 = new emlig(emlig_size); 
     120     
     121 
     122        // emlig* emlig1 = new emlig(emlig_size); 
     123        // emlig* emlig2 = new emlig(emlig_size); 
    125124         
    126125        /* 
     
    142141        }*/ 
    143142         
    144     /* 
     143        /* 
     144    vec condition5 = "-0.3 1.7 1.5"; 
     145        emlig1->add_condition(condition5); 
     146         
    145147        vec condition1 = "1.0 1.0 1.01"; 
    146148        emlig1->add_condition(condition1); 
     149        emlig2->add_condition(condition1); 
    147150 
    148151        vec condition2 = "-1.0 1.0 1.0"; 
    149152        emlig1->add_condition(condition2); 
     153        emlig2->add_condition(condition2); 
    150154 
    151155        vec condition3 = "0.5 -1.01 1.0"; 
    152156        emlig1->add_condition(condition3); 
     157        emlig2->add_condition(condition3); 
     158         
    153159 
    154160        vec condition4 = "-0.5 -1.0 1.0"; 
    155161        emlig1->add_condition(condition4); 
    156  
    157         cout << emlig1->minimal_vertex->get_coordinates(); 
    158  
    159         //vec condition5 = "-0.3 1.7 1.5"; 
    160         //emlig1->add_condition(condition5); 
     162        cout << "************************************************" << endl; 
     163        emlig2->add_condition(condition4); 
     164        cout << "************************************************" << endl; 
     165 
     166        //cout << emlig1->minimal_vertex->get_coordinates(); 
     167 
     168        emlig1->remove_condition(condition5); 
     169        cout << "************************************************" << endl; 
     170         
     171        //emlig1->step_me(0); 
     172        //emlig2->step_me(0); 
     173         
    161174 
    162175        // DA SE POUZIT PRO VYPIS DO SOUBORU 
  • applications/robust/robustlib.cpp

    r1282 r1299  
    44void polyhedron::triangulate(bool should_integrate) 
    55        { 
     6                this->triangulation.clear(); 
     7 
    68                if(should_integrate) 
    79                { 
     
    1416                        { 
    1517                                set<vertex*> new_simplex; 
    16                                 new_simplex.insert((*t_ref).begin(),(*t_ref).end());                             
    17  
    18                                 pair<set<vertex*>::iterator,bool> ret_val = new_simplex.insert(*vertices.begin()); 
    19  
    20                                 if(ret_val.second == true) 
    21                                 { 
     18                                new_simplex.insert((*t_ref).begin(),(*t_ref).end());                     
     19 
     20                                for(set<vertex*>::iterator suitable_vert_ref = vertices.begin();*suitable_vert_ref<*(*t_ref).begin();suitable_vert_ref++) 
     21                                { 
     22                                        new_simplex.insert(*suitable_vert_ref); 
     23 
    2224                                        triangulation.push_back(new_simplex); 
    2325 
     
    2628                                                ((toprow *)this)->probability += ((toprow *)this)->integrate_simplex(new_simplex, 'S'); 
    2729                                        } 
    28                                 }  
     30                                }                                
    2931                        }        
    3032                }                
     
    8789 
    8890                         
    89                                 //cout << endl << "Base coords:" << base_vertex->get_coordinates() << endl; 
     91                                cout << endl << "Base coords:" << base_vertex->get_coordinates() << endl; 
    9092 
    9193                                a_0 = base_vertex->get_coordinates()*cur_condition-as_toprow->condition[0]; 
     
    134136                                                //cout << "a0:" << a_0 << " a0 coords:" << base_vertex->get_coordinates() << " am:" << a_m << " am coords:" << (*vert_ref)->get_coordinates() << endl; 
    135137 
    136                                                 //cout << "Absolute coords:(V"  << row_count << ")" << (*vert_ref)->get_coordinates() << endl; 
     138                                                cout << "Absolute coords:(V"  << row_count << ")" << (*vert_ref)->get_coordinates() << endl; 
    137139                                                //cout << "Relative coords:(V"  << row_count << ")" << relative_coords << endl; 
    138140 
  • applications/robust/robustlib.h

    r1282 r1299  
    4646 
    4747class emlig; 
     48class polyhedron; 
     49 
    4850 
    4951 
     
    6163        int merge_state; 
    6264 
    63          
     65                         
    6466 
    6567public: 
     
    8486        list<polyhedron*> neutralchildren; 
    8587 
    86         list<polyhedron*> totallyneutralgrandchildren; 
    87  
    88         list<polyhedron*> totallyneutralchildren; 
     88        set<polyhedron*> totallyneutralgrandchildren; 
     89 
     90        set<polyhedron*> totallyneutralchildren; 
     91 
     92        set<polyhedron*> grandparents; 
    8993 
    9094        set<vertex*> positiveneutralvertices; 
     
    9498        bool totally_neutral; 
    9599 
    96         list<polyhedron*> mergechildren; 
     100        polyhedron* mergechild; 
    97101 
    98102        polyhedron* positiveparent; 
    99103 
    100         polyhedron* negativeparent; 
     104        polyhedron* negativeparent;      
    101105 
    102106        polyhedron* next_poly; 
     
    132136        { 
    133137                multiplicity--; 
     138        } 
     139 
     140        int get_multiplicity() 
     141        { 
     142                return multiplicity; 
    134143        } 
    135144         
     
    644653                                        if(parent_state == 0) 
    645654                                        { 
    646                                                 current_parent->set_state(child_state, MERGE); 
    647  
    648                                                 if(child_state == 0) 
    649                                                 { 
    650                                                         current_parent->mergechildren.push_back(sender); 
    651                                                 } 
    652                                         } 
    653                                         else 
    654                                         { 
    655                                                 if(child_state == 0) 
    656                                                 { 
    657                                                         if(parent_state > 0) 
     655                                                current_parent->set_state(child_state, MERGE);                                           
     656                                        } 
     657 
     658                                        if(child_state == 0) 
     659                                        { 
     660                                                if(current_parent->mergechild == NULL) 
     661                                                { 
     662                                                        current_parent->mergechild = sender; 
     663                                                }                                                        
     664                                        }                                        
     665 
     666                                        if(is_last) 
     667                                        {                                                
     668                                                if(current_parent->mergechild!=NULL) 
     669                                                { 
     670                                                        if(current_parent->mergechild->get_multiplicity()==1) 
    658671                                                        { 
    659                                                                 sender->positiveparent = current_parent; 
     672                                                                if(parent_state > 0) 
     673                                                                {                                                        
     674                                                                        current_parent->mergechild->positiveparent = current_parent;                                                     
     675                                                                } 
     676 
     677                                                                if(parent_state < 0) 
     678                                                                {                                                        
     679                                                                        current_parent->mergechild->negativeparent = current_parent;                                                     
     680                                                                } 
    660681                                                        } 
    661                                                         else 
    662                                                         { 
    663                                                                 sender->negativeparent = current_parent; 
    664                                                         } 
    665                                                 } 
    666                                         } 
    667  
    668                                         if(is_last) 
    669                                         { 
    670                                                 if(parent_state > 0) 
    671                                                 { 
    672                                                         for(list<polyhedron*>::iterator merge_child = current_parent->mergechildren.begin(); merge_child != current_parent->mergechildren.end();merge_child++) 
    673                                                         { 
    674                                                                 (*merge_child)->positiveparent = current_parent; 
    675                                                         } 
    676                                                 } 
    677  
    678                                                 if(parent_state < 0) 
    679                                                 { 
    680                                                         for(list<polyhedron*>::iterator merge_child = current_parent->mergechildren.begin(); merge_child != current_parent->mergechildren.end();merge_child++) 
    681                                                         { 
    682                                                                 (*merge_child)->negativeparent = current_parent; 
    683                                                         } 
    684                                                 } 
     682                                                } 
     683                                                 
    685684 
    686685                                                if(parent_state == 0) 
    687686                                                { 
    688                                                         for_merging[level+1].push_back(current_parent); 
    689                                                 } 
    690  
    691                                                 current_parent->mergechildren.clear(); 
    692                                         } 
    693  
    694                                          
     687                                                        for_merging[level+1].push_back(current_parent);                                                  
     688                                                } 
     689 
     690                                                current_parent->mergechild = NULL; 
     691                                        }                                        
    695692                                } 
    696693 
    697694                                if(shouldsplit) 
    698695                                        { 
    699                                                 current_parent->totallyneutralgrandchildren.insert(current_parent->totallyneutralgrandchildren.end(),sender->totallyneutralchildren.begin(),sender->totallyneutralchildren.end()); 
     696                                                current_parent->totallyneutralgrandchildren.insert(sender->totallyneutralchildren.begin(),sender->totallyneutralchildren.end()); 
     697 
     698                                                for(set<polyhedron*>::iterator tot_child_ref = sender->totallyneutralchildren.begin();tot_child_ref!=sender->totallyneutralchildren.end();tot_child_ref++) 
     699                                                { 
     700                                                        (*tot_child_ref)->grandparents.insert(current_parent); 
     701                                                } 
    700702 
    701703                                                switch(sender->get_state(SPLIT)) 
     
    721723                                                        if(sender->totally_neutral) 
    722724                                                        { 
    723                                                                 current_parent->totallyneutralchildren.push_back(sender); 
     725                                                                current_parent->totallyneutralchildren.insert(sender); 
    724726                                                        } 
    725727                                                         
     
    733735                                                if(is_last) 
    734736                                                { 
    735                                                         unique(current_parent->totallyneutralgrandchildren.begin(),current_parent->totallyneutralgrandchildren.end()); 
    736  
    737737                                                        if((current_parent->negativechildren.size()>0&&current_parent->positivechildren.size()>0)|| 
    738738                                                                                                                (current_parent->neutralchildren.size()>0&&current_parent->totally_neutral==false)) 
     
    836836        void step_me(int marker) 
    837837        { 
    838                  
     838                /* 
    839839                for(int i = 0;i<statistic.size();i++) 
    840840                { 
     
    849849                        } 
    850850                } 
     851                */ 
    851852 
    852853                /* 
     
    10361037                } 
    10371038 
     1039                if(should_remove) 
     1040                { 
     1041                        set<vertex*> vertices_to_be_reduced;                     
     1042                         
     1043                        int k = 1; 
     1044 
     1045                        for(vector<list<polyhedron*>>::iterator vert_ref = for_merging.begin();vert_ref<for_merging.end();vert_ref++) 
     1046                        { 
     1047                                for(list<polyhedron*>::reverse_iterator merge_ref = vert_ref->rbegin();merge_ref!=vert_ref->rend();merge_ref++) 
     1048                                { 
     1049                                        if((*merge_ref)->get_multiplicity()>1) 
     1050                                        { 
     1051                                                if(k==1) 
     1052                                                { 
     1053                                                        vertices_to_be_reduced.insert((vertex*)(*merge_ref)); 
     1054                                                } 
     1055                                                else 
     1056                                                { 
     1057                                                        (*merge_ref)->lower_multiplicity(); 
     1058                                                } 
     1059                                        } 
     1060                                        else 
     1061                                        { 
     1062                                                toprow* current_positive = (toprow*)(*merge_ref)->positiveparent; 
     1063                                                toprow* current_negative = (toprow*)(*merge_ref)->negativeparent; 
     1064 
     1065                                                current_positive->condition -= toremove; 
     1066                                                current_positive->condition_order--; 
     1067                                                 
     1068                                                current_positive->children.insert(current_positive->children.end(),current_negative->children.begin(),current_negative->children.end()); 
     1069                                                current_positive->children.remove(*merge_ref); 
     1070 
     1071                                                for(list<polyhedron*>::iterator child_ref = current_negative->children.begin();child_ref!=current_negative->children.end();child_ref++) 
     1072                                                { 
     1073                                                        (*child_ref)->parents.remove(current_negative); 
     1074                                                        (*child_ref)->parents.push_back(current_positive); 
     1075                                                } 
     1076                                                 
     1077                                                current_positive->negativechildren.insert(current_positive->negativechildren.end(),current_negative->negativechildren.begin(),current_negative->negativechildren.end());                                                 
     1078                                                 
     1079                                                current_positive->positivechildren.insert(current_positive->positivechildren.end(),current_negative->positivechildren.begin(),current_negative->positivechildren.end()); 
     1080                                                                                                 
     1081                                                current_positive->neutralchildren.insert(current_positive->neutralchildren.end(),current_negative->positivechildren.begin(),current_negative->positivechildren.end()); 
     1082                                         
     1083                                                switch((*merge_ref)->get_state(SPLIT)) 
     1084                                                { 
     1085                                                case -1: 
     1086                                                        current_positive->negativechildren.remove(*merge_ref); 
     1087                                                        break; 
     1088                                                case 0: 
     1089                                                        current_positive->neutralchildren.remove(*merge_ref); 
     1090                                                        break; 
     1091                                                case 1: 
     1092                                                        current_positive->positivechildren.remove(*merge_ref); 
     1093                                                        break; 
     1094                                                } 
     1095 
     1096                                                current_positive->parents.insert(current_positive->parents.begin(),current_negative->parents.begin(),current_negative->parents.end()); 
     1097                                                unique(current_positive->parents.begin(),current_positive->parents.end()); 
     1098 
     1099                                                for(list<polyhedron*>::iterator parent_ref = current_negative->parents.begin();parent_ref!=current_negative->parents.end();parent_ref++) 
     1100                                                { 
     1101                                                        (*parent_ref)->children.remove(current_negative); 
     1102                                                        (*parent_ref)->children.push_back(current_positive); 
     1103                                                } 
     1104 
     1105                                                current_positive->totallyneutralchildren.insert(current_negative->totallyneutralchildren.begin(),current_negative->totallyneutralchildren.end()); 
     1106                                                current_positive->totallyneutralchildren.erase(*merge_ref); 
     1107 
     1108                                                current_positive->totallyneutralgrandchildren.insert(current_negative->totallyneutralgrandchildren.begin(),current_negative->totallyneutralgrandchildren.end()); 
     1109                                                 
     1110                                                current_positive->vertices.insert(current_negative->vertices.begin(),current_negative->vertices.end()); 
     1111                                                current_positive->negativeneutralvertices.insert(current_negative->negativeneutralvertices.begin(),current_negative->negativeneutralvertices.end()); 
     1112                                                current_positive->positiveneutralvertices.insert(current_negative->positiveneutralvertices.begin(),current_negative->positiveneutralvertices.end()); 
     1113                                                 
     1114                                                for(set<vertex*>::iterator vert_ref = (*merge_ref)->vertices.begin();vert_ref!=(*merge_ref)->vertices.end();vert_ref++) 
     1115                                                { 
     1116                                                        if((*vert_ref)->get_multiplicity()==1) 
     1117                                                        { 
     1118                                                                current_positive->vertices.erase(*vert_ref); 
     1119                                                                current_positive->negativeneutralvertices.erase(*vert_ref); 
     1120                                                                current_positive->positiveneutralvertices.erase(*vert_ref); 
     1121                                                        } 
     1122                                                } 
     1123                                                 
     1124                                                if(current_negative->get_state(SPLIT)==0&&!current_negative->totally_neutral) 
     1125                                                { 
     1126                                                        for_splitting[k].remove(current_negative); 
     1127                                                         
     1128                                                        if(current_positive->get_state(SPLIT)!=0||current_positive->totally_neutral) 
     1129                                                        { 
     1130                                                                for_splitting[k].push_back(current_positive); 
     1131                                                        } 
     1132                                                } 
     1133 
     1134                                                if(current_positive->totally_neutral) 
     1135                                                { 
     1136                                                        if(!current_negative->totally_neutral) 
     1137                                                        { 
     1138                                                                for(set<polyhedron*>::iterator grand_ref = current_positive->grandparents.begin();grand_ref!=current_positive->grandparents.end();grand_ref++) 
     1139                                                                { 
     1140                                                                        (*grand_ref)->totallyneutralgrandchildren.erase(current_positive); 
     1141                                                                } 
     1142 
     1143                                                                current_positive->grandparents.clear(); 
     1144                                                        } 
     1145                                                        else 
     1146                                                        { 
     1147                                                                for(set<polyhedron*>::iterator grand_ref = current_negative->grandparents.begin();grand_ref!=current_negative->grandparents.end();grand_ref++) 
     1148                                                                { 
     1149                                                                        (*grand_ref)->totallyneutralgrandchildren.erase(current_negative); 
     1150                                                                        (*grand_ref)->totallyneutralgrandchildren.insert(current_positive); 
     1151                                                                } 
     1152 
     1153                                                                current_positive->grandparents.insert(current_negative->grandparents.begin(),current_negative->grandparents.end()); 
     1154                                                        } 
     1155                                                } 
     1156                                                else 
     1157                                                { 
     1158                                                        if(current_negative->totally_neutral) 
     1159                                                        { 
     1160                                                                for(set<polyhedron*>::iterator grand_ref = current_negative->grandparents.begin();grand_ref!=current_negative->grandparents.end();grand_ref++) 
     1161                                                                { 
     1162                                                                        (*grand_ref)->totallyneutralgrandchildren.erase(current_negative);                                                                       
     1163                                                                } 
     1164                                                        }                                                        
     1165                                                } 
     1166 
     1167                                                current_positive->totally_neutral = (current_positive->totally_neutral && current_negative->totally_neutral); 
     1168 
     1169                                                current_positive->triangulate(k==for_splitting.size()-1); 
     1170                                                 
     1171                                                statistic.delete_polyhedron(k,current_negative); 
     1172 
     1173                                                delete current_negative; 
     1174 
     1175                                                for(list<polyhedron*>::iterator child_ref = (*merge_ref)->children.begin();child_ref!=(*merge_ref)->children.end();child_ref++) 
     1176                                                { 
     1177                                                        (*child_ref)->parents.remove(*merge_ref); 
     1178                                                } 
     1179 
     1180                                                for(list<polyhedron*>::iterator parent_ref = (*merge_ref)->parents.begin();parent_ref!=(*merge_ref)->parents.end();parent_ref++) 
     1181                                                { 
     1182                                                        (*parent_ref)->positivechildren.remove(*merge_ref); 
     1183                                                        (*parent_ref)->negativechildren.remove(*merge_ref); 
     1184                                                        (*parent_ref)->neutralchildren.remove(*merge_ref); 
     1185                                                        (*parent_ref)->children.remove(*merge_ref); 
     1186                                                } 
     1187 
     1188                                                for(set<polyhedron*>::iterator grand_ch_ref = (*merge_ref)->totallyneutralgrandchildren.begin();grand_ch_ref!=(*merge_ref)->totallyneutralgrandchildren.end();grand_ch_ref++) 
     1189                                                { 
     1190                                                        (*grand_ch_ref)->grandparents.erase(*merge_ref); 
     1191                                                } 
     1192 
     1193                                                for(set<polyhedron*>::iterator grand_p_ref = (*merge_ref)->grandparents.begin();grand_p_ref!=(*merge_ref)->grandparents.end();grand_p_ref++) 
     1194                                                { 
     1195                                                        (*grand_p_ref)->totallyneutralgrandchildren.erase(*merge_ref); 
     1196                                                } 
     1197 
     1198                                                statistic.delete_polyhedron(k-1,*merge_ref); 
     1199 
     1200                                                if(k==1) 
     1201                                                { 
     1202                                                        vertices_to_be_reduced.insert((vertex*)(*merge_ref)); 
     1203                                                } 
     1204                                                else 
     1205                                                { 
     1206                                                        delete *merge_ref; 
     1207                                                } 
     1208                                        } 
     1209                                }                        
     1210                         
     1211                                k++; 
     1212 
     1213                        } 
     1214 
     1215                        for(set<vertex*>::iterator vert_ref = vertices_to_be_reduced.begin();vert_ref!=vertices_to_be_reduced.end();vert_ref++) 
     1216                        { 
     1217                                if((*vert_ref)->get_multiplicity()>1) 
     1218                                { 
     1219                                        (*vert_ref)->lower_multiplicity(); 
     1220                                } 
     1221                                else 
     1222                                { 
     1223                                        delete *vert_ref; 
     1224                                } 
     1225                        }                        
     1226                } 
     1227 
    10381228                if(should_add) 
    10391229                { 
     
    10721262                                        { 
    10731263                                                toprow* neutral_toprow = new toprow(); 
    1074  
    1075                                                 neutral_toprow->condition       = zeros(number_of_parameters+1); 
     1264                                                 
     1265                                                neutral_toprow->condition       = ((toprow*)current_polyhedron)->condition; // tohle tu bylo driv: zeros(number_of_parameters+1); 
    10761266                                                neutral_toprow->condition_order = ((toprow*)current_polyhedron)->condition_order+1; 
    10771267 
     
    10851275                                                                                                                                current_polyhedron->totallyneutralgrandchildren.end()); 
    10861276 
    1087                                         for(list<polyhedron*>::iterator grand_ref = current_polyhedron->totallyneutralgrandchildren.begin(); grand_ref != current_polyhedron->totallyneutralgrandchildren.end();grand_ref++) 
    1088                                         { 
    1089                                                 (*grand_ref)->parents.push_back(new_totally_neutral_child); 
    1090  
    1091                                                 new_totally_neutral_child->vertices.insert((*grand_ref)->vertices.begin(),(*grand_ref)->vertices.end()); 
    1092                                         } 
     1277                                         
    10931278 
    10941279                                        // cout << ((toprow*)current_polyhedron)->condition << endl << toadd << endl; 
     
    11001285                                        negative_poly->my_emlig = this; 
    11011286 
     1287                                        for(set<polyhedron*>::iterator grand_ref = current_polyhedron->totallyneutralgrandchildren.begin(); grand_ref != current_polyhedron->totallyneutralgrandchildren.end();grand_ref++) 
     1288                                        { 
     1289                                                (*grand_ref)->parents.push_back(new_totally_neutral_child); 
     1290                                                (*grand_ref)->grandparents.insert(positive_poly); 
     1291                                                (*grand_ref)->grandparents.insert(negative_poly); 
     1292 
     1293                                                new_totally_neutral_child->vertices.insert((*grand_ref)->vertices.begin(),(*grand_ref)->vertices.end()); 
     1294                                        } 
     1295 
     1296                                        positive_poly->children.push_back(new_totally_neutral_child); 
     1297                                        negative_poly->children.push_back(new_totally_neutral_child); 
     1298                                         
     1299 
    11021300                                        for(list<polyhedron*>::iterator parent_ref = current_polyhedron->parents.begin();parent_ref!=current_polyhedron->parents.end();parent_ref++) 
    11031301                                        { 
    1104                                                 (*parent_ref)->totallyneutralgrandchildren.push_back(new_totally_neutral_child); 
     1302                                                (*parent_ref)->totallyneutralgrandchildren.insert(new_totally_neutral_child); 
     1303                                                new_totally_neutral_child->grandparents.insert(*parent_ref); 
    11051304 
    11061305                                                (*parent_ref)->neutralchildren.remove(current_polyhedron); 
     
    11211320                                                                                                                current_polyhedron->parents.end()); 
    11221321 
    1123                                         positive_poly->children.push_back(new_totally_neutral_child); 
    1124                                         negative_poly->children.push_back(new_totally_neutral_child); 
     1322                                         
    11251323 
    11261324                                        new_totally_neutral_child->parents.push_back(positive_poly);