Changeset 1299 for applications/robust
- Timestamp:
- 03/16/11 17:20:48 (14 years ago)
- Location:
- applications/robust
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/robust/main.cpp
r1284 r1299 19 19 20 20 int main ( int argc, char* argv[] ) { 21 22 23 21 24 22 … … 85 83 emliga->add_condition(conditions[k-3]); 86 84 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 94 93 } 95 94 … … 119 118 myfile.close(); 120 119 } 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); 125 124 126 125 /* … … 142 141 }*/ 143 142 144 /* 143 /* 144 vec condition5 = "-0.3 1.7 1.5"; 145 emlig1->add_condition(condition5); 146 145 147 vec condition1 = "1.0 1.0 1.01"; 146 148 emlig1->add_condition(condition1); 149 emlig2->add_condition(condition1); 147 150 148 151 vec condition2 = "-1.0 1.0 1.0"; 149 152 emlig1->add_condition(condition2); 153 emlig2->add_condition(condition2); 150 154 151 155 vec condition3 = "0.5 -1.01 1.0"; 152 156 emlig1->add_condition(condition3); 157 emlig2->add_condition(condition3); 158 153 159 154 160 vec condition4 = "-0.5 -1.0 1.0"; 155 161 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 161 174 162 175 // DA SE POUZIT PRO VYPIS DO SOUBORU -
applications/robust/robustlib.cpp
r1282 r1299 4 4 void polyhedron::triangulate(bool should_integrate) 5 5 { 6 this->triangulation.clear(); 7 6 8 if(should_integrate) 7 9 { … … 14 16 { 15 17 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 22 24 triangulation.push_back(new_simplex); 23 25 … … 26 28 ((toprow *)this)->probability += ((toprow *)this)->integrate_simplex(new_simplex, 'S'); 27 29 } 28 } 30 } 29 31 } 30 32 } … … 87 89 88 90 89 //cout << endl << "Base coords:" << base_vertex->get_coordinates() << endl;91 cout << endl << "Base coords:" << base_vertex->get_coordinates() << endl; 90 92 91 93 a_0 = base_vertex->get_coordinates()*cur_condition-as_toprow->condition[0]; … … 134 136 //cout << "a0:" << a_0 << " a0 coords:" << base_vertex->get_coordinates() << " am:" << a_m << " am coords:" << (*vert_ref)->get_coordinates() << endl; 135 137 136 //cout << "Absolute coords:(V" << row_count << ")" << (*vert_ref)->get_coordinates() << endl;138 cout << "Absolute coords:(V" << row_count << ")" << (*vert_ref)->get_coordinates() << endl; 137 139 //cout << "Relative coords:(V" << row_count << ")" << relative_coords << endl; 138 140 -
applications/robust/robustlib.h
r1282 r1299 46 46 47 47 class emlig; 48 class polyhedron; 49 48 50 49 51 … … 61 63 int merge_state; 62 64 63 65 64 66 65 67 public: … … 84 86 list<polyhedron*> neutralchildren; 85 87 86 list<polyhedron*> totallyneutralgrandchildren; 87 88 list<polyhedron*> totallyneutralchildren; 88 set<polyhedron*> totallyneutralgrandchildren; 89 90 set<polyhedron*> totallyneutralchildren; 91 92 set<polyhedron*> grandparents; 89 93 90 94 set<vertex*> positiveneutralvertices; … … 94 98 bool totally_neutral; 95 99 96 list<polyhedron*> mergechildren;100 polyhedron* mergechild; 97 101 98 102 polyhedron* positiveparent; 99 103 100 polyhedron* negativeparent; 104 polyhedron* negativeparent; 101 105 102 106 polyhedron* next_poly; … … 132 136 { 133 137 multiplicity--; 138 } 139 140 int get_multiplicity() 141 { 142 return multiplicity; 134 143 } 135 144 … … 644 653 if(parent_state == 0) 645 654 { 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) 658 671 { 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 } 660 681 } 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 685 684 686 685 if(parent_state == 0) 687 686 { 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 } 695 692 } 696 693 697 694 if(shouldsplit) 698 695 { 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 } 700 702 701 703 switch(sender->get_state(SPLIT)) … … 721 723 if(sender->totally_neutral) 722 724 { 723 current_parent->totallyneutralchildren. push_back(sender);725 current_parent->totallyneutralchildren.insert(sender); 724 726 } 725 727 … … 733 735 if(is_last) 734 736 { 735 unique(current_parent->totallyneutralgrandchildren.begin(),current_parent->totallyneutralgrandchildren.end());736 737 737 if((current_parent->negativechildren.size()>0&¤t_parent->positivechildren.size()>0)|| 738 738 (current_parent->neutralchildren.size()>0&¤t_parent->totally_neutral==false)) … … 836 836 void step_me(int marker) 837 837 { 838 838 /* 839 839 for(int i = 0;i<statistic.size();i++) 840 840 { … … 849 849 } 850 850 } 851 */ 851 852 852 853 /* … … 1036 1037 } 1037 1038 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 1038 1228 if(should_add) 1039 1229 { … … 1072 1262 { 1073 1263 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); 1076 1266 neutral_toprow->condition_order = ((toprow*)current_polyhedron)->condition_order+1; 1077 1267 … … 1085 1275 current_polyhedron->totallyneutralgrandchildren.end()); 1086 1276 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 1093 1278 1094 1279 // cout << ((toprow*)current_polyhedron)->condition << endl << toadd << endl; … … 1100 1285 negative_poly->my_emlig = this; 1101 1286 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 1102 1300 for(list<polyhedron*>::iterator parent_ref = current_polyhedron->parents.begin();parent_ref!=current_polyhedron->parents.end();parent_ref++) 1103 1301 { 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); 1105 1304 1106 1305 (*parent_ref)->neutralchildren.remove(current_polyhedron); … … 1121 1320 current_polyhedron->parents.end()); 1122 1321 1123 positive_poly->children.push_back(new_totally_neutral_child); 1124 negative_poly->children.push_back(new_totally_neutral_child); 1322 1125 1323 1126 1324 new_totally_neutral_child->parents.push_back(positive_poly);