aboutsummaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
authorAndreas Grois <andreas.grois@jku.at>2015-11-06 13:45:57 +0100
committerAndreas Grois <andreas.grois@jku.at>2015-11-06 13:45:57 +0100
commit4aa67d78e9238a65eb94a762328465e2541fd4c4 (patch)
tree3711d160e87be100f8f31ba806a47b7efa600e56 /main.cpp
parent05714900ad7c1638237749e88faae3ecdb19649e (diff)
Combine and sort results
This change introduces (experimental and not very clean) combining of results. It might be worth writing a disjoint angle range class to get cleaner code here, as the while loops at the end are quite far from being beautiful. In addition the output ranges are sorted by their lower border. I'm using Lambda expressions for this, so C+11 is required. Also, this is currently completely untested.
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp83
1 files changed, 82 insertions, 1 deletions
diff --git a/main.cpp b/main.cpp
index 1620ff4..51e9506 100644
--- a/main.cpp
+++ b/main.cpp
@@ -67,6 +67,7 @@
#include <vector>
#include <cmath>
#include <cstdio>
+#include <algorithm>
#include "anglerange.h"
using namespace std;
@@ -352,7 +353,7 @@ int main(int argc, char* argv[])
}
}
}
-
+/*
cout << "Possible coincident lattice matches with px, qx:" << std::endl;
for(i=0;i<xoverlaps.size();i++)
{
@@ -363,6 +364,86 @@ int main(int argc, char* argv[])
{
cout << (yoverlaps.at(i)).getlower().getval()*180/M_PI << " " << (yoverlaps.at(i)).getupper().getval()*180/M_PI << std::endl;
}
+*/
+ //to make the output more readable, combine the ranges.
+ //first: copy xranges and yranges together:
+ std::vector<anglerange> ranges;
+ ranges.reserve(xoverlaps.size()+yoverlaps.size()+1);
+ ranges.insert(ranges.end(),xoverlaps.begin(),xoverlaps.end());
+ ranges.insert(ranges.end(),yoverlaps.begin(),yoverlaps.end());
+ if(ranges.size()>1) //combining elements only makes sense, if there are at least 2 elements to combine...
+ {
+ bool stop;
+ do
+ {
+ i=0;
+ stop=false;
+ do
+ {
+ j=i+1;
+ do
+ {
+ anglerange tmp = ranges.at(i).combine(ranges.at(j));
+ if(!(tmp.isempty()))
+ {
+ stop=true;
+ ranges.push_back(tmp);
+ ranges.erase(ranges.begin()+j);
+ ranges.erase(ranges.begin()+i);
+ }
+ j++;
+ }
+ while(!stop && j<ranges.size());
+ i++;
+ }
+ while(!stop && i<ranges.size()-1); //the -1 is there, as for i=ranges.size() there is no valid j any more.
+ }
+ while(stop); //yes, here is stop, not !stop, as stop means: stop to iterate over elements, go back to main loop, which should only terminate, if the internal loops finished.
+ }
+
+ //the same thing for commensurate...
+ if(commensurate.size()>1)
+ {
+ bool stop;
+ do
+ {
+ i=0;
+ stop=false;
+ do
+ {
+ j=i+1;
+ do
+ {
+ anglerange tmp = commensurate.at(i).combine(commensurate.at(j));
+ if(!(tmp.isempty()))
+ {
+ stop=true;
+ commensurate.push_back(tmp);
+ commensurate.erase(commensurate.begin()+j);
+ commensurate.erase(commensurate.begin()+i);
+ }
+ j++;
+ }
+ while(!stop && j<commensurate.size());
+ i++;
+ }
+ while(!stop && i<commensurate.size()-1); //the -1 is there, as for i=commensurate.size() there is no valid j any more.
+ }
+ while(stop); //yes, here is stop, not !stop, as stop means: stop to iterate over elements, go back to main loop, which should only terminate, if the internal loops finished.
+ }
+
+ //again,for readability: sort the ranges by their lower limit:
+ {
+ std::sort(ranges.begin(),ranges.end(),[](const anglerange &a,const anglerange &b){return(a.getlower()<b.getlower());});
+ std::sort(commensurate.begin(),commensurate.end(),[](const anglerange &a,const anglerange &b){return(a.getlower()<b.getlower());});
+ }
+
+
+ cout << "Possible coincident lattice matches:" << std::endl;
+ for(i=0;i<ranges.size();i++)
+ {
+ cout << (ranges.at(i)).getlower().getval()*180/M_PI << " " << (ranges.at(i)).getupper().getval()*180/M_PI << std::endl;
+ }
cout << "Possible commensurate lattice matches:" << std::endl;
for(i=0;i<commensurate.size();i++)
{