- // no more bucket
- // backtrack
- root = tmp.root;
- index = tmp.index;
- int t = this.combine.elementAt(next).size() - 2;
- while(true) {
- while(!(t < 0)) {
- tmp = this.combine.elementAt(next).elementAt(t);
- if ((tmp.root != root) || (tmp.index != index)) {
- break;
- }
- t--;
- }
- if(t < 0) {
- // try the bucket in node2combine before
- if(next - 1 < 0) {
- return false;
- } else {
- return innertrial(next - 1, ++layer);
- }
- } else if(tmp.root != root) {
- if((tmp.root == this.lastchoices[next]) &&
- (this.rootNStates.elementAt(this.lastchoices[next]).elementAt(0)[next] == 1)) {
- // only 1 obj left in the chosen bucket
- // can not move this one
- // try the bucket in node2combine before
- if(next - 1 < 0) {
- return false;
- } else {
- return innertrial(next - 1, ++layer);
- }
- }
- this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]--;
- //tmp.root = root;
- int newroot = tmp.root + 1;
- tmp.root = newroot;
- tmp.index = 0;
- this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]++;
- // make all left things in this color bucket reset
- for(t++; t < this.combine.elementAt(next).size(); t++) {
- tmp = this.combine.elementAt(next).elementAt(t);
- this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]--;
- tmp.root = newroot;
- tmp.index = 0;
- this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]++;
- }
- if(layer != 0) {
- return firstexpand(next+1, this.first4choice);
- }
- return true;
- } else if(tmp.index != index) {
- if(this.rootNStates.elementAt(root).elementAt(tmp.index)[next] ==
- this.rootNStates.elementAt(root).elementAt(index)[next]) {
- // break the law of non-increase order inside one color bucket
- // go on search forward
- index = tmp.index;
- } else if(this.rootNStates.elementAt(root).elementAt(tmp.index)[next] <
- this.rootNStates.elementAt(root).elementAt(index)[next] + 2) {
- // break the law of non-increase order inside one color bucket
- // and now they only differ by 1
- // propagate this difference to see if it can fix
- boolean suc = propagateOne(next, root, index, t, tmp);
- if(suc) {
- return suc;
- } else {
- // go on search forward
- index = tmp.index;
- }
- } else {
- this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]--;
- int tmproot = tmp.root;
- int tmpindex = tmp.index;
- tmp.root = root;
- tmp.index = index;
- this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]++;
- int desroot = tmp.root;
- int desindex = tmp.index;
- // make all left things in this color bucket reset
- t++;
- boolean first = true;
- while(t < this.combine.elementAt(next).size()) {
- int k = 0;
- if(first) {
- k = 1;
- first = false;
- }
- for(; (k < this.rootNStates.elementAt(tmproot).elementAt(tmpindex)[next]) && (t < this.combine.elementAt(next).size()); t++) {
- tmp = this.combine.elementAt(next).elementAt(t);
- this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]--;
- tmp.root = desroot;
- tmp.index = desindex;
- this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]++;
- }
- if(k == this.rootNStates.elementAt(tmproot).elementAt(tmpindex)[next]) {
- desindex++;
- }
- }
- if(layer != 0) {
- return firstexpand(next+1, this.first4choice);
- }
- return true;
- }
- }
- }
+ // no more bucket
+ // backtrack
+ root = tmp.root;
+ index = tmp.index;
+ int t = this.combine.elementAt(next).size() - 2;
+ while(true) {
+ while(!(t < 0)) {
+ tmp = this.combine.elementAt(next).elementAt(t);
+ if ((tmp.root != root) || (tmp.index != index)) {
+ break;
+ }
+ t--;
+ }
+ if(t < 0) {
+ // try the bucket in node2combine before
+ if(next - 1 < 0) {
+ return false;
+ } else {
+ return innertrial(next - 1, ++layer);
+ }
+ } else if(tmp.root != root) {
+ if((tmp.root == this.lastchoices[next]) &&
+ (this.rootNStates.elementAt(this.lastchoices[next]).elementAt(0)[next] == 1)) {
+ // only 1 obj left in the chosen bucket
+ // can not move this one
+ // try the bucket in node2combine before
+ if(next - 1 < 0) {
+ return false;
+ } else {
+ return innertrial(next - 1, ++layer);
+ }
+ }
+ this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]--;
+ //tmp.root = root;
+ int newroot = tmp.root + 1;
+ tmp.root = newroot;
+ tmp.index = 0;
+ this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]++;
+ // make all left things in this color bucket reset
+ for(t++; t < this.combine.elementAt(next).size(); t++) {
+ tmp = this.combine.elementAt(next).elementAt(t);
+ this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]--;
+ tmp.root = newroot;
+ tmp.index = 0;
+ this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]++;
+ }
+ if(layer != 0) {
+ return firstexpand(next+1, this.first4choice);
+ }
+ return true;
+ } else if(tmp.index != index) {
+ if(this.rootNStates.elementAt(root).elementAt(tmp.index)[next] ==
+ this.rootNStates.elementAt(root).elementAt(index)[next]) {
+ // break the law of non-increase order inside one color bucket
+ // go on search forward
+ index = tmp.index;
+ } else if(this.rootNStates.elementAt(root).elementAt(tmp.index)[next] <
+ this.rootNStates.elementAt(root).elementAt(index)[next] + 2) {
+ // break the law of non-increase order inside one color bucket
+ // and now they only differ by 1
+ // propagate this difference to see if it can fix
+ boolean suc = propagateOne(next, root, index, t, tmp);
+ if(suc) {
+ return suc;
+ } else {
+ // go on search forward
+ index = tmp.index;
+ }
+ } else {
+ this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]--;
+ int tmproot = tmp.root;
+ int tmpindex = tmp.index;
+ tmp.root = root;
+ tmp.index = index;
+ this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]++;
+ int desroot = tmp.root;
+ int desindex = tmp.index;
+ // make all left things in this color bucket reset
+ t++;
+ boolean first = true;
+ while(t < this.combine.elementAt(next).size()) {
+ int k = 0;
+ if(first) {
+ k = 1;
+ first = false;
+ }
+ for(; (k < this.rootNStates.elementAt(tmproot).elementAt(tmpindex)[next]) && (t < this.combine.elementAt(next).size()); t++) {
+ tmp = this.combine.elementAt(next).elementAt(t);
+ this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]--;
+ tmp.root = desroot;
+ tmp.index = desindex;
+ this.rootNStates.elementAt(tmp.root).elementAt(tmp.index)[next]++;
+ }
+ if(k == this.rootNStates.elementAt(tmproot).elementAt(tmpindex)[next]) {
+ desindex++;
+ }
+ }
+ if(layer != 0) {
+ return firstexpand(next+1, this.first4choice);
+ }
+ return true;
+ }
+ }
+ }