public int MatchPair(Pair pPair) { int len; int num0=this.num0; //throw new NotImplementedException(); // update the string in config if (Convert.ToBoolean(this.up)) // up is longer { if (this.len >= pPair.downlen) // down string will be all matched { // cut those matched to down string this.ConfigMove(pPair.downlen); // add the up string to the config this.ConfigAppend(pPair.up, pPair.uplen); } else // all letters in the config are matched { len = pPair.downlen - this.len; // length of left unmatched dwnn string if (pPair.uplen>len) // up is longer this.ConfigAssign(pPair.up.Substring(len), pPair.uplen-len, 1); else // down is longer, should change the direction of config this.ConfigAssign(pPair.down.Substring(pPair.uplen+this.len), len-pPair.uplen, 0); } } else { if (this.len >= pPair.uplen) // up string will be all matched { // cut those matched to down string this.ConfigMove(pPair.uplen); // add the up string to the config this.ConfigAppend(pPair.down, pPair.downlen); } else // config will be all matched { len = pPair.uplen - this.len; // length of left unmatched dwnn string if (pPair.downlen>len) // down is longer this.ConfigAssign(pPair.down.Substring(len),pPair.downlen-len,0); else // up is longer, should change the direction of config this.ConfigAssign(pPair.up.Substring(len), len-pPair.downlen, 1); } } this.num0 = num0+pPair.diff0; // update depth, selection, and number of visited node this.depth++; PCPSolver.arrSelection[this.depth]=pPair.ID; Add_visited_node_number(); return 1; }
//DominoScene dominoScene; public Game1() { graphics = new GraphicsDeviceManager(this); this.IsMouseVisible = true; Content.RootDirectory = "Content"; //dominoScene = new DominoScene(); Console.WriteLine("PCPSolver:\n Team Members:\n Chris Dillard\n John Futch"); // SIMPLE SOLVABLE INSTANCE // //3 2 //0 01 110 //100 00 11 // // PCPInstance instance = new PCPInstance(); /* Pair p = new Pair(); p.up= "0"; p.down = "100"; Pair p2 = new Pair(); p2.up= "01"; p2.down = "00"; Pair p3 = new Pair(); p3.up = "110"; p3.down = "11"; instance.arrPair = new Pair[3] { p, p2, p3 }; */ Pair p = new Pair(); p.up = "100"; p.down = "1"; Pair p2 = new Pair(); p2.up = "0"; p2.down = "100"; Pair p3 = new Pair(); p3.up = "1"; p3.down = "00"; instance.arrPair = new Pair[3] { p, p2, p3 }; instance.Print(); PCPSolver.SolvePCPInstance(instance, 1); }
// check the configuration can be matched with the pair // output: // -1: cannot be matched // 0: solved // n: n number left in the configuration public int TestMatchingPair(Pair pair) { String str; int len; int configlength; if (Convert.ToBoolean(this.up)) // up is longer { if (this.len >= pair.downlen) { if (Convert.ToBoolean(this.ConfigCmp(pair.down, pair.downlen))) return -1; } else { if (Convert.ToBoolean(this.ConfigCmp(pair.down, this.len))) return -1; str = pair.down.Substring(this.len); len = pair.downlen - this.len; if (len > pair.uplen) len = pair.uplen; if (str==pair.up) return -1; } configlength = this.len + pair.uplen - pair.downlen; } else { if (this.len >= pair.uplen) { if (Convert.ToBoolean(this.ConfigCmp(pair.up, pair.uplen))) return -1; } else { if (Convert.ToBoolean(this.ConfigCmp(pair.up, this.len))) return -1; str = pair.up + this.len; len = pair.uplen - this.len; if (len > pair.downlen) len = pair.downlen; if (str==pair.down) return -1; } configlength = this.len + pair.downlen - pair.uplen; } return Math.Abs(configlength); }