#include #include #include #include #include #include #include "BasicFunctions.h" using namespace std; //Function fuses charge parity int ChargeFusion(int Charge1, int Charge2) { int b1 = Charge1 % 2; int b2 = Charge2 % 2; int r1 = ( Charge1 / 2 ) % 2; int r2 = ( Charge2 / 2 ) % 2; int g1 = ( Charge1 / 4 ) % 2; int g2 = ( Charge2 / 4 ) % 2; int b = ( b1 + b2 ) % 2; int r = ( r1 + r2 ) % 2; int g = ( g1 + g2 ) % 2; int FusionProduct = 4*g + 2*r + b; //returns 4*green edge flipped + 2 * red edge flipped + blue edge flipped return FusionProduct; } vector GetAlternateDummies(vector WrappedCM, int NoOfVertices, int StabXPos[], int StabYPos[]) { int AllRLVertices = NoOfVertices*3; //matrix storing distances between every set of two points int CostMatrix[AllRLVertices][AllRLVertices]; //matrix storing which creases are crossed while travelling between every set of two points int FlipMatrix[AllRLVertices][AllRLVertices]; int MobiusPoints = AllRLVertices * AllRLVertices; int PredecessorMatrix[AllRLVertices][AllRLVertices]; //unwrap adjacency matrix for (int i = 0; i < AllRLVertices; i++) { for (int j = 0; j < AllRLVertices; j++) { CostMatrix[i][j] = WrappedCM[i*AllRLVertices+j]; if ((i < NoOfVertices && j > 2*NoOfVertices -1) || (j < NoOfVertices && i > 2*NoOfVertices -1)) { CostMatrix[i][j] = 999999; } if ((i == 0 && j == NoOfVertices) || (j == 0 && i == NoOfVertices)) { CostMatrix[i][j] = 999999; } } } //store naive crease crosses (not along shortest paths) for (int i = 0; i < AllRLVertices; i++) { for (int j = 0; j < AllRLVertices; j++) { FlipMatrix[i][j] = 0; PredecessorMatrix[i][j] = i; } } // ** Begin Floyd-Warshall Algorithm for All Pairs shortest paths ** for (int k = 0; k < AllRLVertices; k++) { // Pick all vertices as source one by one for (int i = 0; i < AllRLVertices; i++) { // Pick all vertices as destination for the // above picked source for (int j = 0; j < AllRLVertices; j++) { // If vertex k is on the shortest path from // i to j, then update the value of CostMatrix[i][j], and update the predecessor when path travels through k if (CostMatrix[i][k] + CostMatrix[k][j] < CostMatrix[i][j]) { CostMatrix[i][j] = CostMatrix[i][k] + CostMatrix[k][j]; PredecessorMatrix[i][j] = PredecessorMatrix[k][j]; } } } } // ** CostMatrix now stores the shortest distance between every two points in the MS ** //rewrap the results to be able to output them from the function for (int i = 0; i < AllRLVertices; i++) { for (int j = 0; j< AllRLVertices; j++) { int a = i; int b = j; while (a!=b) { FlipMatrix[i][j] = CreaseCross(b,PredecessorMatrix[a][b],NoOfVertices,FlipMatrix[i][j]); b = PredecessorMatrix[a][b]; } } } //let dummy1 be on RB side of red edge //and dummy2 on RG side of red edge //unwrap adjacency matrix //cout << endl; /*cout << "Initialized alternate dummies in cost matrix" << endl; for(int i = 0; i < AllRLVertices; i++) { for ( int j = 0; j < AllRLVertices; j++) { if (CostMatrix[i][j] < 9999) cout << CostMatrix[i][j] << " "; else cout << " "; } cout << endl; }*/ vector DDoubleWrap; for (int i = 0; i < AllRLVertices; i++) { for (int j = 0; j< AllRLVertices; j++) { DDoubleWrap.push_back(CostMatrix[i][j]); } } for (int i = 0; i < AllRLVertices; i++) { for (int j = 0; j< AllRLVertices; j++) { DDoubleWrap.push_back(FlipMatrix[i][j]); } } for (int i = 0; i < AllRLVertices; i++) { for (int j = 0; j< AllRLVertices; j++) { DDoubleWrap.push_back(PredecessorMatrix[i][j]); } } return DDoubleWrap; } void PathPrinter(int i, int j, vector p, int NoOfVertices) { if (i != j) { PathPrinter(i, p[i*NoOfVertices+j], p, NoOfVertices); } cout << j << " "; }