#include #include #include #include // variables ----------------------------------------------------------------- int n[6]; // Aantal waarnemingen per behandeling // n[0] : controle behandeling // n[1] : voor beh. 1 // n[2] : voor beh. 2 // n[3] : voor beh. 3 // n[4] : voor beh. 4 // n[5] : voor beh. 5 int db; // voor debug mode.. int sw; // voor swap; int bb; // voor BB; int ppr; int beh; // aantal beh zonder controle struct pverd { long lengte; // hoeveel elementen zitten erin ? float *coef; // array[..] of float, voor coefficienten int *x1; int *x2; int *x3; int *x4; int *x5; }; struct pfunctie { long lengte; int *f1; int *f2; int *f3; int *f4; int *f5; }; // rangnummer array: int *rang; int *code; // array waar codes instaan van te behandelen cellen; int incd; // aantal cellen voor gegeven n1,n2,n3 int *tempcode; // zelfde als code, maar dan temp, om onderliggende code // op te slaan. int *plaatscode; // om goed te kunnen sorteren... int *codegehad; // om bij te houden welke codes al geweest zijn voor // swap. // indicator functie : int **IND; // permutatiematrix : pfunctie *****PM; double aantal_groter_dan_k=0; // aantal groter dan gegeven k; // P matrix voor polynomen : pverd ******P; // functions ----------------------------------------------------------------- void clrscr() { // voor UNIX : system("clear"); } //---------------------------------------------------------------------------- double fac(double x) { // fac(0)=fac(1) = 1; if ((x==0)||(x==1)) return 1; else return (x*fac(x-1)); } //---------------------------------------------------------------------------- double bino(int a, int b, int c, int d, int e, int f) { // multinomiaalcoef : // fac(a+b+c+d+e+f) / (fac(a)*fac(b)*....*fac(f)); int totaal[] = {a,b,c,d,e,f}; double deling = fac(totaal[0]+totaal[1]+totaal[2]+ totaal[3]+totaal[4]+totaal[5]); int i; for (i=0 ; i <= 5 ; i++) deling /= fac(totaal[i]); return deling; } //---------------------------------------------------------------------------- void printcel(int a1,int a2, int a3, int a4, int a5, int gr) { // bekijk PM[a1]...[a5] long i; for (i=0 ; i < PM[a1][a2][a3][a4][a5].lengte ; i++) { if (gr>=1) cout << PM[a1][a2][a3][a4][a5].f1[i] << " "; if (gr>=2) cout << PM[a1][a2][a3][a4][a5].f2[i] << " "; if (gr>=3) cout << PM[a1][a2][a3][a4][a5].f3[i] << " "; if (gr>=4) cout << PM[a1][a2][a3][a4][a5].f4[i] << " "; if (gr>=5) cout << PM[a1][a2][a3][a4][a5].f5[i] << " "; cout << endl; } cout << endl << PM[a1][a2][a3][a4][a5].lengte << endl; } //---------------------------------------------------------------------------- void print(int *q, int a1, int a2, int a3, int a4, int a5, int h) { // voeg toe aan cel : PM[a1][...][a5]. long tmpl = PM[a1][a2][a3][a4][a5].lengte; int I1=1; int j; for (j=0 ; j<=3 ; j++) { if ((h>j) && (q[j]>q[j+1])) I1=0; } if (I1==0) { if (h>=0) PM[a1][a2][a3][a4][a5].f1[tmpl] = q[0]; if (h>=1) PM[a1][a2][a3][a4][a5].f2[tmpl] = q[1]; if (h>=2) PM[a1][a2][a3][a4][a5].f3[tmpl] = q[2]; if (h>=3) PM[a1][a2][a3][a4][a5].f4[tmpl] = q[3]; if (h>=4) PM[a1][a2][a3][a4][a5].f5[tmpl] = q[4]; PM[a1][a2][a3][a4][a5].lengte++; } } //---------------------------------------------------------------------------- void plus(int *t, int *c, int l, int h) { int j=0; for (int i=l ; i<=h ; i++) t[i] = c[j++]; } //---------------------------------------------------------------------------- void permutate(int *p, int a1, int a2, int a3, int a4, int a5, int s, int l) { // permutates the string p, from index s to l; // p[s] ... p[l]; if (s==l) print(p,a1,a2,a3,a4,a5,l); else if (s+1==l) { // hold identity : print(p,a1,a2,a3,a4,a5,l); // swap last one : int h = p[l-1]; p[l-1] = p[l]; p[l] = h; print(p,a1,a2,a3,a4,a5,l); } else { int *n2 = new int[l-s]; int i,j,k,b; for (i=s ; i<= l ; i++) { k=0; b=p[i]; for (j=s ; j<=l ; j++) if (i!=j) n2[k++] = p[j]; // n2[] is piece after element s. int *p2 = new int[l+1]; // copy : for (int z=0 ; z<=l ; z++) p2[z] = p[z]; // make new string, where b is placed at the // beginning (index s) and n2 pasted behind. p2[s] = b; plus(p2,n2,s+1,l); permutate(p2,a1,a2,a3,a4,a5,s+1,l); } } } //---------------------------------------------------------------------------- void reserveerdimP() { int i; int j; int k; int l; int m; // reserveer 6 dimensies! P = new(pverd*****[n[0]+1]); for (i=0 ; i<=n[0] ; i++) P[i] = new(pverd****[n[1]+1]); for (i=0 ; i<=n[0] ; i++) for (j=0 ; j<=n[1] ; j++) P[i][j] = new(pverd***[n[2]+1]); for (i=0 ; i<=n[0] ; i++) for (j=0 ; j<=n[1] ; j++) for (k=0 ; k<=n[2] ; k++) P[i][j][k] = new(pverd**[n[3]+1]); for (i=0 ; i<=n[0] ; i++) for (j=0 ; j<=n[1] ; j++) for (k=0 ; k<=n[2] ; k++) for (l=0 ; l<=n[3] ; l++) P[i][j][k][l] = new(pverd*[n[4]+1]); for (i=0 ; i<=n[0] ; i++) for (j=0 ; j<=n[1] ; j++) for (k=0 ; k<=n[2] ; k++) for (l=0 ; l<=n[3] ; l++) for (m=0 ; m<=n[4] ; m++) P[i][j][k][l][m] = new(pverd[n[5]+1]); // maak indicator functie : // IND IND = new int*[6]; // 0..5; for (i=0 ; i<=5 ; i++) IND[i] = new int[6]; } //---------------------------------------------------------------------------- void initPM() { int i; int j; int k; int l; int m; // 0..4 : PM = new(pfunctie****[5]); for (i=0 ; i<= 4 ; i++) PM[i] = new(pfunctie***[5]); for (i=0 ; i<= 4 ; i++) for (j=0 ; j<= 4 ; j++) PM[i][j] = new(pfunctie**[5]); for (i=0 ; i<= 4 ; i++) for (j=0 ; j<= 4 ; j++) for (k=0 ; k<= 4 ; k++) PM[i][j][k] = new(pfunctie*[5]); for (i=0 ; i<= 4 ; i++) for (j=0 ; j<= 4 ; j++) for (k=0 ; k<= 4 ; k++) for (l=0 ; l<= 4 ; l++) PM[i][j][k][l] = new(pfunctie[5]); // alle lengtes op 0 zetten : for (i=0 ; i<= 4 ; i++) for (j=0 ; j<= 4 ; j++) for (k=0 ; k<= 4 ; k++) for (l=0 ; l<= 4 ; l++) for (m=0 ; m<= 4 ; m++) PM[i][j][k][l][m].lengte = 0; // opvullen matrix : // voor 4 behandelingen perm : // PM[1][1][1][1] // 100% // lengte wordt gelijk aan 23 : PM[1][1][1][1][0].lengte = 0; PM[1][1][1][1][0].f1 = new int[23]; PM[1][1][1][1][0].f2 = new int[23]; PM[1][1][1][1][0].f3 = new int[23]; PM[1][1][1][1][0].f4 = new int[23]; int pp[] = {1,2,3,4}; permutate(pp,1,1,1,1,0, 0,3); // printcel(1,1,1,1,0, 4); // 2 1 1 // 100% PM[2][1][1][0][0].lengte = 11; PM[2][1][1][0][0].f1 = new int[11]; PM[2][1][1][0][0].f2 = new int[11]; PM[2][1][1][0][0].f3 = new int[11]; PM[2][1][1][0][0].f4 = new int[11]; PM[2][1][1][0][0].f1[0] = 1; PM[2][1][1][0][0].f2[0] = 2; PM[2][1][1][0][0].f3[0] = 4; PM[2][1][1][0][0].f4[0] = 3; PM[2][1][1][0][0].f1[1] = 1; PM[2][1][1][0][0].f2[1] = 3; PM[2][1][1][0][0].f3[1] = 2; PM[2][1][1][0][0].f4[1] = 4; PM[2][1][1][0][0].f1[2] = 1; PM[2][1][1][0][0].f2[2] = 3; PM[2][1][1][0][0].f3[2] = 4; PM[2][1][1][0][0].f4[2] = 2; PM[2][1][1][0][0].f1[3] = 1; PM[2][1][1][0][0].f2[3] = 4; PM[2][1][1][0][0].f3[3] = 2; PM[2][1][1][0][0].f4[3] = 3; PM[2][1][1][0][0].f1[4] = 1; PM[2][1][1][0][0].f2[4] = 4; PM[2][1][1][0][0].f3[4] = 3; PM[2][1][1][0][0].f4[4] = 2; PM[2][1][1][0][0].f1[5] = 2; PM[2][1][1][0][0].f2[5] = 3; PM[2][1][1][0][0].f3[5] = 1; PM[2][1][1][0][0].f4[5] = 4; PM[2][1][1][0][0].f1[6] = 2; PM[2][1][1][0][0].f2[6] = 3; PM[2][1][1][0][0].f3[6] = 4; PM[2][1][1][0][0].f4[6] = 1; PM[2][1][1][0][0].f1[7] = 2; PM[2][1][1][0][0].f2[7] = 4; PM[2][1][1][0][0].f3[7] = 1; PM[2][1][1][0][0].f4[7] = 3; PM[2][1][1][0][0].f1[8] = 2; PM[2][1][1][0][0].f2[8] = 4; PM[2][1][1][0][0].f3[8] = 3; PM[2][1][1][0][0].f4[8] = 1; PM[2][1][1][0][0].f1[9] = 3; PM[2][1][1][0][0].f2[9] = 4; PM[2][1][1][0][0].f3[9] = 1; PM[2][1][1][0][0].f4[9] = 2; PM[2][1][1][0][0].f1[10] = 3; PM[2][1][1][0][0].f2[10] = 4; PM[2][1][1][0][0].f3[10] = 2; PM[2][1][1][0][0].f4[10] = 1; // 1 2 1 // 100% PM[1][2][1][0][0].lengte = 11; PM[1][2][1][0][0].f1 = new int[11]; PM[1][2][1][0][0].f2 = new int[11]; PM[1][2][1][0][0].f3 = new int[11]; PM[1][2][1][0][0].f4 = new int[11]; PM[1][2][1][0][0].f1[0] = 4; PM[1][2][1][0][0].f2[0] = 2; PM[1][2][1][0][0].f3[0] = 3; PM[1][2][1][0][0].f4[0] = 1; PM[1][2][1][0][0].f1[1] = 3; PM[1][2][1][0][0].f2[1] = 2; PM[1][2][1][0][0].f3[1] = 1; PM[1][2][1][0][0].f4[1] = 4; PM[1][2][1][0][0].f1[2] = 4; PM[1][2][1][0][0].f2[2] = 2; PM[1][2][1][0][0].f3[2] = 1; PM[1][2][1][0][0].f4[2] = 3; PM[1][2][1][0][0].f1[3] = 2; PM[1][2][1][0][0].f2[3] = 1; PM[1][2][1][0][0].f3[3] = 3; PM[1][2][1][0][0].f4[3] = 4; PM[1][2][1][0][0].f1[4] = 4; PM[1][2][1][0][0].f2[4] = 1; PM[1][2][1][0][0].f3[4] = 3; PM[1][2][1][0][0].f4[4] = 2; PM[1][2][1][0][0].f1[5] = 2; PM[1][2][1][0][0].f2[5] = 1; PM[1][2][1][0][0].f3[5] = 4; PM[1][2][1][0][0].f4[5] = 3; PM[1][2][1][0][0].f1[6] = 3; PM[1][2][1][0][0].f2[6] = 1; PM[1][2][1][0][0].f3[6] = 4; PM[1][2][1][0][0].f4[6] = 2; PM[1][2][1][0][0].f1[7] = 1; PM[1][2][1][0][0].f2[7] = 2; PM[1][2][1][0][0].f3[7] = 4; PM[1][2][1][0][0].f4[7] = 3; PM[1][2][1][0][0].f1[8] = 3; PM[1][2][1][0][0].f2[8] = 2; PM[1][2][1][0][0].f3[8] = 4; PM[1][2][1][0][0].f4[8] = 1; PM[1][2][1][0][0].f1[9] = 1; PM[1][2][1][0][0].f2[9] = 4; PM[1][2][1][0][0].f3[9] = 3; PM[1][2][1][0][0].f4[9] = 2; PM[1][2][1][0][0].f1[10] = 2; PM[1][2][1][0][0].f2[10] = 4; PM[1][2][1][0][0].f3[10] = 3; PM[1][2][1][0][0].f4[10] = 1; // 1 1 2 // 100% PM[1][1][2][0][0].lengte = 11; PM[1][1][2][0][0].f1 = new int[11]; PM[1][1][2][0][0].f2 = new int[11]; PM[1][1][2][0][0].f3 = new int[11]; PM[1][1][2][0][0].f4 = new int[11]; PM[1][1][2][0][0].f1[0] = 2; PM[1][1][2][0][0].f2[0] = 1; PM[1][1][2][0][0].f3[0] = 3; PM[1][1][2][0][0].f4[0] = 4; PM[1][1][2][0][0].f1[1] = 3; PM[1][1][2][0][0].f2[1] = 4; PM[1][1][2][0][0].f3[1] = 1; PM[1][1][2][0][0].f4[1] = 2; PM[1][1][2][0][0].f1[2] = 4; PM[1][1][2][0][0].f2[2] = 3; PM[1][1][2][0][0].f3[2] = 1; PM[1][1][2][0][0].f4[2] = 2; PM[1][1][2][0][0].f1[3] = 4; PM[1][1][2][0][0].f2[3] = 2; PM[1][1][2][0][0].f3[3] = 3; PM[1][1][2][0][0].f4[3] = 1; PM[1][1][2][0][0].f1[4] = 2; PM[1][1][2][0][0].f2[4] = 4; PM[1][1][2][0][0].f3[4] = 3; PM[1][1][2][0][0].f4[4] = 1; PM[1][1][2][0][0].f1[5] = 2; PM[1][1][2][0][0].f2[5] = 3; PM[1][1][2][0][0].f3[5] = 1; PM[1][1][2][0][0].f4[5] = 4; PM[1][1][2][0][0].f1[6] = 3; PM[1][1][2][0][0].f2[6] = 2; PM[1][1][2][0][0].f3[6] = 1; PM[1][1][2][0][0].f4[6] = 4; PM[1][1][2][0][0].f1[7] = 1; PM[1][1][2][0][0].f2[7] = 4; PM[1][1][2][0][0].f3[7] = 3; PM[1][1][2][0][0].f4[7] = 2; PM[1][1][2][0][0].f1[8] = 4; PM[1][1][2][0][0].f2[8] = 1; PM[1][1][2][0][0].f3[8] = 3; PM[1][1][2][0][0].f4[8] = 2; PM[1][1][2][0][0].f1[9] = 1; PM[1][1][2][0][0].f2[9] = 3; PM[1][1][2][0][0].f3[9] = 2; PM[1][1][2][0][0].f4[9] = 4; PM[1][1][2][0][0].f1[10] = 3; PM[1][1][2][0][0].f2[10] = 1; PM[1][1][2][0][0].f3[10] = 2; PM[1][1][2][0][0].f4[10] = 4; // 3 1 // 100% PM[3][1][0][0][0].lengte = 3; PM[3][1][0][0][0].f1 = new int[3]; PM[3][1][0][0][0].f2 = new int[3]; PM[3][1][0][0][0].f3 = new int[3]; PM[3][1][0][0][0].f4 = new int[3]; PM[3][1][0][0][0].f1[0] = 1; PM[3][1][0][0][0].f2[0] = 2; PM[3][1][0][0][0].f3[0] = 4; PM[3][1][0][0][0].f4[0] = 3; PM[3][1][0][0][0].f1[1] = 1; PM[3][1][0][0][0].f2[1] = 3; PM[3][1][0][0][0].f3[1] = 4; PM[3][1][0][0][0].f4[1] = 2; PM[3][1][0][0][0].f1[2] = 2; PM[3][1][0][0][0].f2[2] = 3; PM[3][1][0][0][0].f3[2] = 4; PM[3][1][0][0][0].f4[2] = 1; // 1 3 // 100% PM[1][3][0][0][0].lengte = 3; PM[1][3][0][0][0].f1 = new int[3]; PM[1][3][0][0][0].f2 = new int[3]; PM[1][3][0][0][0].f3 = new int[3]; PM[1][3][0][0][0].f4 = new int[3]; PM[1][3][0][0][0].f1[0] = 2; PM[1][3][0][0][0].f2[0] = 1; PM[1][3][0][0][0].f3[0] = 3; PM[1][3][0][0][0].f4[0] = 4; PM[1][3][0][0][0].f1[1] = 3; PM[1][3][0][0][0].f2[1] = 4; PM[1][3][0][0][0].f3[1] = 1; PM[1][3][0][0][0].f4[1] = 2; PM[1][3][0][0][0].f1[2] = 4; PM[1][3][0][0][0].f2[2] = 3; PM[1][3][0][0][0].f3[2] = 2; PM[1][3][0][0][0].f4[2] = 1; // 2 2 // 100% PM[2][2][0][0][0].lengte = 5; PM[2][2][0][0][0].f1 = new int[5]; PM[2][2][0][0][0].f2 = new int[5]; PM[2][2][0][0][0].f3 = new int[5]; PM[2][2][0][0][0].f4 = new int[5]; PM[2][2][0][0][0].f1[0] = 1; PM[2][2][0][0][0].f2[0] = 3; PM[2][2][0][0][0].f3[0] = 2; PM[2][2][0][0][0].f4[0] = 4; PM[2][2][0][0][0].f1[1] = 1; PM[2][2][0][0][0].f2[1] = 4; PM[2][2][0][0][0].f3[1] = 2; PM[2][2][0][0][0].f4[1] = 3; PM[2][2][0][0][0].f1[2] = 2; PM[2][2][0][0][0].f2[2] = 4; PM[2][2][0][0][0].f3[2] = 1; PM[2][2][0][0][0].f4[2] = 3; PM[2][2][0][0][0].f1[3] = 3; PM[2][2][0][0][0].f2[3] = 4; PM[2][2][0][0][0].f3[3] = 1; PM[2][2][0][0][0].f4[3] = 2; PM[2][2][0][0][0].f1[4] = 3; PM[2][2][0][0][0].f2[4] = 2; PM[2][2][0][0][0].f3[4] = 1; PM[2][2][0][0][0].f4[4] = 4; } //---------------------------------------------------------------------------- void initP() { int i; int j; int k; int l; int m; int p; // maak hele matrix leeg; // elke struct is reserveerd, maar niet gereserveerd mbt. string- // ruimte; for (i=0 ; i<=n[0] ; i++) for (j=0 ; j<=n[1] ; j++) for (k=0 ; k<=n[2] ; k++) for (l=0 ; l<=n[3] ; l++) for (m=0 ; m<=n[4] ; m++) for (p=0 ; p<=n[5] ; p++) P[i][j][k][l][m][p].lengte = 0; // init plaats opvullen..., deze bestaat altijd. P[0][0][0][0][0][0].lengte = 1; P[0][0][0][0][0][0].coef = new float[1]; P[0][0][0][0][0][0].coef[0] = 1; P[0][0][0][0][0][0].x1 = new int[1]; P[0][0][0][0][0][0].x1[0] = 0; P[0][0][0][0][0][0].x2 = new int[1]; P[0][0][0][0][0][0].x2[0] = 0; P[0][0][0][0][0][0].x3 = new int[1]; P[0][0][0][0][0][0].x3[0] = 0; P[0][0][0][0][0][0].x4 = new int[1]; P[0][0][0][0][0][0].x4[0] = 0; P[0][0][0][0][0][0].x5 = new int[1]; P[0][0][0][0][0][0].x5[0] = 0; } //---------------------------------------------------------------------------- void swapelement(int *v, int i, int j) { // verwissel in v element i met j om; // dit is om codestring te sorteren int h1,h2,h3,h4,h5,h6; // h := i; h1= v[i*6]; h2= v[i*6+1]; h3= v[i*6+2]; h4= v[i*6+3]; h5= v[i*6+4]; h6= v[i*6+5]; // i := j; v[i*6] = v[j*6]; v[i*6+1] = v[j*6+1]; v[i*6+2] = v[j*6+2]; v[i*6+3] = v[j*6+3]; v[i*6+4] = v[j*6+4]; v[i*6+5] = v[j*6+5]; // j := h; v[j*6] = h1; v[j*6+1] = h2; v[j*6+2] = h3; v[j*6+3] = h4; v[j*6+4] = h5; v[j*6+5] = h6; } //---------------------------------------------------------------------------- int elcompare(int *v, int i, int l) { // voor codestring if ((v[i*6]+v[i*6+1]+v[i*6+2]+v[i*6+3]+v[i*6+4]+v[i*6+5]) < (v[l*6]+v[l*6+1]+v[l*6+2]+v[l*6+3]+v[l*6+4]+v[l*6+5])) return -1; else return 1; } //---------------------------------------------------------------------------- void qsortstring(int *v, int l, int h) { // sorteer v met behulp van quicksort methode; // om codestring te sorteren. int i ,last; if (l>=h) return; // dan namelijk niks meer te sorteren; last =l; for (i=l+1; i<=h ; i++) if ( elcompare(v,i,l) < 0 ) swapelement(v,++last,i); swapelement(v,l,last); qsortstring(v,l,last-1); qsortstring(v,last+1,h); } //---------------------------------------------------------------------------- int elcompare2(int *v, int i, int l) { // voor codestring // als i < l dan return -1 anders 1; // dus als i oplopend en l niet, dan wisselen, anders niks... // eerste getal van code niet nodig... int j; int I1=1; for (j=1 ; j<=4 ; j++) { // bekijk i'de code in array : if ( (n[j]>0) && (n[j+1]>0) ) if (v[i*6+j] > v[i*6+j+1]) I1=0; } int I2=1; for (j=1 ; j<=4 ; j++) { // bekijk l'de code in array : if ( (n[j]>0) && (n[j+1]>0) ) if (v[l*6+j] > v[l*6+j+1]) I2=0; } if ((I1==1) && (I2==0)) return -1; if (I1==I2) return 0; if ((I1==0) && (I2==1)) return 1; } //---------------------------------------------------------------------------- void qsortstring2(int *v, int l, int h) { // sorteer v met behulp van quicksort methode; // om codestring te sorteren. int i ,last; if (l>=h) return; // dan namelijk niks meer te sorteren; last =l; for (i=l+1; i<=h ; i++) if ( elcompare2(v,i,l) < 0 ) swapelement(v,++last,i); swapelement(v,l,last); qsortstring2(v,l,last-1); qsortstring2(v,last+1,h); } //---------------------------------------------------------------------------- int elementcomp(pverd v, long i, long l) { // als v[i] < v[j] return -1; // als v[i] = v[j] return 0; // als v[i] > v[j] return 1; // 103 < 201 etc. if (n[1]==0) return 0; else if ( (v.x1[i] == v.x1[l]) && (n[1]>0) ) { // tweede element bekijken; if (n[2]==0) return 0; else if ( (v.x2[i] == v.x2[l]) && (n[2]>0) ) { // derde element bekijken; if (n[3]==0) return 0; else if ( (v.x3[i] == v.x3[l]) && (n[3]>0) ) { // vierde element bekijken; if (n[4]==0) return 0; else if ( (v.x4[i] == v.x4[l]) && (n[4]>0) ) { // vijfde element bekijken. if (n[5]==0) return 0; if ( (v.x5[i] == v.x5[l]) && (n[5]>0) ) return 0; // alles gelijk! if ( (v.x5[i] < v.x5[l]) && (n[5]>0) ) return -1; if ( (v.x5[i] > v.x5[l]) && (n[5]>0) ) return 1; } else { if ( (v.x4[i] < v.x4[l]) && (n[4]>0) ) return -1; if ( (v.x4[i] > v.x4[l]) && (n[4]>0) ) return 1; } } else { if ( (v.x3[i] < v.x3[l]) && (n[3]>0) ) return -1; if ( (v.x3[i] > v.x3[l]) && (n[3]>0) ) return 1; } } else { if ( (v.x2[i] < v.x2[l]) && (n[2]>0) ) return -1; if ( (v.x2[i] > v.x2[l]) && (n[2]>0) ) return 1; } } else { if ( (v.x1[i] < v.x1[l]) && (n[1]>0) ) return -1; if ( (v.x1[i] > v.x1[l]) && (n[1]>0) ) return 1; } } //---------------------------------------------------------------------------- int comp2(pverd p1, long i, pverd p2, long j, int rangx1, int rangx2, int rangx3, int rangx4, int rangx5) { // als v[i] < v[j] return -1; // als v[i] = v[j] return 0; // als v[i] > v[j] return 1; // 103 < 201 etc. if (n[1]==0) return 0; else if ( (p1.x1[i] == p2.x1[j] + rangx1) && (n[1]>0) ) { // tweede element bekijken; if (n[2]==0) return 0; else if ( (p1.x2[i] == p2.x2[j]+rangx2) && (n[2]>0) ) { // derde element bekijken; if (n[3]==0) return 0; else if ( (p1.x3[i] == p2.x3[j]+rangx3) && (n[3]>0) ) { // vierde element bekijken; if (n[4]==0) return 0; else if ( (p1.x4[i] == p2.x4[j]+rangx4) && (n[4]>0) ) { // vijfde element bekijken. if (n[5]==0) return 0; if ( (p1.x5[i] == p2.x5[j]+rangx5) && (n[5]>0) ) return 0; // alles gelijk! if ( (p1.x5[i] < p2.x5[j]+rangx5) && (n[5]>0) ) return -1; if ( (p1.x5[i] > p2.x5[j]+rangx5) && (n[5]>0) ) return 1; } else { if ( (p1.x4[i] < p2.x4[j]+rangx4) && (n[4]>0) ) return -1; if ( (p1.x4[i] > p2.x4[j]+rangx4) && (n[4]>0) ) return 1; } } else { if ( (p1.x3[i] < p2.x3[j]+rangx3) && (n[3]>0) ) return -1; if ( (p1.x3[i] > p2.x3[j]+rangx3) && (n[3]>0) ) return 1; } } else { if ( (p1.x2[i] < p2.x2[j]+rangx2) && (n[2]>0) ) return -1; if ( (p1.x2[i] > p2.x2[j]+rangx2) && (n[2]>0) ) return 1; } } else { if ( (p1.x1[i] < p2.x1[j]+rangx1) && (n[1]>0) ) return -1; if ( (p1.x1[i] > p2.x1[j]+rangx1) && (n[1]>0) ) return 1; } } //---------------------------------------------------------------------------- void swap(pverd v, long i, long j) { // verwissel in v element i met j om; int h1,h2,h3,h4,h5; float c; // h := i; if (n[1]>0) h1 = v.x1[i]; if (n[2]>0) h2 = v.x2[i]; if (n[3]>0) h3 = v.x3[i]; if (n[4]>0) h4 = v.x4[i]; if (n[5]>0) h5 = v.x5[i]; c = v.coef[i]; // i := j; if (n[1]>0) v.x1[i] = v.x1[j]; if (n[2]>0) v.x2[i] = v.x2[j]; if (n[3]>0) v.x3[i] = v.x3[j]; if (n[4]>0) v.x4[i] = v.x4[j]; if (n[5]>0) v.x5[i] = v.x5[j]; v.coef[i] = v.coef[j]; // j := h; if (n[1]>0) v.x1[j] = h1; if (n[2]>0) v.x2[j] = h2; if (n[3]>0) v.x3[j] = h3; if (n[4]>0) v.x4[j] = h4; if (n[5]>0) v.x5[j] = h5; v.coef[j] = c; } //---------------------------------------------------------------------------- void qsort(pverd v, long l, long h) { // sorteer v met behulp van quicksort methode; // aanroep : qsort(s,0,s.lengte-1); long i ,last; if (l>=h) return; // dan namelijk niks meer te sorteren; last =l; for (i=l+1; i<=h ; i++) if ( elementcomp(v,i,l)<0 ) swap(v,++last,i); swap(v,l,last); qsort(v,l,last-1); qsort(v,last+1,h); } //---------------------------------------------------------------------------- void mergesort(pverd &total, pverd tmp, long p) { // pak van plaatsen 0 en plaats p om te beginnen // total is gereserveerd! long i=0; // doorloop eerste gedeelte; long j=p; // doorloop tweede gedeelte; long t=0; // doorloop total; int l; do { if ( (i<=p-1) && (j <= tmp.lengte-1) ) { l = elementcomp(tmp,i,j); if (l>0) { // kopieer j eerst naar total; total.coef[t] = tmp.coef[j]; if (n[1]>0) total.x1[t] = tmp.x1[j]; if (n[2]>0) total.x2[t] = tmp.x2[j]; if (n[3]>0) total.x3[t] = tmp.x3[j]; if (n[4]>0) total.x4[t] = tmp.x4[j]; if (n[5]>0) total.x5[t] = tmp.x5[j]; j++; t++; } else if (l<0) { // kopieer i eerst naar total; total.coef[t] = tmp.coef[i]; if (n[1]>0) total.x1[t] = tmp.x1[i]; if (n[2]>0) total.x2[t] = tmp.x2[i]; if (n[3]>0) total.x3[t] = tmp.x3[i]; if (n[4]>0) total.x4[t] = tmp.x4[i]; if (n[5]>0) total.x5[t] = tmp.x5[i]; i++; t++; } } else if ((i==p) && (j<=tmp.lengte-1)) { // alleen uit j kopieren : total.coef[t] = tmp.coef[j]; if (n[1]>0) total.x1[t] = tmp.x1[j]; if (n[2]>0) total.x2[t] = tmp.x2[j]; if (n[3]>0) total.x3[t] = tmp.x3[j]; if (n[4]>0) total.x4[t] = tmp.x4[j]; if (n[5]>0) total.x5[t] = tmp.x5[j]; j++; t++; } else if ((i<=p-1) && (j==tmp.lengte)) { // alleen uit i kopieren : total.coef[t] = tmp.coef[i]; if (n[1]>0) total.x1[t] = tmp.x1[i]; if (n[2]>0) total.x2[t] = tmp.x2[i]; if (n[3]>0) total.x3[t] = tmp.x3[i]; if (n[4]>0) total.x4[t] = tmp.x4[i]; if (n[5]>0) total.x5[t] = tmp.x5[i]; i++; t++; } } while ( !(i==p && j==tmp.lengte) ); // total.lengte is bekend total.lengte = t; } //---------------------------------------------------------------------------- void printP(int a, int b, int c, int d, int e, int f) { // gooi naar scherm double coeff=0; if (P[a][b][c][d][e][f].lengte == 0) { cout << "P["; if (n[0]>0) cout << a; if (n[1]>0) cout << "," << b; if (n[2]>0) cout << "," << c; if (n[3]>0) cout << "," << d; if (n[4]>0) cout << "," << e; if (n[5]>0) cout << "," << f; cout << "]\n...Cel leeg... " << endl; } else if (P[a][b][c][d][e][f].lengte == -1) { cout << "P["; if (n[0]>0) cout << a; if (n[1]>0) cout << "," << b; if (n[2]>0) cout << "," << c; if (n[3]>0) cout << "," << d; if (n[4]>0) cout << "," << e; if (n[5]>0) cout << "," << f; cout <<"]\n...Cel leeggemaakt, niet meer vullen. " << endl; } else { cout << "P["; if (n[0]>0) cout << a; if (n[1]>0) cout << "," << b; if (n[2]>0) cout << "," << c; if (n[3]>0) cout << "," << d; if (n[4]>0) cout << "," << e; if (n[5]>0) cout << "," << f; cout <<"]\n"; for (long i=0 ; i < P[a][b][c][d][e][f].lengte ; i++) { cout << P[a][b][c][d][e][f].coef[i] << " "; coeff += P[a][b][c][d][e][f].coef[i] ; if (n[1]>0) cout << "* X1["<< P[a][b][c][d][e][f].x1[i] << "]"; if (n[2]>0) cout << "* X2["<< P[a][b][c][d][e][f].x2[i] << "]"; if (n[3]>0) cout << "* X3["<< P[a][b][c][d][e][f].x3[i] << "]"; if (n[4]>0) cout << "* X4["<< P[a][b][c][d][e][f].x4[i] << "]"; if (n[5]>0) cout << "* X5["<< P[a][b][c][d][e][f].x5[i] << "]"; if (i0) { som1 = 0; for (l=0 ; l <= uu[k]-1 ; l++) som1 += (uu[0] + uu[k] - l); for (l=0 ; l <= n[k]-uu[k]-1 ; l++) som1 += (n[0] + n[k] - l); if (som1 < ss) return 1; } } return 0; } } //---------------------------------------------------------------------------- void maakcode(float k2) { // code is al gereserveerd incd=0; // globale var = aantal codes int i,j,k,l,m,p; for (i=0; i<= n[0] ; i++) for (j=0; j<= n[1] ; j++) for (k=0; k<= n[2] ; k++) for (l=0; l<= n[3] ; l++) for (m=0; m<= n[4] ; m++) for (p=0; p<= n[5] ; p++) { code[6*incd] = i; code[6*incd+1] = j; code[6*incd+2] = k; code[6*incd+3] = l; code[6*incd+4] = m; code[6*incd+5] = p; incd++; } // qsortstring(code,0,incd-1); } //---------------------------------------------------------------------------- void maaksubcodes(int a1 , int a2 , int a3 , int a4 , int a5 , int a6 , int &aantaltempcodes2) { aantaltempcodes2=0; int i=0; if (a1>=1) { tempcode[6*i] = a1-1; tempcode[6*i+1] = a2; tempcode[6*i+2] = a3; tempcode[6*i+3] = a4; tempcode[6*i+4] = a5; tempcode[6*i+5] = a6; i++; aantaltempcodes2++; } if (a2>=1) { tempcode[6*i] = a1; tempcode[6*i+1] = a2-1; tempcode[6*i+2] = a3; tempcode[6*i+3] = a4; tempcode[6*i+4] = a5; tempcode[6*i+5] = a6; i++; aantaltempcodes2++; } if (a3>=1) { tempcode[6*i] = a1; tempcode[6*i+1] = a2; tempcode[6*i+2] = a3-1; tempcode[6*i+3] = a4; tempcode[6*i+4] = a5; tempcode[6*i+5] = a6; i++; aantaltempcodes2++; } if (a4>=1) { tempcode[6*i] = a1; tempcode[6*i+1] = a2; tempcode[6*i+2] = a3; tempcode[6*i+3] = a4-1; tempcode[6*i+4] = a5; tempcode[6*i+5] = a6; i++; aantaltempcodes2++; } if (a5>=1) { tempcode[6*i] = a1; tempcode[6*i+1] = a2; tempcode[6*i+2] = a3; tempcode[6*i+3] = a4; tempcode[6*i+4] = a5-1; tempcode[6*i+5] = a6; i++; aantaltempcodes2++; } if (a6>=1) { tempcode[6*i] = a1; tempcode[6*i+1] = a2; tempcode[6*i+2] = a3; tempcode[6*i+3] = a4; tempcode[6*i+4] = a5; tempcode[6*i+5] = a6-1; i++; aantaltempcodes2++; } } //---------------------------------------------------------------------------- void vulP(int a1, int a2, int a3, int a4, int a5, int a6, int aantaltempcodes) { // om code in te lezen. int b1; int b2; int b3; int b4; int b5; int b6; // aan welke behandeling moet worden toegekend ? int I1,I2,I3,I4,I5,I6; long i; // welk rangnummer moet worden toegekend ? int rangtemp; if (aantaltempcodes==1) { // er is maar 1 code b1=tempcode[0]; b2=tempcode[1]; b3=tempcode[2]; b4=tempcode[3]; b5=tempcode[4]; b6=tempcode[5]; if (P[b1][b2][b3][b4][b5][b6].lengte>=0) { // er is maar 1 code // doe vermenigvuldiging en schrijf naar // P[a1][a2][a3][a4][a5][a6] long templ = P[b1][b2][b3][b4][b5][b6].lengte; P[a1][a2][a3][a4][a5][a6].coef = new(float[templ]); if (n[1]>0) P[a1][a2][a3][a4][a5][a6].x1 = new(int[templ]); if (n[2]>0) P[a1][a2][a3][a4][a5][a6].x2 = new(int[templ]); if (n[3]>0) P[a1][a2][a3][a4][a5][a6].x3 = new(int[templ]); if (n[4]>0) P[a1][a2][a3][a4][a5][a6].x4 = new(int[templ]); if (n[5]>0) P[a1][a2][a3][a4][a5][a6].x5 = new(int[templ]); P[a1][a2][a3][a4][a5][a6].lengte = templ; // er is er altijd maar eentje 1, de rest altijd 0. I1 = (a1-b1 > 0); // aan controle toevoegen.. I2 = (a2-b2 > 0); // aan beh1 toevoegen.. I3 = (a3-b3 > 0); // .. I4 = (a4-b4 > 0); I5 = (a5-b5 > 0); I6 = (a6-b6 > 0); // aan beh5 toevoegen if (I1) rangtemp = 0; // geen rang optellen... else rangtemp = rang[a1+I2*a2+I3*a3+I4*a4+I5*a5+I6*a6-1]; for (i=0 ; i0) P[a1][a2][a3][a4][a5][a6].x1[i] = P[b1][b2][b3][b4][b5][b6].x1[i]+I2*rangtemp; if (n[2]>0) P[a1][a2][a3][a4][a5][a6].x2[i] = P[b1][b2][b3][b4][b5][b6].x2[i]+I3*rangtemp; if (n[3]>0) P[a1][a2][a3][a4][a5][a6].x3[i] = P[b1][b2][b3][b4][b5][b6].x3[i]+I4*rangtemp; if (n[4]>0) P[a1][a2][a3][a4][a5][a6].x4[i] = P[b1][b2][b3][b4][b5][b6].x4[i]+I5*rangtemp; if (n[5]>0) P[a1][a2][a3][a4][a5][a6].x5[i] = P[b1][b2][b3][b4][b5][b6].x5[i]+I6*rangtemp; } } else if (P[b1][b2][b3][b4][b5][b6].lengte == -1) { // hoeft geen ruimte te reserveren // struct is er al. P[a1][a2][a3][a4][a5][a6].lengte = -1; } } else { // minstens 2 codes aanwezig pverd temp1; pverd temp2; // reserveer lengte van temp1 en temp2 zeker groot genoeg!.. long aantalres=0; for (i=0 ; i=0) { aantalres += P[tempcode[6*i]][tempcode[6*i+1]][tempcode[6*i+2]] [tempcode[6*i+3]][tempcode[6*i+4]][tempcode[6*i+5]].lengte; } } // aantalres = aantal plaatsen van alle codes! // reserveer genoeg ruimte voor temp1 en temp2 // later teruggeven aan compiler! temp1.lengte = 0; temp1.coef = new(float[aantalres]); if (n[1]>0) temp1.x1 = new(int[aantalres]); if (n[2]>0) temp1.x2 = new(int[aantalres]); if (n[3]>0) temp1.x3 = new(int[aantalres]); if (n[4]>0) temp1.x4 = new(int[aantalres]); if (n[5]>0) temp1.x5 = new(int[aantalres]); temp2.lengte = 0; temp2.coef = new(float[aantalres]); if (n[1]>0) temp2.x1 = new(int[aantalres]); if (n[2]>0) temp2.x2 = new(int[aantalres]); if (n[3]>0) temp2.x3 = new(int[aantalres]); if (n[4]>0) temp2.x4 = new(int[aantalres]); if (n[5]>0) temp2.x5 = new(int[aantalres]); // long i was al gedefinieerd. long j; int test; long k=0; int l; long nn; // init eerste code naar temp1; // dus vul temp1 met eerste code; int welke=1; // of 2. // Eerste code zit dus in temp1. // pak eerste code in array b1=tempcode[0]; b2=tempcode[1]; b3=tempcode[2]; b4=tempcode[3]; b5=tempcode[4]; b6=tempcode[5]; if (P[b1][b2][b3][b4][b5][b6].lengte == -1) { // dan temp1 ook lengte -1 // reserveren is al gebeurd! temp1.lengte = -1; } else if (P[b1][b2][b3][b4][b5][b6].lengte>=0) // dus lengte is eigenlijk al > 0 { // er is altijd maar Ij=1, de rest altijd 0. I1 = (a1-b1 > 0); // aan controle toevoegen.. I2 = (a2-b2 > 0); // aan beh1 toevoegen.. I3 = (a3-b3 > 0); // .. I4 = (a4-b4 > 0); I5 = (a5-b5 > 0); I6 = (a6-b6 > 0); // aan beh5 toevoegen if (I1) rangtemp = 0; // geen rang optellen... else rangtemp = rang[a1+I2*a2+I3*a3+I4*a4+I5*a5+I6*a6-1]; for (i=0 ; i < P[b1][b2][b3][b4][b5][b6].lengte ; i++) { // doe vermenigvuldiging meteen! temp1.coef[i] = P[b1][b2][b3][b4][b5][b6].coef[i]; if (n[1]>0) temp1.x1[i] = P[b1][b2][b3][b4][b5][b6].x1[i]+I2*rangtemp; if (n[2]>0) temp1.x2[i] = P[b1][b2][b3][b4][b5][b6].x2[i]+I3*rangtemp; if (n[3]>0) temp1.x3[i] = P[b1][b2][b3][b4][b5][b6].x3[i]+I4*rangtemp; if (n[4]>0) temp1.x4[i] = P[b1][b2][b3][b4][b5][b6].x4[i]+I5*rangtemp; if (n[5]>0) temp1.x5[i] = P[b1][b2][b3][b4][b5][b6].x5[i]+I6*rangtemp; } temp1.lengte = P[b1][b2][b3][b4][b5][b6].lengte; } // alles gereserveerd! // doorloop alle nn codes! // eerste codes is al in temp1 geschreven! // dus nn = 1..aantaltempcodes -1 for (nn=1 ; nn < aantaltempcodes ; nn++) { // pak n^e code uit tempcode[] b1=tempcode[6*nn]; b2=tempcode[6*nn+1]; b3=tempcode[6*nn+2]; b4=tempcode[6*nn+3]; b5=tempcode[6*nn+4]; b6=tempcode[6*nn+5]; k=0; // om lengte van temp1/temp2 bij te houden voor mergesort if (welke==1) { if ((temp1.lengte==-1)&&(P[b1][b2][b3][b4][b5][b6].lengte>=0)) { // kopieer P[b1][b2][b3][b4][b5][b6] naar temp1; // want temp1 is leeg. // er is er altijd maar eentje 1, de rest altijd 0. I1 = (a1-b1 > 0); // aan controle toevoegen.. I2 = (a2-b2 > 0); // aan beh1 toevoegen.. I3 = (a3-b3 > 0); // .. I4 = (a4-b4 > 0); I5 = (a5-b5 > 0); I6 = (a6-b6 > 0); // aan beh5 toevoegen if (I1) rangtemp = 0; // geen rang optellen... else rangtemp = rang[a1+I2*a2+I3*a3+I4*a4+I5*a5+I6*a6-1]; for (i=0 ; i < P[b1][b2][b3][b4][b5][b6].lengte ; i++) { // doe vermenigvuldiging meteen! temp1.coef[i] = P[b1][b2][b3][b4][b5][b6].coef[i]; if (n[1]>0) temp1.x1[i] = P[b1][b2][b3][b4][b5][b6].x1[i]+I2*rangtemp; if (n[2]>0) temp1.x2[i] = P[b1][b2][b3][b4][b5][b6].x2[i]+I3*rangtemp; if (n[3]>0) temp1.x3[i] = P[b1][b2][b3][b4][b5][b6].x3[i]+I4*rangtemp; if (n[4]>0) temp1.x4[i] = P[b1][b2][b3][b4][b5][b6].x4[i]+I5*rangtemp; if (n[5]>0) temp1.x5[i] = P[b1][b2][b3][b4][b5][b6].x5[i]+I6*rangtemp; } temp1.lengte = P[b1][b2][b3][b4][b5][b6].lengte; // welke=1; } else if (P[b1][b2][b3][b4][b5][b6].lengte>=0) // dus lengte != -1 { // voeg nieuwe code toe aan temp1 // daarna : temp2 = mergesort(temp1); // dus temp2 nu gevuld // dus welke=2; // doorloop dus P[b1][b2][b3][b4][b5][b6]; i=0; // om temp1 te doorlopen; // loop met j , P[b1][b2][b3][b4][b5][b6] door; // er is er altijd maar eentje 1, de rest altijd 0. I1 = (a1-b1 > 0); // aan controle toevoegen.. I2 = (a2-b2 > 0); // aan beh1 toevoegen.. I3 = (a3-b3 > 0); // .. I4 = (a4-b4 > 0); I5 = (a5-b5 > 0); I6 = (a6-b6 > 0); // aan beh5 toevoegen if (I1) rangtemp = 0; // geen rang optellen... else rangtemp = rang[a1+I2*a2+I3*a3+I4*a4+I5*a5+I6*a6-1]; for (j=0 ; j < P[b1][b2][b3][b4][b5][b6].lengte ; j++) { test=1; while (i < temp1.lengte && test==1) { if (comp2(temp1,i,P[b1][b2][b3][b4][b5][b6],j, I2*rangtemp, I3*rangtemp, I4*rangtemp, I5*rangtemp, I6*rangtemp) == -1) i++; else test=0; } if (i < temp1.lengte) { l = comp2(temp1,i,P[b1][b2][b3][b4][b5][b6],j, I2*rangtemp, I3*rangtemp, I4*rangtemp, I5*rangtemp, I6*rangtemp); if (l==0) { temp1.coef[i] += P[b1][b2][b3][b4][b5][b6].coef[j]; i++; } else if (l>0) { // toevoegen aan einde... temp1.coef[temp1.lengte+k] = P[b1][b2][b3][b4][b5][b6].coef[j]; if (n[1]>0) temp1.x1[temp1.lengte+k] = P[b1][b2][b3][b4][b5][b6].x1[j]+I2*rangtemp; if (n[2]>0) temp1.x2[temp1.lengte+k] = P[b1][b2][b3][b4][b5][b6].x2[j]+I3*rangtemp; if (n[3]>0) temp1.x3[temp1.lengte+k] = P[b1][b2][b3][b4][b5][b6].x3[j]+I4*rangtemp; if (n[4]>0) temp1.x4[temp1.lengte+k] = P[b1][b2][b3][b4][b5][b6].x4[j]+I5*rangtemp; if (n[5]>0) temp1.x5[temp1.lengte+k] = P[b1][b2][b3][b4][b5][b6].x5[j]+I6*rangtemp; k++; } } else if (i==temp1.lengte) { temp1.coef[temp1.lengte+k] = P[b1][b2][b3][b4][b5][b6].coef[j]; if (n[1]>0) temp1.x1[temp1.lengte+k] = P[b1][b2][b3][b4][b5][b6].x1[j]+I2*rangtemp; if (n[2]>0) temp1.x2[temp1.lengte+k] = P[b1][b2][b3][b4][b5][b6].x2[j]+I3*rangtemp; if (n[3]>0) temp1.x3[temp1.lengte+k] = P[b1][b2][b3][b4][b5][b6].x3[j]+I4*rangtemp; if (n[4]>0) temp1.x4[temp1.lengte+k] = P[b1][b2][b3][b4][b5][b6].x4[j]+I5*rangtemp; if (n[5]>0) temp1.x5[temp1.lengte+k] = P[b1][b2][b3][b4][b5][b6].x5[j]+I6*rangtemp; k++; } } temp1.lengte += k; // temp2 = mergesort(temp1,0,temp1.lengte-k); mergesort(temp2,temp1,temp1.lengte-k); welke=2; } } else if (welke==2) { if ((temp2.lengte==-1)&&(P[b1][b2][b3][b4][b5][b6].lengte>=0)) { // kopieer P[b1][b2][b3][b4][b5][b6] naar temp2; // er is er altijd maar eentje 1, de rest altijd 0. I1 = (a1-b1 > 0); // aan controle toevoegen.. I2 = (a2-b2 > 0); // aan beh1 toevoegen.. I3 = (a3-b3 > 0); // .. I4 = (a4-b4 > 0); I5 = (a5-b5 > 0); I6 = (a6-b6 > 0); // aan beh5 toevoegen if (I1) rangtemp = 0; // geen rang optellen... else rangtemp = rang[a1+I2*a2+I3*a3+I4*a4+I5*a5+I6*a6-1]; for (i=0 ; i < P[b1][b2][b3][b4][b5][b6].lengte ; i++) { // doe vermenigvuldiging meteen! temp2.coef[i] = P[b1][b2][b3][b4][b5][b6].coef[i]; if (n[1]>0) temp2.x1[i] = P[b1][b2][b3][b4][b5][b6].x1[i]+I2*rangtemp; if (n[2]>0) temp2.x2[i] = P[b1][b2][b3][b4][b5][b6].x2[i]+I3*rangtemp; if (n[3]>0) temp2.x3[i] = P[b1][b2][b3][b4][b5][b6].x3[i]+I4*rangtemp; if (n[4]>0) temp2.x4[i] = P[b1][b2][b3][b4][b5][b6].x4[i]+I5*rangtemp; if (n[5]>0) temp2.x5[i] = P[b1][b2][b3][b4][b5][b6].x5[i]+I6*rangtemp; } temp2.lengte = P[b1][b2][b3][b4][b5][b6].lengte; // welke=2; } else if (P[b1][b2][b3][b4][b5][b6].lengte>=0) // dus niet lengte == -1 { // voeg nieuwe code toe aan temp1 // daarna : temp2 = mergesort(temp1); // dus temp2 nu gevuld // dus welke=2; // doorloop dus P[b1][b2][b3][b4][b5][b6]; i=0; // om temp2 te doorlopen; // loop met j P[b1][b2][b3][b4][b5][b6] door; // er is er altijd maar eentje 1, de rest altijd 0. I1 = (a1-b1 > 0); // aan controle toevoegen.. I2 = (a2-b2 > 0); // aan beh1 toevoegen.. I3 = (a3-b3 > 0); // .. I4 = (a4-b4 > 0); I5 = (a5-b5 > 0); I6 = (a6-b6 > 0); // aan beh5 toevoegen if (I1) rangtemp = 0; // geen rang optellen... else rangtemp = rang[a1+I2*a2+I3*a3+I4*a4+I5*a5+I6*a6-1]; for (j=0 ; j< P[b1][b2][b3][b4][b5][b6].lengte ; j++) { test=1; while (i < temp2.lengte && test==1) { if (comp2(temp2,i,P[b1][b2][b3][b4][b5][b6],j, I2*rangtemp, I3*rangtemp, I4*rangtemp, I5*rangtemp, I6*rangtemp) == -1) i++; else test=0; } if (i < temp2.lengte) { l = comp2(temp2,i,P[b1][b2][b3][b4][b5][b6],j, I2*rangtemp, I3*rangtemp, I4*rangtemp, I5*rangtemp, I6*rangtemp); if (l==0) { temp2.coef[i] += P[b1][b2][b3][b4][b5][b6].coef[j]; i++; } else if (l>0) { // toevoegen aan einde... temp2.coef[temp2.lengte+k] = P[b1][b2][b3][b4][b5][b6].coef[j]; if (n[1]>0) temp2.x1[temp2.lengte+k] = P[b1][b2][b3][b4][b5][b6].x1[j]+I2*rangtemp; if (n[2]>0) temp2.x2[temp2.lengte+k] = P[b1][b2][b3][b4][b5][b6].x2[j]+I3*rangtemp; if (n[3]>0) temp2.x3[temp2.lengte+k] = P[b1][b2][b3][b4][b5][b6].x3[j]+I4*rangtemp; if (n[4]>0) temp2.x4[temp2.lengte+k] = P[b1][b2][b3][b4][b5][b6].x4[j]+I5*rangtemp; if (n[5]>0) temp2.x5[temp2.lengte+k] = P[b1][b2][b3][b4][b5][b6].x5[j]+I6*rangtemp; k++; } } else if (i==temp2.lengte) { temp2.coef[temp2.lengte+k] = P[b1][b2][b3][b4][b5][b6].coef[j]; if (n[1]>0) temp2.x1[temp2.lengte+k] = P[b1][b2][b3][b4][b5][b6].x1[j]+I2*rangtemp; if (n[2]>0) temp2.x2[temp2.lengte+k] = P[b1][b2][b3][b4][b5][b6].x2[j]+I3*rangtemp; if (n[3]>0) temp2.x3[temp2.lengte+k] = P[b1][b2][b3][b4][b5][b6].x3[j]+I4*rangtemp; if (n[4]>0) temp2.x4[temp2.lengte+k] = P[b1][b2][b3][b4][b5][b6].x4[j]+I5*rangtemp; if (n[5]>0) temp2.x5[temp2.lengte+k] = P[b1][b2][b3][b4][b5][b6].x5[j]+I6*rangtemp; k++; } } temp2.lengte += k; mergesort(temp1,temp2,temp2.lengte-k); welke=1; } } // end if welke==2; } // end for (nn) loop; // afhankelijk van 'welke' doe kopieer naar P[a1][a2][a3][a4][a5][a6] // temp1 en temp2 altijd al gesorteerd! if (welke==1) // kopieer van temp1 naar P[a1][a2][a3][a4][a5][a6]; { if (temp1.lengte == -1) { // P[a1][a2][a3][a4][a5][a6] blijft ook leeg! // geen ruimte reserveren P[a1][a2][a3][a4][a5][a6].lengte = -1; } else if (temp1.lengte>=0) { // reserveer lengte P[a1][a2][a3][a4][a5][a6]; P[a1][a2][a3][a4][a5][a6].coef = new(float[temp1.lengte]); if (n[1]>0) P[a1][a2][a3][a4][a5][a6].x1 = new(int[temp1.lengte]); if (n[2]>0) P[a1][a2][a3][a4][a5][a6].x2 = new(int[temp1.lengte]); if (n[3]>0) P[a1][a2][a3][a4][a5][a6].x3 = new(int[temp1.lengte]); if (n[4]>0) P[a1][a2][a3][a4][a5][a6].x4 = new(int[temp1.lengte]); if (n[5]>0) P[a1][a2][a3][a4][a5][a6].x5 = new(int[temp1.lengte]); P[a1][a2][a3][a4][a5][a6].lengte = temp1.lengte; // kopieer van temp1 naar P[a1][a2][a3][a4][a5][a6]. for (i=0 ; i < temp1.lengte ; i++) { P[a1][a2][a3][a4][a5][a6].coef[i] = temp1.coef[i]; if (n[1]>0) P[a1][a2][a3][a4][a5][a6].x1[i] = temp1.x1[i]; if (n[2]>0) P[a1][a2][a3][a4][a5][a6].x2[i] = temp1.x2[i]; if (n[3]>0) P[a1][a2][a3][a4][a5][a6].x3[i] = temp1.x3[i]; if (n[4]>0) P[a1][a2][a3][a4][a5][a6].x4[i] = temp1.x4[i]; if (n[5]>0) P[a1][a2][a3][a4][a5][a6].x5[i] = temp1.x5[i]; } } } else if (welke==2) // kopieer van temp2 naar P[a1][a2][a3][a4][a5][a6]. { if (temp2.lengte == -1) { // P[a1][a2][a3][a4][a5][a6] blijft ook leeg! // geen ruimte reserveren P[a1][a2][a3][a4][a5][a6].lengte = -1; } else if (temp2.lengte>=0) { // reserveer lengte P[a1][a2][a3][a4][a5][a6]; P[a1][a2][a3][a4][a5][a6].coef = new(float[temp2.lengte]); if (n[1]>0) P[a1][a2][a3][a4][a5][a6].x1 = new(int[temp2.lengte]); if (n[2]>0) P[a1][a2][a3][a4][a5][a6].x2 = new(int[temp2.lengte]); if (n[3]>0) P[a1][a2][a3][a4][a5][a6].x3 = new(int[temp2.lengte]); if (n[4]>0) P[a1][a2][a3][a4][a5][a6].x4 = new(int[temp2.lengte]); if (n[5]>0) P[a1][a2][a3][a4][a5][a6].x5 = new(int[temp2.lengte]); P[a1][a2][a3][a4][a5][a6].lengte = temp2.lengte; // kopieer van temp2 naar P[a1][a2][a3][a4][a5][a6]. for (i=0 ; i < temp2.lengte ; i++) { P[a1][a2][a3][a4][a5][a6].coef[i] = temp2.coef[i]; if (n[1]>0) P[a1][a2][a3][a4][a5][a6].x1[i] = temp2.x1[i]; if (n[2]>0) P[a1][a2][a3][a4][a5][a6].x2[i] = temp2.x2[i]; if (n[3]>0) P[a1][a2][a3][a4][a5][a6].x3[i] = temp2.x3[i]; if (n[4]>0) P[a1][a2][a3][a4][a5][a6].x4[i] = temp2.x4[i]; if (n[5]>0) P[a1][a2][a3][a4][a5][a6].x5[i] = temp2.x5[i]; } } } // P[a1][a2][a3][a4][a5][a6] gevuld! // geheugen teruggeven. delete temp1.coef; delete temp2.coef; if (n[1]>0) { delete temp1.x1; delete temp2.x1; } if (n[2]>0) { delete temp1.x2; delete temp2.x2; } if (n[3]>0) { delete temp1.x3; delete temp2.x3; } if (n[4]>0) { delete temp1.x4; delete temp2.x4; } if (n[5]>0) { delete temp1.x5; delete temp2.x5; } // struct temp1 en temp2 zijn na deze procedure weg! } } //---------------------------------------------------------------------------- int check4(int a, int b, int c, int d) { int stapje=0; if (a > b) stapje += (a-b); if (b > c) stapje += (b-c); if (c > d) stapje += (c-d); if (stapje >= 2) return 0; else return 1; // return 1 : cel vullen met swap // return 0 : cel niet vullen met swap } //---------------------------------------------------------------------------- int vulswap4(int a1, int a2, int a3, int a4, int a5, int a6) { // beh == 4 // maak alle permutaties van a1...a6, en vul cel // gebruik perm matrix PM : int i; int code_a[] = {a1,a2,a3,a4,a5,a6}; int aantalswaps = 1; // als code_a oplopend, dan okay... int oplopend = 1; int hetzelfde = 1; for (i=2; i <= beh ; i++) { // lees code_a[] uit. if (code_a[i] < code_a[i-1]) oplopend=0; if (code_a[i] != code_a[1]) hetzelfde=0; } // als code oplopend en swapbaar : if ((oplopend==1)&&(hetzelfde==0)) { //cout << "Code " << code_a[0] << " " // << code_a[1] << " " // << code_a[2] << " " // << code_a[3] << " " // << code_a[4] << " " // << code_a[5] << " kan geswapped worden...\n"; // code kan geswapped worden // want niet oplopend, en swapbaar. int code_b[6]; // om permutatie functie in te lezen.... int bron[6]; // int i : al gedef. int j,k; // om machten in te lezen. int xm1,xm2,xm3,xm4,xm5; long tmpl,ii; int permf[5]; for (i=1 ; i<=4; i++) permf[i]=0; j=0; permf[0]=1; for (i=2; i <=beh ; i++) { // loop code_a[] door, if (code_a[i] == code_a[i-1]) permf[j]++; else permf[++j]=1; } // bekijk : P[permf[0], permf[1] , ....permf[4] ]; // cout << "PM[ ][ ][ ][ ][ ] = "; // for (int zz=0 ; zz <= 4 ; zz++) // cout << permf[zz] << " "; cout << endl; int chcel; // om te kijken of swapcel gevuld moet worden : // loop alle permutatiefuncties door; for (i=0 ; i < PM[permf[0]][permf[1]][permf[2]][permf[3]][permf[4]].lengte ; i++) { for (int z2=0 ; z2 <= 5 ; z2++) bron[z2]=0; // vul bron met permutatiefunctie : if (n[1]>0) bron[1] = PM[permf[0]][permf[1]][permf[2]][permf[3]][permf[4]].f1[i]; if (n[2]>0) bron[2] = PM[permf[0]][permf[1]][permf[2]][permf[3]][permf[4]].f2[i]; if (n[3]>0) bron[3] = PM[permf[0]][permf[1]][permf[2]][permf[3]][permf[4]].f3[i]; if (n[4]>0) bron[4] = PM[permf[0]][permf[1]][permf[2]][permf[3]][permf[4]].f4[i]; if (n[5]>0) bron[5] = PM[permf[0]][permf[1]][permf[2]][permf[3]][permf[4]].f5[i]; // cout << "Bron : "; // for (int zzz=0 ; zzz <= 5 ; zzz++) // cout << bron[zzz] << " "; cout << endl; // bron[] gevuld met permutatiefunctie // maak ind. functies : IND[ ][ ]; // IND[1][2] = 1; als ie van 1 naar 2 moet. // IND[1][2] = 0: // Eerst de rest in IND op 0 zetten : for (j=1 ; j<=5 ; j++) for (k=1 ; k<=5 ; k++) IND[j][k] = 0; for (j = 1; j<=5 ; j++) IND[j][ bron[j] ] = 1; // IND is gevuld : // welke wordt de swapcel ? // code_b[] is swapcel : code_b[0] = code_a[0]; if (n[1]>0) code_b[1] = IND[1][1]*code_a[1]+IND[2][1]*code_a[2] +IND[3][1]*code_a[3] +IND[4][1]*code_a[4]+IND[5][1]*code_a[5]; if (n[2]>0) code_b[2] = IND[1][2]*code_a[1]+IND[2][2]*code_a[2] +IND[3][2]*code_a[3] +IND[4][2]*code_a[4]+IND[5][2]*code_a[5]; if (n[3]>0) code_b[3] = IND[1][3]*code_a[1]+IND[2][3]*code_a[2] +IND[3][3]*code_a[3] +IND[4][3]*code_a[4]+IND[5][3]*code_a[5]; if (n[4]>0) code_b[4] = IND[1][4]*code_a[1]+IND[2][4]*code_a[2] +IND[3][4]*code_a[3] +IND[4][4]*code_a[4]+IND[5][4]*code_a[5]; if (n[5]>0) code_b[5] = IND[1][5]*code_a[1]+IND[2][5]*code_a[2] +IND[3][5]*code_a[3] +IND[4][5]*code_a[4]+IND[5][5]*code_a[5]; if (db) cout << "Swap -> "; if (db) for (int z3=0 ; z3 <= 5 ; z3++) { cout << code_b[z3] << " " ; cout << endl; } tmpl = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].lengte; // moet swapcel gevuld worden ? if (P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].lengte == 0) { chcel = check4(code_b[1],code_b[2],code_b[3],code_b[4]); if (tmpl==-1) { // swapcel wordt ook leeg! P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].lengte = -1; if (db) printP(code_b[0],code_b[1],code_b[2],code_b[3],code_b[4],code_b[5]); } else if (chcel==1) // vullen : { P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].lengte = tmpl; // geheugen reserveren voor code_b : P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].coef = new(float[tmpl]); if (n[1]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x1 = new(int[tmpl]); if (n[2]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x2 = new(int[tmpl]); if (n[3]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x3 = new(int[tmpl]); if (n[4]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x4 = new(int[tmpl]); if (n[5]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x5 = new(int[tmpl]); // kopieer info van code_a naar code_b, met // behulp van swap met bron[]. for (ii=0 ; ii < tmpl ; ii++) { // lees machten uit code_a. if (n[1]>0) xm1 = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x1[ii]; if (n[2]>0) xm2 = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x2[ii]; if (n[3]>0) xm3 = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x3[ii]; if (n[4]>0) xm4 = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x4[ii]; if (n[5]>0) xm5 = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x5[ii]; // kopieer coef : P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].coef[ii] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].coef[ii]; if (n[1]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x1[ii] = IND[1][1]*xm1 +IND[2][1]*xm2 +IND[3][1]*xm3 +IND[4][1]*xm4 +IND[5][1]*xm5; if (n[2]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x2[ii] = IND[1][2]*xm1 +IND[2][2]*xm2 +IND[3][2]*xm3 +IND[4][2]*xm4 +IND[5][2]*xm5; if (n[3]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x3[ii] = IND[1][3]*xm1 +IND[2][3]*xm2 +IND[3][3]*xm3 +IND[4][3]*xm4 +IND[5][3]*xm5; if (n[4]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x4[ii] = IND[1][4]*xm1 +IND[2][4]*xm2 +IND[3][4]*xm3 +IND[4][4]*xm4 +IND[5][4]*xm5; if (n[5]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x5[ii] = IND[1][5]*xm1 +IND[2][5]*xm2 +IND[3][5]*xm3 +IND[4][5]*xm4 +IND[5][5]*xm5; } // swapcode is gevuld, nu nog SORTEREN! qsort(P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]],0,P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].lengte-1); } else if (chcel==0) { P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].lengte = -1; if (db) printP(code_b[0],code_b[1],code_b[2],code_b[3],code_b[4],code_b[5]); } if (db) printP(code_b[0],code_b[1],code_b[2],code_b[3],code_b[4],code_b[5]); aantalswaps++; } } } return aantalswaps; } //---------------------------------------------------------------------------- int vulswap2(int a1, int a2, int a3, int a4, int a5, int a6) { // alleen een 2-verwisseling doen : int code_a[] = {a1,a2,a3,a4,a5,a6}; int aantalswaps=1; if ( (code_a[1] != code_a[2]) && (P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].lengte==0) ) // als swapcel leeg is, dan vullen, anders niet. { if (db) cout << "\nSwap -> Cel [" << code_a[0] << "," << code_a[2] << "," << code_a[1] << "," << code_a[3] << "," << code_a[4] << "," << code_a[5] << "]\n"; if (P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].lengte==-1) P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].lengte=-1; else { long i; long tmpl = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].lengte; P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].coef = new(float[tmpl]); P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].x1 = new(int[tmpl]); P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].x2 = new(int[tmpl]); for (i=0 ; i < tmpl ; i++) { P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].coef[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].coef[i]; P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].x1[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x2[i]; P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].x2[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x1[i]; } P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].lengte = tmpl; qsort(P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]],0,tmpl-1); } aantalswaps++; if (db) printP(code_a[0],code_a[2],code_a[1],code_a[3],code_a[4],code_a[5]); } return aantalswaps; } //---------------------------------------------------------------------------- int check3(int a, int b, int c) { int stapje=0; if (a > b) stapje += (a-b); if (b > c) stapje += (b-c); if (stapje >= 2) return 0; else return 1; // return 1 : cel vullen met swap // return 0 : cel niet vullen met swap } //---------------------------------------------------------------------------- int vulswap3(int a1, int a2, int a3, int a4, int a5, int a6) { // doe een 3-verwisseling : int code_a[] = {a1,a2,a3,a4,a5,a6}; int chcel; int aantalswaps=1; long i; long tmpl = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].lengte; // 1-3-2 if ( P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]].lengte==0 ) { chcel = check3(code_a[1],code_a[3],code_a[2]); // =1 : echt vullen met swap; // =0 : swapcel hoeft niet gevuld te worden if (db) cout << "\nSwap -> Cel [" << code_a[0] << "," << code_a[1] << "," << code_a[3] << "," << code_a[2] << "," << code_a[4] << "," << code_a[5] << "]\n"; if ( tmpl ==-1) P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]].lengte=-1; else if (chcel==1) { P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]].coef = new(float[tmpl]); P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]].x1 = new(int[tmpl]); P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]].x2 = new(int[tmpl]); P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]].x3 = new(int[tmpl]); for (i=0 ; i < tmpl ; i++) { P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]].coef[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].coef[i]; P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]].x1[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x1[i]; P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]].x2[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x3[i]; P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]].x3[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x2[i]; } P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]].lengte = tmpl; qsort(P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]],0,tmpl-1); } else if (chcel == 0) P[code_a[0]][code_a[1]][code_a[3]][code_a[2]][code_a[4]][code_a[5]].lengte=-1; if (db) printP(code_a[0],code_a[1],code_a[3],code_a[2],code_a[4],code_a[5]); aantalswaps++; } // 2-1-3 if ( P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].lengte==0 ) { chcel = check3(code_a[2],code_a[1],code_a[3]); if (db) cout << "\nSwap -> Cel [" << code_a[0] << "," << code_a[2] << "," << code_a[1] << "," << code_a[3] << "," << code_a[4] << "," << code_a[5] << "]\n"; if ( tmpl ==-1) P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].lengte=-1; else if (chcel == 1) { P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].coef = new(float[tmpl]); P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].x1 = new(int[tmpl]); P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].x2 = new(int[tmpl]); P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].x3 = new(int[tmpl]); for (i=0 ; i < tmpl ; i++) { P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].coef[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].coef[i]; P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].x1[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x2[i]; P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].x2[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x1[i]; P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].x3[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x3[i]; } P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].lengte = tmpl; qsort(P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]],0,tmpl-1); } else if (chcel==0) P[code_a[0]][code_a[2]][code_a[1]][code_a[3]][code_a[4]][code_a[5]].lengte=-1; if (db) printP(code_a[0],code_a[2],code_a[1],code_a[3],code_a[4],code_a[5]); aantalswaps++; } // 2-3-1 if ( P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]].lengte==0 ) { chcel = check3(code_a[2],code_a[3],code_a[1]); if (db) cout << "\nSwap -> Cel [" << code_a[0] << "," << code_a[2] << "," << code_a[3] << "," << code_a[1] << "," << code_a[4] << "," << code_a[5] << "]\n"; if ( tmpl ==-1) P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]].lengte=-1; else if (chcel ==1) { P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]].coef = new(float[tmpl]); P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]].x1 = new(int[tmpl]); P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]].x2 = new(int[tmpl]); P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]].x3 = new(int[tmpl]); for (i=0 ; i < tmpl ; i++) { P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]].coef[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].coef[i]; P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]].x1[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x2[i]; P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]].x2[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x3[i]; P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]].x3[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x1[i]; } P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]].lengte = tmpl; qsort(P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]],0,tmpl-1); } else if (chcel==0) P[code_a[0]][code_a[2]][code_a[3]][code_a[1]][code_a[4]][code_a[5]].lengte=-1; aantalswaps++; if (db) printP(code_a[0],code_a[2],code_a[3],code_a[1],code_a[4],code_a[5]); } // 3-1-2 if ( P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]].lengte==0 ) { chcel = check3(code_a[3],code_a[1],code_a[2]); if (db) cout << "\nSwap -> Cel [" << code_a[0] << "," << code_a[3] << "," << code_a[1] << "," << code_a[2] << "," << code_a[4] << "," << code_a[5] << "]\n"; if ( tmpl ==-1) P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]].lengte=-1; else if (chcel == 1) { P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]].coef = new(float[tmpl]); P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]].x1 = new(int[tmpl]); P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]].x2 = new(int[tmpl]); P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]].x3 = new(int[tmpl]); for (i=0 ; i < tmpl ; i++) { P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]].coef[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].coef[i]; P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]].x1[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x3[i]; P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]].x2[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x1[i]; P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]].x3[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x2[i]; } P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]].lengte = tmpl; qsort(P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]],0,tmpl-1); } else if (chcel == 0) P[code_a[0]][code_a[3]][code_a[1]][code_a[2]][code_a[4]][code_a[5]].lengte=-1; aantalswaps++; if (db) printP(code_a[0],code_a[3],code_a[1],code_a[2],code_a[4],code_a[5]); } // 3-2-1 if ( P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]].lengte==0 ) { chcel = check3(code_a[3],code_a[2],code_a[1]); if (db) cout << "\nSwap -> Cel [" << code_a[0] << "," << code_a[3] << "," << code_a[2] << "," << code_a[1] << "," << code_a[4] << "," << code_a[5] << "]\n"; if ( tmpl ==-1) P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]].lengte=-1; else if (chcel == 1) { P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]].coef = new(float[tmpl]); P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]].x1 = new(int[tmpl]); P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]].x2 = new(int[tmpl]); P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]].x3 = new(int[tmpl]); for (i=0 ; i < tmpl ; i++) { P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]].coef[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].coef[i]; P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]].x1[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x3[i]; P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]].x2[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x2[i]; P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]].x3[i] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x1[i]; } P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]].lengte = tmpl; qsort(P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]],0,tmpl-1); } else if (chcel ==0) P[code_a[0]][code_a[3]][code_a[2]][code_a[1]][code_a[4]][code_a[5]].lengte=-1; aantalswaps++; if (db) printP(code_a[0],code_a[3],code_a[2],code_a[1],code_a[4],code_a[5]); } return aantalswaps; } //---------------------------------------------------------------------------- int vulswap5(int a1, int a2, int a3, int a4, int a5, int a6) { // maak alle permutaties van a1...a6, en vul cel int code_a[] = {a1,a2,a3,a4,a5,a6}; int code_b[6]; int bron[6]; int doel[6]; int aantalswaps=1; int testperm,inrij; int i,j,k; int tempmacht; int xm1,xm2,xm3,xm4,xm5; long tmpl,ii; // haal codes eruit die iets zou kunnen zijn : // als codegehad[i]==0 ,dan code nog niet door swap gevuld. for (i = plaatscode[a1+a2+a3+a4+a5+a6] ; i < plaatscode[a1+a2+a3+a4+a5+a6+1] ; i++) { if (codegehad[i]==0) // dan nog niet gevuld door swap { testperm=1; // haal deze code uit code[]. code_b[0] = code[6*i]; code_b[1] = code[6*i+1]; code_b[2] = code[6*i+2]; code_b[3] = code[6*i+3]; code_b[4] = code[6*i+4]; code_b[5] = code[6*i+5]; // is code b1..b6 een swap van a1..a6 ? //cout << "swap ? : " // << code_b[0] << " " // << code_b[1] << " " // << code_b[2] << " " // << code_b[3] << " " // << code_b[4] << " " // << code_b[5] << endl; // als code_b al gevuld is // of code_b is al gevuld EN geshrinkt, dan geen swap! // dus lengte == -1 of >0 if (P[code_b[0]][code_b[1]][code_b[2]] [code_b[3]][code_b[4]][code_b[5]].lengte != 0) testperm=0; // als code_b hetzelfde als code_a dan geen swap! if ((code_a[0]==code_b[0])&& (code_a[1]==code_b[1])&& (code_a[2]==code_b[2])&& (code_a[3]==code_b[3])&& (code_a[4]==code_b[4])&& (code_a[5]==code_b[5])) testperm=0; // eigen code! // als eerste getal niet gelijk ,dan ook geen swap! if (code_a[0] != code_b[0]) testperm=0; // kan nog steeds swap zijn : if (testperm==1) // hij is nog steeds 1. { for (j=0 ; j<=5 ; j++) { bron[j]=0; doel[j]=0; } j=1; while (j<=5 && testperm) { // pak element j^e uit code_a; inrij=0; for (k=1 ; k<=5 && inrij==0 ; k++) { if ( (code_a[j]==code_b[k]) && (doel[k]==0)) { doel[k]=1; bron[j]=k; inrij=1; } } if (inrij==0) testperm=0; j++; } } if (testperm==1) { // code b1..b6 is inderdaad een swap van // code a1..a6. // vul b1..b6 met behulp van a1..a6 if (db) cout << "-> Swap -> "; if (db) cout << code_b[0] << " " << code_b[1] << " " << code_b[2] << " " << code_b[3] << " " << code_b[4] << " " << code_b[5] << endl; // vul swap cel met info : // met behulp van bron[]. // ruimte reserveren voor swap cel... // bekijk lengte van code_a : tmpl = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].lengte; if (tmpl != -1) { // lengte != -1 P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].lengte = tmpl; P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].coef = new(float[tmpl]); if (n[1]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x1 = new(int[tmpl]); if (n[2]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x2 = new(int[tmpl]); if (n[3]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x3 = new(int[tmpl]); if (n[4]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x4 = new(int[tmpl]); if (n[5]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x5 = new(int[tmpl]); // kopieer info van code_a naar code_b, met // behulp van swap met bron[]. // maak ind. functies : IND[ ][ ]; // IND[1][2] = 1; als ie van 1 naar 2 moet. // IND[1][2] = 0: // De rest in IND op 0 zetten : for (j=1 ; j<=5 ; j++) for (k=1 ; k<=5 ; k++) IND[j][k] = 0; // vul de rest volgens permutatiearray bron[] : for (j = 1; j<=5 ; j++) IND[j][ bron[j] ] = 1; for (ii=0 ; ii < tmpl ; ii++) { // lees machten uit uit code_a. if (n[1]>0) xm1 = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x1[ii]; if (n[2]>0) xm2 = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x2[ii]; if (n[3]>0) xm3 = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x3[ii]; if (n[4]>0) xm4 = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x4[ii]; if (n[5]>0) xm5 = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].x5[ii]; // kopieer coef : P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].coef[ii] = P[code_a[0]][code_a[1]][code_a[2]][code_a[3]][code_a[4]][code_a[5]].coef[ii]; if (n[1]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x1[ii] = IND[1][1]*xm1 +IND[2][1]*xm2 +IND[3][1]*xm3 +IND[4][1]*xm4 +IND[5][1]*xm5; if (n[2]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x2[ii] = IND[1][2]*xm1 +IND[2][2]*xm2 +IND[3][2]*xm3 +IND[4][2]*xm4 +IND[5][2]*xm5; if (n[3]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x3[ii] = IND[1][3]*xm1 +IND[2][3]*xm2 +IND[3][3]*xm3 +IND[4][3]*xm4 +IND[5][3]*xm5; if (n[4]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x4[ii] = IND[1][4]*xm1 +IND[2][4]*xm2 +IND[3][4]*xm3 +IND[4][4]*xm4 +IND[5][4]*xm5; if (n[5]>0) P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].x5[ii] = IND[1][5]*xm1 +IND[2][5]*xm2 +IND[3][5]*xm3 +IND[4][5]*xm4 +IND[5][5]*xm5; } codegehad[i]=1; // swapcode is gevuld, nu nog SORTEREN! qsort(P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]],0,tmpl-1); if (db) printP(code_b[0],code_b[1],code_b[2],code_b[3],code_b[4],code_b[5]); aantalswaps++; } else { // alleen code vullen met lengte -1, // niet reserveren ! P[code_b[0]][code_b[1]][code_b[2]][code_b[3]][code_b[4]][code_b[5]].lengte = -1; if (db) printP(code_b[0],code_b[1],code_b[2],code_b[3],code_b[4],code_b[5]); codegehad[i]=1; aantalswaps++; } } // anders niks doen, want code is geen // permutatie en naar volgende code kijken. } // kijk naar volgende code ,want deze heb je al gehad. } return aantalswaps; } //---------------------------------------------------------------------------- void delete_uit_P(int a1,int a2,int a3,int a4, int a5, int a6, long nrele) { // maak coef 0. P[a1][a2][a3][a4][a5][a6].coef[nrele] = 0; } //---------------------------------------------------------------------------- double shrinkcelP(int a1, int a2, int a3, int a4, int a5, int a6, float ff) { int da[] = {a1,a2,a3,a4,a5,a6}; long aantaldel=0; double tussenaantal=0; // shrink met behulp van ff :" // cel is zeker met lengte > 0 // want hij is net gevuld met recursie : // loop cel element voor element door : long i; if (db) printP(a1,a2,a3,a4,a5,a6); int bijvoeg[5]; int j,k; for (j=0 ; j<=5 ; j++) bijvoeg[j]=0; int testweg; for (i=0 ; i < P[a1][a2][a3][a4][a5][a6].lengte ; i++) { // voeg maximum toe : testweg = 0; for (k=1 ; k<=5 && testweg==0 ; k++) { if (n[k]>0) { bijvoeg[k-1] = 0; for (j=n[0]+n[k]-1 ; j>=n[0]+da[k] ; j--) bijvoeg[k-1] += rang[j]; if (db) cout << "max (" << k << ") " << bijvoeg[k-1] << endl; if (k==1) if (bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x1[i]< ff) { if (db) cout << "term weggooien (1) : " << bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x1[i] << " < " << ff << endl; delete_uit_P(a1,a2,a3,a4,a5,a6,i); aantaldel++; testweg=1; } if (k==2) if (bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x2[i]< ff) { if (db) cout << "term weggooien (2) : " << bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x2[i] << " < " << ff << endl; delete_uit_P(a1,a2,a3,a4,a5,a6,i); aantaldel++; testweg=1; } if (k==3) if (bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x3[i]< ff) { if (db) cout << "term weggooien (3) : " << bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x3[i] << " < " << ff << endl; delete_uit_P(a1,a2,a3,a4,a5,a6,i); aantaldel++; testweg=1; } if (k==4) if (bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x4[i]< ff) { if (db) cout << "term weggooien (4) : " << bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x4[i] << " < " << ff << endl; delete_uit_P(a1,a2,a3,a4,a5,a6,i); aantaldel++; testweg=1; } if (k==5) if (bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x5[i]< ff) { if (db) cout << "term weggooien (5) : " << bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x5[i] << " < " << ff << endl; delete_uit_P(a1,a2,a3,a4,a5,a6,i); aantaldel++; testweg=1; } } } if (testweg==0) { // B&B maximum heeft niks gedaan ... // dus probeer B&B minimum : int termwegmin=0; for (k=1 ; k<=5 && testweg==0 ; k++) { if (n[k]>0) { bijvoeg[k-1] = 0; for (j = da[0]+da[k]+1 ; j <= da[0]+n[k] ; j++) bijvoeg[k-1] += j; if (db) cout << "min (" << k << ") " << bijvoeg[k-1] << endl; if (k==1) if (bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x1[i] < ff) { if (db) cout << "erg gebeurt niks met (1) : " << bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x1[i] << " < " << ff << endl; testweg=1; } else termwegmin++; if (k==2) if (bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x2[i]< ff) { if (db) cout << "erg gebeurt niks met (2) : " << bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x2[i] << " < " << ff << endl; testweg=1; } else termwegmin++; if (k==3) if (bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x3[i]< ff) { if (db) cout << "erg gebeurt niks met (3) : " << bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x3[i] << " < " << ff << endl; testweg=1; } else termwegmin++; if (k==4) if (bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x4[i]< ff) { if (db) cout << "erg gebeurt niks met (4) : " << bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x4[i] << " < " << ff << endl; testweg=1; } else termwegmin++; if (k==5) if (bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x5[i]< ff) { if (db) cout << "erg gebeurt niks met (5) : " << bijvoeg[k-1] + P[a1][a2][a3][a4][a5][a6].x5[i] << " < " << ff << endl; // testweg=1; } else termwegmin++; } } if (termwegmin==beh) { if (db) cout << "term weggooien min\n"; tussenaantal += P[a1][a2][a3][a4][a5][a6].coef[i] * bino(n[0]-da[0],n[1]-da[1],n[2]-da[2],n[3]-da[3],n[4]-da[4],n[5]-da[5]); if (db) cout << "Bijdrage bino : " << bino(n[0]-da[0],n[1]-da[1],n[2]-da[2],n[3]-da[3],n[4]-da[4],n[5]-da[5]) << endl; delete_uit_P(a1,a2,a3,a4,a5,a6,i); aantaldel++; } } char hoi[10]; if (db) cin >> hoi; } // Cellen verkleinen ???? if ((aantaldel>0) && (aantaldel < P[a1][a2][a3][a4][a5][a6].lengte)) { // cel kleiner maken pverd temp; long nieuwecellen = P[a1][a2][a3][a4][a5][a6].lengte - aantaldel; temp.coef = new float[nieuwecellen]; if (n[1]>0) temp.x1 = new int[nieuwecellen]; if (n[2]>0) temp.x2 = new int[nieuwecellen]; if (n[3]>0) temp.x3 = new int[nieuwecellen]; if (n[4]>0) temp.x4 = new int[nieuwecellen]; if (n[5]>0) temp.x5 = new int[nieuwecellen]; long j=0; for (i=0 ; i < P[a1][a2][a3][a4][a5][a6].lengte ; i++) { if (P[a1][a2][a3][a4][a5][a6].coef[i] !=0) { temp.coef[j] = P[a1][a2][a3][a4][a5][a6].coef[i]; if (n[1]>0) temp.x1[j] = P[a1][a2][a3][a4][a5][a6].x1[i]; if (n[2]>0) temp.x2[j] = P[a1][a2][a3][a4][a5][a6].x2[i]; if (n[3]>0) temp.x3[j] = P[a1][a2][a3][a4][a5][a6].x3[i]; if (n[4]>0) temp.x4[j] = P[a1][a2][a3][a4][a5][a6].x4[i]; if (n[5]>0) temp.x5[j] = P[a1][a2][a3][a4][a5][a6].x5[i]; j++; } } P[a1][a2][a3][a4][a5][a6].lengte = nieuwecellen; delete P[a1][a2][a3][a4][a5][a6].coef; P[a1][a2][a3][a4][a5][a6].coef = temp.coef; if (n[1]>0) { delete P[a1][a2][a3][a4][a5][a6].x1; P[a1][a2][a3][a4][a5][a6].x1 = temp.x1; } if (n[2]>0) { delete P[a1][a2][a3][a4][a5][a6].x2; P[a1][a2][a3][a4][a5][a6].x2 = temp.x2; } if (n[3]>0) { delete P[a1][a2][a3][a4][a5][a6].x3; P[a1][a2][a3][a4][a5][a6].x3 = temp.x3; } if (n[4]>0) { delete P[a1][a2][a3][a4][a5][a6].x4; P[a1][a2][a3][a4][a5][a6].x4 = temp.x4; } if (n[5]>0) { delete P[a1][a2][a3][a4][a5][a6].x5; P[a1][a2][a3][a4][a5][a6].x5 = temp.x5; } } else if (aantaldel == P[a1][a2][a3][a4][a5][a6].lengte) { // hele cel weggooien! P[a1][a2][a3][a4][a5][a6].lengte = -1; delete P[a1][a2][a3][a4][a5][a6].coef; if (n[1]>0) delete P[a1][a2][a3][a4][a5][a6].x1; if (n[2]>0) delete P[a1][a2][a3][a4][a5][a6].x2; if (n[3]>0) delete P[a1][a2][a3][a4][a5][a6].x3; if (n[4]>0) delete P[a1][a2][a3][a4][a5][a6].x4; if (n[5]>0) delete P[a1][a2][a3][a4][a5][a6].x5; } if (db) cout << "Verkleinde cel : \n"; if (db) printP(a1,a2,a3,a4,a5,a6); return tussenaantal; } //---------------------------------------------------------------------------- void maakverdelingP(float kk) { int X0,X1,X2,X3,X4,X5; int pprc; char tempy[10]; int aantalsw; double aantalshrink; int aantaltempcodes; // for (int i=0; i < incd ; i++) for (X0=0 ; X0 <= n[0] ; X0++) for (X1=0 ; X1 <= n[1] ; X1++) for (X2=0 ; X2 <= n[2] ; X2++) for (X3=0 ; X3 <= n[3] ; X3++) for (X4=0 ; X4 <= n[4] ; X4++) for (X5=0 ; X5 <= n[5] ; X5++) { if (P[X0][X1][X2][X3][X4][X5].lengte==0) // dus cel leeg, kan gevuld worden { if (db) cout << "\nVullen : Cel [" << X0 << "," << X1 << "," << X2 << "," << X3 << "," << X4 << "," << X5 << "]\n"; // aantaltempcodes : aantal onderliggende codes // van P[X0][X1][X2][X3][X4][X5] pprc = mpreprocessing(X0,X1,X2,X3,X4,X5,kk); if (pprc==1) { // cel mag leeg; // geen bijdrage : P[X0][X1][X2][X3][X4][X5].lengte = -1; aantalshrink = 0; } else if (pprc==0) { // cel kan niet leeg gemaakt worden : // dus recursie : maaksubcodes(X0,X1,X2,X3,X4,X5,aantaltempcodes); // printstring(tempcode,aantaltempcodes); vulP(X0,X1,X2,X3,X4,X5,aantaltempcodes); // cel shrink met bhv. ff : if (bb) aantalshrink = shrinkcelP(X0,X1,X2,X3,X4,X5,kk); else aantalshrink = 0; } // maak swap. if (sw) { if (beh==1) aantalsw = 1; // alleen 2 verwisseling // dus speciale proc if (beh==2) { if (X2-X1 < 2) aantalsw = vulswap2(X0,X1,X2,X3,X4,X5); else { P[X0][X2][X1][X3][X4][X5].lengte =-1; aantalsw = 2; } } // 3 verwisseling // maar 6 gevallen : uitwerken if (beh==3) aantalsw = vulswap3(X0,X1,X2,X3,X4,X5); // 4 perm // gebruik permutatie matrix if (beh==4) aantalsw = vulswap4(X0,X1,X2,X3,X4,X5); // nog niet helemaal klaar! if (beh==5) aantalsw = vulswap5(X0,X1,X2,X3,X4,X5); } else aantalsw = 1; aantal_groter_dan_k += aantalsw * aantalshrink; if (db) { cout << "aantalsw : " << aantalsw << endl; cout << "aantalshrink : " << aantalshrink << endl; cout << "aantal groter dan k " << aantal_groter_dan_k << endl; cout << "Enter : " ; cin >> tempy; } // cout << "lengte : " << P[X0][X1][X2][X3][X4][X5].lengte << endl; } } } // main ---------------------------------------------------------------------- void main(int argc, char **argv) { // clrscr(); // test maximum : // cout << bino(13,13,13,13,13,0) << endl; // cout << "PROG 8 " // << "Methode van Steel.\n\n" // << " - Swap\n" // << " - Branch and Bound\n" // << " - Preprocessing\n\n"; // cout << "Geef aantal behandeling (zonder controle) 1<= ... <=4 : "; // cin >> beh; beh = atoi(argv[1]); // cout << "Geef aantal waarnemingen per behandeling (niet controle) : "; int aantalw; // cin >> aantalw; aantalw = atoi(argv[2]); int i; for (i=1 ; i<=5 ; i++) n[i] = aantalw * (beh >= i ); // cout << "Geef aantal waarnemingen van controle : "; // cin >> n[0]; n[0] = atoi(argv[3]); rang = new(int[n[0]+n[1]]); // vul rang[] met rangnummers; for(i=0 ; i < n[0]+n[1] ; i++) rang[i] = i+1; // altijd genoeg reserveren voor tempcode // maximaal 6 codes, dus 6*6 reserveren... tempcode = new(int[36]); // reserveer ook ruimte voor code long aantalcd = 6*(n[0]+1)*(n[1]+1)*(n[2]+1)*(n[3]+1)*(n[4]+1)*(n[5]+1); // cout << "Reserveer : " << aantalcd << endl; code = new(int[aantalcd]); float kk; // cout << "\nToetsingsgrootheid S : "; // cout << "Geef observatie s, waarvoor P(S>=s) : "; // cin >> kk; kk = atof(argv[4]); // cout << "Debug (0/1) ? : " ; cin >> db; // cout << "Swap (0/1) ? : " ; cin >> sw; // cout << "Branch & Bound (0/1) ? : " ; cin >> bb; // cout << "Preproc (0/1) ? : " ; cin >> ppr; db = atoi(argv[5]); sw = atoi(argv[6]); bb = atoi(argv[7]); ppr = atoi(argv[8]); // maak codes om door te lopen voor recursie, zodat je // in de juiste volgorde codes doorloopt. // cout << "maakcode : \n"; // maakcode(kk); // cout << "maakcode done... \n"; // printstring(code,incd); // char hoi2[10]; cout << "enter : "; // cin >> hoi2; // incd = aantalcodes ,code[] = lijst van door te lopen codes if (beh==4) { // permutatiematrix invullen : // cout << "Begin initPM : \n"; initPM(); // cout << "Perm matrix init...\n"; } // dim reserveren. // cout << "Begin reserveren matrix: \n"; reserveerdimP(); // cout << "Reserveren matrix done...\n"; // de rest van de lengtes wordt op 0 gezet. // en eerste plaatsen opgevuld // cout << "Begin reserveren init : \n"; initP(); // cout << "P matrix init...\n"; // cout << "\nGebruikte toetsingsgrootheid S : " << kk << endl; // cout << "\nCalculating....\n"; maakverdelingP(kk); // cout << "Done...\n\n"; // cout << "Aantal_groter_dan_K : " << aantal_groter_dan_k << endl; double totaalaantal = fac(n[0]+n[1]+n[2]+n[3]+n[4]+n[5]); for (i=0 ; i<=5 ; i++) totaalaantal /= fac(n[i]); // cout << "Totaal : " << totaalaantal << endl; double kans = aantal_groter_dan_k / totaalaantal; // cout << "P(S>=" << kk << ") : "; cout << kans << endl; // char hoi[10]; // cout << "print : "; // cin >> hoi; // if (hoi[0]=='y') // printP(n[0],n[1],n[2],n[3],n[4],n[5]); } // end main ------------------------------------------------------------------