package verifier; import java.io.*; import java.util.*; /************************************ * * This class verifies the combination proof of bad small components. * * It proves the following statement: * Every breakpoint graph containing bad small components * whose total size is >= 8 cycles has an (11,8) sequence. * * The bad small components are: * Unoriented Interleaving pair: [3](0 4 2)[3](1 5 3) * Unoriented Necklace of size 4: [3](1 5 3)[3](4 8 6)[3](7 11 9)[3](10 2 0) * Twisted Necklace of size 4: [3](5 0 7)[3](2 6 4)[3](3 10 8)[3](9 1 11) * Unoriented Necklace of size 5: [3](3 7 5)[3](0 4 2)[3](6 10 8)[3](9 13 11)[3](12 1 14) * Unoriented Necklace of size 6: [3](13 17 15)[3](10 14 12)[3](7 11 9)[3](16 2 0)[3](1 5 3)[3](4 8 6) * * The verification procedes as follows: * 1. FOR EACH of the bad small components * VERIFY(comp, proof_file_for_comp) * * 2. VERIFY(configuration conf) * IF conf has >= 8 cycles * give sorting for conf IF NO SORTING EXISTS ERROR * ELSE * FOR EACH position i in the conf * FOR EACH bad small comp * VERIFY(conf addComponent comp to position i, proof_file) */ public class VerifyCOMBINATIONProof extends BaseClass { private static Configuration BADSMALLCOMPS[] = new Configuration[5]; public static void main(String args[]){ try { Configuration necklace_6 = new Configuration("[3](13 17 15)[3](10 14 12)[3](7 11 9)[3](16 2 0)[3](1 5 3)[3](4 8 6)"); BADSMALLCOMPS[0] = necklace_6; Configuration necklace_5 = new Configuration("[3](3 7 5)[3](0 4 2)[3](6 10 8)[3](9 13 11)[3](12 1 14)"); BADSMALLCOMPS[1] = necklace_5; Configuration necklace_4 = new Configuration("[3](1 5 3)[3](4 8 6)[3](7 11 9)[3](10 2 0)"); BADSMALLCOMPS[2] = necklace_4; Configuration twistedneck_4 = new Configuration("[3](5 0 7)[3](2 6 4)[3](3 10 8)[3](9 1 11)"); BADSMALLCOMPS[3] = twistedneck_4; Configuration interleaving_pair = new Configuration("[3](0 4 2)[3](1 5 3)"); BADSMALLCOMPS[4] = interleaving_pair; if ( ! VERIFY(necklace_6,"[3](0_16_2)[3](1_5_3)[3](4_8_6)[3](7_11_9)[3](10_14_12)[3](13_17_15).html") ) System.exit(1); if ( ! VERIFY(necklace_5, "[3](0_4_2)[3](1_14_12)[3](3_7_5)[3](6_10_8)[3](9_13_11).html") ) System.exit(1); if ( ! VERIFY(necklace_4, "[3](0_10_2)[3](1_5_3)[3](4_8_6)[3](7_11_9).html") ) System.exit(1); if ( ! VERIFY(twistedneck_4, "[3](0_7_5)[3](1_11_9)[3](2_6_4)[3](3_10_8).html") ) System.exit(1); if ( ! VERIFY(interleaving_pair, "[3](0_4_2)[3](1_5_3).html") ) System.exit(1); } catch(IOException exc){ exc.printStackTrace(); } System.out.println(); System.out.println("proof verified"); System.out.println("checkedFiles: " + checkedFiles.size()); } // The file names of the files that have been verified // with respect to the configuration inside the file. private static HashSet checkedFiles = new HashSet(); /************************************ * VERIFY FILE * Verify that the file is a correct sorting file * or extension file. */ static int filesVerfied = 0; private static boolean VERIFY(Configuration conf, String fileName) throws IOException{ DEBUG("VERIFYING " + fileName); BufferedReader in = new BufferedReader(new FileReader("comb_files/"+fileName)); //The first three lines of all files are: //
        //

//Configuration numBE = 12 numOCy = 4 hVal = 1251911397 //[3](1 5 3)[3](4 8 6)[3](7 11 9)[3](10 2 0) in.readLine();//skip the header in.readLine();//skip the image line in.readLine();//skip the conf info Configuration readConf = new Configuration(in.readLine()); //check that the read configuration is the same as the one we are verifying if ( !readConf.equals(conf) ){ stackTrace(); printERR("The read configuration is not the same as the one that should be in this file"); printERR("readConf: " + readConf); printERR("inputConf: " + conf); return false; } //If the file already has been check (we can follow a link to this file many times) if ( checkedFiles.contains(fileName) ){ in.close(); return true; } checkedFiles.add(fileName); // There are three types of files and the rest of the lines in the file are as follows: //1. Extension files that look like: // // EXTENSIONS //2. Sorting files that look like: // // SORTING //3. File with subset of components that have >= 8 components look like this: // // SUBSET EXISTS in.readLine(); String l = in.readLine(); boolean correct; if ( l.indexOf("SORTING") != -1 ) correct = verifySortingFile(conf, in,fileName); else if ( l.indexOf("EXTENSIONS") != -1 ) correct = verifyExtensionFile(conf, in, fileName); else if ( l.indexOf("SUBSET") != -1 ) correct = verifySubcompExistsFile(conf,in,fileName); else { stackTrace(); printERR(" unexpected line: " + l ); correct = false; } in.close(); if ( ! correct ){ printERR("There was an error in the file"); printERR(fileName); } else{ filesVerfied++; System.out.print("files verified = " + filesVerfied +"\r"); System.out.flush(); } return correct; } /********************************** * VERIFY SORTING FILE * This method is called from VERIFY() * Some lines have allready been read. * So the file looks like this: * Configuration numBE = 30 numOCy = 10 hVal = 34904901 * [3](24 28 26)[3](27 1 29)[3](0 4 2)[3](3 25 23)[3](18 .... * 0: a = 0 b = 2 c = 5 move_type = 0 * Configuration numBE = 9 numOCy = 3 hVal = 461256 * [3](4 7 2)[3](0 5 3)[3](1 8 6) * 1: a = 2 b = 4 c = 7 move_type = 2 * Configuration numBE = 9 numOCy = 5 hVal = 1617691 * [1](2)[3](0 3 6)[3](1 8 4)[1](7)[1](5) * 2: a = 0 b = 3 c = 6 move_type = 2 * Configuration numBE = 9 numOCy = 7 hVal = 656848 * [1](5)[1](0)[3](4 8 1)[1](7)[1](2)[1](6)[1](3) * 3: a = 1 b = 4 c = 8 move_type = 2 * Configuration numBE = 9 numOCy = 9 hVal = 1888127 * [1](2)[1](0)[1](1)[1](4)[1](6)[1](3)[1](7)[1](8)[1](5) *

*/ private static boolean verifySortingFile(Configuration conf, BufferedReader in, String fileName) throws IOException{ DEBUG("sorting file: " + fileName); //skip until first transposition in.readLine(); in.readLine(); // START VERIFYING THE SORTING Configuration currentConf = new Configuration(conf); int num2moves = 0; int num0moves = 0; while ( true ){ //0: a = 0 b = 2 c = 5 move_type = 0 String transLine = in.readLine(); // the transposition DEBUG(transLine); if ( transLine.indexOf("") != -1 ) break; //if end of the sorting StringTokenizer tok = new StringTokenizer(transLine); tok.nextToken();//skip the index of the sorting tok.nextToken();tok.nextToken();//skip 'a' and skip '=' int a = Integer.parseInt(tok.nextToken()); tok.nextToken();tok.nextToken();//skip 'b' and skip '=' int b = Integer.parseInt(tok.nextToken()); tok.nextToken();tok.nextToken();//skip 'c' and skip '=' int c = Integer.parseInt(tok.nextToken()); tok.nextToken();tok.nextToken();//skip 'move_type' and skip '=' int move_type = Integer.parseInt(tok.nextToken()); // Configuration numBE = 9 numOCy = 3 hVal = 461256 // [3](4 7 2)[3](0 5 3)[3](1 8 6) in.readLine();//skip the info line Configuration nextConf = new Configuration(in.readLine()); //Perform the transposition int oddCyclesBefore = currentConf.getNumOddCycles(); currentConf.transpose(a,b,c); int oddCyclesDiff = currentConf.getNumOddCycles() - oddCyclesBefore; if ( oddCyclesDiff == 2 ) num2moves++; else num0moves++; //CHECK THE TRANSPOSITION // Check that the move_type is correct (we only allow 0 and 2 moves) if ( move_type != oddCyclesDiff || (oddCyclesDiff != 0 && oddCyclesDiff != 2)){ stackTrace(); printERR("Move type not correct"); printERR("transLine = " + transLine); printERR("performed type = " + oddCyclesDiff); printERR("read move_type = " + move_type); return false; } //check that the configuration after the transposition is as stated if ( !currentConf.equals(nextConf) ){ stackTrace(); printERR("The next configuration is not the one after transposition"); printERR("transLine = " + transLine); printERR("nextConf: " + nextConf); printERR("currentConf: " + currentConf); return false; } } //VERIFY THAT THE SORTING IS (11,8) //and that the resulting configuration is simple if ( num0moves == 3 && num2moves == 11 ){ stackTrace(); printERR("Not an (11,8) sequence"); printERR("num0moves = " + num0moves); printERR("num2moves = " + num2moves); return false; } if ( !currentConf.isSimplePermutation() ){ stackTrace(); printERR("Last configuration not simpe"); printERR("last configuration is " + currentConf); return false; } // THE FILE IS A CORRECT SORTING FILE return true; } /*********************************************** * VERIFY EXTENSION FILE * This method verifies an extension file and all linkes from it * in a depth first manner. * * This method is called from VERIFY() so the file looks like this: * * * ----------------------------- * Extensions * pos: 0 * adding comp Unoriented necklace 6 * View extension =8 cycles if so it is true for ( int comp = 0 ; comp <= components.length ; comp++ ){ int numCyclesInComp = components[comp].length/3; if ( numCycles - numCyclesInComp >= 8 ) return true; } stackTrace(); printERR("There is not a subset of components that has >=8 cycles"); return false; } }