DCBraidReduction.h

Go to the documentation of this file.
00001 // Contents: Classes implementing divide and conquer algorithm for braid reduction
00002 
00003 //
00004 // Principal Author: Alexei Miasnikov (2006)
00005 //
00006 // Status:
00007 //
00008 // Revision History:
00009 //
00010 
00011 #ifndef DC_BRAID_REDUCTION_H
00012 #define DC_BRAID_REDUCTION_H
00013 
00014 #include <list>
00015 #include "Word.h"
00016 #include "ShortBraidForm.h"
00017 #include <iterator>
00018 
00019 class Partition
00020 {
00021  public:
00022   virtual list<int> getPartition(const Word& w )=0;
00023 };
00024 
00025 class Perturbation
00026 {
00027  public:
00028   virtual Word perturb( const Word& w)=0;
00029 };
00030 
00031 class UniformPartition : public Partition
00032 {
00033  public:
00034   UniformPartition(){}
00035   list<int> getPartition(const Word& w ){
00036     list<int> indices;
00037 
00038     int k=10;  
00039     int segment = int(w.length() / k);
00040     int last_segment = w.length() - k*int(w.length() / k);
00041     
00042     for( int i=1;i<k-1;i++)
00043       indices.push_back(segment*i);
00044     
00045     if (last_segment  >= segment / 2){
00046       indices.push_back(segment*(k-1));
00047       indices.push_back(segment*(k-1)+ last_segment );
00048     } else {
00049       indices.push_back(segment*(k-1) + last_segment);
00050     }
00051     return indices;
00052   }
00053 
00054 };
00055 
00056 
00057 struct CommDivider
00058 {
00059   int length;
00060   int begin;
00061   int end;
00062   int gen;
00063   friend ostream& operator << (ostream& out, const CommDivider& cd){
00064     out << "( " << cd.length << " : " << cd.gen <<  " | " 
00065         << cd.begin << " , " << cd.end << " )" << flush;
00066     return out;
00067   }
00068 };
00069 
00070 struct lCommDivider
00071 {
00072   bool operator () (const CommDivider& c1,const CommDivider& c2 ) {
00073     return (c1.length < c2.length);
00074   }
00075 };
00076 
00077 class MaxCommutePartition
00078 {
00079  public:
00080   MaxCommutePartition( int n, const Word& w ): N(n-1)
00081     {
00082       findCommutParts( w );
00083     }
00084   
00085     const vector<CommDivider>& getPartition() const { return partition; }
00086 
00087  private:
00088   void findCommutParts( const Word& w ){
00089     
00090     
00091     int i=0;
00092     int LEN_THRESHOLD = 5;
00093 
00094     vector<int> positions(N+2,-1); // +2 for the left and right padding
00095     //vector<int> lastPos(N+2,0);
00096     
00097     for (ConstWordIterator wI=w.begin();wI!=w.end();wI++,i++){
00098       Generator g = *wI;
00099       int absg = abs(g);
00100       int pos = max(positions[absg],max(positions[absg-1],positions[absg+1])) + 1;
00101       
00102       if ( pos - positions[absg] > LEN_THRESHOLD) {
00103         if (absg > 1 && absg < N-1 ){
00104           CommDivider cd;
00105           cd.length = pos - positions[absg];
00106           cd.begin = positions[absg] + 1;
00107           cd.end = pos - 1;
00108           cd.gen = absg;
00109           partition.push_back( cd );
00110         }
00111       }
00112 
00113       //      lastPos[absg]   = positions[absg];
00114       positions[absg] = pos;
00115       
00116     }
00117     sort(partition.begin(),partition.end(),lCommDivider());
00118     copy(partition.begin(),partition.end(),ostream_iterator<CommDivider>(cout,"\n"));
00119   }
00120  private:
00121   int N;
00122   vector<CommDivider> partition;
00123 };
00124 
00125 
00126 
00127 //
00128 //
00129 //   DCBraidReduction
00130 //
00131 //
00132 
00133 class DCBraidReduction
00134 {
00135  public:
00136   DCBraidReduction(int n, Perturbation* pert, Partition* part): 
00137     thePerturb( pert ),
00138     thePartition( part ),
00139     N( n ) {}
00140   
00141 
00142   Word shorten( const Word& w ) const {
00143     Word sw = shortenBraid( N, w );
00144     list<int> indices = thePartition->getPartition( w );
00145     list<int>::const_iterator iI = indices.begin();
00146     int c_index = *iI;
00147 
00148     Word result;
00149     int i=0;
00150     for( WordIterator I=sw.begin();I!=sw.end();I++,i++){
00151       Word p_w;
00152       if ( i < c_index || iI == indices.end())
00153         p_w.push_back(*I);
00154       else {
00155         result *= shortenBraid(N,p_w);
00156         p_w = Word();
00157         iI++;
00158         c_index = *I;
00159       }
00160     }
00161     
00162     cout << result << endl;
00163     return result;
00164   }
00165  private:
00166 
00167   int N;
00168   Perturbation* thePerturb;
00169   Partition*    thePartition;
00170   
00171 };
00172 
00173 
00174 
00175 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Mon Sep 26 18:43:45 2011 for CRyptography And Groups (CRAG) by  doxygen 1.6.1